Camera updates

This commit is contained in:
MyNameIsBatman 2021-06-15 14:39:23 -03:00
parent 2b1e75b06f
commit 5389d4c1b0
8 changed files with 189 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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