Update camera

This commit is contained in:
Bill 2021-06-15 16:52:08 -04:00
parent 72c6e83544
commit f98a70a871
15 changed files with 214 additions and 172 deletions

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,9 @@
import { Texture } from 'pixi.js';
export interface IRoomCameraWidgetEffect
{
name: string;
minLevel: number;
texture: Texture;
colorMatrix: number[];
}

View File

@ -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<string, IRoomCameraWidgetEffect>;
isLoaded: boolean;
}

View File

@ -0,0 +1,7 @@
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
export interface IRoomCameraWidgetSelectedEffect
{
effect: IRoomCameraWidgetEffect;
alpha: number;
}

View File

@ -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;
}
}

View File

@ -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<string, IRoomCameraWidgetEffect>;
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<string>('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<string, IRoomCameraWidgetEffect>
{
return this._effects;
}
public get events(): IEventDispatcher
{
return this._events;
}
public get isLoaded(): boolean
{
return this._isLoaded;
}
}

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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<string, RoomObjectBadgeImageAssetListener[]>;
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<string, RoomCameraWidgetEditorEffect>;
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<string>('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<string>('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<string, RoomCameraWidgetEditorEffect>
{
return this._loadedEffects;
}
public get isLoaded(): boolean
{
return this._loaded;
}
}

View File

@ -1,5 +1,4 @@
export * from './RoomBackgroundColorEvent';
export * from './RoomCameraWidgetManagerEvent';
export * from './RoomEngineDimmerStateEvent';
export * from './RoomEngineEvent';
export * from './RoomEngineObjectEvent';