Merge branch 'main' into dev

This commit is contained in:
Bill 2021-12-25 22:08:20 -05:00
commit d7156d7c8e
8 changed files with 2692 additions and 866 deletions

View File

@ -1,2 +1,17 @@
# Nitro Renderer
nitro-renderer is a Javascript library for rendering Nitro in the browser using PixiJS
## Installation
npm
```
npm install @nitrots/nitro-renderer
```
yarn
```
yarn add @nitrots/nitro-renderer
```

2046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,32 @@
{
"name": "@nitrots/nitro-renderer",
"version": "1.1.0",
"description": "Javascript library for rendering Nitro in the browser using PixiJS",
"version": "1.1.1",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://git.krews.org/nitro/nitro-renderer"
"url": "https://git.krews.org/nitro/nitro-renderer.git"
},
"license": "GPL-3.0",
"bugs": {
"url": "https://git.krews.org/nitro/nitro-renderer/issues"
},
"homepage": "https://git.krews.org/nitro/nitro-renderer",
"type": "module",
"main": "./index.ts",
"scripts": {
"compile": "tsc --project ./tsconfig.json",
"eslint": "eslint ./src --fix",
"postinstall": "node ./post-install.js"
},
"private": true,
"dependencies": {
"@pixi/canvas-renderer": "^6.2.0",
"@pixi/extract": "^6.2.0",
"@pixi/filter-adjustment": "^4.1.3",
"@pixi/tilemap": "^3.2.2",
"pako": "^2.0.4",
"pixi.js": "^6.2.0",
"tslib": "^2.3.1"
"pixi.js": "^6.2.0"
},
"devDependencies": {
"@types/pako": "^1.0.2",

View File

@ -1,4 +1,4 @@
import { BaseTexture, Resource, Texture } from '@pixi/core';
import { Resource, Texture } from '@pixi/core';
import { Loader, LoaderResource } from '@pixi/loaders';
import { Spritesheet } from '@pixi/spritesheet';
import { IGraphicAsset } from '../../room';
@ -170,7 +170,7 @@ export class AssetManager extends Disposable implements IAssetManager
const nitroBundle = new NitroBundle(resource.data);
const assetData = (nitroBundle.jsonFile as IAssetData);
if(!assetData || !assetData.type)
if(!assetData)
{
onDownloaded(loader, resource, false);
@ -231,77 +231,7 @@ export class AssetManager extends Disposable implements IAssetManager
onDownloaded(loader, resource, true);
}
else if(resource.type === LoaderResource.TYPE.JSON)
{
const assetData = (resource.data as IAssetData);
if(!assetData || !assetData.type)
{
onDownloaded(loader, resource, false);
return;
}
if(assetData.spritesheet && Object.keys(assetData.spritesheet).length)
{
const imageName = (assetData.spritesheet.meta && assetData.spritesheet.meta.image);
if(!imageName || !imageName.length)
{
onDownloaded(loader, resource, false);
return;
}
const imageUrl = (resource.url.substring(0, (resource.url.lastIndexOf('/') + 1)) + imageName);
const baseTexture = BaseTexture.from(imageUrl);
if(baseTexture.valid)
{
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
}
else
{
baseTexture.once('loaded', () =>
{
baseTexture.removeAllListeners();
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
});
baseTexture.once('error', () =>
{
baseTexture.removeAllListeners();
onDownloaded(loader, resource, false);
});
}
return;
}
this.createCollection(assetData, null);
onDownloaded(loader, resource, true);
return;
}
if(resource.type === LoaderResource.TYPE.IMAGE)
else if(resource.type === LoaderResource.TYPE.IMAGE)
{
if(resource.texture.valid)
{

View File

@ -6,6 +6,7 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
{
private _definitions: Map<string, unknown>;
private _pendingUrls: string[];
private _missingKeys: string[];
constructor()
{
@ -13,16 +14,16 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
this._definitions = new Map();
this._pendingUrls = [];
this._missingKeys = [];
this.onConfigurationLoaded = this.onConfigurationLoaded.bind(this);
}
protected onInit(): void
{
//@ts-ignore
const defaultConfig = this.getDefaultConfig();
this.parseConfiguration(this.getDefaultConfig(), true);
this._pendingUrls = defaultConfig['config.urls'] as string[];
this._pendingUrls = this.getValue<string[]>('config.urls').slice();
this.loadNextConfiguration();
}
@ -33,8 +34,6 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
{
this.dispatchConfigurationEvent(ConfigurationEvent.LOADED);
this.parseConfiguration(this.getDefaultConfig());
return;
}
@ -84,7 +83,7 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
this.events && this.events.dispatchEvent(new ConfigurationEvent(type));
}
private parseConfiguration(data: { [index: string]: any }): boolean
private parseConfiguration(data: { [index: string]: any }, overrides: boolean = false): boolean
{
if(!data) return false;
@ -96,12 +95,16 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
{
let value = data[key];
if(typeof value === 'string')
{
value = this.interpolate((value as string), regex);
}
if(typeof value === 'string') value = this.interpolate((value as string), regex);
this._definitions.set(key, value);
if(this._definitions.has(key))
{
if(overrides) this.setValue(key, value);
}
else
{
this.setValue(key, value);
}
}
return true;
@ -145,6 +148,9 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
if(existing === undefined)
{
if(this._missingKeys.indexOf(key) >= 0) return value;
this._missingKeys.push(key);
this.logger.warn(`Missing configuration key: ${ key }`);
existing = value;

View File

@ -1,4 +1,4 @@
import { BaseTexture, Resource, Texture } from '@pixi/core';
import { Resource, Texture } from '@pixi/core';
import { Loader, LoaderResource } from '@pixi/loaders';
import { Spritesheet } from '@pixi/spritesheet';
import { IAssetData } from '../../core/asset/interfaces';
@ -559,7 +559,7 @@ export class RoomContentLoader implements IFurnitureDataListener
const nitroBundle = new NitroBundle(resource.data);
const assetData = (nitroBundle.jsonFile as IAssetData);
if(!assetData || !assetData.type)
if(!assetData)
{
onDownloaded(loader, resource, false);
@ -619,74 +619,6 @@ export class RoomContentLoader implements IFurnitureDataListener
onDownloaded(loader, resource, true);
}
else if(resource.type === LoaderResource.TYPE.JSON)
{
const assetData = (resource.data as IAssetData);
if(!assetData.type)
{
onDownloaded(loader, resource, false);
return;
}
if(assetData.spritesheet && Object.keys(assetData.spritesheet).length)
{
const imageName = (assetData.spritesheet.meta && assetData.spritesheet.meta.image);
if(!imageName || !imageName.length)
{
onDownloaded(loader, resource, false);
return;
}
const imageUrl = (resource.url.substring(0, (resource.url.lastIndexOf('/') + 1)) + imageName);
const baseTexture = BaseTexture.from(imageUrl);
if(baseTexture.valid)
{
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
}
else
{
baseTexture.once('loaded', () =>
{
baseTexture.removeAllListeners();
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
});
baseTexture.once('error', () =>
{
baseTexture.removeAllListeners();
onDownloaded(loader, resource, false);
});
}
return;
}
this.createCollection(assetData, null);
onDownloaded(loader, resource, true);
}
else
{
onDownloaded(loader, resource, false);

View File

@ -160,7 +160,6 @@ export class BadgeImageManager implements IDisposable
url = (Nitro.instance.getConfiguration<string>('badge.asset.url')).replace('%badgename%', badge);
break;
case BadgeImageManager.GROUP_BADGE:
//url = (Nitro.instance.getConfiguration<string>('badge.asset.group.url')).replace('%badgedata%', badge);
url = badge;
break;
}

1296
yarn.lock Normal file

File diff suppressed because it is too large Load Diff