@digitalcanopy/assets 0.1.0 → 1.1.0

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.
Files changed (42) hide show
  1. package/README.md +55 -0
  2. package/dist/catalog/index.d.mts +94 -0
  3. package/dist/catalog/index.d.ts +94 -0
  4. package/dist/catalog/index.js +540 -0
  5. package/dist/catalog/index.mjs +30 -0
  6. package/dist/chunk-BUUV7WRE.mjs +502 -0
  7. package/dist/chunk-CIMJYYCP.mjs +3612 -0
  8. package/dist/chunk-FECYZWQ6.mjs +278 -0
  9. package/dist/chunk-MFWLT2XV.mjs +47 -0
  10. package/dist/index.d.mts +5 -0
  11. package/dist/index.d.ts +5 -0
  12. package/dist/index.js +4483 -0
  13. package/dist/index.mjs +74 -0
  14. package/dist/manifests/index.d.mts +79 -0
  15. package/dist/manifests/index.d.ts +79 -0
  16. package/dist/manifests/index.js +3647 -0
  17. package/dist/manifests/index.mjs +24 -0
  18. package/dist/registry/index.d.mts +98 -0
  19. package/dist/registry/index.d.ts +98 -0
  20. package/dist/registry/index.js +321 -0
  21. package/dist/registry/index.mjs +12 -0
  22. package/dist/resolvers/cdn.d.mts +16 -0
  23. package/dist/resolvers/cdn.d.ts +16 -0
  24. package/dist/resolvers/cdn.js +76 -0
  25. package/dist/resolvers/cdn.mjs +16 -0
  26. package/dist/types-Cy3PZIX4.d.mts +52 -0
  27. package/dist/types-_dmvJ9qx.d.ts +52 -0
  28. package/package.json +32 -11
  29. package/scripts/generate-manifests.mjs +0 -409
  30. package/src/__tests__/manifests.test.ts +0 -129
  31. package/src/__tests__/resolvers.test.ts +0 -55
  32. package/src/__tests__/sync-r2.test.ts +0 -82
  33. package/src/index.ts +0 -2
  34. package/src/manifests/index.ts +0 -81
  35. package/src/manifests/isometric-tiles.atlas.json +0 -592
  36. package/src/manifests/keys.ts +0 -160
  37. package/src/manifests/modular-characters.atlas.json +0 -856
  38. package/src/manifests/playing-cards.atlas.json +0 -1408
  39. package/src/manifests/ui-sprites.atlas.json +0 -568
  40. package/src/resolvers/index.ts +0 -62
  41. package/tsconfig.build.json +0 -12
  42. package/tsconfig.json +0 -20
@@ -0,0 +1,52 @@
1
+ import { SpriteBounds, AnchorPoint } from './manifests/index.mjs';
2
+
3
+ /**
4
+ * Standard metadata shape stored in catalog.assets (PostgreSQL JSONB).
5
+ */
6
+ interface CatalogAssetMetadata {
7
+ format?: 'png' | 'svg' | 'ogg' | 'wav' | 'mp3' | string;
8
+ width?: number;
9
+ height?: number;
10
+ license?: string;
11
+ layer?: string;
12
+ duration_ms?: number;
13
+ radius?: number;
14
+ restitution?: number;
15
+ frame?: SpriteBounds;
16
+ anchor?: AnchorPoint;
17
+ pack?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Universal Game Asset Catalog Record.
22
+ * Represents a row in the catalog.assets PostgreSQL table.
23
+ */
24
+ interface CatalogAsset {
25
+ id?: string;
26
+ app_scope: CatalogAppScope;
27
+ category: CatalogCategory;
28
+ asset_key: string;
29
+ cdn_url: string;
30
+ metadata: CatalogAssetMetadata;
31
+ created_at?: string;
32
+ }
33
+ /**
34
+ * Direct mapping to raw catalog.assets database row.
35
+ */
36
+ interface CatalogAssetRow {
37
+ id: string;
38
+ app_scope: string;
39
+ category: string;
40
+ asset_key: string;
41
+ cdn_url: string;
42
+ metadata: Record<string, unknown>;
43
+ created_at: string;
44
+ }
45
+ type CatalogAssetInsert = Omit<CatalogAsset, 'id' | 'created_at'> & {
46
+ id?: string;
47
+ };
48
+ type CatalogAssetUpdate = Partial<Omit<CatalogAsset, 'id' | 'created_at'>>;
49
+ type CatalogAppScope = 'avatar-studio' | 'critterverse' | 'wsw' | 'puk-huk' | 'cozy' | 'all' | (string & {});
50
+ type CatalogCategory = 'avatar_base' | 'avatar_hair' | 'avatar_eyes' | 'avatar_mouth' | 'avatar_outfit' | 'avatar_hat' | 'avatar_accessory' | 'avatar_frame' | 'critter_head' | 'critter_body' | 'critter_limbs' | 'critter_wings' | 'critter_tail' | 'critter_horns' | 'card_back' | 'card_face' | 'physics_puck' | 'physics_bumper' | 'isometric_building' | 'isometric_tile' | 'particle_fx' | 'ui_audio' | 'impact_audio' | (string & {});
51
+
52
+ export type { CatalogAppScope as C, CatalogAsset as a, CatalogAssetInsert as b, CatalogAssetMetadata as c, CatalogAssetRow as d, CatalogAssetUpdate as e, CatalogCategory as f };
@@ -0,0 +1,52 @@
1
+ import { SpriteBounds, AnchorPoint } from './manifests/index.js';
2
+
3
+ /**
4
+ * Standard metadata shape stored in catalog.assets (PostgreSQL JSONB).
5
+ */
6
+ interface CatalogAssetMetadata {
7
+ format?: 'png' | 'svg' | 'ogg' | 'wav' | 'mp3' | string;
8
+ width?: number;
9
+ height?: number;
10
+ license?: string;
11
+ layer?: string;
12
+ duration_ms?: number;
13
+ radius?: number;
14
+ restitution?: number;
15
+ frame?: SpriteBounds;
16
+ anchor?: AnchorPoint;
17
+ pack?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Universal Game Asset Catalog Record.
22
+ * Represents a row in the catalog.assets PostgreSQL table.
23
+ */
24
+ interface CatalogAsset {
25
+ id?: string;
26
+ app_scope: CatalogAppScope;
27
+ category: CatalogCategory;
28
+ asset_key: string;
29
+ cdn_url: string;
30
+ metadata: CatalogAssetMetadata;
31
+ created_at?: string;
32
+ }
33
+ /**
34
+ * Direct mapping to raw catalog.assets database row.
35
+ */
36
+ interface CatalogAssetRow {
37
+ id: string;
38
+ app_scope: string;
39
+ category: string;
40
+ asset_key: string;
41
+ cdn_url: string;
42
+ metadata: Record<string, unknown>;
43
+ created_at: string;
44
+ }
45
+ type CatalogAssetInsert = Omit<CatalogAsset, 'id' | 'created_at'> & {
46
+ id?: string;
47
+ };
48
+ type CatalogAssetUpdate = Partial<Omit<CatalogAsset, 'id' | 'created_at'>>;
49
+ type CatalogAppScope = 'avatar-studio' | 'critterverse' | 'wsw' | 'puk-huk' | 'cozy' | 'all' | (string & {});
50
+ type CatalogCategory = 'avatar_base' | 'avatar_hair' | 'avatar_eyes' | 'avatar_mouth' | 'avatar_outfit' | 'avatar_hat' | 'avatar_accessory' | 'avatar_frame' | 'critter_head' | 'critter_body' | 'critter_limbs' | 'critter_wings' | 'critter_tail' | 'critter_horns' | 'card_back' | 'card_face' | 'physics_puck' | 'physics_bumper' | 'isometric_building' | 'isometric_tile' | 'particle_fx' | 'ui_audio' | 'impact_audio' | (string & {});
51
+
52
+ export type { CatalogAppScope as C, CatalogAsset as a, CatalogAssetInsert as b, CatalogAssetMetadata as c, CatalogAssetRow as d, CatalogAssetUpdate as e, CatalogCategory as f };
package/package.json CHANGED
@@ -1,34 +1,55 @@
1
1
  {
2
2
  "name": "@digitalcanopy/assets",
3
- "version": "0.1.0",
4
- "main": "./src/index.ts",
5
- "types": "./src/index.ts",
3
+ "version": "1.1.0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
6
11
  "publishConfig": {
7
12
  "access": "public"
8
13
  },
9
14
  "exports": {
10
15
  ".": {
11
- "types": "./src/index.ts",
12
- "default": "./src/index.ts"
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.mjs",
18
+ "require": "./dist/index.js"
13
19
  },
14
20
  "./manifests": {
15
- "types": "./src/manifests/index.ts",
16
- "default": "./src/manifests/index.ts"
21
+ "types": "./dist/manifests/index.d.ts",
22
+ "import": "./dist/manifests/index.mjs",
23
+ "require": "./dist/manifests/index.js"
17
24
  },
18
25
  "./resolvers": {
19
- "types": "./src/resolvers/index.ts",
20
- "default": "./src/resolvers/index.ts"
26
+ "types": "./dist/resolvers/cdn.d.ts",
27
+ "import": "./dist/resolvers/cdn.mjs",
28
+ "require": "./dist/resolvers/cdn.js"
29
+ },
30
+ "./catalog": {
31
+ "types": "./dist/catalog/index.d.ts",
32
+ "import": "./dist/catalog/index.mjs",
33
+ "require": "./dist/catalog/index.js"
34
+ },
35
+ "./registry": {
36
+ "types": "./dist/registry/index.d.ts",
37
+ "import": "./dist/registry/index.mjs",
38
+ "require": "./dist/registry/index.js"
21
39
  }
22
40
  },
23
41
  "scripts": {
24
- "build": "tsc -p tsconfig.build.json",
42
+ "build": "tsup src/index.ts src/manifests/index.ts src/resolvers/cdn.ts src/catalog/index.ts src/registry/index.ts --dts --format cjs,esm",
25
43
  "typecheck": "tsc --noEmit",
26
44
  "test": "vitest run",
27
- "test:boundaries": "vitest run"
45
+ "test:boundaries": "vitest run",
46
+ "test:tarball": "node scripts/smoke-test-tarball.mjs",
47
+ "test:hot-swap": "node scripts/verify-hot-swap.mjs"
28
48
  },
29
49
  "devDependencies": {
30
50
  "@types/pngjs": "^6.0.5",
31
51
  "pngjs": "^7.0.0",
52
+ "tsup": "^8.5.1",
32
53
  "typescript": "^5.7.3",
33
54
  "vitest": "^3.0.5"
34
55
  }
@@ -1,409 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { PNG } from 'pngjs';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- const MANIFESTS_DIR = path.resolve(__dirname, '../src/manifests');
10
- const DIST_ATLASES_DIR = path.resolve(__dirname, '../dist/atlases');
11
-
12
- if (!fs.existsSync(MANIFESTS_DIR)) {
13
- fs.mkdirSync(MANIFESTS_DIR, { recursive: true });
14
- }
15
-
16
- export function calculateMaxBottom(frames) {
17
- const values = Object.values(frames);
18
- if (values.length === 0) return 0;
19
- return Math.max(...values.map((f) => f.frame.y + f.frame.h));
20
- }
21
-
22
- export function calculateMaxRight(frames) {
23
- const values = Object.values(frames);
24
- if (values.length === 0) return 0;
25
- return Math.max(...values.map((f) => f.frame.x + f.frame.w));
26
- }
27
-
28
- /**
29
- * Creates an actual, valid PNG atlas image buffer corresponding to the manifest layout.
30
- * If source sprites exist in spritesDir, composites them onto the canvas.
31
- * Otherwise, generates an accurate framed canvas with pixel-matching dimensions.
32
- */
33
- export function createAtlasPng(manifest, spritesDir = null) {
34
- const { w, h } = manifest.meta.size;
35
- const atlas = new PNG({ width: w, height: h });
36
-
37
- for (const [key, frameData] of Object.entries(manifest.frames)) {
38
- const { x, y, w: fw, h: fh } = frameData.frame;
39
- let composited = false;
40
-
41
- if (spritesDir && fs.existsSync(spritesDir)) {
42
- const candidates = [
43
- path.join(spritesDir, `${key}.png`),
44
- path.join(spritesDir, key.replace(/^char-[a-z]+-/, '') + '.png'),
45
- path.join(spritesDir, key.replace(/^tile-isometric-/, '') + '.png'),
46
- path.join(spritesDir, key.replace(/^button-/, '') + '.png'),
47
- ];
48
- for (const candidate of candidates) {
49
- if (fs.existsSync(candidate)) {
50
- try {
51
- const spritePng = PNG.sync.read(fs.readFileSync(candidate));
52
- PNG.bitblt(
53
- spritePng,
54
- atlas,
55
- 0,
56
- 0,
57
- Math.min(fw, spritePng.width),
58
- Math.min(fh, spritePng.height),
59
- x,
60
- y
61
- );
62
- composited = true;
63
- break;
64
- } catch {
65
- // fallback to rendered frame
66
- }
67
- }
68
- }
69
- }
70
-
71
- if (!composited) {
72
- // Draw crisp frame boundaries so the generated sheet is visually inspectable
73
- for (let px = 0; px < fw; px++) {
74
- for (let py = 0; py < fh; py++) {
75
- const idx = ((y + py) * w + (x + px)) << 2;
76
- const isBorder = px === 0 || px === fw - 1 || py === 0 || py === fh - 1;
77
- if (isBorder) {
78
- atlas.data[idx] = 180;
79
- atlas.data[idx + 1] = 190;
80
- atlas.data[idx + 2] = 210;
81
- atlas.data[idx + 3] = 255;
82
- } else {
83
- atlas.data[idx] = 25;
84
- atlas.data[idx + 1] = 30;
85
- atlas.data[idx + 2] = 40;
86
- atlas.data[idx + 3] = 230;
87
- }
88
- }
89
- }
90
- }
91
- }
92
-
93
- return PNG.sync.write(atlas);
94
- }
95
-
96
- // ─── 1. Playing Cards Atlas ──────────────────────────────────────────────────
97
- const SUITS = ['spades', 'hearts', 'clubs', 'diamonds'];
98
- const VALUES = ['a', '02', '03', '04', '05', '06', '07', '08', '09', '10', 'j', 'q', 'k'];
99
- const CARDBACKS = ['blue', 'red', 'green', 'yellow', 'cyan', 'default'];
100
-
101
- const playingCardFrames = {};
102
- const playingCardKeys = [];
103
-
104
- let cardX = 0;
105
- let cardY = 0;
106
- const CARD_W = 140;
107
- const CARD_H = 190;
108
- const ATLAS_MAX_W = 2048;
109
-
110
- for (const suit of SUITS) {
111
- for (const val of VALUES) {
112
- const key = `card-${suit}-${val}`;
113
- playingCardKeys.push(key);
114
- playingCardFrames[key] = {
115
- frame: { x: cardX, y: cardY, w: CARD_W, h: CARD_H },
116
- rotated: false,
117
- trimmed: false,
118
- spriteSourceSize: { x: 0, y: 0, w: CARD_W, h: CARD_H },
119
- sourceSize: { w: CARD_W, h: CARD_H },
120
- anchor: { ax: 0.5, ay: 0.5 },
121
- };
122
- cardX += CARD_W;
123
- if (cardX + CARD_W > ATLAS_MAX_W) {
124
- cardX = 0;
125
- cardY += CARD_H;
126
- }
127
- }
128
- }
129
-
130
- for (const back of CARDBACKS) {
131
- const key = `cardback-${back}`;
132
- playingCardKeys.push(key);
133
- playingCardFrames[key] = {
134
- frame: { x: cardX, y: cardY, w: CARD_W, h: CARD_H },
135
- rotated: false,
136
- trimmed: false,
137
- spriteSourceSize: { x: 0, y: 0, w: CARD_W, h: CARD_H },
138
- sourceSize: { w: CARD_W, h: CARD_H },
139
- anchor: { ax: 0.5, ay: 0.5 },
140
- };
141
- cardX += CARD_W;
142
- if (cardX + CARD_W > ATLAS_MAX_W) {
143
- cardX = 0;
144
- cardY += CARD_H;
145
- }
146
- }
147
-
148
- const playingCardsAtlas = {
149
- meta: {
150
- app: 'sunshade-atlas-pipeline',
151
- version: '1.0.0',
152
- image: 'https://cdn.sunshade.icu/assets/kenney/cards/playing-cards-atlas.png',
153
- format: 'RGBA8888',
154
- size: { w: ATLAS_MAX_W, h: calculateMaxBottom(playingCardFrames) },
155
- scale: '1',
156
- pack: 'playing-cards',
157
- },
158
- frames: playingCardFrames,
159
- };
160
-
161
- // ─── 2. Isometric Tiles Atlas ────────────────────────────────────────────────
162
- const ISO_TILE_NAMES = [
163
- 'tile-isometric-grass',
164
- 'tile-isometric-dirt',
165
- 'tile-isometric-stone',
166
- 'tile-isometric-water',
167
- 'tile-isometric-sand',
168
- 'tile-isometric-wood-floor',
169
- 'tile-isometric-dungeon-floor',
170
- 'tile-isometric-wall-stone',
171
- 'tile-isometric-wall-wood',
172
- 'tile-isometric-wall-corner',
173
- 'tile-isometric-stairs-stone',
174
- 'tile-isometric-stairs-wood',
175
- 'tile-isometric-door-closed',
176
- 'tile-isometric-door-open',
177
- 'tile-isometric-chest-closed',
178
- 'tile-isometric-chest-open',
179
- 'tile-isometric-barrel',
180
- 'tile-isometric-crate',
181
- 'tile-isometric-bookshelf',
182
- 'tile-isometric-table',
183
- 'tile-isometric-chair',
184
- 'tile-isometric-pillar',
185
- 'tile-isometric-torch',
186
- 'tile-isometric-rug',
187
- ];
188
-
189
- const isoFrames = {};
190
- let isoX = 0;
191
- let isoY = 0;
192
- const ISO_W = 256;
193
- const ISO_H = 128;
194
-
195
- for (const tile of ISO_TILE_NAMES) {
196
- isoFrames[tile] = {
197
- frame: { x: isoX, y: isoY, w: ISO_W, h: ISO_H },
198
- rotated: false,
199
- trimmed: false,
200
- spriteSourceSize: { x: 0, y: 0, w: ISO_W, h: ISO_H },
201
- sourceSize: { w: ISO_W, h: ISO_H },
202
- anchor: { ax: 0.5, ay: 0.75 },
203
- };
204
- isoX += ISO_W;
205
- if (isoX + ISO_W > ATLAS_MAX_W) {
206
- isoX = 0;
207
- isoY += ISO_H;
208
- }
209
- }
210
-
211
- const isometricAtlas = {
212
- meta: {
213
- app: 'sunshade-atlas-pipeline',
214
- version: '1.0.0',
215
- image: 'https://cdn.sunshade.icu/assets/kenney/isometric-miniature-dungeon/isometric-tiles-atlas.png',
216
- format: 'RGBA8888',
217
- size: { w: ATLAS_MAX_W, h: calculateMaxBottom(isoFrames) },
218
- scale: '1',
219
- pack: 'isometric-tiles',
220
- },
221
- frames: isoFrames,
222
- };
223
-
224
- // ─── 3. Modular Characters Atlas ─────────────────────────────────────────────
225
- const CHAR_CATEGORIES = {
226
- face: ['face-0', 'face-1', 'face-2', 'face-3', 'face-4', 'face-5', 'face-6', 'face-7'],
227
- hair: ['hair-blonde-0', 'hair-blonde-1', 'hair-brown-0', 'hair-brown-1', 'hair-black-0', 'hair-black-1', 'hair-red-0'],
228
- pants: ['pants-blue-0', 'pants-blue-1', 'pants-green-0', 'pants-red-0', 'pants-black-0', 'pants-white-0'],
229
- shirts: ['shirt-blue-0', 'shirt-blue-1', 'shirt-green-0', 'shirt-red-0', 'shirt-black-0', 'shirt-white-0'],
230
- shoes: ['shoes-brown-0', 'shoes-black-0', 'shoes-white-0', 'shoes-red-0'],
231
- skin: ['skin-beige-0', 'skin-brown-0', 'skin-dark-0', 'skin-light-0'],
232
- };
233
-
234
- const charFrames = {};
235
- const charKeys = [];
236
- let charX = 0;
237
- let charY = 0;
238
- const CHAR_W = 128;
239
- const CHAR_H = 128;
240
-
241
- for (const [cat, items] of Object.entries(CHAR_CATEGORIES)) {
242
- for (const item of items) {
243
- const key = `char-${cat}-${item}`;
244
- charKeys.push(key);
245
- charFrames[key] = {
246
- frame: { x: charX, y: charY, w: CHAR_W, h: CHAR_H },
247
- rotated: false,
248
- trimmed: false,
249
- spriteSourceSize: { x: 0, y: 0, w: CHAR_W, h: CHAR_H },
250
- sourceSize: { w: CHAR_W, h: CHAR_H },
251
- anchor: { ax: 0.5, ay: 0.5 },
252
- };
253
- charX += CHAR_W;
254
- if (charX + CHAR_W > ATLAS_MAX_W) {
255
- charX = 0;
256
- charY += CHAR_H;
257
- }
258
- }
259
- }
260
-
261
- const charactersAtlas = {
262
- meta: {
263
- app: 'sunshade-atlas-pipeline',
264
- version: '1.0.0',
265
- image: 'https://cdn.sunshade.icu/assets/kenney/modular-characters/modular-characters-atlas.png',
266
- format: 'RGBA8888',
267
- size: { w: ATLAS_MAX_W, h: calculateMaxBottom(charFrames) },
268
- scale: '1',
269
- pack: 'modular-characters',
270
- },
271
- frames: charFrames,
272
- };
273
-
274
- // ─── 4. UI Sprites Atlas ─────────────────────────────────────────────────────
275
- const UI_SPRITE_NAMES = [
276
- 'button-default',
277
- 'button-hover',
278
- 'button-pressed',
279
- 'button-disabled',
280
- 'button-round-blue',
281
- 'button-round-green',
282
- 'button-round-red',
283
- 'button-round-yellow',
284
- 'panel-wooden',
285
- 'panel-metal',
286
- 'panel-glass',
287
- 'icon-checkmark',
288
- 'icon-cross',
289
- 'icon-arrow-up',
290
- 'icon-arrow-down',
291
- 'icon-arrow-left',
292
- 'icon-arrow-right',
293
- 'icon-settings',
294
- 'icon-star',
295
- 'slider-bar',
296
- 'slider-knob',
297
- 'bar-progress-bg',
298
- 'bar-progress-fill',
299
- ];
300
-
301
- const uiFrames = {};
302
- let uiX = 0;
303
- let uiY = 0;
304
- const UI_W = 128;
305
- const UI_H = 128;
306
-
307
- for (const sprite of UI_SPRITE_NAMES) {
308
- uiFrames[sprite] = {
309
- frame: { x: uiX, y: uiY, w: UI_W, h: UI_H },
310
- rotated: false,
311
- trimmed: false,
312
- spriteSourceSize: { x: 0, y: 0, w: UI_W, h: UI_H },
313
- sourceSize: { w: UI_W, h: UI_H },
314
- anchor: { ax: 0.5, ay: 0.5 },
315
- };
316
- uiX += UI_W;
317
- if (uiX + UI_W > ATLAS_MAX_W) {
318
- uiX = 0;
319
- uiY += UI_H;
320
- }
321
- }
322
-
323
- const uiAtlas = {
324
- meta: {
325
- app: 'sunshade-atlas-pipeline',
326
- version: '1.0.0',
327
- image: 'https://cdn.sunshade.icu/assets/kenney/ui-pack/ui-sprites-atlas.png',
328
- format: 'RGBA8888',
329
- size: { w: ATLAS_MAX_W, h: calculateMaxBottom(uiFrames) },
330
- scale: '1',
331
- pack: 'ui-sprites',
332
- },
333
- frames: uiFrames,
334
- };
335
-
336
- // ─── 5. Generator Function ──────────────────────────────────────────────────
337
- export function generateAllManifests(options = {}) {
338
- const manifestsDir = options.manifestsDir || MANIFESTS_DIR;
339
- const generateImages = options.generateImages ?? true;
340
- const imagesDir = options.imagesDir || DIST_ATLASES_DIR;
341
-
342
- if (!fs.existsSync(manifestsDir)) {
343
- fs.mkdirSync(manifestsDir, { recursive: true });
344
- }
345
-
346
- const manifests = [
347
- { name: 'playing-cards.atlas.json', imageName: 'playing-cards-atlas.png', data: playingCardsAtlas },
348
- { name: 'isometric-tiles.atlas.json', imageName: 'isometric-tiles-atlas.png', data: isometricAtlas },
349
- { name: 'modular-characters.atlas.json', imageName: 'modular-characters-atlas.png', data: charactersAtlas },
350
- { name: 'ui-sprites.atlas.json', imageName: 'ui-sprites-atlas.png', data: uiAtlas },
351
- ];
352
-
353
- for (const item of manifests) {
354
- fs.writeFileSync(
355
- path.join(manifestsDir, item.name),
356
- JSON.stringify(item.data, null, 2),
357
- 'utf-8'
358
- );
359
- }
360
-
361
- const keysTsContent = `/**
362
- * Autocomplete Key Definitions and Constants for Kenney Asset Packs
363
- * Generated by sunshade-atlas-pipeline
364
- */
365
-
366
- export const PLAYING_CARDS = ${JSON.stringify(playingCardKeys, null, 2)} as const;
367
- export type PlayingCardKey = (typeof PLAYING_CARDS)[number];
368
-
369
- export const ISOMETRIC_TILES = ${JSON.stringify(ISO_TILE_NAMES, null, 2)} as const;
370
- export type IsometricTileKey = (typeof ISOMETRIC_TILES)[number];
371
-
372
- export const MODULAR_CHARACTERS = ${JSON.stringify(charKeys, null, 2)} as const;
373
- export type ModularCharacterKey = (typeof MODULAR_CHARACTERS)[number];
374
-
375
- export const UI_SPRITES = ${JSON.stringify(UI_SPRITE_NAMES, null, 2)} as const;
376
- export type UiSpriteKey = (typeof UI_SPRITES)[number];
377
- `;
378
-
379
- fs.writeFileSync(path.join(manifestsDir, 'keys.ts'), keysTsContent, 'utf-8');
380
-
381
- if (generateImages) {
382
- if (!fs.existsSync(imagesDir)) {
383
- fs.mkdirSync(imagesDir, { recursive: true });
384
- }
385
- for (const item of manifests) {
386
- const buffer = createAtlasPng(item.data, options.spritesDir);
387
- fs.writeFileSync(path.join(imagesDir, item.imageName), buffer);
388
- }
389
- console.log(`🖼️ Generated ${manifests.length} atlas PNG sheets in ${imagesDir}`);
390
- }
391
-
392
- return { manifests, keysCount: playingCardKeys.length + ISO_TILE_NAMES.length + charKeys.length + UI_SPRITE_NAMES.length };
393
- }
394
-
395
- // ─── CLI Execution ───────────────────────────────────────────────────────────
396
- if (process.argv[1] === fileURLToPath(import.meta.url)) {
397
- try {
398
- const res = generateAllManifests();
399
- console.log('✅ Generated lightweight atlas manifests:');
400
- console.log(' - playing-cards.atlas.json');
401
- console.log(' - isometric-tiles.atlas.json');
402
- console.log(' - modular-characters.atlas.json');
403
- console.log(' - ui-sprites.atlas.json');
404
- console.log(' - keys.ts (with strict TypeScript types & constants)\n');
405
- } catch (err) {
406
- console.error('❌ Manifest generation failed:', err);
407
- process.exitCode = 1;
408
- }
409
- }