🆙 cleanup and small fix to the json

This commit is contained in:
duckietm
2026-02-05 13:42:27 +01:00
parent 17ae1bd644
commit bed34615c1
4 changed files with 2 additions and 34 deletions
+1 -26
View File
@@ -41,8 +41,6 @@ export class AssetManager implements IAssetManager
return existing;
}
NitroLogger.warn(`AssetManager: Asset not found: ${name}`);
return null;
}
@@ -99,7 +97,6 @@ export class AssetManager implements IAssetManager
{
if(!url || !url.length) return false;
// ✅ NEW: Local bundled assets (no generic.asset.url)
if(url.startsWith('local://'))
{
const key = url.substring('local://'.length);
@@ -173,52 +170,32 @@ export class AssetManager implements IAssetManager
}
}
/**
* ✅ Loads room assets from bundled code:
* - /packages/assets/src/assets/room/room.asset.json
* - /packages/assets/src/assets/room/images/*.png
*
* This loads individual PNG files instead of a spritesheet, then uses
* the JSON asset definitions for proper x, y offsets, flipH settings, etc.
*/
private async loadLocalRoom(): Promise<void>
{
// 1) Load room JSON locally (bundled)
const roomDataModule = await import('./assets/room/room.asset.json');
const roomData = (roomDataModule.default ?? roomDataModule) as IAssetData;
// 2) Create collection WITHOUT spritesheet
// Note: Constructor calls define(), but assets won't be created since textures don't exist yet
const collection = this.createCollection(roomData, null) as GraphicAssetCollection;
if(!collection) return;
// 3) Load all images from the bundled assets
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 };
// 4) Register textures in the collection's _textures map
// getLibraryAsset() prepends collection name, so for asset 'wall_texture_64_0_wall_white'
// it looks for 'room_wall_texture_64_0_wall_white' in _textures
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, ''); // e.g., "room_wall_texture_64_0_wall_white"
const rawName = file.replace(/\.png$/i, '');
const texture = await Assets.load<Texture>(imageUrl);
if(!texture) continue;
// Register in AssetManager's global _textures for direct lookups
this.setTexture(rawName, texture);
// Register in collection's _textures with the full name (room_...)
// This is what getLibraryAsset() will look for when defining assets
collection.textures.set(rawName, texture);
// Also register without the "room_" prefix for direct lookups
if(rawName.startsWith('room_'))
{
const normalizedName = rawName.substring('room_'.length);
@@ -227,8 +204,6 @@ export class AssetManager implements IAssetManager
}
}
// 5) Now call define() again to process asset definitions with correct x, y offsets
// Assets that were skipped before (no textures) will now be created properly
collection.define(roomData);
}
@@ -5606,8 +5606,7 @@
"size": 64,
"allLayers": [
{
"color": 8703727,
"backgroundColor": "#84C6DF"
"color": 8703727
},
{
"items": [
@@ -413,7 +413,6 @@ export class RoomPlane implements IRoomPlane
const animationLayers: PlaneVisualizationAnimationLayer[] = [];
if(planeType === RoomPlane.TYPE_LANDSCAPE && planeVisualization?.allLayers)
{
// Always use the room collection for animation assets (clouds etc.) since they are stored there
const animationAssetCollection = roomCollection;
for(const layer of planeVisualization.allLayers)
{
@@ -554,7 +553,6 @@ export class RoomPlane implements IRoomPlane
if(this._lastLandscapeDebugSignature !== landscapeDebugSignature)
{
this._lastLandscapeDebugSignature = landscapeDebugSignature;
console.debug('[RoomPlane] Loaded landscape background', landscapeDebugPayload);
}
this._planeSprite = new TilingSprite({
@@ -120,25 +120,21 @@ export class PlaneVisualizationAnimationLayer
const assetWidth = item.bitmapData.width;
const assetHeight = item.bitmapData.height;
// Render at primary position
if(this.isVisible(point.x, point.y, assetWidth, assetHeight, canvas.width, canvas.height))
{
this.renderSprite(item, point.x, point.y, canvas);
}
// Wrap horizontally (left side)
if(this.isVisible(point.x - maxX, point.y, assetWidth, assetHeight, canvas.width, canvas.height))
{
this.renderSprite(item, point.x - maxX, point.y, canvas);
}
// Wrap vertically (top side)
if(this.isVisible(point.x, point.y - maxY, assetWidth, assetHeight, canvas.width, canvas.height))
{
this.renderSprite(item, point.x, point.y - maxY, canvas);
}
// Wrap both (top-left corner)
if(this.isVisible(point.x - maxX, point.y - maxY, assetWidth, assetHeight, canvas.width, canvas.height))
{
this.renderSprite(item, point.x - maxX, point.y - maxY, canvas);