From f98a70a87190ad0fdb0ef0beb0ec232095e1a4f0 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 15 Jun 2021 16:52:08 -0400 Subject: [PATCH] Update camera --- src/nitro/INitro.ts | 2 + src/nitro/Nitro.ts | 9 ++ src/nitro/camera/IRoomCameraWidgetEffect.ts | 9 ++ src/nitro/camera/IRoomCameraWidgetManager.ts | 12 ++ .../camera/IRoomCameraWidgetSelectedEffect.ts | 7 ++ src/nitro/camera/RoomCameraWidgetEffect.ts | 48 ++++++++ src/nitro/camera/RoomCameraWidgetManager.ts | 103 +++++++++++++++++ .../camera/RoomCameraWidgetSelectedEffect.ts | 23 ++++ .../events/RoomCameraWidgetManagerEvent.ts | 2 +- src/nitro/room/IRoomEngine.ts | 2 - src/nitro/room/RoomEngine.ts | 10 -- .../RoomCameraWidgetEditorEffect.ts | 28 ----- .../RoomCameraWidgetEditorSelectedEffect.ts | 22 ---- .../camera-widget/RoomCameraWidgetManager.ts | 108 ------------------ src/nitro/room/events/index.ts | 1 - 15 files changed, 214 insertions(+), 172 deletions(-) create mode 100644 src/nitro/camera/IRoomCameraWidgetEffect.ts create mode 100644 src/nitro/camera/IRoomCameraWidgetManager.ts create mode 100644 src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts create mode 100644 src/nitro/camera/RoomCameraWidgetEffect.ts create mode 100644 src/nitro/camera/RoomCameraWidgetManager.ts create mode 100644 src/nitro/camera/RoomCameraWidgetSelectedEffect.ts rename src/nitro/{room => camera}/events/RoomCameraWidgetManagerEvent.ts (73%) delete mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts delete mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts delete mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetManager.ts diff --git a/src/nitro/INitro.ts b/src/nitro/INitro.ts index 6f61b6fe..b085637f 100644 --- a/src/nitro/INitro.ts +++ b/src/nitro/INitro.ts @@ -6,6 +6,7 @@ import { INitroCore } from '../core/INitroCore'; import { NitroTimer } from '../core/utils/NitroTimer'; import { IRoomManager } from '../room/IRoomManager'; import { IAvatarRenderManager } from './avatar/IAvatarRenderManager'; +import { IRoomCameraWidgetManager } from './camera/IRoomCameraWidgetManager'; import { INitroCommunicationManager } from './communication/INitroCommunicationManager'; import { INitroLocalizationManager } from './localization/INitroLocalizationManager'; import { IRoomEngine } from './room/IRoomEngine'; @@ -38,6 +39,7 @@ export interface INitro extends Application sessionDataManager: ISessionDataManager; roomSessionManager: IRoomSessionManager; roomManager: IRoomManager; + cameraManager: IRoomCameraWidgetManager; width: number; height: number; time: number; diff --git a/src/nitro/Nitro.ts b/src/nitro/Nitro.ts index a286a053..651b0c3f 100644 --- a/src/nitro/Nitro.ts +++ b/src/nitro/Nitro.ts @@ -12,6 +12,8 @@ import { IRoomManager } from '../room/IRoomManager'; import { RoomManager } from '../room/RoomManager'; import { AvatarRenderManager } from './avatar/AvatarRenderManager'; import { IAvatarRenderManager } from './avatar/IAvatarRenderManager'; +import { IRoomCameraWidgetManager } from './camera/IRoomCameraWidgetManager'; +import { RoomCameraWidgetManager } from './camera/RoomCameraWidgetManager'; import { INitroCommunicationManager } from './communication/INitroCommunicationManager'; import { NitroCommunicationManager } from './communication/NitroCommunicationManager'; import { LegacyExternalInterface } from './externalInterface/LegacyExternalInterface'; @@ -53,6 +55,7 @@ export class Nitro extends Application implements INitro private _sessionDataManager: ISessionDataManager; private _roomSessionManager: IRoomSessionManager; private _roomManager: IRoomManager; + private _cameraManager: IRoomCameraWidgetManager; private _linkTrackers: ILinkEventTracker[]; private _workerTrackers: IWorkerEventTracker[]; @@ -93,6 +96,7 @@ export class Nitro extends Application implements INitro this._sessionDataManager = new SessionDataManager(this._communication); this._roomSessionManager = new RoomSessionManager(this._communication, this._roomEngine); this._roomManager = new RoomManager(this._roomEngine, this._roomEngine.visualizationFactory, this._roomEngine.logicFactory); + this._cameraManager = new RoomCameraWidgetManager(); this._linkTrackers = []; this._workerTrackers = []; @@ -391,6 +395,11 @@ export class Nitro extends Application implements INitro return this._roomManager; } + public get cameraManager(): IRoomCameraWidgetManager + { + return this._cameraManager; + } + public get width(): number { return (this.renderer.width / this.renderer.resolution); diff --git a/src/nitro/camera/IRoomCameraWidgetEffect.ts b/src/nitro/camera/IRoomCameraWidgetEffect.ts new file mode 100644 index 00000000..954947b1 --- /dev/null +++ b/src/nitro/camera/IRoomCameraWidgetEffect.ts @@ -0,0 +1,9 @@ +import { Texture } from 'pixi.js'; + +export interface IRoomCameraWidgetEffect +{ + name: string; + minLevel: number; + texture: Texture; + colorMatrix: number[]; +} diff --git a/src/nitro/camera/IRoomCameraWidgetManager.ts b/src/nitro/camera/IRoomCameraWidgetManager.ts new file mode 100644 index 00000000..029f1ee7 --- /dev/null +++ b/src/nitro/camera/IRoomCameraWidgetManager.ts @@ -0,0 +1,12 @@ +import { IEventDispatcher } from '../../core'; +import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect'; +import { IRoomCameraWidgetSelectedEffect } from './IRoomCameraWidgetSelectedEffect'; + +export interface IRoomCameraWidgetManager +{ + init(): void; + applyEffects(image: HTMLImageElement, selectedEffects: IRoomCameraWidgetSelectedEffect[]): HTMLImageElement; + events: IEventDispatcher; + effects: Map; + isLoaded: boolean; +} diff --git a/src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts b/src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts new file mode 100644 index 00000000..3bb3b2c7 --- /dev/null +++ b/src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts @@ -0,0 +1,7 @@ +import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect'; + +export interface IRoomCameraWidgetSelectedEffect +{ + effect: IRoomCameraWidgetEffect; + alpha: number; +} diff --git a/src/nitro/camera/RoomCameraWidgetEffect.ts b/src/nitro/camera/RoomCameraWidgetEffect.ts new file mode 100644 index 00000000..8cd285ea --- /dev/null +++ b/src/nitro/camera/RoomCameraWidgetEffect.ts @@ -0,0 +1,48 @@ +import { Texture } from 'pixi.js'; +import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect'; + +export class RoomCameraWidgetEffect implements IRoomCameraWidgetEffect +{ + private _name: string; + private _minLevel: number = -1; + private _texture: Texture = null; + private _colorMatrix: number[] = null; + + constructor(name: string, minLevel: number = -1, texture: Texture = null, colorMatrix: number[] = null) + { + this._name = name; + this._minLevel = minLevel; + this._texture = texture; + this._colorMatrix = colorMatrix; + } + + public get name(): string + { + return this._name; + } + + public get texture(): Texture + { + return this._texture; + } + + public set texture(texture: Texture) + { + this._texture = texture; + } + + public get colorMatrix(): number[] + { + return this._colorMatrix; + } + + public set colorMatrix(colorMatrix: number[]) + { + this._colorMatrix = colorMatrix; + } + + public get minLevel(): number + { + return this._minLevel; + } +} diff --git a/src/nitro/camera/RoomCameraWidgetManager.ts b/src/nitro/camera/RoomCameraWidgetManager.ts new file mode 100644 index 00000000..4fb0f505 --- /dev/null +++ b/src/nitro/camera/RoomCameraWidgetManager.ts @@ -0,0 +1,103 @@ +import { Container, filters, Sprite, Texture } from 'pixi.js'; +import { EventDispatcher, IEventDispatcher } from '../../core'; +import { TextureUtils } from '../../room'; +import { Nitro } from '../Nitro'; +import { RoomCameraWidgetManagerEvent } from './events/RoomCameraWidgetManagerEvent'; +import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect'; +import { IRoomCameraWidgetManager } from './IRoomCameraWidgetManager'; +import { IRoomCameraWidgetSelectedEffect } from './IRoomCameraWidgetSelectedEffect'; +import { RoomCameraWidgetEffect } from './RoomCameraWidgetEffect'; + +export class RoomCameraWidgetManager implements IRoomCameraWidgetManager +{ + private _effects: Map; + private _events: IEventDispatcher; + private _isLoaded: boolean; + + constructor() + { + this._effects = new Map(); + this._events = new EventDispatcher(); + this._isLoaded = false; + } + + public init(): void + { + if(this._isLoaded) return; + + this._isLoaded = true; + + const imagesUrl = Nitro.instance.getConfiguration('image.library.url') + 'Habbo-Stories/'; + const effects = Nitro.instance.getConfiguration<{ name: string, colorMatrix?: number[], minLevel: number, enabled: boolean }[]>('camera.available.effects'); + + for(const effect of effects) + { + if(!effect.enabled) continue; + + const cameraEffect = new RoomCameraWidgetEffect(effect.name, effect.minLevel); + + if(effect.colorMatrix.length) + { + cameraEffect.colorMatrix = effect.colorMatrix; + } + else + { + cameraEffect.texture = Texture.from(imagesUrl + effect.name + '.png'); + } + + this._effects.set(cameraEffect.name, cameraEffect); + } + + this.events.dispatchEvent(new RoomCameraWidgetManagerEvent(RoomCameraWidgetManagerEvent.INITIALIZED)); + } + + public applyEffects(image: HTMLImageElement, selectedEffects: IRoomCameraWidgetSelectedEffect[]): HTMLImageElement + { + const container = new Container(); + const texture = Texture.from(image); + const sprite = new Sprite(texture); + + container.addChild(sprite); + + for(const selectedEffect of selectedEffects) + { + const effect = selectedEffect.effect; + + if(!effect) continue; + + if(effect.colorMatrix) + { + const filter = new filters.ColorMatrixFilter(); + + filter.matrix = effect.colorMatrix; + filter.alpha = selectedEffect.alpha; + + if(!sprite.filters) sprite.filters = [ filter ]; + } + else + { + const effectSprite = new Sprite(effect.texture); + effectSprite.alpha = selectedEffect.alpha; + + container.addChild(effectSprite); + } + } + + return TextureUtils.generateImage(container); + } + + public get effects(): Map + { + return this._effects; + } + + public get events(): IEventDispatcher + { + return this._events; + } + + public get isLoaded(): boolean + { + return this._isLoaded; + } +} diff --git a/src/nitro/camera/RoomCameraWidgetSelectedEffect.ts b/src/nitro/camera/RoomCameraWidgetSelectedEffect.ts new file mode 100644 index 00000000..9cbf2217 --- /dev/null +++ b/src/nitro/camera/RoomCameraWidgetSelectedEffect.ts @@ -0,0 +1,23 @@ +import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect'; + +export class RoomCameraWidgetSelectedEffect +{ + private _effect: IRoomCameraWidgetEffect; + private _alpha: number; + + constructor(effect: IRoomCameraWidgetEffect, alpha: number) + { + this._effect = effect; + this._alpha = alpha; + } + + public get effect(): IRoomCameraWidgetEffect + { + return this._effect; + } + + public get alpha(): number + { + return this._alpha; + } +} diff --git a/src/nitro/room/events/RoomCameraWidgetManagerEvent.ts b/src/nitro/camera/events/RoomCameraWidgetManagerEvent.ts similarity index 73% rename from src/nitro/room/events/RoomCameraWidgetManagerEvent.ts rename to src/nitro/camera/events/RoomCameraWidgetManagerEvent.ts index 578f8ce4..fb5abd8b 100644 --- a/src/nitro/room/events/RoomCameraWidgetManagerEvent.ts +++ b/src/nitro/camera/events/RoomCameraWidgetManagerEvent.ts @@ -2,7 +2,7 @@ import { NitroEvent } from '../../../core/events/NitroEvent'; export class RoomCameraWidgetManagerEvent extends NitroEvent { - public static INITIALIZED: string = 'RCWM_INITIALIZED'; + public static INITIALIZED: string = 'RCWM_INITIALIZED'; constructor(type: string) { diff --git a/src/nitro/room/IRoomEngine.ts b/src/nitro/room/IRoomEngine.ts index 6352ea18..9d11d2fa 100644 --- a/src/nitro/room/IRoomEngine.ts +++ b/src/nitro/room/IRoomEngine.ts @@ -11,7 +11,6 @@ import { IVector3D } from '../../room/utils/IVector3D'; import { PetCustomPart } from '../avatar/pets/PetCustomPart'; import { IRoomSessionManager } from '../session/IRoomSessionManager'; import { ISessionDataManager } from '../session/ISessionDataManager'; -import { RoomCameraWidgetManager } from './camera-widget/RoomCameraWidgetManager'; import { IGetImageListener } from './IGetImageListener'; import { ImageResult } from './ImageResult'; import { IObjectData } from './object/data/IObjectData'; @@ -103,5 +102,4 @@ export interface IRoomEngine extends INitroManager disposed: boolean; selectedAvatarId: number; isDecorating: boolean; - roomCameraWidgetManager: RoomCameraWidgetManager; } diff --git a/src/nitro/room/RoomEngine.ts b/src/nitro/room/RoomEngine.ts index f3620571..b06af370 100644 --- a/src/nitro/room/RoomEngine.ts +++ b/src/nitro/room/RoomEngine.ts @@ -41,7 +41,6 @@ import { IRoomSessionManager } from '../session/IRoomSessionManager'; import { ISessionDataManager } from '../session/ISessionDataManager'; import { MouseEventType } from '../ui/MouseEventType'; import { FurniId } from '../utils/FurniId'; -import { RoomCameraWidgetManager } from './camera-widget/RoomCameraWidgetManager'; import { RoomBackgroundColorEvent } from './events/RoomBackgroundColorEvent'; import { RoomEngineEvent } from './events/RoomEngineEvent'; import { RoomEngineObjectEvent } from './events/RoomEngineObjectEvent'; @@ -163,7 +162,6 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato private _mouseCursorUpdate: boolean; private _badgeListenerObjects: Map; private _logicFactory: IRoomObjectLogicFactory; - private _roomCameraWidgetManager: RoomCameraWidgetManager; constructor(communication: INitroCommunicationManager) { @@ -204,7 +202,6 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato this._roomDraggingAlwaysCenters = false; this._roomAllowsDragging = true; this._badgeListenerObjects = new Map(); - this._roomCameraWidgetManager = new RoomCameraWidgetManager(this.events); this.runVisibilityUpdate = this.runVisibilityUpdate.bind(this); this.processRoomObjectEvent = this.processRoomObjectEvent.bind(this); @@ -244,8 +241,6 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato this._roomSessionManager.events.addEventListener(RoomSessionEvent.ENDED, this.onRoomSessionEvent); } - this._roomCameraWidgetManager.initialize(); - this.events.addEventListener(RoomContentLoader.LOADER_READY, this.onRoomContentLoaderReadyEvent); Nitro.instance.ticker.add(this.update, this); @@ -3665,9 +3660,4 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato return this._roomManager.getRoomInstance(roomId.toString()).getRoomObjectsForCategory(categoryId).length; } - - public get roomCameraWidgetManager(): RoomCameraWidgetManager - { - return this._roomCameraWidgetManager; - } } diff --git a/src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts b/src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts deleted file mode 100644 index 804760c3..00000000 --- a/src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts +++ /dev/null @@ -1,28 +0,0 @@ -export class RoomCameraWidgetEditorEffect -{ - private _name: string; - private _colorMatrix: number[]; - private _minLevel: number; - - constructor(name: string, minLevel: number, colorMatrix?: number[]) - { - this._name = name; - this._minLevel = minLevel; - this._colorMatrix = colorMatrix ?? []; - } - - public get name(): string - { - return this._name; - } - - public get colorMatrix(): number[] - { - return this._colorMatrix; - } - - public get minLevel(): number - { - return this._minLevel; - } -} diff --git a/src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts b/src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts deleted file mode 100644 index bfce8d1e..00000000 --- a/src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { RoomCameraWidgetEditorEffect } from './RoomCameraWidgetEditorEffect'; -export class RoomCameraWidgetEditorSelectedEffect -{ - private _effect: RoomCameraWidgetEditorEffect; - private _alpha: number; - - constructor(effect: RoomCameraWidgetEditorEffect, alpha: number) - { - this._effect = effect; - this._alpha = alpha; - } - - public get effect(): RoomCameraWidgetEditorEffect - { - return this._effect; - } - - public get alpha(): number - { - return this._alpha; - } -} diff --git a/src/nitro/room/camera-widget/RoomCameraWidgetManager.ts b/src/nitro/room/camera-widget/RoomCameraWidgetManager.ts deleted file mode 100644 index 8ed36e0c..00000000 --- a/src/nitro/room/camera-widget/RoomCameraWidgetManager.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Container, Sprite, Texture } from 'pixi.js'; -import { Nitro } from '../../Nitro'; -import { IEventDispatcher } from './../../../core/events/IEventDispatcher'; -import { IGraphicAsset } from './../../../room/object/visualization/utils/IGraphicAsset'; -import { TextureUtils } from './../../../room/utils/TextureUtils'; -import { RoomCameraWidgetManagerEvent } from './../events/RoomCameraWidgetManagerEvent'; -import { RoomCameraWidgetEditorEffect } from './RoomCameraWidgetEditorEffect'; -import { RoomCameraWidgetEditorSelectedEffect } from './RoomCameraWidgetEditorSelectedEffect'; - -export class RoomCameraWidgetManager -{ - private _loaded: boolean; - private _loadedEffects: Map; - private _events: IEventDispatcher; - - constructor(events: IEventDispatcher) - { - this._loaded = false; - this._loadedEffects = new Map(); - this._events = events; - } - - public initialize(): void - { - const urls: string[] = []; - - const imagesUrl = Nitro.instance.getConfiguration('image.library.url') + 'Habbo-Stories/'; - const effects = Nitro.instance.getConfiguration<{ name: string, colorMatrix?: number[], minLevel: number, enabled: boolean }[]>('camera.available.effects'); - - for(const effect of effects) - { - if(effect.enabled) - { - if(!effect.colorMatrix) urls.push(imagesUrl + effect.name + '.png'); - - this._loadedEffects.set(effect.name, new RoomCameraWidgetEditorEffect(effect.name, effect.minLevel, effect.colorMatrix)); - } - } - - Nitro.instance.core.asset.downloadAssets(urls, (status: boolean) => - { - console.log('LOADED', status) - this._loaded = true; - this._events.dispatchEvent(new RoomCameraWidgetManagerEvent(RoomCameraWidgetManagerEvent.INITIALIZED)); - }); - } - - public editImage(image: HTMLImageElement, selectedEffects: RoomCameraWidgetEditorSelectedEffect[]): HTMLImageElement - { - const container = new Container(); - const texture = Texture.from(image); - const sprite = new Sprite(texture); - - container.addChild(sprite); - - for(const selectedEffect of selectedEffects) - { - if(selectedEffect.effect.colorMatrix.length > 0) - { - const filter = new PIXI.filters.ColorMatrixFilter(); - - if(!sprite.filters) sprite.filters = []; - - sprite.filters.push(filter); - - filter.matrix = selectedEffect.effect.colorMatrix; - filter.alpha = selectedEffect.alpha; - } - else - { - const effectAsset = this.getEffectAsset(selectedEffect.effect.name); - - if(!effectAsset) continue; - - const effectSprite = new Sprite(effectAsset.texture); - effectSprite.alpha = selectedEffect.alpha; - container.addChild(effectSprite); - } - } - - return TextureUtils.generateImage(container); - } - - public getEffectAsset(name: string): IGraphicAsset | null - { - const effect = this._loadedEffects.get(name); - - if(!effect) return null; - - if(effect.colorMatrix.length > 0) return null; - - const imagesUrl = Nitro.instance.getConfiguration('image.library.url') + 'Habbo-Stories/'; - - console.log('asset', imagesUrl + effect.name + '.png', Nitro.instance.core.asset.getAsset(imagesUrl + effect.name + '.png')); - - return Nitro.instance.core.asset.getAsset(effect.name + '.png'); - } - - public get loadedEffects(): Map - { - return this._loadedEffects; - } - - public get isLoaded(): boolean - { - return this._loaded; - } -} diff --git a/src/nitro/room/events/index.ts b/src/nitro/room/events/index.ts index a61d77d2..18ba5258 100644 --- a/src/nitro/room/events/index.ts +++ b/src/nitro/room/events/index.ts @@ -1,5 +1,4 @@ export * from './RoomBackgroundColorEvent'; -export * from './RoomCameraWidgetManagerEvent'; export * from './RoomEngineDimmerStateEvent'; export * from './RoomEngineEvent'; export * from './RoomEngineObjectEvent';