feat: refine builder skill chip flows
This commit is contained in:
@@ -3,7 +3,11 @@ import { spawnSync } from 'node:child_process';
|
||||
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { basename, join, resolve } from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { ISAC_DATA_TABLES, quoteIdentifier } from './isac-data-tables.mjs';
|
||||
import {
|
||||
ISAC_DATA_FORMAT_VERSION,
|
||||
ISAC_DATA_TABLES,
|
||||
quoteIdentifier,
|
||||
} from './isac-data-tables.mjs';
|
||||
|
||||
const snapshotArgument = process.argv
|
||||
.slice(2)
|
||||
@@ -22,7 +26,7 @@ const snapshotPath = resolve(snapshotArgument);
|
||||
const snapshot = JSON.parse(await readFile(snapshotPath, 'utf8'));
|
||||
if (
|
||||
snapshot?.format !== 'shd-build-isac-data' ||
|
||||
snapshot?.version !== 4 ||
|
||||
snapshot?.version !== ISAC_DATA_FORMAT_VERSION ||
|
||||
!Array.isArray(snapshot.tables) ||
|
||||
!Array.isArray(snapshot.icons)
|
||||
) {
|
||||
@@ -39,6 +43,87 @@ if (
|
||||
'The ISAC snapshot table manifest is incomplete or out of order.',
|
||||
);
|
||||
}
|
||||
const abilityRows = snapshot.tables.find(
|
||||
(table) => table.name === 'specialization_abilities',
|
||||
).rows;
|
||||
const abilitiesById = new Map(
|
||||
abilityRows.map((row) => [String(row.id ?? ''), row]),
|
||||
);
|
||||
const skillChipRows = snapshot.tables.find(
|
||||
(table) => table.name === 'skill_chip_sets',
|
||||
).rows;
|
||||
const activeSkillChipCounts = new Map();
|
||||
for (const row of skillChipRows) {
|
||||
const abilityId = String(row.specialization_ability_id ?? '');
|
||||
if (!abilityId || !abilitiesById.has(abilityId)) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a Skill Chip definition with a missing ability reference "${abilityId}".`,
|
||||
);
|
||||
}
|
||||
if (Number(row.active) !== 1) continue;
|
||||
const count = (activeSkillChipCounts.get(abilityId) ?? 0) + 1;
|
||||
if (count > 3) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot assigns more than three active Skill Chip definitions to ability "${abilityId}".`,
|
||||
);
|
||||
}
|
||||
activeSkillChipCounts.set(abilityId, count);
|
||||
}
|
||||
const skillChipLinks = snapshot.tables.find(
|
||||
(table) => table.name === 'specialization_ability_skill_chip_links',
|
||||
).rows;
|
||||
const linkedAbilityIds = new Set();
|
||||
for (const row of skillChipLinks) {
|
||||
const abilityId = row.ability_id;
|
||||
const compatibleAbilityId = row.compatible_ability_id;
|
||||
if (
|
||||
typeof abilityId !== 'string' ||
|
||||
!abilityId ||
|
||||
typeof compatibleAbilityId !== 'string' ||
|
||||
!compatibleAbilityId
|
||||
) {
|
||||
throw new Error(
|
||||
'The ISAC snapshot contains a Skill Chip sharing link with malformed ability references.',
|
||||
);
|
||||
}
|
||||
if (abilityId === compatibleAbilityId) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a self-referencing Skill Chip sharing link for ability "${abilityId}".`,
|
||||
);
|
||||
}
|
||||
if (abilityId >= compatibleAbilityId) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a Skill Chip sharing link that is not in canonical ability order: "${abilityId}", "${compatibleAbilityId}".`,
|
||||
);
|
||||
}
|
||||
const ability = abilitiesById.get(abilityId);
|
||||
const compatibleAbility = abilitiesById.get(compatibleAbilityId);
|
||||
if (!ability || !compatibleAbility) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a Skill Chip sharing link with a missing ability reference: "${abilityId}", "${compatibleAbilityId}".`,
|
||||
);
|
||||
}
|
||||
if (Number(ability.active) !== 1 || Number(compatibleAbility.active) !== 1) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a Skill Chip sharing link with an inactive ability: "${abilityId}", "${compatibleAbilityId}".`,
|
||||
);
|
||||
}
|
||||
if (ability.specialization_id !== compatibleAbility.specialization_id) {
|
||||
throw new Error(
|
||||
`The ISAC snapshot contains a cross-specialization Skill Chip sharing link: "${abilityId}", "${compatibleAbilityId}".`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
linkedAbilityIds.has(abilityId) ||
|
||||
linkedAbilityIds.has(compatibleAbilityId)
|
||||
) {
|
||||
throw new Error(
|
||||
'The ISAC snapshot contains more than one Skill Chip sharing link touching an ability.',
|
||||
);
|
||||
}
|
||||
linkedAbilityIds.add(abilityId);
|
||||
linkedAbilityIds.add(compatibleAbilityId);
|
||||
}
|
||||
for (const kind of ['weapon', 'gear']) {
|
||||
const options = snapshot.tables.find(
|
||||
(table) => table.name === `${kind}_mod_secondary_options`,
|
||||
|
||||
Reference in New Issue
Block a user