From 5389d4c1b0e5ed406e8d52226920a0ac831a5b28 Mon Sep 17 00:00:00 2001 From: MyNameIsBatman Date: Tue, 15 Jun 2021 14:39:23 -0300 Subject: [PATCH] Camera updates --- src/nitro/room/IRoomEngine.ts | 4 +- src/nitro/room/RoomEngine.ts | 18 ++- .../RoomCameraWidgetEditorEffect.ts | 28 +++++ .../RoomCameraWidgetEditorSelectedEffect.ts | 22 ++++ .../camera-widget/RoomCameraWidgetManager.ts | 108 ++++++++++++++++++ .../events/RoomCameraWidgetManagerEvent.ts | 11 ++ src/nitro/room/events/index.ts | 1 + .../FurnitureThumbnailVisualization.ts | 2 +- 8 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts create mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts create mode 100644 src/nitro/room/camera-widget/RoomCameraWidgetManager.ts create mode 100644 src/nitro/room/events/RoomCameraWidgetManagerEvent.ts diff --git a/src/nitro/room/IRoomEngine.ts b/src/nitro/room/IRoomEngine.ts index af24f853..6352ea18 100644 --- a/src/nitro/room/IRoomEngine.ts +++ b/src/nitro/room/IRoomEngine.ts @@ -11,6 +11,7 @@ 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'; @@ -86,7 +87,7 @@ export interface IRoomEngine extends INitroManager processRoomObjectOperation(objectId: number, category: number, operation: string): boolean; processRoomObjectPlacement(placementSource: string, id: number, category: number, typeId: number, legacyString?: string, stuffData?: IObjectData, state?: number, frameNumber?: number, posture?: string): boolean; dispatchMouseEvent(canvasId: number, x: number, y: number, type: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean, buttonDown: boolean): void; - createRoomScreenshot(roomId: number, canvasId?: number, bounds?: Rectangle): void; + createRoomScreenshot(roomId: number, canvasId?: number, bounds?: Rectangle): HTMLImageElement; modifyRoomObjectData(objectId: number, objectCategory: number, colorHex: string, text: string): boolean; deleteRoomObject(objectId: number, objectCategory: number): boolean; sessionDataManager: ISessionDataManager; @@ -102,4 +103,5 @@ 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 ce8f1807..f3620571 100644 --- a/src/nitro/room/RoomEngine.ts +++ b/src/nitro/room/RoomEngine.ts @@ -41,6 +41,7 @@ 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'; @@ -162,6 +163,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato private _mouseCursorUpdate: boolean; private _badgeListenerObjects: Map; private _logicFactory: IRoomObjectLogicFactory; + private _roomCameraWidgetManager: RoomCameraWidgetManager; constructor(communication: INitroCommunicationManager) { @@ -202,6 +204,7 @@ 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); @@ -241,6 +244,8 @@ 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); @@ -3438,7 +3443,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato return null; } - public createRoomScreenshot(roomId: number, canvasId: number = -1, bounds: Rectangle = null): void + public createRoomScreenshot(roomId: number, canvasId: number = -1, bounds: Rectangle = null): HTMLImageElement { let canvas: IRoomRenderingCanvas = null; @@ -3467,8 +3472,10 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato image.src = base64; - const newWindow = window.open(''); - newWindow.document.write(image.outerHTML); + /*const newWindow = window.open(''); + newWindow.document.write(image.outerHTML);*/ + + return image; } public objectsInitialized(k: string): void @@ -3658,4 +3665,9 @@ 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 new file mode 100644 index 00000000..804760c3 --- /dev/null +++ b/src/nitro/room/camera-widget/RoomCameraWidgetEditorEffect.ts @@ -0,0 +1,28 @@ +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 new file mode 100644 index 00000000..bfce8d1e --- /dev/null +++ b/src/nitro/room/camera-widget/RoomCameraWidgetEditorSelectedEffect.ts @@ -0,0 +1,22 @@ +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 new file mode 100644 index 00000000..8ed36e0c --- /dev/null +++ b/src/nitro/room/camera-widget/RoomCameraWidgetManager.ts @@ -0,0 +1,108 @@ +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/RoomCameraWidgetManagerEvent.ts b/src/nitro/room/events/RoomCameraWidgetManagerEvent.ts new file mode 100644 index 00000000..578f8ce4 --- /dev/null +++ b/src/nitro/room/events/RoomCameraWidgetManagerEvent.ts @@ -0,0 +1,11 @@ +import { NitroEvent } from '../../../core/events/NitroEvent'; + +export class RoomCameraWidgetManagerEvent extends NitroEvent +{ + public static INITIALIZED: string = 'RCWM_INITIALIZED'; + + constructor(type: string) + { + super(type); + } +} diff --git a/src/nitro/room/events/index.ts b/src/nitro/room/events/index.ts index 18ba5258..a61d77d2 100644 --- a/src/nitro/room/events/index.ts +++ b/src/nitro/room/events/index.ts @@ -1,4 +1,5 @@ export * from './RoomBackgroundColorEvent'; +export * from './RoomCameraWidgetManagerEvent'; export * from './RoomEngineDimmerStateEvent'; export * from './RoomEngineEvent'; export * from './RoomEngineObjectEvent'; diff --git a/src/nitro/room/object/visualization/furniture/FurnitureThumbnailVisualization.ts b/src/nitro/room/object/visualization/furniture/FurnitureThumbnailVisualization.ts index 407113f2..0971f7c2 100644 --- a/src/nitro/room/object/visualization/furniture/FurnitureThumbnailVisualization.ts +++ b/src/nitro/room/object/visualization/furniture/FurnitureThumbnailVisualization.ts @@ -147,4 +147,4 @@ export class FurnitureThumbnailVisualization extends FurnitureAnimatedVisualizat { return [this._type, k, 'thumb', _arg_2].join('_'); } -} \ No newline at end of file +}