import globalJSON from '../../../../global/affinity.json'; /** * Precomputed character pair and trio affinity. */ export interface Affinity { /** * First character in the relation. */ chara_a: number; /** * Second character in the relation. * chara_a < chara_b is an invariant. */ chara_b: number; /** * Third character in the relation, if it is a trio relation. * If defined, chara_b < chara_c is an invariant. */ chara_c?: number; /** * Total base compatibility between characters in the relation. */ affinity: number; } export const affinity = { global: globalJSON as Affinity[], } as const; export function lookup(aff: Affinity[], chara_a: number, chara_b: number, chara_c?: number): number { const [a, b, c] = [chara_a, chara_b, chara_c ?? Infinity].sort((a, b) => a - b); const r = aff.find((v) => v.chara_a === a && v.chara_b === b && (v.chara_c ?? Infinity) === c); return r?.affinity ?? 0; }