diff --git a/packages/assets/package.json b/packages/assets/package.json index 8d8bf122..586612d0 100644 --- a/packages/assets/package.json +++ b/packages/assets/package.json @@ -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" diff --git a/packages/assets/src/AssetManager.ts b/packages/assets/src/AssetManager.ts index 8b1544fd..f4f4cd91 100644 --- a/packages/assets/src/AssetManager.ts +++ b/packages/assets/src/AssetManager.ts @@ -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(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(`data:${ contentType };base64,${ base64 }`); - - this.setTexture(url, texture); - break; - } } return true; diff --git a/yarn.lock b/yarn.lock index a3fab47c..ce04fcdb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"