From ae14bc7b891639d9c0a4db4dadcbfe33cb9ff831 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:52:35 -0500 Subject: [PATCH] [duel-cards] connect.qid is optional (omitted without a Wikidata item), matching #72's ConnectKeys Co-Authored-By: Claude Opus 5.5 --- shared/duel/derive.ts | 10 +++++----- tests/duel-cards-derive.test.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shared/duel/derive.ts b/shared/duel/derive.ts index f6b180a..85956f1 100644 --- a/shared/duel/derive.ts +++ b/shared/duel/derive.ts @@ -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; diff --git a/tests/duel-cards-derive.test.ts b/tests/duel-cards-derive.test.ts index 5f522ec..473ebbb 100644 --- a/tests/duel-cards-derive.test.ts +++ b/tests/duel-cards-derive.test.ts @@ -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, 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');