mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts][pixi-v7][pixi-v8] Fix asset loaders not throwing when http response is not ok. See #3042.
This commit is contained in:
parent
2fe33f5760
commit
a7754a3313
@ -69,9 +69,10 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
|
|||||||
async load (url: string): Promise<RawAtlas> {
|
async load (url: string): Promise<RawAtlas> {
|
||||||
const response = await settings.ADAPTER.fetch(url);
|
const response = await settings.ADAPTER.fetch(url);
|
||||||
|
|
||||||
const txt = await response.text();
|
if (!response.ok)
|
||||||
|
throw new Error(`[${loaderName}] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
|
||||||
|
|
||||||
return txt;
|
return await response.text();
|
||||||
},
|
},
|
||||||
|
|
||||||
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
||||||
@ -107,7 +108,6 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
|
|||||||
// we will wait for all promises for the textures at the same time at the end.
|
// we will wait for all promises for the textures at the same time at the end.
|
||||||
const textureLoadingPromises = [];
|
const textureLoadingPromises = [];
|
||||||
|
|
||||||
|
|
||||||
// setting preferCreateImageBitmap to false for loadTextures loader to allow loading PMA images
|
// setting preferCreateImageBitmap to false for loadTextures loader to allow loading PMA images
|
||||||
let oldPreferCreateImageBitmap = true;
|
let oldPreferCreateImageBitmap = true;
|
||||||
for (const parser of loader.parsers) {
|
for (const parser of loader.parsers) {
|
||||||
|
|||||||
@ -36,11 +36,11 @@ type SkeletonBinaryAsset = Uint8Array;
|
|||||||
|
|
||||||
const loaderName = "spineSkeletonLoader";
|
const loaderName = "spineSkeletonLoader";
|
||||||
|
|
||||||
function isJson(resource: any): resource is SkeletonJsonAsset {
|
function isJson (resource: any): resource is SkeletonJsonAsset {
|
||||||
return resource.hasOwnProperty("bones");
|
return resource.hasOwnProperty("bones");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isBuffer(resource: any): resource is SkeletonBinaryAsset {
|
function isBuffer (resource: any): resource is SkeletonBinaryAsset {
|
||||||
return resource instanceof Uint8Array;
|
return resource instanceof Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,18 +55,19 @@ const spineLoaderExtension: AssetExtension<SkeletonJsonAsset | SkeletonBinaryAss
|
|||||||
name: loaderName,
|
name: loaderName,
|
||||||
},
|
},
|
||||||
|
|
||||||
test(url) {
|
test (url) {
|
||||||
return checkExtension(url, ".skel");
|
return checkExtension(url, ".skel");
|
||||||
},
|
},
|
||||||
|
|
||||||
async load(url: string): Promise<SkeletonBinaryAsset> {
|
async load (url: string): Promise<SkeletonBinaryAsset> {
|
||||||
const response = await settings.ADAPTER.fetch(url);
|
const response = await settings.ADAPTER.fetch(url);
|
||||||
|
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer());
|
if (!response.ok)
|
||||||
|
throw new Error(`[${loaderName}] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
|
||||||
|
|
||||||
return buffer;
|
return new Uint8Array(await response.arrayBuffer());
|
||||||
},
|
},
|
||||||
testParse(asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
||||||
const isJsonSpineModel = checkExtension(options.src!, ".json") && isJson(asset);
|
const isJsonSpineModel = checkExtension(options.src!, ".json") && isJson(asset);
|
||||||
const isBinarySpineModel = checkExtension(options.src!, ".skel") && isBuffer(asset);
|
const isBinarySpineModel = checkExtension(options.src!, ".skel") && isBuffer(asset);
|
||||||
const isExplicitLoadParserSet = options.loadParser === loaderName;
|
const isExplicitLoadParserSet = options.loadParser === loaderName;
|
||||||
|
|||||||
@ -83,9 +83,10 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
|
|||||||
async load (url: string): Promise<RawAtlas> {
|
async load (url: string): Promise<RawAtlas> {
|
||||||
const response = await DOMAdapter.get().fetch(url);
|
const response = await DOMAdapter.get().fetch(url);
|
||||||
|
|
||||||
const txt = await response.text();
|
if (!response.ok)
|
||||||
|
throw new Error(`[${loaderName}] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
|
||||||
|
|
||||||
return txt;
|
return await response.text();
|
||||||
},
|
},
|
||||||
|
|
||||||
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
||||||
|
|||||||
@ -69,9 +69,10 @@ const spineLoaderExtension: AssetExtension<SkeletonJsonAsset | SkeletonBinaryAss
|
|||||||
async load (url: string): Promise<SkeletonBinaryAsset> {
|
async load (url: string): Promise<SkeletonBinaryAsset> {
|
||||||
const response = await DOMAdapter.get().fetch(url);
|
const response = await DOMAdapter.get().fetch(url);
|
||||||
|
|
||||||
const buffer = new Uint8Array(await response.arrayBuffer());
|
if (!response.ok)
|
||||||
|
throw new Error(`[${loaderName}] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
|
||||||
|
|
||||||
return buffer;
|
return new Uint8Array(await response.arrayBuffer());
|
||||||
},
|
},
|
||||||
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
|
||||||
const isJsonSpineModel = checkExtension(options.src!, '.json') && isJson(asset);
|
const isJsonSpineModel = checkExtension(options.src!, '.json') && isJson(asset);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user