More updates

This commit is contained in:
Bill 2025-01-14 19:36:01 -05:00
parent feae4d4542
commit 23c0d29688
5 changed files with 52 additions and 3 deletions

View File

@ -10,6 +10,7 @@ export interface IRoomContentLoader
{
init(): Promise<void>;
processFurnitureData(furnitureData: IFurnitureData[]): void;
downloadAssetSync(type: string): void
downloadAsset(type: string): Promise<void>;
isLoaderType(type: string): boolean;
getCollection(name: string): IGraphicAssetCollection;

View File

@ -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

View File

@ -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<number, IPetColorResult> = 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<void>
{
const assetUrl: string = this.getAssetUrls(type)?.[0];

View File

@ -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

View File

@ -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);