Asset / logger updates

This commit is contained in:
Bill 2022-11-17 12:44:32 -05:00
parent e8ce6c7efb
commit 7bc6496a5e
15 changed files with 44 additions and 163 deletions

View File

@ -1,5 +1,6 @@
import { BaseTexture, Resource, Texture } from '@pixi/core';
import { Spritesheet } from '@pixi/spritesheet';
import { NitroLogger } from '../common';
import { ArrayBufferToBase64, NitroBundle } from '../utils';
import { GraphicAssetCollection } from './GraphicAssetCollection';
import { IAssetData } from './IAssetData';
@ -86,14 +87,11 @@ export class AssetManager implements IAssetManager
{
if(!urls || !urls.length) return true;
const responses = await Promise.all(urls.map(url => fetch(url)));
if(!responses || !responses.length) return false;
try
{
for(const response of responses)
for await (const url of urls)
{
const response = await fetch(url);
const contentType = response.headers.get('Content-Type');
switch(contentType)
@ -137,14 +135,16 @@ export class AssetManager implements IAssetManager
}
}
}
return true;
}
catch (err)
{
console.error(err);
}
NitroLogger.error(err);
return true;
return false;
}
}
private async processAsset(baseTexture: BaseTexture, data: IAssetData): Promise<void>

View File

@ -1,6 +1,5 @@
import { IDisposable } from './IDisposable';
import { INitroEvent } from './INitroEvent';
import { INitroLogger } from './INitroLogger';
export interface IEventDispatcher extends IDisposable
{
@ -8,5 +7,4 @@ export interface IEventDispatcher extends IDisposable
removeEventListener(type: string, callback: Function): void;
removeAllListeners(): void;
dispatchEvent(event: INitroEvent): boolean;
logger: INitroLogger;
}

View File

@ -1,8 +0,0 @@
export interface INitroLogger
{
log(...message: any[]): void;
error(...message: any[]): void;
warn(...message: any[]): void;
description: string | number;
print: boolean;
}

View File

@ -1,11 +1,9 @@
import { IDisposable } from './IDisposable';
import { IEventDispatcher } from './IEventDispatcher';
import { INitroLogger } from './INitroLogger';
export interface INitroManager extends IDisposable
{
init(): void;
logger: INitroLogger;
events: IEventDispatcher;
isLoaded: boolean;
isLoading: boolean;

View File

@ -1,77 +1,30 @@
import { INitroLogger } from './INitroLogger';
export class NitroLogger implements INitroLogger
export class NitroLogger
{
private _name: string;
private _description: string | number;
private _print: boolean;
public static DEBUG_ENABLED: boolean = false;
constructor(name: string, description: string | number = null)
public static log(...messages: any[]): void
{
this._name = name;
this._description = description;
this._print = true;
if(!this.DEBUG_ENABLED) return;
console.log(this.logPrefix(), ...messages);
}
public log(...message: any[]): void
public static error(...messages: any[]): void
{
this.printMessage('log', ...message);
if(!this.DEBUG_ENABLED) return;
console.error(this.logPrefix(), ...messages);
}
public error(...message: any[]): void
public static warn(...messages: any[]): void
{
this.printMessage('error', ...message);
}
if(!this.DEBUG_ENABLED) return;
public warn(...message: any[]): void
{
this.printMessage('warn', ...message);
}
public printMessage(modus: string, ...message: any[]): void
{
if(!this._print) return;
NitroLogger.log(this._name, modus, ...message);
console.warn(this.logPrefix(), ...messages);
}
private static logPrefix(): string
{
return '[Nitro]';
}
public static log(...messages: any[]): void
{
console.log(this.logPrefix(), ...messages);
}
public static error(...messages: any[]): void
{
console.error(this.logPrefix(), ...messages);
}
public static warn(...messages: any[]): void
{
console.warn(this.logPrefix(), ...messages);
}
public get description(): string | number
{
return this._description;
}
public set description(description: string | number)
{
this._description = description;
}
public get print(): boolean
{
return this._print;
}
public set print(flag: boolean)
{
this._print = flag;
}
}

View File

@ -2,7 +2,6 @@ export * from './IDisposable';
export * from './IEventDispatcher';
export * from './ILinkEventTracker';
export * from './INitroEvent';
export * from './INitroLogger';
export * from './INitroManager';
export * from './IUpdateReceiver';
export * from './NitroLogger';

View File

@ -1,16 +1,14 @@
import { IDisposable, IEventDispatcher, INitroEvent, INitroLogger, NitroConfiguration, NitroLogger } from '../../api';
import { IDisposable, IEventDispatcher, INitroEvent, NitroConfiguration, NitroLogger } from '../../api';
import { Disposable } from './Disposable';
export class EventDispatcher extends Disposable implements IEventDispatcher, IDisposable
{
private _logger: INitroLogger;
private _listeners: Map<string, Function[]>;
constructor()
{
super();
this._logger = new NitroLogger(this.constructor.name);
this._listeners = new Map();
}
@ -61,7 +59,7 @@ export class EventDispatcher extends Disposable implements IEventDispatcher, IDi
{
if(!event) return false;
if(NitroConfiguration.getValue<boolean>('system.dispatcher.log')) this._logger.log('Dispatched Event', event.type);
if(NitroConfiguration.getValue<boolean>('system.dispatcher.log')) NitroLogger.log('Dispatched Event', event.type);
this.processEvent(event);
@ -94,7 +92,7 @@ export class EventDispatcher extends Disposable implements IEventDispatcher, IDi
catch (err)
{
this._logger.error(err.stack);
NitroLogger.error(err.stack);
return;
}
@ -105,9 +103,4 @@ export class EventDispatcher extends Disposable implements IEventDispatcher, IDi
{
this._listeners.clear();
}
public get logger(): INitroLogger
{
return this._logger;
}
}

View File

@ -1,22 +1,18 @@
import { IEventDispatcher, INitroLogger, INitroManager, NitroLogger } from '../../api';
import { IEventDispatcher, INitroManager } from '../../api';
import { Disposable } from './Disposable';
import { EventDispatcher } from './EventDispatcher';
export class NitroManager extends Disposable implements INitroManager
{
private _logger: INitroLogger;
private _events: IEventDispatcher;
private _isLoaded: boolean;
private _isLoading: boolean;
constructor(logger: INitroLogger = null)
constructor()
{
super();
this._logger = logger instanceof NitroLogger ? logger : new NitroLogger(this.constructor.name);
this._events = new EventDispatcher();
this._isLoaded = false;
@ -53,11 +49,6 @@ export class NitroManager extends Disposable implements INitroManager
this.init();
}
public get logger(): INitroLogger
{
return this._logger;
}
public get events(): IEventDispatcher
{
return this._events;

View File

@ -13,6 +13,8 @@ export class AnimationManager implements IAnimationManager
public registerAnimation(structure: AvatarStructure, _arg_2: { [index: string]: IAssetAnimation }): boolean
{
if(!_arg_2) return false;
const animationData = _arg_2[Object.keys(_arg_2)[0]];
const animation = new Animation(structure, animationData);

View File

@ -108,52 +108,6 @@ export class RoomUnitStatusParser implements IMessageParser
}
}
// const totalActions = actionParts.length;
// if(totalActions)
// {
// for(let i = 0; i < totalActions; i++)
// {
// const action = actionParts[i];
// if(!action) continue;
// console.log(action);
// const [ key, value, extra ] = action.split(' ');
// if(!key || !value) continue;
// switch(key)
// {
// case 'mv':
// [ targetX, targetY, targetZ ] = value.split(',').map(a => parseFloat(a));
// didMove = true;
// break;
// case 'sit': {
// const sitHeight = parseFloat(value);
// if(extra !== undefined) canStandUp = value === '1';
// height = sitHeight;
// break;
// }
// case 'lay': {
// const layHeight = parseFloat(value);
// height = layHeight;
// break;
// }
// }
// statusActions.push(new RoomUnitStatusAction(key, value));
// }
// }
this._statuses.push(new RoomUnitStatusMessage(unitId, x, y, z, height, headDirection, direction, targetX, targetY, targetZ, didMove, canStandUp, statusActions));
}
}

View File

@ -3366,7 +3366,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
//return new RenderRoomThumbnailMessageComposer(_local_12, _local_10, _local_11, this._activeRoomId, this._sessionDataManager._Str_8500);
}
console.log(_local_10, _local_11, _local_12);
NitroLogger.log(_local_10, _local_11, _local_12);
//return new RenderRoomMessageComposer(_local_12, _local_10, _local_11, this._activeRoomId, this._sessionDataManager._Str_8500);

View File

@ -1,5 +1,5 @@
import { Graphics } from '@pixi/graphics';
import { IVector3D, Vector3d } from '../../../../../../../api';
import { IVector3D, NitroLogger, Vector3d } from '../../../../../../../api';
import { NitroRenderTexture } from '../../../../../../../pixi-proxy';
import { PlaneMaterialCell } from './PlaneMaterialCell';
@ -193,19 +193,19 @@ export class PlaneMaterialCellColumn
this.renderRepeatNone(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_BORDERS:
console.log('REPEAT_MODE_BORDERS');
NitroLogger.log('REPEAT_MODE_BORDERS');
// this.renderRepeatBorders(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_CENTER:
console.log('REPEAT_MODE_CENTER');
NitroLogger.log('REPEAT_MODE_CENTER');
// this.renderRepeatCenter(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_FIRST:
console.log('REPEAT_MODE_FIRST');
NitroLogger.log('REPEAT_MODE_FIRST');
// this.renderRepeatFirst(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_LAST:
console.log('REPEAT_MODE_LAST');
NitroLogger.log('REPEAT_MODE_LAST');
// this.renderRepeatLast(normal);
break;
default:

View File

@ -48,7 +48,7 @@ export class FurnitureDataLoader extends EventDispatcher
{
if(!error) return;
console.error(error);
NitroLogger.error(error);
this.dispatchEvent(new NitroEvent(FurnitureDataLoader.FURNITURE_DATA_ERROR));
}

View File

@ -1,4 +1,4 @@
import { AdvancedMap, IAdvancedMap, IMusicController, INitroEvent, ISoundManager, NitroConfiguration } from '../../api';
import { AdvancedMap, IAdvancedMap, IMusicController, INitroEvent, ISoundManager, NitroConfiguration, NitroLogger } from '../../api';
import { NitroManager } from '../../core';
import { NitroSettingsEvent, NitroSoundEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomEngineSamplePlaybackEvent } from '../../events';
import { Nitro } from '../Nitro';
@ -117,7 +117,7 @@ export class SoundManager extends NitroManager implements ISoundManager
}
catch (e)
{
console.log(e);
NitroLogger.error(e);
}
}
@ -180,7 +180,7 @@ export class SoundManager extends NitroManager implements ISoundManager
}
catch (e)
{
console.log(e);
NitroLogger.error(e);
}
}
@ -202,7 +202,7 @@ export class SoundManager extends NitroManager implements ISoundManager
}
catch (e)
{
console.log(e);
NitroLogger.error(e);
}
}

View File

@ -1,4 +1,5 @@
import { Howl, Howler } from 'howler';
import { NitroLogger } from '../../../api';
import { Nitro } from '../../Nitro';
import { SoundManagerEvent } from '../events';
import { TraxData } from '../trax/TraxData';
@ -127,7 +128,7 @@ export class MusicPlayer
{
const sampleSound = await this.getSample(sample.id);
const sampleCount = Math.ceil( (sample.length * 2) / Math.ceil(sampleSound.duration()));
const sampleCount = Math.ceil((sample.length * 2) / Math.ceil(sampleSound.duration()));
for(let i = 0; i < sampleCount; i++)
{
@ -141,7 +142,7 @@ export class MusicPlayer
this._sequence.push(sequenceEntryArray);
}
if(this._playLength <= 0) this._playLength = Math.max(...this._sequence.map( (value: ISequenceEntry[] ) => value.length));
if(this._playLength <= 0) this._playLength = Math.max(...this._sequence.map((value: ISequenceEntry[]) => value.length));
}
public async preloadSamplesForSong(song: string): Promise<void>
@ -153,7 +154,7 @@ export class MusicPlayer
private async loadSong(songId: number): Promise<Howl>
{
return new Promise <Howl>((resolve, reject) =>
return new Promise<Howl>((resolve, reject) =>
{
const sample = new Howl({
src: [this._sampleUrl.replace('%sample%', songId.toString())],
@ -168,7 +169,7 @@ export class MusicPlayer
sample.once('loaderror', () =>
{
console.log('failed to load sample ' + songId);
NitroLogger.error('failed to load sample ' + songId);
reject('failed to load sample ' + songId);
});
});