@digitalcanopy/assets 0.0.0-stage → 1.0.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.
package/README.md CHANGED
@@ -1,3 +1,46 @@
1
- # Temporary Holding Version
1
+ # @digitalcanopy/assets
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Decoupled game and application asset ecosystem for SunShade & Digital Canopy. Hosts zero binary media in repositories, resolving images and audio through Cloudflare R2 edge CDN and providing lightweight Flame/WebGL JSON sprite manifests with strict TypeScript autocomplete keys.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @digitalcanopy/assets
9
+ # or
10
+ yarn add @digitalcanopy/assets
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **Zero-Binary Repository Hygiene**: Eliminates multi-megabyte PNG, SVG, WAV, and OGG binaries from client git repos.
16
+ - **CDN URL Resolvers**: Fast edge URL generation targeting `https://cdn.sunshade.icu/assets/kenney/` with immutable caching headers.
17
+ - `getKenneyAssetUrl(pack, path, extension)`
18
+ - `getKenneyCardUrl(cardKey, extension)`
19
+ - `getKenneyCharacterUrl(category, itemKey, extension)`
20
+ - `getKenneyAudioUrl(soundName, extension)`
21
+ - **Flame & WebGL Atlas Manifests**:
22
+ - `playingCardsAtlas`: 52 face cards + 6 card back variations (140x190 frames).
23
+ - `isometricTilesAtlas`: 24 2.5D isometric tiles with pivot anchors `(0.5, 0.75)`.
24
+ - `modularCharactersAtlas`: 35 modular avatar components across 6 categories.
25
+ - `uiSpritesAtlas`: 23 UI elements (buttons, panels, icons, progress bars).
26
+ - **Flame Coordinate Converter**: `toFlameSpriteData(manifest, frameKey)` converts manifest entries directly into `[srcPosition, srcSize, anchor]` tuples for Flutter Flame `SpriteComponent.fromFrame`.
27
+ - **Strict TypeScript Keys**: Exported constant arrays and union types (`PLAYING_CARDS`, `ISOMETRIC_TILES`, `MODULAR_CHARACTERS`, `UI_SPRITES`) for IDE autocomplete.
28
+
29
+ ## Usage
30
+
31
+ ```typescript
32
+ import {
33
+ getKenneyCardUrl,
34
+ toFlameSpriteData,
35
+ playingCardsAtlas,
36
+ PLAYING_CARDS,
37
+ } from '@digitalcanopy/assets';
38
+
39
+ // Resolve asset URL directly from edge CDN
40
+ const cardUrl = getKenneyCardUrl('card-spades-10');
41
+ // => "https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png"
42
+
43
+ // Map coordinates for Flame engine
44
+ const spriteData = toFlameSpriteData(playingCardsAtlas, 'card-spades-a');
45
+ // => { srcPosition: [0, 0], srcSize: [140, 190], anchor: [0.5, 0.5] }
46
+ ```
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@digitalcanopy/assets",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js"
15
+ },
16
+ "./manifests": {
17
+ "types": "./dist/manifests/index.d.ts",
18
+ "import": "./dist/manifests/index.mjs",
19
+ "require": "./dist/manifests/index.js"
20
+ },
21
+ "./resolvers": {
22
+ "types": "./dist/resolvers/cdn.d.ts",
23
+ "import": "./dist/resolvers/cdn.mjs",
24
+ "require": "./dist/resolvers/cdn.js"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "tsup src/index.ts src/manifests/index.ts src/resolvers/cdn.ts --dts --format cjs,esm",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "vitest run",
31
+ "test:boundaries": "vitest run"
32
+ },
33
+ "devDependencies": {
34
+ "@types/pngjs": "^6.0.5",
35
+ "pngjs": "^7.0.0",
36
+ "tsup": "^8.5.1",
37
+ "typescript": "^5.7.3",
38
+ "vitest": "^3.0.5"
39
+ }
40
+ }
@@ -0,0 +1,409 @@
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
+ }
@@ -0,0 +1,129 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ playingCardsAtlas,
4
+ isometricTilesAtlas,
5
+ modularCharactersAtlas,
6
+ uiSpritesAtlas,
7
+ getFrameCoordinates,
8
+ toFlameSpriteData,
9
+ PLAYING_CARDS,
10
+ ISOMETRIC_TILES,
11
+ MODULAR_CHARACTERS,
12
+ UI_SPRITES,
13
+ } from '../manifests/index';
14
+
15
+ describe('@digitalcanopy/assets Atlas Manifests', () => {
16
+ describe('Playing Cards Atlas', () => {
17
+ it('has valid metadata and image path', () => {
18
+ expect(playingCardsAtlas.meta.pack).toBe('playing-cards');
19
+ expect(playingCardsAtlas.meta.image).toBe(
20
+ 'https://cdn.sunshade.icu/assets/kenney/cards/playing-cards-atlas.png'
21
+ );
22
+ expect(playingCardsAtlas.meta.size.w).toBe(2048);
23
+ expect(playingCardsAtlas.meta.size.h).toBeGreaterThan(0);
24
+ });
25
+
26
+ it('contains all cards defined in PLAYING_CARDS autocomplete keys', () => {
27
+ expect(Object.keys(playingCardsAtlas.frames).length).toBe(PLAYING_CARDS.length);
28
+ for (const cardKey of PLAYING_CARDS) {
29
+ const frame = playingCardsAtlas.frames[cardKey];
30
+ expect(frame).toBeDefined();
31
+ expect(frame.frame.w).toBe(140);
32
+ expect(frame.frame.h).toBe(190);
33
+ expect(frame.frame.x).toBeGreaterThanOrEqual(0);
34
+ expect(frame.frame.y).toBeGreaterThanOrEqual(0);
35
+ }
36
+ });
37
+ });
38
+
39
+ describe('Isometric Tiles Atlas', () => {
40
+ it('has valid metadata and image path', () => {
41
+ expect(isometricTilesAtlas.meta.pack).toBe('isometric-tiles');
42
+ expect(isometricTilesAtlas.meta.image).toBe(
43
+ 'https://cdn.sunshade.icu/assets/kenney/isometric-miniature-dungeon/isometric-tiles-atlas.png'
44
+ );
45
+ expect(isometricTilesAtlas.meta.size.w).toBe(2048);
46
+ expect(isometricTilesAtlas.meta.size.h).toBe(384);
47
+ });
48
+
49
+ it('contains all isometric tiles defined in ISOMETRIC_TILES keys', () => {
50
+ expect(Object.keys(isometricTilesAtlas.frames).length).toBe(ISOMETRIC_TILES.length);
51
+ for (const tileKey of ISOMETRIC_TILES) {
52
+ const frame = isometricTilesAtlas.frames[tileKey];
53
+ expect(frame).toBeDefined();
54
+ expect(frame.frame.w).toBe(256);
55
+ expect(frame.frame.h).toBe(128);
56
+ expect(frame.anchor).toEqual({ ax: 0.5, ay: 0.75 });
57
+ }
58
+ });
59
+ });
60
+
61
+ describe('Modular Characters Atlas', () => {
62
+ it('has valid metadata and image path', () => {
63
+ expect(modularCharactersAtlas.meta.pack).toBe('modular-characters');
64
+ expect(modularCharactersAtlas.meta.image).toBe(
65
+ 'https://cdn.sunshade.icu/assets/kenney/modular-characters/modular-characters-atlas.png'
66
+ );
67
+ });
68
+
69
+ it('contains all character parts defined in MODULAR_CHARACTERS keys', () => {
70
+ expect(Object.keys(modularCharactersAtlas.frames).length).toBe(MODULAR_CHARACTERS.length);
71
+ for (const charKey of MODULAR_CHARACTERS) {
72
+ const frame = modularCharactersAtlas.frames[charKey];
73
+ expect(frame).toBeDefined();
74
+ expect(frame.frame.w).toBe(128);
75
+ expect(frame.frame.h).toBe(128);
76
+ }
77
+ });
78
+ });
79
+
80
+ describe('UI Sprites Atlas', () => {
81
+ it('has valid metadata and image path', () => {
82
+ expect(uiSpritesAtlas.meta.pack).toBe('ui-sprites');
83
+ expect(uiSpritesAtlas.meta.image).toBe(
84
+ 'https://cdn.sunshade.icu/assets/kenney/ui-pack/ui-sprites-atlas.png'
85
+ );
86
+ });
87
+
88
+ it('contains all UI sprites defined in UI_SPRITES keys', () => {
89
+ expect(Object.keys(uiSpritesAtlas.frames).length).toBe(UI_SPRITES.length);
90
+ for (const uiKey of UI_SPRITES) {
91
+ const frame = uiSpritesAtlas.frames[uiKey];
92
+ expect(frame).toBeDefined();
93
+ expect(frame.frame.w).toBeGreaterThan(0);
94
+ expect(frame.frame.h).toBeGreaterThan(0);
95
+ }
96
+ });
97
+ });
98
+
99
+ describe('Helper Functions', () => {
100
+ it('getFrameCoordinates returns correct frame or undefined', () => {
101
+ const frame = getFrameCoordinates(playingCardsAtlas, 'card-spades-a');
102
+ expect(frame).toBeDefined();
103
+ expect(frame?.frame.x).toBe(0);
104
+ expect(frame?.frame.y).toBe(0);
105
+
106
+ const missing = getFrameCoordinates(playingCardsAtlas, 'non-existent-card');
107
+ expect(missing).toBeUndefined();
108
+ });
109
+
110
+ it('toFlameSpriteData formats flame sprite component coordinates', () => {
111
+ const cardData = toFlameSpriteData(playingCardsAtlas, 'card-spades-a');
112
+ expect(cardData).toEqual({
113
+ srcPosition: [0, 0],
114
+ srcSize: [140, 190],
115
+ anchor: [0.5, 0.5],
116
+ });
117
+
118
+ const tileData = toFlameSpriteData(isometricTilesAtlas, 'tile-isometric-grass');
119
+ expect(tileData).toEqual({
120
+ srcPosition: [0, 0],
121
+ srcSize: [256, 128],
122
+ anchor: [0.5, 0.75],
123
+ });
124
+
125
+ const nullData = toFlameSpriteData(playingCardsAtlas, 'non-existent');
126
+ expect(nullData).toBeNull();
127
+ });
128
+ });
129
+ });