BlueGit

timfa questward

Files

questward / client / scripts / write-placeholder-assets.mjs

write-placeholder-assets.mjs

write-placeholder-assets.mjs 3.8 KiB Download Raw
1import { join } from "node:path";
2import { fillRect, makeRgba, writeRgbaPng } from "../../server/src/assets/placeholderPng.js";
3
4const root = join(import.meta.dirname, "..", "assets");
5
6function solid (file, color, border = [20, 20, 24, 255])
7{
8 const image = makeRgba(16, 16, color);
9 fillRect(image, 0, 0, 16, 1, border);
10 fillRect(image, 0, 15, 16, 1, border);
11 fillRect(image, 0, 0, 1, 16, border);
12 fillRect(image, 15, 0, 1, 16, border);
13 writeRgbaPng(file, 16, 16, image.pixels);
14}
15
16function overlay (file, color)
17{
18 const image = makeRgba(16, 16, [0, 0, 0, 0]);
19 fillRect(image, 4, 3, 8, 11, color);
20 writeRgbaPng(file, 16, 16, image.pixels);
21}
22
23function torchBloom (file)
24{
25 const image = makeRgba(16, 16, [0, 0, 0, 0]);
26 const rings = [
27 { x: 3, y: 2, w: 10, h: 10, rgba: [180, 48, 12, 90] },
28 { x: 4, y: 3, w: 8, h: 8, rgba: [230, 110, 24, 160] },
29 { x: 5, y: 4, w: 6, h: 6, rgba: [255, 190, 48, 220] },
30 { x: 6, y: 5, w: 4, h: 4, rgba: [255, 245, 200, 255] }
31 ];
32 for (const ring of rings)
33 { fillRect(image, ring.x, ring.y, ring.w, ring.h, ring.rgba); }
34 writeRgbaPng(file, 16, 16, image.pixels);
35}
36
37solid(join(root, "items", "paper", "paper.png"), [232, 224, 196, 255]);
38solid(join(root, "items", "apple", "apple.png"), [196, 48, 48, 255]);
39solid(join(root, "items", "stick", "stick.png"), [140, 92, 44, 255]);
40solid(join(root, "items", "blank-cheque", "blank-cheque.png"), [168, 214, 168, 255]);
41solid(join(root, "items", "clothing", "shirt.png"), [72, 112, 176, 255]);
42solid(join(root, "blocks", "spawner", "spawner.png"), [168, 64, 196, 255], [80, 20, 96, 255]);
43solid(join(root, "blocks", "bank", "bank.png"), [212, 176, 72, 255], [96, 72, 16, 255]);
44solid(join(root, "blocks", "church-altar", "church-altar.png"), [210, 210, 220, 255], [76, 72, 88, 255]);
45solid(join(root, "mobs", "deer", "deer.png"), [120, 78, 42, 255]);
46solid(join(root, "mobs", "rat", "rat.png"), [96, 88, 72, 255], [40, 36, 28, 255]);
47overlay(join(root, "items", "stick", "stick-equip.png"), [150, 98, 46, 230]);
48overlay(join(root, "items", "clothing", "shirt-equip.png"), [72, 112, 176, 230]);
49solid(join(root, "items", "lantern", "lantern.png"), [180, 120, 40, 255]);
50solid(join(root, "items", "bones", "bones.png"), [218, 210, 180, 255], [92, 84, 68, 255]);
51solid(join(root, "items", "skull", "skull.png"), [205, 198, 170, 255], [80, 72, 60, 255]);
52overlay(join(root, "items", "lantern", "lantern-equip.png"), [200, 130, 48, 230]);
53torchBloom(join(root, "items", "lantern", "lantern-equip-bloom.png"));
54torchBloom(join(root, "blocks", "torch", "torch-bloom.png"));
55
56function writeWaterSheet (file, base, wave, foam)
57{
58 const frames = 4;
59 const width = 16 * frames;
60 const height = 16;
61 const image = makeRgba(width, height, base);
62 for (let f = 0; f < frames; f++)
63 {
64 const ox = f * 16;
65 for (let y = 0; y < 16; y++)
66 {
67 const t = y / 15;
68 fillRect(image, ox, y, 16, 1, [
69 Math.round(base[0] * (1 - t * 0.15)),
70 Math.round(base[1] * (1 - t * 0.08)),
71 Math.round(base[2] * (1 + t * 0.05)),
72 255
73 ]);
74 }
75 for (let i = 0; i < 3; i++)
76 {
77 const y = 3 + ((i * 4 + f) % 10);
78 const x0 = ox + ((f * 3 + i * 5) % 12);
79 fillRect(image, x0, y, 5, 1, wave);
80 fillRect(image, x0 + 1, y - 1, 3, 1, foam);
81 }
82 }
83 writeRgbaPng(file, width, height, image.pixels);
84}
85
86writeWaterSheet(join(root, "grounds", "water", "water.png"), [48, 118, 168, 255], [90, 170, 210, 255], [170, 220, 240, 220]);
87writeWaterSheet(join(root, "grounds", "deep-water", "deep-water.png"), [28, 72, 118, 255], [55, 120, 170, 255], [110, 170, 210, 200]);
88
89{
90 const image = makeRgba(24, 8, [0, 0, 0, 0]);
91 fillRect(image, 1, 2, 22, 4, [240, 220, 160, 220]);
92 fillRect(image, 0, 3, 24, 2, [255, 245, 200, 255]);
93 writeRgbaPng(join(root, "fx", "melee-swipe", "melee-swipe.png"), 24, 8, image.pixels);
94}
95
96console.log("Wrote placeholder sprites under client/assets.");