@flighthq/spritesheet 0.1.0 → 0.2.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/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/spritesheetData.d.ts +2 -33
- package/dist/spritesheetData.d.ts.map +1 -1
- package/dist/spritesheetData.js.map +1 -1
- package/package.json +11 -10
- package/dist/spritesheetTimelineSource.d.ts +0 -3
- package/dist/spritesheetTimelineSource.d.ts.map +0 -1
- package/dist/spritesheetTimelineSource.js +0 -38
- package/dist/spritesheetTimelineSource.js.map +0 -1
- package/src/spritesheetTimelineSource.test.ts +0 -60
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,5 @@ export * from './spritesheetData';
|
|
|
4
4
|
export * from './spritesheetFrame';
|
|
5
5
|
export * from './spritesheetFrom';
|
|
6
6
|
export * from './spritesheetPlayer';
|
|
7
|
-
export * from './spritesheetTimelineSource';
|
|
8
7
|
export * from './spritesheetValidation';
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,5 @@ export * from './spritesheetData';
|
|
|
4
4
|
export * from './spritesheetFrame';
|
|
5
5
|
export * from './spritesheetFrom';
|
|
6
6
|
export * from './spritesheetPlayer';
|
|
7
|
-
export * from './spritesheetTimelineSource';
|
|
8
7
|
export * from './spritesheetValidation';
|
|
9
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
3
|
-
direction: SpritesheetAnimationDirection;
|
|
4
|
-
frameDuration: number;
|
|
5
|
-
frameDurations: number[] | null;
|
|
6
|
-
frameNames: string[];
|
|
7
|
-
loop: boolean;
|
|
8
|
-
name: string;
|
|
9
|
-
originX: number;
|
|
10
|
-
originY: number;
|
|
11
|
-
}
|
|
12
|
-
export interface SpritesheetFrameData {
|
|
13
|
-
height: number;
|
|
14
|
-
name: string;
|
|
15
|
-
offsetX: number;
|
|
16
|
-
offsetY: number;
|
|
17
|
-
pivotX: number | null;
|
|
18
|
-
pivotY: number | null;
|
|
19
|
-
rotated: boolean;
|
|
20
|
-
sourceHeight: number;
|
|
21
|
-
sourceWidth: number;
|
|
22
|
-
width: number;
|
|
23
|
-
x: number;
|
|
24
|
-
y: number;
|
|
25
|
-
}
|
|
26
|
-
export interface SpritesheetData {
|
|
27
|
-
animations: SpritesheetAnimationData[];
|
|
28
|
-
frames: SpritesheetFrameData[];
|
|
29
|
-
imageFile: string;
|
|
30
|
-
imageHeight: number;
|
|
31
|
-
imageWidth: number;
|
|
32
|
-
scale: number;
|
|
33
|
-
}
|
|
1
|
+
import type { SpritesheetAnimationData, SpritesheetData, SpritesheetFrameData } from '@flighthq/types';
|
|
2
|
+
export type { SpritesheetAnimationData, SpritesheetData, SpritesheetFrameData };
|
|
34
3
|
export declare function createSpritesheetAnimationData(obj?: Partial<SpritesheetAnimationData>): SpritesheetAnimationData;
|
|
35
4
|
export declare function createSpritesheetData(obj?: Partial<SpritesheetData>): SpritesheetData;
|
|
36
5
|
export declare function createSpritesheetFrameData(obj?: Partial<SpritesheetFrameData>): SpritesheetFrameData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spritesheetData.d.ts","sourceRoot":"","sources":["../src/spritesheetData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"spritesheetData.d.ts","sourceRoot":"","sources":["../src/spritesheetData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAIvG,YAAY,EAAE,wBAAwB,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC;AAEhF,wBAAgB,8BAA8B,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAWhH;AAED,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CASrF;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAepG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spritesheetData.js","sourceRoot":"","sources":["../src/spritesheetData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spritesheetData.js","sourceRoot":"","sources":["../src/spritesheetData.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,8BAA8B,CAAC,GAAuC;IACpF,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,SAAS,IAAI,SAAS;QACtC,aAAa,EAAE,GAAG,EAAE,aAAa,IAAI,GAAG;QACxC,cAAc,EAAE,GAAG,EAAE,cAAc,IAAI,IAAI;QAC3C,UAAU,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE;QACjC,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,IAAI;QACvB,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE;QACrB,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,CAAC;QAC1B,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,CAAC;KAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAA8B;IAClE,OAAO;QACL,UAAU,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE;QACjC,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,EAAE;QACzB,SAAS,EAAE,GAAG,EAAE,SAAS,IAAI,EAAE;QAC/B,WAAW,EAAE,GAAG,EAAE,WAAW,IAAI,CAAC;QAClC,UAAU,EAAE,GAAG,EAAE,UAAU,IAAI,CAAC;QAChC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAmC;IAC5E,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;QACxB,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE;QACrB,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,CAAC;QAC1B,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,CAAC;QAC1B,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,IAAI;QAC3B,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,IAAI;QAC3B,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,KAAK;QAC9B,YAAY,EAAE,GAAG,EAAE,YAAY,IAAI,CAAC;QACpC,WAAW,EAAE,GAAG,EAAE,WAAW,IAAI,CAAC;QAClC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QACtB,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;QACd,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;KACf,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/spritesheet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/flighthq/flight.git",
|
|
7
|
+
"directory": "packages/spritesheet"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
@@ -27,15 +32,11 @@
|
|
|
27
32
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@flighthq/
|
|
31
|
-
"@flighthq/
|
|
32
|
-
"@flighthq/
|
|
33
|
-
"@flighthq/
|
|
34
|
-
"@flighthq/
|
|
35
|
-
"@flighthq/signals": "0.1.0",
|
|
36
|
-
"@flighthq/textureatlas": "0.1.0",
|
|
37
|
-
"@flighthq/tileset": "0.1.0",
|
|
38
|
-
"@flighthq/types": "0.1.0"
|
|
35
|
+
"@flighthq/entity": "0.2.0",
|
|
36
|
+
"@flighthq/signals": "0.2.0",
|
|
37
|
+
"@flighthq/textureatlas": "0.2.0",
|
|
38
|
+
"@flighthq/tileset": "0.2.0",
|
|
39
|
+
"@flighthq/types": "0.2.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"typescript": "^5.3.0"
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Spritesheet, SpritesheetAnimation, TimelineSource } from '@flighthq/types';
|
|
2
|
-
export declare function createSpritesheetTimelineSource(spritesheet: Readonly<Spritesheet>, animation: Readonly<SpritesheetAnimation>): TimelineSource;
|
|
3
|
-
//# sourceMappingURL=spritesheetTimelineSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spritesheetTimelineSource.d.ts","sourceRoot":"","sources":["../src/spritesheetTimelineSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyB,WAAW,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAUhH,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,EAClC,SAAS,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GACxC,cAAc,CA0BhB"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createBitmap } from '@flighthq/displayobject';
|
|
2
|
-
import { addNodeChild, invalidateNodeLocalTransform } from '@flighthq/node';
|
|
3
|
-
// Exposes a spritesheet animation as a TimelineSource so a MovieClip can play it (the spritesheet side of
|
|
4
|
-
// the timeline frame-source contract — `@flighthq/timeline` consumes `TimelineSource`, this produces one,
|
|
5
|
-
// and neither depends on the other beyond the shared interface in `@flighthq/types`). Each frame swaps
|
|
6
|
-
// the displayed atlas region and offset on a bitmap the source lazily creates as a child of the target
|
|
7
|
-
// the first time it constructs onto that target; tracking the bitmap per target keeps the source
|
|
8
|
-
// shareable across many MovieClips.
|
|
9
|
-
//
|
|
10
|
-
// Bind it with `setMovieClipSource(clip, createSpritesheetTimelineSource(sheet, anim))`, then `playMovieClip`.
|
|
11
|
-
export function createSpritesheetTimelineSource(spritesheet, animation) {
|
|
12
|
-
const bitmaps = new WeakMap();
|
|
13
|
-
return {
|
|
14
|
-
totalFrames: animation.frames.length,
|
|
15
|
-
labels: [],
|
|
16
|
-
frameRate: 1000 / animation.frameDuration,
|
|
17
|
-
constructFrame(target, frame) {
|
|
18
|
-
const atlas = spritesheet.atlas;
|
|
19
|
-
if (atlas === null)
|
|
20
|
-
return;
|
|
21
|
-
let bitmap = bitmaps.get(target);
|
|
22
|
-
if (bitmap === undefined) {
|
|
23
|
-
bitmap = createBitmap();
|
|
24
|
-
bitmap.data.image = atlas.image;
|
|
25
|
-
addNodeChild(target, bitmap);
|
|
26
|
-
bitmaps.set(target, bitmap);
|
|
27
|
-
}
|
|
28
|
-
const sheetFrame = spritesheet.frames[animation.frames[frame - 1]];
|
|
29
|
-
if (sheetFrame === undefined)
|
|
30
|
-
return;
|
|
31
|
-
bitmap.data.sourceRectangle = atlas.regions[sheetFrame.id];
|
|
32
|
-
bitmap.x = sheetFrame.offsetX - animation.originX;
|
|
33
|
-
bitmap.y = sheetFrame.offsetY - animation.originY;
|
|
34
|
-
invalidateNodeLocalTransform(bitmap);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=spritesheetTimelineSource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spritesheetTimelineSource.js","sourceRoot":"","sources":["../src/spritesheetTimelineSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAG5E,0GAA0G;AAC1G,0GAA0G;AAC1G,uGAAuG;AACvG,uGAAuG;AACvG,iGAAiG;AACjG,oCAAoC;AACpC,EAAE;AACF,+GAA+G;AAC/G,MAAM,UAAU,+BAA+B,CAC7C,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
|
|
2
|
-
import { createImageResource } from '@flighthq/image';
|
|
3
|
-
import { addTextureAtlasRegion, createTextureAtlas } from '@flighthq/textureatlas';
|
|
4
|
-
import type { DisplayObject } from '@flighthq/types';
|
|
5
|
-
|
|
6
|
-
import { createSpritesheet } from './spritesheet';
|
|
7
|
-
import { createSpritesheetAnimation } from './spritesheetAnimation';
|
|
8
|
-
import { createSpritesheetFrame } from './spritesheetFrame';
|
|
9
|
-
import { createSpritesheetTimelineSource } from './spritesheetTimelineSource';
|
|
10
|
-
|
|
11
|
-
function makeSheet(frameCount: number) {
|
|
12
|
-
const img = document.createElement('img') as HTMLImageElement;
|
|
13
|
-
const source = createImageResource(img);
|
|
14
|
-
source.width = 128;
|
|
15
|
-
source.height = 32;
|
|
16
|
-
const atlas = createTextureAtlas({ image: source });
|
|
17
|
-
const frames = [];
|
|
18
|
-
for (let i = 0; i < frameCount; i++) {
|
|
19
|
-
addTextureAtlasRegion(atlas, i * 32, 0, 32, 32);
|
|
20
|
-
frames.push(createSpritesheetFrame({ id: i }));
|
|
21
|
-
}
|
|
22
|
-
const sheet = createSpritesheet({ atlas });
|
|
23
|
-
sheet.frames = frames;
|
|
24
|
-
return sheet;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('createSpritesheetTimelineSource', () => {
|
|
28
|
-
it('reports totalFrames from the animation and frameRate from frameDuration', () => {
|
|
29
|
-
const sheet = makeSheet(3);
|
|
30
|
-
const anim = createSpritesheetAnimation({ frameDuration: 200, frames: [0, 1, 2] });
|
|
31
|
-
|
|
32
|
-
const source = createSpritesheetTimelineSource(sheet, anim);
|
|
33
|
-
|
|
34
|
-
expect(source.totalFrames).toBe(3);
|
|
35
|
-
expect(source.frameRate).toBeCloseTo(1000 / 200);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('lazily creates one bitmap child on the target and shows the frame region', () => {
|
|
39
|
-
const sheet = makeSheet(2);
|
|
40
|
-
const anim = createSpritesheetAnimation({ frameDuration: 100, frames: [0, 1] });
|
|
41
|
-
const source = createSpritesheetTimelineSource(sheet, anim);
|
|
42
|
-
const target = createDisplayContainer();
|
|
43
|
-
|
|
44
|
-
source.constructFrame(target as DisplayObject, 1);
|
|
45
|
-
source.constructFrame(target as DisplayObject, 2);
|
|
46
|
-
|
|
47
|
-
const children = getDisplayObjectRuntime(target).children;
|
|
48
|
-
expect(children).not.toBeNull();
|
|
49
|
-
expect(children!.length).toBe(1); // reused across frames, not one-per-frame
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('does not throw when the spritesheet has no atlas', () => {
|
|
53
|
-
const sheet = createSpritesheet({ atlas: null });
|
|
54
|
-
sheet.frames = [];
|
|
55
|
-
const anim = createSpritesheetAnimation({ frameDuration: 100, frames: [0] });
|
|
56
|
-
const source = createSpritesheetTimelineSource(sheet, anim);
|
|
57
|
-
|
|
58
|
-
expect(() => source.constructFrame(createDisplayContainer() as DisplayObject, 1)).not.toThrow();
|
|
59
|
-
});
|
|
60
|
-
});
|