diff --git a/scripts/wire-images.js b/scripts/wire-images.js new file mode 100644 index 0000000..7bdf274 --- /dev/null +++ b/scripts/wire-images.js @@ -0,0 +1,117 @@ +#!/usr/bin/env bun + +import { existsSync, readFileSync, writeFileSync } from "node:fs"; + +const MANIFEST_PATH = "assets/images/board_game/image_manifest.json"; +const BASE_PATH = "assets/images/board_game/"; + +const manifest = JSON.parse(readFileSync(MANIFEST_PATH, "utf8")); + +// build lookup tables: +// baseById: id -> first non-upgraded path (for base cards, relics, potions, enemies) +// upgradedById: id -> first upgraded path (for + cards) +const baseById = {}; +const upgradedById = {}; + +for (const [key, id] of Object.entries(manifest)) { + const fullPath = `assets/images/board_game/${key}`; + if (!existsSync(fullPath)) continue; + const path = BASE_PATH + key; + const isUpgraded = key.includes("_upgraded/"); + + if (isUpgraded) { + if (!upgradedById[id]) upgradedById[id] = path; + } else { + if (!baseById[id]) baseById[id] = path; + } +} + +// --- cards.json --- +const cardsRaw = readFileSync("data/cards.json", "utf8"); +const cards = JSON.parse(cardsRaw); + +let cardsUpdated = 0; +let cardsSkipped = 0; + +for (const [cardId, card] of Object.entries(cards)) { + const isUpgraded = cardId.endsWith("+"); + const baseId = isUpgraded ? cardId.slice(0, -1) : cardId; + const lookup = isUpgraded ? upgradedById : baseById; + const match = lookup[baseId]; + + if (match) { + card.image = match; + cardsUpdated++; + } else { + cardsSkipped++; + } +} + +writeFileSync("data/cards.json", `${JSON.stringify(cards, null, 2)}\n`); +console.debug(`cards.json: ${cardsUpdated} updated, ${cardsSkipped} no match`); + +// --- relics.json --- +const relicsRaw = readFileSync("data/relics.json", "utf8"); +const relics = JSON.parse(relicsRaw); + +let relicsUpdated = 0; +let relicsSkipped = 0; + +for (const relic of relics) { + const match = baseById[relic.id]; + if (match) { + relic.image = match; + relicsUpdated++; + } else { + relicsSkipped++; + } +} + +writeFileSync("data/relics.json", `${JSON.stringify(relics, null, 2)}\n`); +console.debug( + `relics.json: ${relicsUpdated} updated, ${relicsSkipped} no match`, +); + +// --- potions.json --- +const potionsRaw = readFileSync("data/potions.json", "utf8"); +const potions = JSON.parse(potionsRaw); + +let potionsUpdated = 0; +let potionsSkipped = 0; + +for (const potion of potions) { + const match = baseById[potion.id]; + if (match) { + potion.image = match; + potionsUpdated++; + } else { + potionsSkipped++; + } +} + +writeFileSync("data/potions.json", `${JSON.stringify(potions, null, 2)}\n`); +console.debug( + `potions.json: ${potionsUpdated} updated, ${potionsSkipped} no match`, +); + +// --- enemies.json --- +const enemiesRaw = readFileSync("data/enemies.json", "utf8"); +const enemies = JSON.parse(enemiesRaw); + +let enemiesUpdated = 0; +let enemiesSkipped = 0; + +for (const [enemyId, enemy] of Object.entries(enemies)) { + const match = baseById[enemyId]; + if (match) { + enemy.image = match; + enemiesUpdated++; + } else { + enemiesSkipped++; + } +} + +writeFileSync("data/enemies.json", `${JSON.stringify(enemies, null, 2)}\n`); +console.debug( + `enemies.json: ${enemiesUpdated} updated, ${enemiesSkipped} no match`, +);