[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:
2026-11-17 22:52:35 -05:00
co-authored by Claude Opus 5.5
parent 57d2fc2fc7
commit ae14bc7b89
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -38,8 +38,8 @@ export interface ConnectKeys {
links: number[]; links: number[];
/** P31 Q-ids, excluding human and taxon (the Kin tier). */ /** P31 Q-ids, excluding human and taxon (the Kin tier). */
p31: string[]; p31: string[];
/** This card's Wikidata item, and the item Q-ids its claims cite (Linked tier). */ /** This card's Wikidata item (omitted when it has none), and the item Q-ids its claims cite (Linked tier). */
qid: string | null; qid?: string;
cites: string[]; cites: string[];
} }
@@ -177,7 +177,7 @@ export function connectKeysFor(title: string, profile: CardProfile): ConnectKeys
centuries: [...centuries].sort((a, b) => a - b), centuries: [...centuries].sort((a, b) => a - b),
links: [...new Set(profile.links ?? [])].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(), 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(), 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)); const meets = (x: readonly (string | number)[], y: readonly (string | number)[]) => x.some(v => y.includes(v));
for (const tier of tiers) { for (const tier of tiers) {
if (tier === 'Linked' && (a.connect.links.includes(b.pageId) || b.connect.links.includes(a.pageId) 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)) || (b.connect.qid !== undefined && a.connect.cites.includes(b.connect.qid))
|| (a.connect.qid !== null && b.connect.cites.includes(a.connect.qid)))) return tier; || (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 === '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 === '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; if (tier === 'Kin' && meets(a.connect.p31, b.connect.p31)) return tier;
+2 -2
View File
@@ -71,7 +71,7 @@ test('costs, bodies and keyword caps stay in range', () => {
if (c.type === 'Figure') { if (c.type === 'Figure') {
assert.ok(c.cost >= 1 && c.cost <= 6, c.title); assert.ok(c.cost >= 1 && c.cost <= 6, c.title);
const taxed = c.keywords.filter(k => DERIVE_RULES.taxedKeywords.includes(k)).length; 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.equal(c.power! + c.toughness!, DERIVE_RULES.bodyBudget[c.cost] - taxed, c.title);
assert.ok(c.power! >= 1 && c.toughness! >= 1, c.title); assert.ok(c.power! >= 1 && c.toughness! >= 1, c.title);
} else if (c.type === 'Location') { } 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', () => { 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 => 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'); 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('g', 7, { cites: ['Q100'] })), 'Linked');
assert.equal(connectedTier(a, base('h', 8, { centuries: [20] }, 'Figure')), null, 'Contemporary needs different types'); assert.equal(connectedTier(a, base('h', 8, { centuries: [20] }, 'Figure')), null, 'Contemporary needs different types');