@digitalcanopy/assets 0.0.0-stage → 0.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.
- package/README.md +45 -2
- package/package.json +33 -4
- package/scripts/generate-manifests.mjs +409 -0
- package/src/__tests__/manifests.test.ts +129 -0
- package/src/__tests__/resolvers.test.ts +55 -0
- package/src/__tests__/sync-r2.test.ts +82 -0
- package/src/index.ts +2 -0
- package/src/manifests/index.ts +81 -0
- package/src/manifests/isometric-tiles.atlas.json +592 -0
- package/src/manifests/keys.ts +160 -0
- package/src/manifests/modular-characters.atlas.json +856 -0
- package/src/manifests/playing-cards.atlas.json +1408 -0
- package/src/manifests/ui-sprites.atlas.json +568 -0
- package/src/resolvers/index.ts +62 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
validateTaxonomyPath,
|
|
7
|
+
runSync,
|
|
8
|
+
verifyCdnEndpoint,
|
|
9
|
+
} from '../../../../scripts/sync-kenney-r2.mjs';
|
|
10
|
+
|
|
11
|
+
describe('Cloudflare R2 Taxonomy Validation', () => {
|
|
12
|
+
let tempFixtureDir: string;
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
tempFixtureDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kenney-test-fixtures-'));
|
|
16
|
+
const cardsPack = path.join(tempFixtureDir, 'kenney_cards');
|
|
17
|
+
const charPack = path.join(tempFixtureDir, 'kenney_modular-characters');
|
|
18
|
+
|
|
19
|
+
fs.mkdirSync(cardsPack, { recursive: true });
|
|
20
|
+
fs.mkdirSync(charPack, { recursive: true });
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync(path.join(cardsPack, 'spades_10.png'), 'fake-png-data');
|
|
23
|
+
fs.writeFileSync(path.join(charPack, 'base_01.png'), 'fake-png-data');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
if (tempFixtureDir && fs.existsSync(tempFixtureDir)) {
|
|
28
|
+
fs.rmSync(tempFixtureDir, { recursive: true, force: true });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('accepts valid modular character paths', () => {
|
|
33
|
+
const res = validateTaxonomyPath('assets/kenney/modular-characters/base_01.png');
|
|
34
|
+
expect(res.valid).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('accepts valid playing card paths', () => {
|
|
38
|
+
const res = validateTaxonomyPath('assets/kenney/cards/spades_10.png');
|
|
39
|
+
expect(res.valid).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('accepts valid UI audio paths', () => {
|
|
43
|
+
const res = validateTaxonomyPath('assets/kenney/ui-pack/sounds/click-a.ogg');
|
|
44
|
+
expect(res.valid).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('rejects keys without assets/kenney/ prefix', () => {
|
|
48
|
+
const res = validateTaxonomyPath('other/path/image.png');
|
|
49
|
+
expect(res.valid).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('handles dry-run mode without invoking remote uploader', async () => {
|
|
53
|
+
const mockUploader = vi.fn();
|
|
54
|
+
const res = await runSync({ dryRun: true, sourceDir: tempFixtureDir, uploader: mockUploader });
|
|
55
|
+
expect(mockUploader).not.toHaveBeenCalled();
|
|
56
|
+
expect(res.success).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('invokes uploader for each validated file in active mode', async () => {
|
|
60
|
+
const uploadedKeys: string[] = [];
|
|
61
|
+
const mockUploader = vi.fn((bucket, key) => {
|
|
62
|
+
uploadedKeys.push(key);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const res = await runSync({ dryRun: false, sourceDir: tempFixtureDir, uploader: mockUploader });
|
|
66
|
+
expect(res.success).toBe(true);
|
|
67
|
+
expect(mockUploader).toHaveBeenCalled();
|
|
68
|
+
expect(uploadedKeys.length).toBe(2);
|
|
69
|
+
expect(uploadedKeys).toContain('assets/kenney/cards/spades_10.png');
|
|
70
|
+
expect(uploadedKeys).toContain('assets/kenney/modular-characters/base_01.png');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('propagates errors and aborts when uploader fails', async () => {
|
|
74
|
+
const failingUploader = vi.fn(() => {
|
|
75
|
+
throw new Error('R2 write permission denied');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await expect(
|
|
79
|
+
runSync({ dryRun: false, sourceDir: tempFixtureDir, uploader: failingUploader })
|
|
80
|
+
).rejects.toThrow('R2 write permission denied');
|
|
81
|
+
});
|
|
82
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import playingCardsAtlasJson from './playing-cards.atlas.json';
|
|
2
|
+
import isometricTilesAtlasJson from './isometric-tiles.atlas.json';
|
|
3
|
+
import modularCharactersAtlasJson from './modular-characters.atlas.json';
|
|
4
|
+
import uiSpritesAtlasJson from './ui-sprites.atlas.json';
|
|
5
|
+
|
|
6
|
+
export * from './keys';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Atlas and Sprite Sheet Coordinate Specifications
|
|
10
|
+
* Compatible with Flame (Flutter) and HTML5 Canvas / Pixi / WebGL
|
|
11
|
+
*/
|
|
12
|
+
export interface SpriteBounds {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
w: number;
|
|
16
|
+
h: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AnchorPoint {
|
|
20
|
+
ax: number;
|
|
21
|
+
ay: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AtlasFrame {
|
|
25
|
+
frame: SpriteBounds;
|
|
26
|
+
rotated?: boolean;
|
|
27
|
+
trimmed?: boolean;
|
|
28
|
+
spriteSourceSize?: SpriteBounds;
|
|
29
|
+
sourceSize?: { w: number; h: number };
|
|
30
|
+
anchor?: AnchorPoint;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AtlasManifest {
|
|
34
|
+
meta: {
|
|
35
|
+
app: string;
|
|
36
|
+
version: string;
|
|
37
|
+
image: string;
|
|
38
|
+
format: string;
|
|
39
|
+
size: { w: number; h: number };
|
|
40
|
+
scale: string;
|
|
41
|
+
pack: string;
|
|
42
|
+
};
|
|
43
|
+
frames: Record<string, AtlasFrame>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AssetManifestMetadata {
|
|
47
|
+
pack_id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
category: string;
|
|
50
|
+
license: string;
|
|
51
|
+
total_assets: number;
|
|
52
|
+
cdn_base: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const playingCardsAtlas = playingCardsAtlasJson as AtlasManifest;
|
|
56
|
+
export const isometricTilesAtlas = isometricTilesAtlasJson as AtlasManifest;
|
|
57
|
+
export const modularCharactersAtlas = modularCharactersAtlasJson as AtlasManifest;
|
|
58
|
+
export const uiSpritesAtlas = uiSpritesAtlasJson as AtlasManifest;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves frame coordinate data from an atlas manifest.
|
|
62
|
+
*/
|
|
63
|
+
export function getFrameCoordinates(
|
|
64
|
+
manifest: AtlasManifest,
|
|
65
|
+
frameKey: string
|
|
66
|
+
): AtlasFrame | undefined {
|
|
67
|
+
return manifest.frames[frameKey];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Formats coordinates for Flame (Flutter) SpriteComponent.fromFrame data mapping.
|
|
72
|
+
*/
|
|
73
|
+
export function toFlameSpriteData(manifest: AtlasManifest, frameKey: string) {
|
|
74
|
+
const frameData = manifest.frames[frameKey];
|
|
75
|
+
if (!frameData) return null;
|
|
76
|
+
return {
|
|
77
|
+
srcPosition: [frameData.frame.x, frameData.frame.y] as [number, number],
|
|
78
|
+
srcSize: [frameData.frame.w, frameData.frame.h] as [number, number],
|
|
79
|
+
anchor: [frameData.anchor?.ax ?? 0.5, frameData.anchor?.ay ?? 0.5] as [number, number],
|
|
80
|
+
};
|
|
81
|
+
}
|