| 1 | #!/usr/bin/env node |
| 2 | /** |
| 3 | * Magenta placeholder projectile art: one PNG per spell under |
| 4 | * client/assets/fx/projectile/spell-<element>-<tier>-<spellId>.png |
| 5 | * |
| 6 | * Canvas is 16×16. Facing: the RIGHT side (+X) is the front/tip — the same |
| 7 | * convention as arrow.png. Runtime rotates with atan2(dy, dx) so 0° = flying east. |
| 8 | * |
| 9 | * Magenta (R≈B, G < R) is recolored at runtime via spellProjectileTint(element). |
| 10 | * Replace any file with hand-drawn art; keep magenta for tintable regions. |
| 11 | * |
| 12 | * node client/scripts/write-spell-projectile-template.mjs |
| 13 | */ |
| 14 | import { unlinkSync, readdirSync } from "node:fs"; |
| 15 | import { join, dirname } from "node:path"; |
| 16 | import { fileURLToPath } from "node:url"; |
| 17 | import { writeRgbaPng, makeRgba, fillRect } from "../../server/src/assets/placeholderPng.js"; |
| 18 | import { SPELL_DEFINITIONS, spellProjectileStem } from "../../shared/definitions/spells.js"; |
| 19 | |
| 20 | const SIZE = 16; |
| 21 | /** Offset so the original 8×8 diamond sits centred on the 16×16 canvas. */ |
| 22 | const OX = 4; |
| 23 | const OY = 4; |
| 24 | const OUT_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "assets", "fx", "projectile"); |
| 25 | |
| 26 | /** Pure magenta mask + a lighter magenta highlight (G channel → white at runtime). */ |
| 27 | const MAGENTA = [220, 0, 220, 255]; |
| 28 | const MAGENTA_HI = [255, 120, 255, 255]; |
| 29 | |
| 30 | const keep = new Set(["arrow.png", "arrow-tipped.png"]); |
| 31 | const wanted = new Set(); |
| 32 | |
| 33 | let wrote = 0; |
| 34 | for (const def of Object.values(SPELL_DEFINITIONS)) |
| 35 | { |
| 36 | const stem = spellProjectileStem(def.element, def.tier, def.spellId); |
| 37 | wanted.add(`${stem}.png`); |
| 38 | const file = join(OUT_DIR, `${stem}.png`); |
| 39 | const image = makeRgba(SIZE, SIZE, [0, 0, 0, 0]); |
| 40 | fillRect(image, OX + 3, OY + 1, 2, 1, MAGENTA); |
| 41 | fillRect(image, OX + 2, OY + 2, 4, 1, MAGENTA); |
| 42 | fillRect(image, OX + 1, OY + 3, 6, 2, MAGENTA); |
| 43 | fillRect(image, OX + 2, OY + 5, 4, 1, MAGENTA); |
| 44 | fillRect(image, OX + 3, OY + 6, 2, 1, MAGENTA); |
| 45 | fillRect(image, OX + 3, OY + 3, 2, 2, MAGENTA_HI); |
| 46 | writeRgbaPng(file, SIZE, SIZE, image.pixels); |
| 47 | wrote += 1; |
| 48 | } |
| 49 | |
| 50 | for (const name of readdirSync(OUT_DIR)) |
| 51 | { |
| 52 | if (!name.startsWith("spell-") || !name.endsWith(".png")) |
| 53 | { continue; } |
| 54 | if (wanted.has(name) || keep.has(name)) |
| 55 | { continue; } |
| 56 | unlinkSync(join(OUT_DIR, name)); |
| 57 | console.log(`Removed obsolete ${name}`); |
| 58 | } |
| 59 | |
| 60 | console.log(`Wrote ${wrote} magenta spell projectile placeholders (${SIZE}×${SIZE}) in ${OUT_DIR}`); |