diff --git a/packages/api/src/nitro/room/IRoomContentLoader.ts b/packages/api/src/nitro/room/IRoomContentLoader.ts index 7e4c9566..f2dc7d26 100644 --- a/packages/api/src/nitro/room/IRoomContentLoader.ts +++ b/packages/api/src/nitro/room/IRoomContentLoader.ts @@ -10,6 +10,7 @@ export interface IRoomContentLoader { init(): Promise; processFurnitureData(furnitureData: IFurnitureData[]): void; + downloadAssetSync(type: string): void downloadAsset(type: string): Promise; isLoaderType(type: string): boolean; getCollection(name: string): IGraphicAssetCollection; diff --git a/packages/assets/src/AssetManager.ts b/packages/assets/src/AssetManager.ts index bf9e998e..8f683ff1 100644 --- a/packages/assets/src/AssetManager.ts +++ b/packages/assets/src/AssetManager.ts @@ -57,7 +57,7 @@ export class AssetManager implements IAssetManager { if(!name) return null; - return this._collections.get(name); + return this._collections.get(name) ?? null; } public createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection diff --git a/packages/room/src/RoomContentLoader.ts b/packages/room/src/RoomContentLoader.ts index 687d3c77..dd60f399 100644 --- a/packages/room/src/RoomContentLoader.ts +++ b/packages/room/src/RoomContentLoader.ts @@ -330,6 +330,54 @@ export class RoomContentLoader implements IRoomContentLoader return false; } + public downloadAssetSync(type: string): void + { + const assetUrl: string = this.getAssetUrls(type)?.[0]; + + if(!assetUrl || !assetUrl.length) return; + + if((this._pendingContentTypes.indexOf(type) >= 0)) return; + + this._pendingContentTypes.push(type); + + GetAssetManager() + .downloadAsset(assetUrl) + .then(() => + { + const petIndex = this._pets[type]; + + if(petIndex !== undefined) + { + const collection = this.getCollection(type); + const keys = collection.getPaletteNames(); + const palettes: Map = new Map(); + + for(const key of keys) + { + const palette = collection.getPalette(key); + const paletteData = collection.data.palettes[key]; + + const primaryColor = palette.primaryColor; + const secondaryColor = palette.secondaryColor; + const breed = ((paletteData.breed !== undefined) ? paletteData.breed : 0); + const tag = ((paletteData.colorTag !== undefined) ? paletteData.colorTag : -1); + const master = ((paletteData.master !== undefined) ? paletteData.master : false); + const layerTags = ((paletteData.tags !== undefined) ? paletteData.tags : []); + + palettes.set(parseInt(key), new PetColorResult(primaryColor, secondaryColor, breed, tag, key, master, layerTags)); + } + + this._petColors.set(petIndex, palettes); + } + + GetEventDispatcher().dispatchEvent(new RoomContentLoadedEvent(RoomContentLoadedEvent.RCLE_SUCCESS, type)); + }) + .catch((err) => + { + GetEventDispatcher().dispatchEvent(new RoomContentLoadedEvent(RoomContentLoadedEvent.RCLE_FAILURE, type)); + }); + } + public async downloadAsset(type: string): Promise { const assetUrl: string = this.getAssetUrls(type)?.[0]; diff --git a/packages/room/src/RoomEngine.ts b/packages/room/src/RoomEngine.ts index 934d6cce..2642b3f3 100644 --- a/packages/room/src/RoomEngine.ts +++ b/packages/room/src/RoomEngine.ts @@ -3230,7 +3230,7 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService public isRoomContentTypeLoaded(name: string): boolean { - return (this._roomContentLoader.getCollection(name) !== null); + return !!this._roomContentLoader.getCollection(name); } public getPetColorResult(petIndex: number, paletteIndex: number): IPetColorResult diff --git a/packages/room/src/RoomManager.ts b/packages/room/src/RoomManager.ts index 15738ec3..f492dfe6 100644 --- a/packages/room/src/RoomManager.ts +++ b/packages/room/src/RoomManager.ts @@ -98,7 +98,7 @@ export class RoomManager implements IRoomManager, IRoomInstanceContainer { isLoading = true; - GetRoomContentLoader().downloadAsset(type); + GetRoomContentLoader().downloadAssetSync(type); assetName = GetRoomContentLoader().getPlaceholderName(type); asset = GetRoomContentLoader().getCollection(assetName);