@flighthq/scene2d-resources 0.3.0 → 0.3.1-next.320.fe56fc2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadScene2DImageResources.d.ts","sourceRoot":"","sources":["../src/loadScene2DImageResources.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"loadScene2DImageResources.d.ts","sourceRoot":"","sources":["../src/loadScene2DImageResources.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,gCAAgC,EAChC,eAAe,EACf,qBAAqB,EAEtB,MAAM,0BAA0B,CAAC;AAKlC,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,eAAe,EACzB,OAAO,CAAC,EAAE,QAAQ,CAAC,gCAAgC,CAAC,GACnD,OAAO,CAAC,qBAAqB,CAAC,CAkChC"}
|
|
@@ -9,7 +9,7 @@ export async function loadScene2DImageResources(document, options) {
|
|
|
9
9
|
const signal = options?.signal ?? new AbortController().signal;
|
|
10
10
|
const fetch = options?.fetch ?? rejectExternalImageResource;
|
|
11
11
|
let loaded = 0;
|
|
12
|
-
const
|
|
12
|
+
const sources = await Promise.all(selected.map(async (reference) => {
|
|
13
13
|
try {
|
|
14
14
|
return await resolveImageResourceReference(reference, fetch, signal);
|
|
15
15
|
}
|
|
@@ -24,24 +24,24 @@ export async function loadScene2DImageResources(document, options) {
|
|
|
24
24
|
const unresolved = [];
|
|
25
25
|
for (let i = 0; i < selected.length; i++) {
|
|
26
26
|
const reference = selected[i];
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
27
|
+
const source = sources[i];
|
|
28
|
+
if (source === null) {
|
|
29
29
|
unresolved.push(reference);
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
|
-
bindScene2DImageResourceTextures(reference,
|
|
32
|
+
bindScene2DImageResourceTextures(reference, source);
|
|
33
33
|
resolved.push(reference);
|
|
34
34
|
}
|
|
35
35
|
return { document, resolved, unresolved };
|
|
36
36
|
}
|
|
37
|
-
// Fans one decoded
|
|
37
|
+
// Fans one decoded source out to every Texture the reference names. setTextureSource bumps each texture's
|
|
38
38
|
// version, so renderers holding GPU handles against these textures re-upload on their next draw.
|
|
39
|
-
function bindScene2DImageResourceTextures(reference,
|
|
39
|
+
function bindScene2DImageResourceTextures(reference, source) {
|
|
40
40
|
const textures = reference.textures;
|
|
41
41
|
if (textures === undefined)
|
|
42
42
|
return;
|
|
43
43
|
for (let i = 0; i < textures.length; i++)
|
|
44
|
-
setTextureSource(textures[i],
|
|
44
|
+
setTextureSource(textures[i], source);
|
|
45
45
|
}
|
|
46
46
|
// A document with no external images never needs a fetch seam, so the default reports the miss rather than
|
|
47
47
|
// making the caller supply a fetcher it has no use for.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadScene2DImageResources.js","sourceRoot":"","sources":["../src/loadScene2DImageResources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAU9D,2GAA2G;AAC3G,4GAA4G;AAC5G,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,QAAyB,EACzB,OAAoD;IAEpD,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAC7C,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAC1E,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC,MAAM,CAAC;IAC/D,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,2BAA2B,CAAC;IAC5D,IAAI,MA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author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,17 +38,18 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/audio": "0.3.
|
|
42
|
-
"@flighthq/entity": "0.3.
|
|
43
|
-
"@flighthq/image": "0.3.
|
|
44
|
-
"@flighthq/node": "0.3.
|
|
45
|
-
"@flighthq/scene2d": "0.3.
|
|
46
|
-
"@flighthq/scene2d-formats": "0.3.
|
|
47
|
-
"@flighthq/signals": "0.3.
|
|
48
|
-
"@flighthq/texture": "0.3.
|
|
49
|
-
"@flighthq/types": "0.3.
|
|
41
|
+
"@flighthq/audio": "0.3.1-next.320.fe56fc2",
|
|
42
|
+
"@flighthq/entity": "0.3.1-next.320.fe56fc2",
|
|
43
|
+
"@flighthq/image": "0.3.1-next.320.fe56fc2",
|
|
44
|
+
"@flighthq/node": "0.3.1-next.320.fe56fc2",
|
|
45
|
+
"@flighthq/scene2d": "0.3.1-next.320.fe56fc2",
|
|
46
|
+
"@flighthq/scene2d-formats": "0.3.1-next.320.fe56fc2",
|
|
47
|
+
"@flighthq/signals": "0.3.1-next.320.fe56fc2",
|
|
48
|
+
"@flighthq/texture": "0.3.1-next.320.fe56fc2",
|
|
49
|
+
"@flighthq/types": "0.3.1-next.320.fe56fc2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"@flighthq/image-codec": "*",
|
|
52
53
|
"typescript": "^5.3.0"
|
|
53
54
|
},
|
|
54
55
|
"description": "Renderer-neutral Scene2D documents with explicit application slot and image resource resolution",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { clearImageDecoders, registerImageDecoder } from '@flighthq/image-codec/contract';
|
|
1
2
|
// @vitest-environment jsdom
|
|
2
3
|
import { createEmbeddedImageResourceReference, createExternalImageResourceReference } from '@flighthq/image/contract';
|
|
3
4
|
import { createDisplayObject } from '@flighthq/scene2d/contract';
|
|
4
5
|
import { connectSignal, createSignal } from '@flighthq/signals/contract';
|
|
5
6
|
import { createTexture, getTextureSource } from '@flighthq/texture/contract';
|
|
6
7
|
import type { Image, ImageResourceReference, Scene2DImageResourceLoadProgress } from '@flighthq/types/contract';
|
|
7
|
-
import { ResourceResolutionState } from '@flighthq/types/contract';
|
|
8
|
+
import { BitmapTextureSourceKind, ResourceResolutionState } from '@flighthq/types/contract';
|
|
8
9
|
|
|
9
10
|
import { loadScene2DImageResources } from './loadScene2DImageResources';
|
|
10
11
|
import { createScene2DDocument } from './scene2DDocument';
|
|
@@ -15,14 +16,16 @@ function externalResource(uri: string): ImageResourceReference {
|
|
|
15
16
|
return createExternalImageResourceReference(uri);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// The embedded path decodes through an HTMLImageElement, which is why this file runs under jsdom.
|
|
19
19
|
beforeEach(() => {
|
|
20
|
-
|
|
20
|
+
registerImageDecoder('image/png', async () => ({
|
|
21
|
+
data: new Uint8ClampedArray([0x11, 0x22, 0x33, 0xff]),
|
|
22
|
+
height: 1,
|
|
23
|
+
width: 1,
|
|
24
|
+
}));
|
|
21
25
|
});
|
|
22
26
|
|
|
23
27
|
afterEach(() => {
|
|
24
|
-
|
|
25
|
-
delete (HTMLImageElement.prototype as Partial<HTMLImageElement>).decode;
|
|
28
|
+
clearImageDecoders();
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
describe('loadScene2DImageResources', () => {
|
|
@@ -112,6 +115,6 @@ describe('loadScene2DImageResources', () => {
|
|
|
112
115
|
createScene2DDocument(createDisplayObject(), [], 'acme', null, [reference]),
|
|
113
116
|
);
|
|
114
117
|
expect(resources.resolved).toEqual([reference]);
|
|
115
|
-
expect(getTextureSource(texture)).
|
|
118
|
+
expect(getTextureSource(texture)?.kind).toBe(BitmapTextureSourceKind);
|
|
116
119
|
});
|
|
117
120
|
});
|