Update configruation

This commit is contained in:
Bill 2021-07-30 14:12:07 -04:00
parent a86ab2bb3b
commit bc066e2916
6 changed files with 52 additions and 15 deletions

View File

@ -194,12 +194,12 @@ export class SocketConnection extends EventDispatcher implements IConnection
if(!encoded) if(!encoded)
{ {
if(Nitro.instance.getConfiguration<boolean>('communication.packet.log')) console.log(`Encoding Failed: ${ composer.constructor.name }`); if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) console.log(`Encoding Failed: ${ composer.constructor.name }`);
continue; continue;
} }
if(Nitro.instance.getConfiguration<boolean>('communication.packet.log')) console.log(`OutgoingComposer: [${ header }] ${ composer.constructor.name }`, message); if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) console.log(`OutgoingComposer: [${ header }] ${ composer.constructor.name }`, message);
this.write(encoded.getBuffer()); this.write(encoded.getBuffer());
} }
@ -257,7 +257,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
if(!messages || !messages.length) continue; if(!messages || !messages.length) continue;
if(Nitro.instance.getConfiguration<boolean>('communication.packet.log')) if(Nitro.instance.getConfiguration<boolean>('system.packet.log'))
{ {
console.log(`IncomingMessage: [${ wrapper.header }] ${ messages[0].constructor.name }`, messages[0].parser); console.log(`IncomingMessage: [${ wrapper.header }] ${ messages[0].constructor.name }`, messages[0].parser);
} }
@ -291,7 +291,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
if(!events || !events.length) if(!events || !events.length)
{ {
if(Nitro.instance.getConfiguration<boolean>('communication.packet.log')) if(Nitro.instance.getConfiguration<boolean>('system.packet.log'))
{ {
console.log(`IncomingMessage: [${ wrapper.header }] UNREGISTERED`, wrapper); console.log(`IncomingMessage: [${ wrapper.header }] UNREGISTERED`, wrapper);
} }

View File

@ -6,12 +6,14 @@ import { IConfigurationManager } from './IConfigurationManager';
export class ConfigurationManager extends NitroManager implements IConfigurationManager export class ConfigurationManager extends NitroManager implements IConfigurationManager
{ {
private _definitions: AdvancedMap<string, unknown>; private _definitions: AdvancedMap<string, unknown>;
private _pendingUrls: string[];
constructor() constructor()
{ {
super(); super();
this._definitions = new AdvancedMap(); this._definitions = new AdvancedMap();
this._pendingUrls = [];
this.onConfigurationLoaded = this.onConfigurationLoaded.bind(this); this.onConfigurationLoaded = this.onConfigurationLoaded.bind(this);
} }
@ -19,7 +21,38 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
protected onInit(): void protected onInit(): void
{ {
//@ts-ignore //@ts-ignore
this.loadConfigurationFromUrl(NitroConfig.configurationUrl); let urls: string[] = NitroConfig.configurationUrls;
if(!urls || !urls.length)
{
//@ts-ignore
const url: string = NitroConfig.configurationUrl;
if(url && url.length) urls = [ url ];
}
if(!urls || !urls.length)
{
this.dispatchConfigurationEvent(ConfigurationEvent.FAILED);
return;
}
this._pendingUrls = urls;
this.loadNextConfiguration();
}
private loadNextConfiguration(): void
{
if(!this._pendingUrls.length)
{
this.dispatchConfigurationEvent(ConfigurationEvent.LOADED);
return;
}
this.loadConfigurationFromUrl(this._pendingUrls[0]);
} }
public loadConfigurationFromUrl(url: string): void public loadConfigurationFromUrl(url: string): void
@ -33,17 +66,21 @@ export class ConfigurationManager extends NitroManager implements IConfiguration
fetch(url) fetch(url)
.then(response => response.json()) .then(response => response.json())
.then(data => this.onConfigurationLoaded(data)) .then(data => this.onConfigurationLoaded(data, url))
.catch(err => this.onConfigurationFailed(err)); .catch(err => this.onConfigurationFailed(err));
} }
private onConfigurationLoaded(data: { [index: string]: any }): void private onConfigurationLoaded(data: { [index: string]: any }, url: string): void
{ {
if(!data) return; if(!data) return;
if(this.parseConfiguration(data)) if(this.parseConfiguration(data))
{ {
this.dispatchConfigurationEvent(ConfigurationEvent.LOADED); const index = this._pendingUrls.indexOf(url);
if(index >= 0) this._pendingUrls.splice(index, 1);
this.loadNextConfiguration();
return; return;
} }

View File

@ -217,8 +217,8 @@ export class Nitro extends Application implements INitro
private onConfigurationLoadedEvent(event: ConfigurationEvent): void private onConfigurationLoadedEvent(event: ConfigurationEvent): void
{ {
const animationFPS = this.getConfiguration<number>('animation.fps', 24); const animationFPS = this.getConfiguration<number>('system.animation.fps', 24);
const limitsFPS = this.getConfiguration<boolean>('limits.fps', true); const limitsFPS = this.getConfiguration<boolean>('system.limits.fps', true);
if(limitsFPS) Nitro.instance.ticker.maxFPS = animationFPS; if(limitsFPS) Nitro.instance.ticker.maxFPS = animationFPS;
} }

View File

@ -84,7 +84,7 @@ export class NitroCommunicationDemo extends NitroManager
this.dispatchCommunicationDemoEvent(NitroCommunicationDemoEvent.CONNECTION_ESTABLISHED, connection); this.dispatchCommunicationDemoEvent(NitroCommunicationDemoEvent.CONNECTION_ESTABLISHED, connection);
if(Nitro.instance.getConfiguration<boolean>('communication.pong.manually', false)) this.startPonging(); if(Nitro.instance.getConfiguration<boolean>('system.pong.manually', false)) this.startPonging();
this.startHandshake(connection); this.startHandshake(connection);
@ -177,7 +177,7 @@ export class NitroCommunicationDemo extends NitroManager
{ {
this.stopPonging(); this.stopPonging();
this._pongInterval = setInterval(this.sendPong, Nitro.instance.getConfiguration<number>('communication.pong.interval.ms', 20000)); this._pongInterval = setInterval(this.sendPong, Nitro.instance.getConfiguration<number>('system.pong.interval.ms', 20000));
} }
private stopPonging(): void private stopPonging(): void

View File

@ -139,8 +139,8 @@ export class LandscapeRasterizer extends PlaneRasterizer
const assetId = item.assetId; const assetId = item.assetId;
const x = this.getCoordinateValue(item.x || '', item.randomX || ''); const x = this.getCoordinateValue(item.x || '', item.randomX || '');
const y = this.getCoordinateValue(item.y || '', item.randomY || ''); const y = this.getCoordinateValue(item.y || '', item.randomY || '');
const speedX = item.speedX ? item.speedX / Nitro.instance.getConfiguration<number>('animation.fps') : 0; const speedX = item.speedX ? item.speedX / Nitro.instance.getConfiguration<number>('system.animation.fps') : 0;
const speedY = item.speedY ? item.speedY / Nitro.instance.getConfiguration<number>('animation.fps') : 0; const speedY = item.speedY ? item.speedY / Nitro.instance.getConfiguration<number>('system.animation.fps') : 0;
animationItems.push({ animationItems.push({
asset: assetId, asset: assetId,

View File

@ -74,7 +74,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
this._container = container; this._container = container;
this._geometry = new RoomGeometry(scale, new Vector3d(-135, 30, 0), new Vector3d(11, 11, 5), new Vector3d(-135, 0.5, 0)); this._geometry = new RoomGeometry(scale, new Vector3d(-135, 30, 0), new Vector3d(11, 11, 5), new Vector3d(-135, 0.5, 0));
this._animationFPS = Nitro.instance.getConfiguration<number>('animation.fps', 24); this._animationFPS = Nitro.instance.getConfiguration<number>('system.animation.fps', 24);
this._renderTimestamp = 0; this._renderTimestamp = 0;
this._totalTimeRunning = 0; this._totalTimeRunning = 0;
this._lastFrame = 0; this._lastFrame = 0;