🆙 refectorimng room.nitro to be loaded by the renderer

This commit is contained in:
duckietm
2026-02-04 11:05:18 +01:00
parent 6a8dfc6c14
commit e056013d5d
158 changed files with 55 additions and 3666 deletions
+52 -2
View File
@@ -4,6 +4,7 @@ import { AnimatedGIF } from '@pixi/gif';
import { Assets, Spritesheet, SpritesheetData, Texture } from 'pixi.js';
import { GraphicAssetCollection } from './GraphicAssetCollection';
export class AssetManager implements IAssetManager
{
private _textures: Map<string, Texture> = new Map();
@@ -84,7 +85,6 @@ export class AssetManager implements IAssetManager
return true;
}
catch (err)
{
NitroLogger.error(err);
@@ -99,6 +99,20 @@ export class AssetManager implements IAssetManager
{
if(!url || !url.length) return false;
if(url.startsWith('local://'))
{
const key = url.substring('local://'.length);
switch(key)
{
case 'room':
await this.loadLocalRoom();
return true;
}
return false;
}
if(url.endsWith('.nitro') || url.endsWith('.gif'))
{
const response = await fetch(url);
@@ -150,7 +164,6 @@ export class AssetManager implements IAssetManager
return true;
}
catch (err)
{
NitroLogger.error(err);
@@ -159,6 +172,43 @@ export class AssetManager implements IAssetManager
}
}
private async loadLocalRoom(): Promise<void>
{
const roomDataModule = await import('./assets/room/room.asset.json');
const roomData = (roomDataModule.default ?? roomDataModule) as IAssetData;
const collection = this.createCollection(roomData, null) as GraphicAssetCollection;
if(!collection) return;
const roomImages = import.meta.glob('./assets/room/*.png', { eager: true });
const roomImagesSub = import.meta.glob('./assets/room/images/*.png', { eager: true });
const merged = { ...roomImages, ...roomImagesSub };
for(const path in merged)
{
const mod = merged[path];
const imageUrl = (mod.default ?? mod) as string;
const file = path.split('/').pop()!;
const rawName = file.replace(/\.png$/i, '');
const texture = await Assets.load<Texture>(imageUrl);
if(!texture) continue;
this.setTexture(rawName, texture);
collection.textures.set(rawName, texture);
if(rawName.startsWith('room_'))
{
const normalizedName = rawName.substring('room_'.length);
this.setTexture(normalizedName, texture);
collection.textures.set(normalizedName, texture);
}
}
collection.define(roomData);
}
private async processAsset(texture: Texture, data: IAssetData): Promise<IGraphicAssetCollection>
{
let spritesheet: Spritesheet<SpritesheetData> = null;