You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-20 07:26:18 +00:00
🆙 cleanup and small fix to the json
This commit is contained in:
@@ -41,8 +41,6 @@ export class AssetManager implements IAssetManager
|
|||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
|
||||||
NitroLogger.warn(`AssetManager: Asset not found: ${name}`);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +97,6 @@ export class AssetManager implements IAssetManager
|
|||||||
{
|
{
|
||||||
if(!url || !url.length) return false;
|
if(!url || !url.length) return false;
|
||||||
|
|
||||||
// ✅ NEW: Local bundled assets (no generic.asset.url)
|
|
||||||
if(url.startsWith('local://'))
|
if(url.startsWith('local://'))
|
||||||
{
|
{
|
||||||
const key = url.substring('local://'.length);
|
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>
|
private async loadLocalRoom(): Promise<void>
|
||||||
{
|
{
|
||||||
// 1) Load room JSON locally (bundled)
|
|
||||||
const roomDataModule = await import('./assets/room/room.asset.json');
|
const roomDataModule = await import('./assets/room/room.asset.json');
|
||||||
const roomData = (roomDataModule.default ?? roomDataModule) as IAssetData;
|
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;
|
const collection = this.createCollection(roomData, null) as GraphicAssetCollection;
|
||||||
if(!collection) return;
|
if(!collection) return;
|
||||||
|
|
||||||
// 3) Load all images from the bundled assets
|
|
||||||
const roomImages = import.meta.glob('./assets/room/*.png', { eager: true });
|
const roomImages = import.meta.glob('./assets/room/*.png', { eager: true });
|
||||||
const roomImagesSub = import.meta.glob('./assets/room/images/*.png', { eager: true });
|
const roomImagesSub = import.meta.glob('./assets/room/images/*.png', { eager: true });
|
||||||
const merged = { ...roomImages, ...roomImagesSub };
|
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)
|
for(const path in merged)
|
||||||
{
|
{
|
||||||
const mod = merged[path];
|
const mod = merged[path];
|
||||||
const imageUrl = (mod.default ?? mod) as string;
|
const imageUrl = (mod.default ?? mod) as string;
|
||||||
|
|
||||||
const file = path.split('/').pop()!;
|
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);
|
const texture = await Assets.load<Texture>(imageUrl);
|
||||||
if(!texture) continue;
|
if(!texture) continue;
|
||||||
|
|
||||||
// Register in AssetManager's global _textures for direct lookups
|
|
||||||
this.setTexture(rawName, texture);
|
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);
|
collection.textures.set(rawName, texture);
|
||||||
|
|
||||||
// Also register without the "room_" prefix for direct lookups
|
|
||||||
if(rawName.startsWith('room_'))
|
if(rawName.startsWith('room_'))
|
||||||
{
|
{
|
||||||
const normalizedName = rawName.substring('room_'.length);
|
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);
|
collection.define(roomData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5606,8 +5606,7 @@
|
|||||||
"size": 64,
|
"size": 64,
|
||||||
"allLayers": [
|
"allLayers": [
|
||||||
{
|
{
|
||||||
"color": 8703727,
|
"color": 8703727
|
||||||
"backgroundColor": "#84C6DF"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"items": [
|
"items": [
|
||||||
|
|||||||
@@ -413,7 +413,6 @@ export class RoomPlane implements IRoomPlane
|
|||||||
const animationLayers: PlaneVisualizationAnimationLayer[] = [];
|
const animationLayers: PlaneVisualizationAnimationLayer[] = [];
|
||||||
if(planeType === RoomPlane.TYPE_LANDSCAPE && planeVisualization?.allLayers)
|
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;
|
const animationAssetCollection = roomCollection;
|
||||||
for(const layer of planeVisualization.allLayers)
|
for(const layer of planeVisualization.allLayers)
|
||||||
{
|
{
|
||||||
@@ -554,7 +553,6 @@ export class RoomPlane implements IRoomPlane
|
|||||||
if(this._lastLandscapeDebugSignature !== landscapeDebugSignature)
|
if(this._lastLandscapeDebugSignature !== landscapeDebugSignature)
|
||||||
{
|
{
|
||||||
this._lastLandscapeDebugSignature = landscapeDebugSignature;
|
this._lastLandscapeDebugSignature = landscapeDebugSignature;
|
||||||
console.debug('[RoomPlane] Loaded landscape background', landscapeDebugPayload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._planeSprite = new TilingSprite({
|
this._planeSprite = new TilingSprite({
|
||||||
|
|||||||
-4
@@ -120,25 +120,21 @@ export class PlaneVisualizationAnimationLayer
|
|||||||
const assetWidth = item.bitmapData.width;
|
const assetWidth = item.bitmapData.width;
|
||||||
const assetHeight = item.bitmapData.height;
|
const assetHeight = item.bitmapData.height;
|
||||||
|
|
||||||
// Render at primary position
|
|
||||||
if(this.isVisible(point.x, point.y, assetWidth, assetHeight, canvas.width, canvas.height))
|
if(this.isVisible(point.x, point.y, assetWidth, assetHeight, canvas.width, canvas.height))
|
||||||
{
|
{
|
||||||
this.renderSprite(item, point.x, point.y, canvas);
|
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))
|
if(this.isVisible(point.x - maxX, point.y, assetWidth, assetHeight, canvas.width, canvas.height))
|
||||||
{
|
{
|
||||||
this.renderSprite(item, point.x - maxX, point.y, canvas);
|
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))
|
if(this.isVisible(point.x, point.y - maxY, assetWidth, assetHeight, canvas.width, canvas.height))
|
||||||
{
|
{
|
||||||
this.renderSprite(item, point.x, point.y - maxY, canvas);
|
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))
|
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);
|
this.renderSprite(item, point.x - maxX, point.y - maxY, canvas);
|
||||||
|
|||||||
Reference in New Issue
Block a user