/**
* Builds 100% GUI icons in assets/game/icons1x/. Uses extracted assets and reads authored icon mips from the install.
* Non-mip assets use the same truncating box filter as tools/pieces.ts.
* bun bench/slint/make-icons.ts
*/
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { crop, decodePng, encodePng } from '../../tools/bench/png'
import path from 'node:path'
import { styleInstall } from '../../tools/dump-styles'
import { boxResize } from '../../tools/style-slices'
const HALVE = [
['sprites/search_icon', 'search'], ['sprites/refresh', 'refresh'], ['sprites/trash', 'trash'],
['sprites/dropdown', 'dropdown'], ['sprites/warning_white', 'warning'],
['sprites/table-sort-arrow-down-active', 'sort-down-active'], ['sprites/table-sort-arrow-down-white', 'sort-down-white'], ['sprites/table-sort-arrow-down-hover', 'sort-down-hover'],
['sprites/table-sort-arrow-up-active', 'sort-up-active'], ['sprites/table-sort-arrow-up-white', 'sort-up-white'], ['sprites/table-sort-arrow-up-hover', 'sort-up-hover'],
['icons/mod-manager/ban', 'ban'], ['icons/mod-manager/ban-hovered', 'ban-hovered'], ['icons/mod-manager/ban-clicked', 'ban-clicked'], ['icons/mod-manager/ban-selected', 'ban-selected'],
] as const
const KEEP = [['sprites/mod_dependency_arrow', 'dependency-arrow'], ['missing-thumbnail', 'missing-thumbnail']] as const
const dir = 'assets/game/icons1x'
mkdirSync(dir, { recursive: true })
for (const [src, name] of HALVE) {
const img = decodePng(readFileSync(`assets/game/${src}.png`))
writeFileSync(`${dir}/${name}.png`, encodePng(boxResize(img, img.width / 2, img.height / 2)))
}
// GUI mip files carry an authored 16px image after the 32px source. The game
// selects that mip at 100%; filtering the 32px source loses the icon's details.
for (const [file, name] of [['search','search'],['refresh','refresh'],['trash','trash'],['dropdown','dropdown'],['warning-white','warning'],['downloading','download']]) {
const image = decodePng(readFileSync(path.join(styleInstall(), 'data/core/graphics/icons/mip', file + '.png')))
writeFileSync(`${dir}/${name}.png`, encodePng(crop(image, 32, 0, 16, 16)))
}
const spaceAge = decodePng(readFileSync('assets/game/sprites/space-age.png'))
writeFileSync(`${dir}/space-age.png`, encodePng(boxResize(spaceAge, 20, 20)))
for (const [src, name] of KEEP) writeFileSync(`${dir}/${name}.png`, readFileSync(`assets/game/${src}.png`))
const dependency = decodePng(readFileSync(path.join(styleInstall(), 'data/core/graphics/icons/mip/go-to-minibutton-arrow.png')))
writeFileSync(`${dir}/dependency-arrow.png`, encodePng(crop(dependency, 16, 0, 8, 8)))
console.log(`icons1x: ${HALVE.length + KEEP.length + 1} files`)
// A crisp 16px external-link glyph; tool-button colours and size match the authored game icons.
const openBrowser = { width: 16, height: 16, data: new Uint8Array(16 * 16 * 4) }
for (let y = 0; y < 16; y++) for (let x = 0; x < 16; x++) {
const box = ((x === 2 || x === 3) && y >= 6 && y <= 13) || ((y === 12 || y === 13) && x >= 2 && x <= 10) || ((x === 9 || x === 10) && y >= 9 && y <= 13) || ((y === 5 || y === 6) && x >= 2 && x <= 6)
const arrow = ((y === 2 || y === 3) && x >= 8 && x <= 13) || ((x === 12 || x === 13) && y >= 2 && y <= 7) || (x + y >= 14 && x + y <= 16 && x >= 6 && x <= 12 && y >= 3 && y <= 9)
if (box || arrow) openBrowser.data.set([0, 0, 0, 255], (y * 16 + x) * 4)
}
writeFileSync(`${dir}/open-browser.png`, encodePng(openBrowser))
// utility-sprites.lua `close`: 32px source, rendered at the title-bar icon size.
const close = decodePng(readFileSync(path.join(styleInstall(), 'data/core/graphics/icons/close.png')))
writeFileSync(`${dir}/close.png`, encodePng(boxResize(close, 16, 16)))