/**
* Writes src/view/widgets/pieces.slint: one `Pieces` global with an image property per entry of
* assets/game/pieces/1/index.json (nine-slice borders included, because Slint needs them as literals).
* Run after `bun tools/pieces.ts --scale 1`
*/
import { readFileSync, writeFileSync } from 'node:fs'
import type { PiecesIndex } from '../../tools/pieces'
const dir = process.argv[2] ?? 'assets/game/pieces/1'
const index = JSON.parse(readFileSync(`${dir}/index.json`, 'utf8')) as PiecesIndex
const lines = [
'// Generated by bench/slint/gen-pieces.ts from assets/game/pieces/1/index.json (game 2.0.77). Do not edit.',
'// Every graphical set the Mods window uses, cut from gui-new.png at 1x; borders are in screen px.',
'export global Pieces {',
]
for (const [key, p] of Object.entries(index.pieces)) {
const slice = p.nineSlice.some(Boolean) ? `, nine-slice(${p.nineSlice.join(' ')})` : ''
lines.push(` out property <image> ${key.replaceAll('_', '-')}: @image-url("../../../${dir}/${p.file}"${slice});`)
}
lines.push('}', '')
writeFileSync('src/view/widgets/pieces.slint', lines.join('\n'))
console.log(`pieces.slint: ${Object.keys(index.pieces).length} images (game ${index.gameVersion})`)