mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-19 06:46:28 +01:00
Merge branch 'main' into dev
This commit is contained in:
commit
d7156d7c8e
15
README.md
15
README.md
@ -1,2 +1,17 @@
|
|||||||
# Nitro Renderer
|
# 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
|
||||||
|
```
|
||||||
|
2052
package-lock.json
generated
2052
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,26 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "@nitrots/nitro-renderer",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"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",
|
"type": "module",
|
||||||
"main": "./index.ts",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc --project ./tsconfig.json",
|
"compile": "tsc --project ./tsconfig.json",
|
||||||
"eslint": "eslint ./src --fix",
|
"eslint": "eslint ./src --fix",
|
||||||
"postinstall": "node ./post-install.js"
|
"postinstall": "node ./post-install.js"
|
||||||
},
|
},
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pixi/canvas-renderer": "^6.2.0",
|
"@pixi/canvas-renderer": "^6.2.0",
|
||||||
"@pixi/extract": "^6.2.0",
|
"@pixi/extract": "^6.2.0",
|
||||||
"@pixi/filter-adjustment": "^4.1.3",
|
"@pixi/filter-adjustment": "^4.1.3",
|
||||||
"@pixi/tilemap": "^3.2.2",
|
"@pixi/tilemap": "^3.2.2",
|
||||||
"pako": "^2.0.4",
|
"pako": "^2.0.4",
|
||||||
"pixi.js": "^6.2.0",
|
"pixi.js": "^6.2.0"
|
||||||
"tslib": "^2.3.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/pako": "^1.0.2",
|
"@types/pako": "^1.0.2",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseTexture, Resource, Texture } from '@pixi/core';
|
import { Resource, Texture } from '@pixi/core';
|
||||||
import { Loader, LoaderResource } from '@pixi/loaders';
|
import { Loader, LoaderResource } from '@pixi/loaders';
|
||||||
import { Spritesheet } from '@pixi/spritesheet';
|
import { Spritesheet } from '@pixi/spritesheet';
|
||||||
import { IGraphicAsset } from '../../room';
|
import { IGraphicAsset } from '../../room';
|
||||||
@ -170,7 +170,7 @@ export class AssetManager extends Disposable implements IAssetManager
|
|||||||
const nitroBundle = new NitroBundle(resource.data);
|
const nitroBundle = new NitroBundle(resource.data);
|
||||||
const assetData = (nitroBundle.jsonFile as IAssetData);
|
const assetData = (nitroBundle.jsonFile as IAssetData);
|
||||||
|
|
||||||
if(!assetData || !assetData.type)
|
if(!assetData)
|
||||||
{
|
{
|
||||||
onDownloaded(loader, resource, false);
|
onDownloaded(loader, resource, false);
|
||||||
|
|
||||||
@ -231,77 +231,7 @@ export class AssetManager extends Disposable implements IAssetManager
|
|||||||
onDownloaded(loader, resource, true);
|
onDownloaded(loader, resource, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(resource.type === LoaderResource.TYPE.JSON)
|
else if(resource.type === LoaderResource.TYPE.IMAGE)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if(resource.texture.valid)
|
if(resource.texture.valid)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
{
|
{
|
||||||
private _definitions: Map<string, unknown>;
|
private _definitions: Map<string, unknown>;
|
||||||
private _pendingUrls: string[];
|
private _pendingUrls: string[];
|
||||||
|
private _missingKeys: string[];
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
@ -13,16 +14,16 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
|
|
||||||
this._definitions = new Map();
|
this._definitions = new Map();
|
||||||
this._pendingUrls = [];
|
this._pendingUrls = [];
|
||||||
|
this._missingKeys = [];
|
||||||
|
|
||||||
this.onConfigurationLoaded = this.onConfigurationLoaded.bind(this);
|
this.onConfigurationLoaded = this.onConfigurationLoaded.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onInit(): void
|
protected onInit(): void
|
||||||
{
|
{
|
||||||
//@ts-ignore
|
this.parseConfiguration(this.getDefaultConfig(), true);
|
||||||
const defaultConfig = this.getDefaultConfig();
|
|
||||||
|
|
||||||
this._pendingUrls = defaultConfig['config.urls'] as string[];
|
this._pendingUrls = this.getValue<string[]>('config.urls').slice();
|
||||||
|
|
||||||
this.loadNextConfiguration();
|
this.loadNextConfiguration();
|
||||||
}
|
}
|
||||||
@ -33,8 +34,6 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
{
|
{
|
||||||
this.dispatchConfigurationEvent(ConfigurationEvent.LOADED);
|
this.dispatchConfigurationEvent(ConfigurationEvent.LOADED);
|
||||||
|
|
||||||
this.parseConfiguration(this.getDefaultConfig());
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
this.events && this.events.dispatchEvent(new ConfigurationEvent(type));
|
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;
|
if(!data) return false;
|
||||||
|
|
||||||
@ -96,12 +95,16 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
{
|
{
|
||||||
let value = data[key];
|
let value = data[key];
|
||||||
|
|
||||||
if(typeof value === 'string')
|
if(typeof value === 'string') value = this.interpolate((value as string), regex);
|
||||||
{
|
|
||||||
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;
|
return true;
|
||||||
@ -145,6 +148,9 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
|
|||||||
|
|
||||||
if(existing === undefined)
|
if(existing === undefined)
|
||||||
{
|
{
|
||||||
|
if(this._missingKeys.indexOf(key) >= 0) return value;
|
||||||
|
|
||||||
|
this._missingKeys.push(key);
|
||||||
this.logger.warn(`Missing configuration key: ${ key }`);
|
this.logger.warn(`Missing configuration key: ${ key }`);
|
||||||
|
|
||||||
existing = value;
|
existing = value;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseTexture, Resource, Texture } from '@pixi/core';
|
import { Resource, Texture } from '@pixi/core';
|
||||||
import { Loader, LoaderResource } from '@pixi/loaders';
|
import { Loader, LoaderResource } from '@pixi/loaders';
|
||||||
import { Spritesheet } from '@pixi/spritesheet';
|
import { Spritesheet } from '@pixi/spritesheet';
|
||||||
import { IAssetData } from '../../core/asset/interfaces';
|
import { IAssetData } from '../../core/asset/interfaces';
|
||||||
@ -559,7 +559,7 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
const nitroBundle = new NitroBundle(resource.data);
|
const nitroBundle = new NitroBundle(resource.data);
|
||||||
const assetData = (nitroBundle.jsonFile as IAssetData);
|
const assetData = (nitroBundle.jsonFile as IAssetData);
|
||||||
|
|
||||||
if(!assetData || !assetData.type)
|
if(!assetData)
|
||||||
{
|
{
|
||||||
onDownloaded(loader, resource, false);
|
onDownloaded(loader, resource, false);
|
||||||
|
|
||||||
@ -619,74 +619,6 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
|
|
||||||
onDownloaded(loader, resource, true);
|
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
|
else
|
||||||
{
|
{
|
||||||
onDownloaded(loader, resource, false);
|
onDownloaded(loader, resource, false);
|
||||||
|
@ -160,7 +160,6 @@ export class BadgeImageManager implements IDisposable
|
|||||||
url = (Nitro.instance.getConfiguration<string>('badge.asset.url')).replace('%badgename%', badge);
|
url = (Nitro.instance.getConfiguration<string>('badge.asset.url')).replace('%badgename%', badge);
|
||||||
break;
|
break;
|
||||||
case BadgeImageManager.GROUP_BADGE:
|
case BadgeImageManager.GROUP_BADGE:
|
||||||
//url = (Nitro.instance.getConfiguration<string>('badge.asset.group.url')).replace('%badgedata%', badge);
|
|
||||||
url = badge;
|
url = badge;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user