castle-web-cli 0.4.228 → 0.4.230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-prompts.d.ts +11 -3
- package/dist/agent-prompts.js +153 -53
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +43 -33
- package/dist/api.d.ts +47 -2
- package/dist/api.js +85 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +59 -0
- package/dist/castleJson.js +267 -3
- package/dist/check.js +27 -1
- package/dist/cloudGit.d.ts +20 -1
- package/dist/cloudGit.js +267 -10
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSessionChild.js +3 -1
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +229 -44
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +145 -33
- package/dist/index.js +8 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +125 -8
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +145 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +94 -13
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/sourceLineage.d.ts +42 -0
- package/dist/sourceLineage.js +380 -0
- package/dist/webSourceSync.d.ts +11 -0
- package/dist/webSourceSync.js +26 -9
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +301 -52
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +6 -1
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +208 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +86 -6
- package/kits/base/sdk/multiplayer.js +157 -4
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +49 -2
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +85 -6
- package/kits/base/sdk/server/wrapper.js +393 -30
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +146 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1001 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +241 -0
- package/kits/hub-game/code/client/hookLayer.js +230 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +131 -0
- package/kits/hub-game/code/client/talk.js +259 -0
- package/kits/hub-game/code/client/together.js +365 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +247 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1904 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +527 -0
- package/kits/hub-game/code/server/npcs.js +745 -0
- package/kits/hub-game/code/server/party.js +381 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2230 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1139 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +224 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +714 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +286 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-together.mjs +183 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +25 -5
- package/kits/physics-3d/CLAUDE.md +6 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/world3d.js +65 -1
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
// Writes the kit's `pixel` avatar set: `models/pixel/avatar-0.pxmodel` to
|
|
2
|
+
// `avatar-3.pxmodel` (the Castle mascot, Kai, Mimi and Nox) and the pixel
|
|
3
|
+
// drawings they wear, `drawings/pixel/*.sprite`. Run from the kit:
|
|
4
|
+
// `node scripts/gen-avatars-pixel.mjs`. The models and the drawings are this
|
|
5
|
+
// script's output; change a character here and run it again. A drawing in
|
|
6
|
+
// `drawings/pixel/` that the script does not write is deleted.
|
|
7
|
+
//
|
|
8
|
+
// The style is a voxel figure on a 7 cm pixel grid wearing drawn skins, with
|
|
9
|
+
// no outline. What every avatar keeps, because the kit and the phone budget
|
|
10
|
+
// depend on it:
|
|
11
|
+
// - part ids `torso`, `head`, `legL`, `legR`, `armL`, `armR` (the walk moves
|
|
12
|
+
// them), head and arms under `torso`, feet on y = 0, facing +z;
|
|
13
|
+
// - at most 1,500 triangles and 8 draw calls: one per moving part for its
|
|
14
|
+
// skin, plus one each for the flat-coloured extras on the head and on the
|
|
15
|
+
// torso (ears, pigtails, a tail);
|
|
16
|
+
// - no glow.
|
|
17
|
+
//
|
|
18
|
+
// A skinned part is a `loft`, not a box. A box draws one image per face and
|
|
19
|
+
// every image is a draw call; a loft wraps ONE image once round its rings, so
|
|
20
|
+
// a part's front, sides and back are all drawn for a single call. The rings
|
|
21
|
+
// have a point per pixel of the part's outline, so every pixel of the drawing
|
|
22
|
+
// is a square of the grid on the model.
|
|
23
|
+
|
|
24
|
+
import fs from 'node:fs';
|
|
25
|
+
import path from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const KIT_DIR = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
const MODEL_DIR = path.join(KIT_DIR, 'models', 'pixel');
|
|
30
|
+
const ART_DIR = path.join(KIT_DIR, 'drawings', 'pixel');
|
|
31
|
+
// Art refs are deck-root paths: the kit as a deck imports it.
|
|
32
|
+
const ART_REF = 'imports/castle.hub-game/drawings/pixel';
|
|
33
|
+
|
|
34
|
+
// One pixel of every drawing, in metres.
|
|
35
|
+
const PX = 0.07;
|
|
36
|
+
// A step in a part's shape (a brim, a shoe's toe) is a ring this many pixels
|
|
37
|
+
// above or below the ring it steps from, so its flat face takes one row of
|
|
38
|
+
// the drawing.
|
|
39
|
+
const STEP = 0.04;
|
|
40
|
+
const LOOK = { outline: 0, rim: 0, ao: 0.2 };
|
|
41
|
+
// Colours come out darker than written under the engine's lights.
|
|
42
|
+
const BRIGHT = 2;
|
|
43
|
+
// The mascot is near-black; it is lifted less, so it stays black.
|
|
44
|
+
const MASCOT_BRIGHT = 1.6;
|
|
45
|
+
|
|
46
|
+
const round = (n) => Math.round(n * 1000) / 1000;
|
|
47
|
+
const m = (pixels) => round(pixels * PX);
|
|
48
|
+
|
|
49
|
+
//
|
|
50
|
+
// Shapes: a part's plan is a set of pixel cells [i, j], the cell covering
|
|
51
|
+
// x in i..i+1 and z in j..j+1.
|
|
52
|
+
//
|
|
53
|
+
|
|
54
|
+
function rect(x0, x1, z0, z1) {
|
|
55
|
+
const cells = [];
|
|
56
|
+
for (let i = x0; i < x1; i++) {
|
|
57
|
+
for (let j = z0; j < z1; j++) {
|
|
58
|
+
cells.push([i, j]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return cells;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// A rect with its four corner cells cut away.
|
|
65
|
+
function notched(x0, x1, z0, z1) {
|
|
66
|
+
const corner = ([i, j]) => (i === x0 || i === x1 - 1) && (j === z0 || j === z1 - 1);
|
|
67
|
+
return rect(x0, x1, z0, z1).filter((cell) => !corner(cell));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A pixel circle: `widths` are its rows' widths from back to front, centred
|
|
71
|
+
// in a square `size` cells wide.
|
|
72
|
+
function disc(size, widths) {
|
|
73
|
+
const inset = (size - widths.length) / 2;
|
|
74
|
+
return widths.flatMap((width, row) => {
|
|
75
|
+
const x0 = (size - width) / 2;
|
|
76
|
+
return rect(x0, x0 + width, inset + row, inset + row + 1);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The outline of a set of cells: its pixel edges in order, counter-clockwise
|
|
81
|
+
// seen from above, starting at the front's left end. Each edge says which way
|
|
82
|
+
// it faces and which column of that side's drawing it shows. The shape must
|
|
83
|
+
// have no holes or dents (every row and column of cells is one run), so each
|
|
84
|
+
// column of each side's drawing lands on exactly one edge.
|
|
85
|
+
function outlineOf(cells) {
|
|
86
|
+
const has = new Set(cells.map(([i, j]) => `${i},${j}`));
|
|
87
|
+
const xs = cells.map(([i]) => i);
|
|
88
|
+
const zs = cells.map(([, j]) => j);
|
|
89
|
+
const box = {
|
|
90
|
+
x0: Math.min(...xs),
|
|
91
|
+
x1: Math.max(...xs) + 1,
|
|
92
|
+
z0: Math.min(...zs),
|
|
93
|
+
z1: Math.max(...zs) + 1,
|
|
94
|
+
};
|
|
95
|
+
const from = new Map();
|
|
96
|
+
const add = (facing, col, a, b) => from.set(a.join(), { facing, col, a, b });
|
|
97
|
+
for (const [i, j] of cells) {
|
|
98
|
+
if (!has.has(`${i},${j + 1}`)) {
|
|
99
|
+
add('front', i - box.x0, [i, j + 1], [i + 1, j + 1]);
|
|
100
|
+
}
|
|
101
|
+
if (!has.has(`${i + 1},${j}`)) {
|
|
102
|
+
add('right', box.z1 - 1 - j, [i + 1, j + 1], [i + 1, j]);
|
|
103
|
+
}
|
|
104
|
+
if (!has.has(`${i},${j - 1}`)) {
|
|
105
|
+
add('back', box.x1 - 1 - i, [i + 1, j], [i, j]);
|
|
106
|
+
}
|
|
107
|
+
if (!has.has(`${i - 1},${j}`)) {
|
|
108
|
+
add('left', j - box.z0, [i, j], [i, j + 1]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const edges = [[...from.values()].find((edge) => edge.facing === 'front' && edge.col === 0)];
|
|
112
|
+
while (edges.length < from.size) {
|
|
113
|
+
edges.push(from.get(edges[edges.length - 1].b.join()));
|
|
114
|
+
}
|
|
115
|
+
return { edges, box };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Where a ring of `points` sits when the part is narrower at some height: the
|
|
119
|
+
// same points held inside the rect `[x0, x1, z0, z1]`. Every pixel of the
|
|
120
|
+
// drawing stays where it was; the ones outside the rect fold away.
|
|
121
|
+
function clamped(points, [x0, x1, z0, z1]) {
|
|
122
|
+
return points.map(([x, z]) => [Math.min(x1, Math.max(x0, x)), Math.min(z1, Math.max(z0, z))]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//
|
|
126
|
+
// Skins
|
|
127
|
+
//
|
|
128
|
+
|
|
129
|
+
const mirrored = (rows) => rows.map((row) => [...row].reverse().join(''));
|
|
130
|
+
|
|
131
|
+
// The drawing a shape wears: one row of pixels per row of `faces`, one column
|
|
132
|
+
// per edge of the outline. `faces` are the part seen from its front, its
|
|
133
|
+
// right (+x) side, its back and its left side, each as wide as the shape's
|
|
134
|
+
// bounding box; a left that is not given is the right's mirror image.
|
|
135
|
+
function wrapOf(name, edges, box, faces) {
|
|
136
|
+
const sides = { ...faces, left: faces.left ?? mirrored(faces.right) };
|
|
137
|
+
const widths = {
|
|
138
|
+
front: box.x1 - box.x0,
|
|
139
|
+
back: box.x1 - box.x0,
|
|
140
|
+
right: box.z1 - box.z0,
|
|
141
|
+
left: box.z1 - box.z0,
|
|
142
|
+
};
|
|
143
|
+
for (const [side, rows] of Object.entries(sides)) {
|
|
144
|
+
if (rows.length !== sides.front.length || rows.some((row) => row.length !== widths[side])) {
|
|
145
|
+
throw new Error(`${name}: the ${side} is not ${widths[side]} x ${sides.front.length}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return sides.front.map((_, row) =>
|
|
149
|
+
edges.map((edge) => sides[edge.facing][row][edge.col]).join(''),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const sprites = new Map();
|
|
154
|
+
|
|
155
|
+
function sprite(name, palette, grid) {
|
|
156
|
+
const used = new Set(grid.join(''));
|
|
157
|
+
for (const key of used) {
|
|
158
|
+
if (!palette[key]) {
|
|
159
|
+
throw new Error(`${name}: no colour "${key}"`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const kept = Object.fromEntries(Object.entries(palette).filter(([key]) => used.has(key)));
|
|
163
|
+
// The compact form, as Castle's pixel editor saves it.
|
|
164
|
+
const text = `${JSON.stringify({ format: 'compact', palette: kept, grid }, null, 2)}\n`;
|
|
165
|
+
sprites.set(`${name}.sprite`, text);
|
|
166
|
+
return `${ART_REF}/${name}.sprite`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Parts
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
// A skinned part. `cells` is its plan at its widest, `origin` the plan's
|
|
174
|
+
// [x, z] that sits on the part's pivot, and `bottom` how far its lowest row
|
|
175
|
+
// starts above the pivot, all in pixels. `shapeAt(row)` narrows a row of the
|
|
176
|
+
// drawing (0 is the top row) to the rect it gives. Rows narrower than the row
|
|
177
|
+
// beside them leave a step, coloured by the wider row. Each end closes to a
|
|
178
|
+
// point, so it takes the colours of its end row, unless it is `open`: an end
|
|
179
|
+
// that is always hidden is left as the loft's own cap.
|
|
180
|
+
function skinned(
|
|
181
|
+
id,
|
|
182
|
+
{
|
|
183
|
+
parent,
|
|
184
|
+
position,
|
|
185
|
+
cells,
|
|
186
|
+
origin,
|
|
187
|
+
bottom = 0,
|
|
188
|
+
shapeAt = () => null,
|
|
189
|
+
faces,
|
|
190
|
+
art,
|
|
191
|
+
open = '',
|
|
192
|
+
bright = BRIGHT,
|
|
193
|
+
},
|
|
194
|
+
) {
|
|
195
|
+
const { edges } = outlineOf(cells);
|
|
196
|
+
const base = edges.map((edge) => edge.a);
|
|
197
|
+
const rows = faces.front.length;
|
|
198
|
+
// Runs of rows with one shape, from the bottom up.
|
|
199
|
+
const tiers = [];
|
|
200
|
+
for (let row = rows - 1; row >= 0; row--) {
|
|
201
|
+
const shape = shapeAt(row);
|
|
202
|
+
const key = JSON.stringify(shape);
|
|
203
|
+
if (tiers.length === 0 || tiers[tiers.length - 1].key !== key) {
|
|
204
|
+
const ring = shape ? clamped(base, shape) : base;
|
|
205
|
+
const [xs, zs] = [ring.map(([x]) => x), ring.map(([, z]) => z)];
|
|
206
|
+
const [x0, x1, z0, z1] = [Math.min(...xs), Math.max(...xs), Math.min(...zs), Math.max(...zs)];
|
|
207
|
+
tiers.push({
|
|
208
|
+
key,
|
|
209
|
+
ring,
|
|
210
|
+
area: (x1 - x0) * (z1 - z0),
|
|
211
|
+
centre: ring.map(() => [(x0 + x1) / 2, (z0 + z1) / 2]),
|
|
212
|
+
top: 0,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
tiers[tiers.length - 1].top = rows - row;
|
|
216
|
+
}
|
|
217
|
+
const sections = [];
|
|
218
|
+
const section = (y, ring) =>
|
|
219
|
+
sections.push({
|
|
220
|
+
y: m(bottom + y),
|
|
221
|
+
points: ring.map(([x, z]) => [m(x - origin[0]), m(z - origin[1])]),
|
|
222
|
+
});
|
|
223
|
+
if (open.includes('bottom')) {
|
|
224
|
+
section(0, tiers[0].ring);
|
|
225
|
+
} else {
|
|
226
|
+
section(0, tiers[0].centre);
|
|
227
|
+
section(STEP, tiers[0].ring);
|
|
228
|
+
}
|
|
229
|
+
tiers.forEach((tier, k) => {
|
|
230
|
+
const next = tiers[k + 1];
|
|
231
|
+
if (!next && open.includes('top')) {
|
|
232
|
+
section(tier.top, tier.ring);
|
|
233
|
+
} else if (!next) {
|
|
234
|
+
section(tier.top - STEP, tier.ring);
|
|
235
|
+
section(tier.top, tier.centre);
|
|
236
|
+
} else if (next.area < tier.area) {
|
|
237
|
+
section(tier.top - STEP, tier.ring);
|
|
238
|
+
section(tier.top, next.ring);
|
|
239
|
+
} else {
|
|
240
|
+
section(tier.top, tier.ring);
|
|
241
|
+
section(tier.top + STEP, next.ring);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const part = { id, kind: 'loft', flat: true, sections, art, roughness: 1, brightness: bright };
|
|
245
|
+
if (parent) {
|
|
246
|
+
part.parent = parent;
|
|
247
|
+
}
|
|
248
|
+
part.position = position.map(m);
|
|
249
|
+
return part;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// A flat-coloured block from corner to corner, in pixels from its parent's
|
|
253
|
+
// pivot.
|
|
254
|
+
function block(id, parent, [x0, x1], [y0, y1], [z0, z1], color, { mirror, bright = BRIGHT } = {}) {
|
|
255
|
+
const part = {
|
|
256
|
+
id,
|
|
257
|
+
parent,
|
|
258
|
+
flat: true,
|
|
259
|
+
size: [m(x1 - x0), m(y1 - y0), m(z1 - z0)],
|
|
260
|
+
position: [m((x0 + x1) / 2), m((y0 + y1) / 2), m((z0 + z1) / 2)],
|
|
261
|
+
color,
|
|
262
|
+
roughness: 1,
|
|
263
|
+
brightness: bright,
|
|
264
|
+
};
|
|
265
|
+
if (mirror) {
|
|
266
|
+
part.mirror = 'x';
|
|
267
|
+
}
|
|
268
|
+
return part;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// One colour key per row, the same on all four sides of a part `width` by
|
|
272
|
+
// `depth` pixels.
|
|
273
|
+
function banded(bands, width, depth) {
|
|
274
|
+
const side = (count) => [...bands].map((key) => key.repeat(count));
|
|
275
|
+
return { front: side(width), right: side(depth), back: side(width) };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// The limbs every avatar has: square arms two pixels thick that swing from a
|
|
279
|
+
// pixel below their top, and legs three pixels thick whose two lowest rows
|
|
280
|
+
// are a shoe with a toe. `arm` and `leg` are their drawings' faces, a row per
|
|
281
|
+
// pixel of length; `shoulder` is the arm's inner top corner, [x, y] in pixels
|
|
282
|
+
// from the torso pivot. Legs that touch are half a pixel thinner on the inside
|
|
283
|
+
// from the row `gapFrom` down, which leaves a gap between them.
|
|
284
|
+
function limbs(name, palette, { arm, leg, shoulder, legX, gapFrom = Infinity, bright = BRIGHT }) {
|
|
285
|
+
const armArt = sprite(`${name}-arm`, palette, wrapOf(`${name}-arm`, ...armShape(), arm));
|
|
286
|
+
const legArt = sprite(`${name}-leg`, palette, wrapOf(`${name}-leg`, ...legShape(), leg));
|
|
287
|
+
const hip = leg.front.length;
|
|
288
|
+
const parts = [];
|
|
289
|
+
for (const [side, sx] of [
|
|
290
|
+
['L', 1],
|
|
291
|
+
['R', -1],
|
|
292
|
+
]) {
|
|
293
|
+
parts.push(
|
|
294
|
+
skinned(`leg${side}`, {
|
|
295
|
+
position: [sx * legX, hip, 0],
|
|
296
|
+
cells: LEG_CELLS,
|
|
297
|
+
origin: [1.5, 1.5],
|
|
298
|
+
bottom: -hip,
|
|
299
|
+
shapeAt: (row) => [
|
|
300
|
+
sx > 0 && row >= gapFrom ? 0.5 : 0,
|
|
301
|
+
sx < 0 && row >= gapFrom ? 2.5 : 3,
|
|
302
|
+
0,
|
|
303
|
+
row < hip - 2 ? 3 : 4,
|
|
304
|
+
],
|
|
305
|
+
faces: leg,
|
|
306
|
+
art: legArt,
|
|
307
|
+
open: 'top',
|
|
308
|
+
bright,
|
|
309
|
+
}),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
for (const [side, sx] of [
|
|
313
|
+
['L', 1],
|
|
314
|
+
['R', -1],
|
|
315
|
+
]) {
|
|
316
|
+
parts.push(
|
|
317
|
+
skinned(`arm${side}`, {
|
|
318
|
+
parent: 'torso',
|
|
319
|
+
position: [sx * (shoulder[0] + 1), shoulder[1] - 1, 0],
|
|
320
|
+
cells: ARM_CELLS,
|
|
321
|
+
origin: [1, 1],
|
|
322
|
+
bottom: 1 - arm.front.length,
|
|
323
|
+
faces: arm,
|
|
324
|
+
art: armArt,
|
|
325
|
+
bright,
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return parts;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const ARM_CELLS = rect(0, 2, 0, 2);
|
|
333
|
+
const LEG_CELLS = rect(0, 3, 0, 4);
|
|
334
|
+
const armShape = () => {
|
|
335
|
+
const { edges, box } = outlineOf(ARM_CELLS);
|
|
336
|
+
return [edges, box];
|
|
337
|
+
};
|
|
338
|
+
const legShape = () => {
|
|
339
|
+
const { edges, box } = outlineOf(LEG_CELLS);
|
|
340
|
+
return [edges, box];
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// A leg's faces from one colour key per row: the toe is the front of the two
|
|
344
|
+
// lowest rows, so the sides are a column wider than the leg is deep.
|
|
345
|
+
const legBands = (bands) => banded(bands, 3, 4);
|
|
346
|
+
|
|
347
|
+
function wrapped(name, palette, cells, faces) {
|
|
348
|
+
const { edges, box } = outlineOf(cells);
|
|
349
|
+
return sprite(name, palette, wrapOf(name, edges, box, faces));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//
|
|
353
|
+
// 0: the Castle mascot. One black body with a domed top, one almond eye and
|
|
354
|
+
// the logo's white sheen down its side, as a pixel drawing on a round voxel
|
|
355
|
+
// body. The body is the `head`, so the idle look-around turns the eye and the
|
|
356
|
+
// sheen together; the `torso` is a block hidden inside it that carries the
|
|
357
|
+
// arms.
|
|
358
|
+
//
|
|
359
|
+
|
|
360
|
+
// The rows of a pixel circle as blocks, one per width, each as deep as the
|
|
361
|
+
// rows at least that wide.
|
|
362
|
+
function discBlocks(id, parent, widths, [y0, y1], color, bright) {
|
|
363
|
+
return [...new Set(widths)].map((width) => {
|
|
364
|
+
const depth = widths.filter((other) => other >= width).length;
|
|
365
|
+
return block(
|
|
366
|
+
`${id}${width}`,
|
|
367
|
+
parent,
|
|
368
|
+
[-width / 2, width / 2],
|
|
369
|
+
[y0, y1],
|
|
370
|
+
[-depth / 2, depth / 2],
|
|
371
|
+
color,
|
|
372
|
+
{ bright },
|
|
373
|
+
);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function mascot() {
|
|
378
|
+
const palette = { k: '#3a3644', d: '#2a2632', W: '#ffffff', P: '#17141d' };
|
|
379
|
+
const bright = MASCOT_BRIGHT;
|
|
380
|
+
const size = 11;
|
|
381
|
+
const legs = 4;
|
|
382
|
+
const body = disc(size, [5, 7, 9, 11, 11, 11, 11, 11, 9, 7, 5]);
|
|
383
|
+
// The front of the straight part of the body: the sheen down the second
|
|
384
|
+
// column, and the eye right of the middle, as in the logo.
|
|
385
|
+
const front = [
|
|
386
|
+
'kWkkkkkkkkk',
|
|
387
|
+
'kWkkkkkkkkk',
|
|
388
|
+
'kWkkkWWWWkk',
|
|
389
|
+
'kWkkWWPPWWk',
|
|
390
|
+
'kWkWWPPWPWW',
|
|
391
|
+
'kWkWWPPPPWW',
|
|
392
|
+
'kWkkWWPPWWk',
|
|
393
|
+
'kWkkkWWWWkk',
|
|
394
|
+
'kWkkkkkkkkk',
|
|
395
|
+
'kWkkkkkkkkk',
|
|
396
|
+
'kkkkkkkkkkk',
|
|
397
|
+
'ddddddddddd',
|
|
398
|
+
];
|
|
399
|
+
const plain = front.map((_, row) => (row === front.length - 1 ? 'd' : 'k').repeat(size));
|
|
400
|
+
// Round the body the drawing's columns sit on stepped faces. A side's
|
|
401
|
+
// columns nearest the front are the steps between the front's columns, and
|
|
402
|
+
// carry on the front's drawing.
|
|
403
|
+
const sideOf = (cols) =>
|
|
404
|
+
plain.map((row, r) =>
|
|
405
|
+
[...row].map((key, c) => (cols[c] === undefined ? key : front[r][cols[c]])).join(''),
|
|
406
|
+
);
|
|
407
|
+
const faces = {
|
|
408
|
+
front,
|
|
409
|
+
right: sideOf({ 0: 7, 1: 8, 2: 9 }),
|
|
410
|
+
back: plain,
|
|
411
|
+
left: sideOf({ 10: 3, 9: 2, 8: 1 }),
|
|
412
|
+
};
|
|
413
|
+
const top = front.length;
|
|
414
|
+
const parts = limbs('castle', palette, {
|
|
415
|
+
arm: banded('kkWW', 2, 2),
|
|
416
|
+
leg: legBands('kkkk'),
|
|
417
|
+
shoulder: [6, 6],
|
|
418
|
+
legX: 2.5,
|
|
419
|
+
bright,
|
|
420
|
+
});
|
|
421
|
+
parts.push(
|
|
422
|
+
{
|
|
423
|
+
...block('torso', null, [-2, 2], [0.5, 2.5], [-2, 2], palette.k, { bright }),
|
|
424
|
+
position: [0, m(legs), 0],
|
|
425
|
+
offset: [0, m(1.5), 0],
|
|
426
|
+
},
|
|
427
|
+
skinned('head', {
|
|
428
|
+
parent: 'torso',
|
|
429
|
+
position: [0, 0, 0],
|
|
430
|
+
cells: body,
|
|
431
|
+
origin: [size / 2, size / 2],
|
|
432
|
+
faces,
|
|
433
|
+
art: wrapped('castle-body', palette, body, faces),
|
|
434
|
+
bright,
|
|
435
|
+
}),
|
|
436
|
+
// The dome: three smaller pixel circles, and the sheen carried up it as a
|
|
437
|
+
// white pixel on the corner of the lower two.
|
|
438
|
+
...discBlocks('domeA', 'head', [5, 7, 9, 9, 9, 9, 9, 7, 5], [top, top + 2], palette.k, bright),
|
|
439
|
+
...discBlocks('domeB', 'head', [3, 5, 7, 7, 7, 5, 3], [top + 2, top + 3], palette.k, bright),
|
|
440
|
+
...discBlocks('domeC', 'head', [3, 5, 5, 5, 3], [top + 3, top + 3.5], palette.k, bright),
|
|
441
|
+
block('sheenA', 'head', [-4.6, -3.5], [top, top + 2.1], [1.5, 2.6], palette.W, { bright }),
|
|
442
|
+
block('sheenB', 'head', [-3.6, -2.5], [top + 2, top + 3.1], [0.5, 1.6], palette.W, { bright }),
|
|
443
|
+
);
|
|
444
|
+
return { name: 'Castle', parts };
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
//
|
|
448
|
+
// The other three are kids' figures: a big head with its corners cut, a small
|
|
449
|
+
// body, short arms.
|
|
450
|
+
//
|
|
451
|
+
|
|
452
|
+
const HEAD_CELLS = notched(0, 8, 0, 8);
|
|
453
|
+
const LEGS = 5;
|
|
454
|
+
const TORSO = 6;
|
|
455
|
+
|
|
456
|
+
// A head whose top and bottom rows step in a pixel, unless `flatTop`.
|
|
457
|
+
function headShape(rows, { flatTop = false } = {}) {
|
|
458
|
+
return (row) => ((row === 0 && !flatTop) || row === rows - 1 ? [1, 7, 1, 7] : [0, 8, 0, 8]);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
//
|
|
462
|
+
// 1: Kai, a kid in a backwards cap with a backpack.
|
|
463
|
+
//
|
|
464
|
+
|
|
465
|
+
function kai() {
|
|
466
|
+
const palette = {
|
|
467
|
+
Y: '#ffc928',
|
|
468
|
+
y: '#f28a1a',
|
|
469
|
+
h: '#3d2616',
|
|
470
|
+
s: '#c47a45',
|
|
471
|
+
d: '#9c5a30',
|
|
472
|
+
K: '#241a2e',
|
|
473
|
+
W: '#ffffff',
|
|
474
|
+
m: '#7a2a22',
|
|
475
|
+
B: '#2f7bf0',
|
|
476
|
+
L: '#7fb6ff',
|
|
477
|
+
n: '#2a3a9c',
|
|
478
|
+
};
|
|
479
|
+
const head = {
|
|
480
|
+
front: [
|
|
481
|
+
'YYYYYYYY',
|
|
482
|
+
'YYYhhYYY',
|
|
483
|
+
'yyyyyyyy',
|
|
484
|
+
'hhsssshh',
|
|
485
|
+
'sKWssKWs',
|
|
486
|
+
'sKKssKKs',
|
|
487
|
+
'sdssssds',
|
|
488
|
+
'ssmWWmss',
|
|
489
|
+
'ssssssss',
|
|
490
|
+
],
|
|
491
|
+
right: [
|
|
492
|
+
'YYYYYYYY',
|
|
493
|
+
'YYYYYYYY',
|
|
494
|
+
'yyyyyyyy',
|
|
495
|
+
'shhhhhhh',
|
|
496
|
+
'sshhhhhh',
|
|
497
|
+
'ssdshhhh',
|
|
498
|
+
'sssshhhh',
|
|
499
|
+
'ssssshhs',
|
|
500
|
+
'ssssssss',
|
|
501
|
+
],
|
|
502
|
+
back: [
|
|
503
|
+
'YYYYYYYY',
|
|
504
|
+
'YYYYYYYY',
|
|
505
|
+
'yyyyyyyy',
|
|
506
|
+
'hhhhhhhh',
|
|
507
|
+
'hhhhhhhh',
|
|
508
|
+
'hhhhhhhh',
|
|
509
|
+
'shhhhhhs',
|
|
510
|
+
'sshhhhss',
|
|
511
|
+
'ssssssss',
|
|
512
|
+
],
|
|
513
|
+
};
|
|
514
|
+
// The backpack is part of the torso's shape, on the four middle rows.
|
|
515
|
+
const torsoCells = [...rect(0, 6, 0, 4), ...rect(1, 5, -2, 0)];
|
|
516
|
+
const torso = {
|
|
517
|
+
front: ['YYssYY', 'YBYYBY', 'YBYYBY', 'YYYYYY', 'YyyyyY', 'yyyyyy'],
|
|
518
|
+
right: ['YYYYYY', 'YYYYBB', 'YYYYBB', 'YYYYLL', 'YYYYBB', 'yyyyyy'],
|
|
519
|
+
back: ['YYYYYY', 'YLLLLY', 'YBBBBY', 'YBLLBY', 'YBBBBY', 'yyyyyy'],
|
|
520
|
+
};
|
|
521
|
+
const parts = limbs('kai', palette, {
|
|
522
|
+
arm: banded('YYys', 2, 2),
|
|
523
|
+
leg: legBands('nnsWW'),
|
|
524
|
+
shoulder: [3, TORSO - 1],
|
|
525
|
+
legX: 1.5,
|
|
526
|
+
gapFrom: 2,
|
|
527
|
+
});
|
|
528
|
+
parts.push(
|
|
529
|
+
skinned('torso', {
|
|
530
|
+
position: [0, LEGS, 0],
|
|
531
|
+
cells: torsoCells,
|
|
532
|
+
origin: [3, 2],
|
|
533
|
+
shapeAt: (row) => (row >= 1 && row <= 4 ? null : [0, 6, 0, 4]),
|
|
534
|
+
faces: torso,
|
|
535
|
+
art: wrapped('kai-torso', palette, torsoCells, torso),
|
|
536
|
+
open: 'top',
|
|
537
|
+
}),
|
|
538
|
+
skinned('head', {
|
|
539
|
+
parent: 'torso',
|
|
540
|
+
position: [0, TORSO, 0],
|
|
541
|
+
cells: HEAD_CELLS,
|
|
542
|
+
origin: [4, 4],
|
|
543
|
+
shapeAt: headShape(9),
|
|
544
|
+
faces: head,
|
|
545
|
+
art: wrapped('kai-head', palette, HEAD_CELLS, head),
|
|
546
|
+
}),
|
|
547
|
+
// The cap's brim, out of the back of its band, and the button on top.
|
|
548
|
+
block('brim', 'head', [-3, 3], [6, 7], [-6, -4], palette.y),
|
|
549
|
+
block('button', 'head', [-1, 1], [9, 9.5], [-1, 1], palette.y),
|
|
550
|
+
);
|
|
551
|
+
return { name: 'Kai', parts };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
//
|
|
555
|
+
// 2: Mimi, pink hair in two pigtails and a skirt.
|
|
556
|
+
//
|
|
557
|
+
|
|
558
|
+
function mimi() {
|
|
559
|
+
const palette = {
|
|
560
|
+
H: '#ff4f9a',
|
|
561
|
+
P: '#d92f7c',
|
|
562
|
+
L: '#ff9cc8',
|
|
563
|
+
f: '#ffd9b0',
|
|
564
|
+
K: '#3a1a3a',
|
|
565
|
+
W: '#ffffff',
|
|
566
|
+
b: '#ff8f8f',
|
|
567
|
+
m: '#c2405a',
|
|
568
|
+
T: '#19c8c0',
|
|
569
|
+
t: '#0e9a98',
|
|
570
|
+
S: '#ffe14d',
|
|
571
|
+
};
|
|
572
|
+
const head = {
|
|
573
|
+
front: [
|
|
574
|
+
'HHHHHHHH',
|
|
575
|
+
'HHLLLHHH',
|
|
576
|
+
'HHHHHHHH',
|
|
577
|
+
'HfHffHfH',
|
|
578
|
+
'HKWffKWH',
|
|
579
|
+
'HKKffKKH',
|
|
580
|
+
'fbfmmfbf',
|
|
581
|
+
'ffffffff',
|
|
582
|
+
],
|
|
583
|
+
right: [
|
|
584
|
+
'HHHHHHHH',
|
|
585
|
+
'HHLLHHHH',
|
|
586
|
+
'HHHHHHHH',
|
|
587
|
+
'fHHHHHHH',
|
|
588
|
+
'ffHHPHHH',
|
|
589
|
+
'ffHHPHPH',
|
|
590
|
+
'fffHHHPH',
|
|
591
|
+
'ffffHHHH',
|
|
592
|
+
],
|
|
593
|
+
back: [
|
|
594
|
+
'HHHHHHHH',
|
|
595
|
+
'HHLLLLHH',
|
|
596
|
+
'HHHHHHHH',
|
|
597
|
+
'HHHPHHHH',
|
|
598
|
+
'HHHPHHHH',
|
|
599
|
+
'HHHPHHHH',
|
|
600
|
+
'HHHPHHHH',
|
|
601
|
+
'HHHHHHHH',
|
|
602
|
+
],
|
|
603
|
+
};
|
|
604
|
+
// The skirt is the torso's two lowest rows, each a step wider.
|
|
605
|
+
const torsoCells = rect(0, 8, 0, 6);
|
|
606
|
+
const torso = {
|
|
607
|
+
front: ['TTTffTTT', 'TTTSSTTT', 'TTSWWSTT', 'TTTSSTTT', 'tttttttt', 'TtTtTtTt'],
|
|
608
|
+
right: ['TTTTTT', 'TTTTTT', 'TTTTTT', 'TTTTTT', 'tttttt', 'TtTtTt'],
|
|
609
|
+
back: ['TTTTTTTT', 'TTTSSTTT', 'TTSWWSTT', 'TTTSSTTT', 'tttttttt', 'TtTtTtTt'],
|
|
610
|
+
};
|
|
611
|
+
const skirt = [[1, 7, 1, 5], [1, 7, 1, 5], [1, 7, 1, 5], [1, 7, 1, 5], [1, 7, 0, 6], null];
|
|
612
|
+
const parts = limbs('mimi', palette, {
|
|
613
|
+
arm: banded('TTff', 2, 2),
|
|
614
|
+
leg: legBands('WWWHP'),
|
|
615
|
+
shoulder: [3, TORSO - 1],
|
|
616
|
+
legX: 1.5,
|
|
617
|
+
gapFrom: 0,
|
|
618
|
+
});
|
|
619
|
+
parts.push(
|
|
620
|
+
skinned('torso', {
|
|
621
|
+
position: [0, LEGS, 0],
|
|
622
|
+
cells: torsoCells,
|
|
623
|
+
origin: [4, 3],
|
|
624
|
+
shapeAt: (row) => skirt[row],
|
|
625
|
+
faces: torso,
|
|
626
|
+
art: wrapped('mimi-torso', palette, torsoCells, torso),
|
|
627
|
+
open: 'top',
|
|
628
|
+
}),
|
|
629
|
+
skinned('head', {
|
|
630
|
+
parent: 'torso',
|
|
631
|
+
position: [0, TORSO, 0],
|
|
632
|
+
cells: HEAD_CELLS,
|
|
633
|
+
origin: [4, 4],
|
|
634
|
+
shapeAt: headShape(8),
|
|
635
|
+
faces: head,
|
|
636
|
+
art: wrapped('mimi-head', palette, HEAD_CELLS, head),
|
|
637
|
+
}),
|
|
638
|
+
// A hairband over the top, down to a tie on each pigtail.
|
|
639
|
+
block('band', 'head', [-3.1, 3.1], [7.8, 8.25], [-1.5, -0.5], palette.S),
|
|
640
|
+
block('bandSide', 'head', [3, 4.15], [6, 7.15], [-1.5, -0.5], palette.S, { mirror: true }),
|
|
641
|
+
block('tie', 'head', [4, 5.2], [4.8, 6], [-1.6, -0.4], palette.S, { mirror: true }),
|
|
642
|
+
block('pigtail', 'head', [4.5, 6.5], [1.5, 5.5], [-2, 0], palette.H, { mirror: true }),
|
|
643
|
+
block('pigtailTip', 'head', [5, 6], [0.5, 1.5], [-1.5, -0.5], palette.P, { mirror: true }),
|
|
644
|
+
);
|
|
645
|
+
return { name: 'Mimi', parts };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
//
|
|
649
|
+
// 3: Nox, a night cat: ears, yellow eyes and a tail.
|
|
650
|
+
//
|
|
651
|
+
|
|
652
|
+
function nox() {
|
|
653
|
+
const palette = {
|
|
654
|
+
N: '#7a5cff',
|
|
655
|
+
n: '#5438d6',
|
|
656
|
+
M: '#ece6ff',
|
|
657
|
+
Y: '#ffd83d',
|
|
658
|
+
K: '#1a1430',
|
|
659
|
+
p: '#ff8fb0',
|
|
660
|
+
R: '#ff4d5e',
|
|
661
|
+
};
|
|
662
|
+
const head = {
|
|
663
|
+
front: [
|
|
664
|
+
'NNNNNNNN',
|
|
665
|
+
'NNnNNnNN',
|
|
666
|
+
'NNNNNNNN',
|
|
667
|
+
'YKYNNYKY',
|
|
668
|
+
'YKYNNYKY',
|
|
669
|
+
'NNMppMNN',
|
|
670
|
+
'NMMMMMMN',
|
|
671
|
+
'NNMMMMNN',
|
|
672
|
+
],
|
|
673
|
+
right: [
|
|
674
|
+
'NNNNNNNN',
|
|
675
|
+
'NNNnnNNN',
|
|
676
|
+
'NNNNNNNN',
|
|
677
|
+
'NNnnnNNN',
|
|
678
|
+
'NNNNNNNN',
|
|
679
|
+
'NNNnnnNN',
|
|
680
|
+
'MNNNNNNN',
|
|
681
|
+
'NNNNNNNN',
|
|
682
|
+
],
|
|
683
|
+
back: [
|
|
684
|
+
'NNNNNNNN',
|
|
685
|
+
'NNnnnnNN',
|
|
686
|
+
'NNNNNNNN',
|
|
687
|
+
'NnnnnnnN',
|
|
688
|
+
'NNNNNNNN',
|
|
689
|
+
'NNnnnnNN',
|
|
690
|
+
'NNNNNNNN',
|
|
691
|
+
'NNNNNNNN',
|
|
692
|
+
],
|
|
693
|
+
};
|
|
694
|
+
const torsoCells = rect(0, 6, 0, 4);
|
|
695
|
+
const torso = {
|
|
696
|
+
front: ['RRRRRR', 'NNYYNN', 'NMMMMN', 'NMMMMN', 'NMMMMN', 'NNMMNN'],
|
|
697
|
+
right: ['RRRR', 'NNNN', 'NnnN', 'NNNN', 'NnnN', 'NNNN'],
|
|
698
|
+
back: ['RRRRRR', 'NNNNNN', 'NnnnnN', 'NNNNNN', 'NnnnnN', 'NNNNNN'],
|
|
699
|
+
};
|
|
700
|
+
const parts = limbs('nox', palette, {
|
|
701
|
+
arm: banded('NNNM', 2, 2),
|
|
702
|
+
leg: legBands('NNNMM'),
|
|
703
|
+
shoulder: [3, TORSO - 1],
|
|
704
|
+
legX: 1.5,
|
|
705
|
+
gapFrom: 1,
|
|
706
|
+
});
|
|
707
|
+
parts.push(
|
|
708
|
+
skinned('torso', {
|
|
709
|
+
position: [0, LEGS, 0],
|
|
710
|
+
cells: torsoCells,
|
|
711
|
+
origin: [3, 2],
|
|
712
|
+
faces: torso,
|
|
713
|
+
art: wrapped('nox-torso', palette, torsoCells, torso),
|
|
714
|
+
open: 'top',
|
|
715
|
+
}),
|
|
716
|
+
skinned('head', {
|
|
717
|
+
parent: 'torso',
|
|
718
|
+
position: [0, TORSO, 0],
|
|
719
|
+
cells: HEAD_CELLS,
|
|
720
|
+
origin: [4, 4],
|
|
721
|
+
shapeAt: headShape(8, { flatTop: true }),
|
|
722
|
+
faces: head,
|
|
723
|
+
art: wrapped('nox-head', palette, HEAD_CELLS, head),
|
|
724
|
+
}),
|
|
725
|
+
// Stepped ears, pink inside, and two stripes between them.
|
|
726
|
+
block('ear', 'head', [1, 4], [8, 9], [-1, 1], palette.N, { mirror: true }),
|
|
727
|
+
block('earMid', 'head', [2, 4], [9, 10], [-1, 1], palette.N, { mirror: true }),
|
|
728
|
+
block('earTip', 'head', [3, 4], [10, 11], [-1, 1], palette.N, { mirror: true }),
|
|
729
|
+
block('earIn', 'head', [2, 3], [8, 10], [1, 1.2], palette.p, { mirror: true }),
|
|
730
|
+
block('stripeA', 'head', [-1, 1], [8, 8.15], [0.5, 1.5], palette.n),
|
|
731
|
+
block('stripeB', 'head', [-1, 1], [8, 8.15], [-2.5, -1.5], palette.n),
|
|
732
|
+
// Not `tail`: that id is a gait hook, which would be a draw call more.
|
|
733
|
+
block('catTail', 'torso', [-1, 1], [0, 2], [-5, -2], palette.N),
|
|
734
|
+
block('catTailUp', 'torso', [-1, 1], [2, 4], [-6, -4], palette.n),
|
|
735
|
+
block('catTailTip', 'torso', [-1, 1], [4, 5.5], [-6, -4], palette.M),
|
|
736
|
+
);
|
|
737
|
+
return { name: 'Nox', parts };
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
//
|
|
741
|
+
// Writing
|
|
742
|
+
//
|
|
743
|
+
|
|
744
|
+
function write(index, { name, parts }) {
|
|
745
|
+
const lines = [
|
|
746
|
+
'{',
|
|
747
|
+
' "format": "pxmodel",',
|
|
748
|
+
` "name": ${JSON.stringify(name)},`,
|
|
749
|
+
' "triangles": 1500,',
|
|
750
|
+
` "look": ${JSON.stringify(LOOK)},`,
|
|
751
|
+
' "parts": [',
|
|
752
|
+
parts.map((part) => ` ${JSON.stringify(part)}`).join(',\n'),
|
|
753
|
+
' ]',
|
|
754
|
+
'}',
|
|
755
|
+
'',
|
|
756
|
+
];
|
|
757
|
+
fs.writeFileSync(path.join(MODEL_DIR, `avatar-${index}.pxmodel`), lines.join('\n'));
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
fs.mkdirSync(MODEL_DIR, { recursive: true });
|
|
761
|
+
fs.mkdirSync(ART_DIR, { recursive: true });
|
|
762
|
+
[mascot, kai, mimi, nox].forEach((make, index) => write(index, make()));
|
|
763
|
+
// A sprite this set no longer draws goes; nothing else in the folder is touched.
|
|
764
|
+
for (const entry of fs.readdirSync(ART_DIR, { withFileTypes: true })) {
|
|
765
|
+
if (entry.isFile() && entry.name.endsWith('.sprite') && !sprites.has(entry.name)) {
|
|
766
|
+
fs.rmSync(path.join(ART_DIR, entry.name));
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
for (const [file, text] of sprites) {
|
|
770
|
+
fs.writeFileSync(path.join(ART_DIR, file), text);
|
|
771
|
+
}
|