[duel-cards] connect.qid is optional (omitted without a Wikidata item), matching #72's ConnectKeys
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,8 +38,8 @@ export interface ConnectKeys {
|
||||
links: number[];
|
||||
/** P31 Q-ids, excluding human and taxon (the Kin tier). */
|
||||
p31: string[];
|
||||
/** This card's Wikidata item, and the item Q-ids its claims cite (Linked tier). */
|
||||
qid: string | null;
|
||||
/** This card's Wikidata item (omitted when it has none), and the item Q-ids its claims cite (Linked tier). */
|
||||
qid?: string;
|
||||
cites: string[];
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ export function connectKeysFor(title: string, profile: CardProfile): ConnectKeys
|
||||
centuries: [...centuries].sort((a, b) => a - b),
|
||||
links: [...new Set(profile.links ?? [])].sort((a, b) => a - b),
|
||||
p31: [...new Set(profile.instanceOf.map(c => c.id).filter(id => id !== 'Q5' && id !== 'Q16521'))].sort(),
|
||||
qid: profile.wikidataId,
|
||||
...(profile.wikidataId ? { qid: profile.wikidataId } : {}),
|
||||
cites: [...new Set(profile.cites ?? [])].sort(),
|
||||
};
|
||||
}
|
||||
@@ -310,8 +310,8 @@ export function connectedTier(a: DuelCard, b: DuelCard,
|
||||
const meets = (x: readonly (string | number)[], y: readonly (string | number)[]) => x.some(v => y.includes(v));
|
||||
for (const tier of tiers) {
|
||||
if (tier === 'Linked' && (a.connect.links.includes(b.pageId) || b.connect.links.includes(a.pageId)
|
||||
|| (b.connect.qid !== null && a.connect.cites.includes(b.connect.qid))
|
||||
|| (a.connect.qid !== null && b.connect.cites.includes(a.connect.qid)))) return tier;
|
||||
|| (b.connect.qid !== undefined && a.connect.cites.includes(b.connect.qid))
|
||||
|| (a.connect.qid !== undefined && b.connect.cites.includes(a.connect.qid)))) return tier;
|
||||
if (tier === 'Compatriot' && meets(a.connect.countries, b.connect.countries)) return tier;
|
||||
if (tier === 'Contemporary' && a.type !== b.type && meets(a.connect.centuries, b.connect.centuries)) return tier;
|
||||
if (tier === 'Kin' && meets(a.connect.p31, b.connect.p31)) return tier;
|
||||
|
||||
@@ -71,7 +71,7 @@ test('costs, bodies and keyword caps stay in range', () => {
|
||||
if (c.type === 'Figure') {
|
||||
assert.ok(c.cost >= 1 && c.cost <= 6, c.title);
|
||||
const taxed = c.keywords.filter(k => DERIVE_RULES.taxedKeywords.includes(k)).length;
|
||||
assert.ok(c.connect.qid === null || /^Q\d+$/.test(c.connect.qid));
|
||||
assert.ok(c.connect.qid === undefined || /^Q\d+$/.test(c.connect.qid));
|
||||
assert.equal(c.power! + c.toughness!, DERIVE_RULES.bodyBudget[c.cost] - taxed, c.title);
|
||||
assert.ok(c.power! >= 1 && c.toughness! >= 1, c.title);
|
||||
} else if (c.type === 'Location') {
|
||||
@@ -181,7 +181,7 @@ test('Portals: keyword hits decide, ties go to the type default, no hits is Neut
|
||||
|
||||
test('Connected: Linked beats Compatriot beats Contemporary beats Kin; a card is never connected to itself', () => {
|
||||
const base = (id: string, pageId: number, connect: Partial<DuelCard['connect']>, type: DuelCard['type'] = 'Event'): DuelCard =>
|
||||
({ ...byTitle('Tom Ewell'), cardId: id, pageId, type, connect: { countries: [], centuries: [], links: [], p31: [], qid: null, cites: [], ...connect } });
|
||||
({ ...byTitle('Tom Ewell'), cardId: id, pageId, type, connect: { countries: [], centuries: [], links: [], p31: [], cites: [], ...connect } });
|
||||
const a = base('a', 1, { links: [2], countries: ['France'], centuries: [20], p31: ['Q1'], qid: 'Q100' }, 'Figure');
|
||||
assert.equal(connectedTier(a, base('g', 7, { cites: ['Q100'] })), 'Linked');
|
||||
assert.equal(connectedTier(a, base('h', 8, { centuries: [20] }, 'Figure')), null, 'Contemporary needs different types');
|
||||
|
||||
Reference in New Issue
Block a user