Fix badge loading

This commit is contained in:
billsonnn 2024-03-26 22:43:17 -04:00
parent 38a9c746bf
commit d372ecd599
3 changed files with 18 additions and 12 deletions

View File

@ -16,7 +16,8 @@
"@nitrots/api": "1.0.0",
"@nitrots/eslint-config": "1.0.0",
"@nitrots/utils": "1.0.0",
"pixi.js": "^8.0.4"
"pixi.js": "^8.0.4",
"@pixi/gif": "^3.0.0"
},
"devDependencies": {
"typescript": "~5.4.2"

View File

@ -1,5 +1,6 @@
import { IAssetData, IAssetManager, IGraphicAsset, IGraphicAssetCollection } from '@nitrots/api';
import { ArrayBufferToBase64, NitroBundle, NitroLogger } from '@nitrots/utils';
import { NitroBundle, NitroLogger } from '@nitrots/utils';
import '@pixi/gif';
import { Assets, Spritesheet, SpritesheetData, Texture } from 'pixi.js';
import { GraphicAssetCollection } from './GraphicAssetCollection';
@ -100,6 +101,15 @@ export class AssetManager implements IAssetManager
{
if(!url || !url.length) return false;
if(url.endsWith('.png') || url.endsWith('.jpg') || url.endsWith('.jpeg') || url.endsWith('.gif'))
{
const texture = await Assets.load<Texture>(url);
this.setTexture(url, texture);
return true;
}
const response = await fetch(url);
if(response.status !== 200) return false;
@ -117,16 +127,6 @@ export class AssetManager implements IAssetManager
await this.processAsset(nitroBundle.texture, nitroBundle.jsonFile as IAssetData);
break;
}
case 'image/png':
case 'image/jpeg':
case 'image/gif': {
const buffer = await response.arrayBuffer();
const base64 = ArrayBufferToBase64(buffer);
const texture = await Assets.load<Texture>(`data:${ contentType };base64,${ base64 }`);
this.setTexture(url, texture);
break;
}
}
return true;

View File

@ -199,6 +199,11 @@
resolved "https://registry.yarnpkg.com/@pixi/colord/-/colord-2.9.6.tgz#7e4e7851480da6fd3cef4e331f008d60be7e1204"
integrity sha512-nezytU2pw587fQstUu1AsJZDVEynjskwOL+kibwcdxsMBFqPsFFNA7xl0ii/gXuDi6M0xj3mfRJj8pBSc2jCfA==
"@pixi/gif@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@pixi/gif/-/gif-3.0.0.tgz#dbd3e1bfb2a5d83a84965f5b517cc5dcb8407862"
integrity sha512-0am94k1SEwacW6anOiNT9vt3vnefEaiMxkg30nMwvqU3XkIO6sSsFBgQM3UArjDG/quYsujjyZZkyhl7yBF6GQ==
"@rollup/plugin-typescript@^11.1.6":
version "11.1.6"
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz#724237d5ec12609ec01429f619d2a3e7d4d1b22b"