mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-26 17:30:52 +01:00
Merge branch 'fix/variable-cleanup' of https://git.krews.org/nitro/nitro-renderer into fix/variable-cleanup
This commit is contained in:
commit
35850e1bb2
@ -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;
|
||||
|
@ -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);
|
||||
|
9
src/nitro/camera/IRoomCameraWidgetEffect.ts
Normal file
9
src/nitro/camera/IRoomCameraWidgetEffect.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Texture } from 'pixi.js';
|
||||
|
||||
export interface IRoomCameraWidgetEffect
|
||||
{
|
||||
name: string;
|
||||
minLevel: number;
|
||||
texture: Texture;
|
||||
colorMatrix: number[];
|
||||
}
|
12
src/nitro/camera/IRoomCameraWidgetManager.ts
Normal file
12
src/nitro/camera/IRoomCameraWidgetManager.ts
Normal 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;
|
||||
}
|
7
src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts
Normal file
7
src/nitro/camera/IRoomCameraWidgetSelectedEffect.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
|
||||
|
||||
export interface IRoomCameraWidgetSelectedEffect
|
||||
{
|
||||
effect: IRoomCameraWidgetEffect;
|
||||
alpha: number;
|
||||
}
|
48
src/nitro/camera/RoomCameraWidgetEffect.ts
Normal file
48
src/nitro/camera/RoomCameraWidgetEffect.ts
Normal 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;
|
||||
}
|
||||
}
|
105
src/nitro/camera/RoomCameraWidgetManager.ts
Normal file
105
src/nitro/camera/RoomCameraWidgetManager.ts
Normal file
@ -0,0 +1,105 @@
|
||||
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 = [];
|
||||
|
||||
sprite.filters.push(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;
|
||||
}
|
||||
}
|
23
src/nitro/camera/RoomCameraWidgetSelectedEffect.ts
Normal file
23
src/nitro/camera/RoomCameraWidgetSelectedEffect.ts
Normal 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;
|
||||
}
|
||||
}
|
11
src/nitro/camera/events/RoomCameraWidgetManagerEvent.ts
Normal file
11
src/nitro/camera/events/RoomCameraWidgetManagerEvent.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { IMessageConfiguration } from '../../core/communication/messages/IMessageConfiguration';
|
||||
import { ApproveNameMessageComposer, CatalogApproveNameResultEvent, SellablePetPalettesEvent } from './messages';
|
||||
import { ApproveNameMessageComposer, CatalogApproveNameResultEvent, RoomUnitGiveHandItemPetComposer, SellablePetPalettesEvent } from './messages';
|
||||
import { AvailabilityStatusMessageEvent } from './messages/incoming/availability/AvailabilityStatusMessageEvent';
|
||||
import { CatalogClubEvent } from './messages/incoming/catalog/CatalogClubEvent';
|
||||
import { CatalogClubGiftsEvent } from './messages/incoming/catalog/CatalogClubGiftsEvent';
|
||||
@ -918,6 +918,7 @@ export class NitroMessages implements IMessageConfiguration
|
||||
this._composers.set(OutgoingHeader.UNIT_DANCE, RoomUnitDanceComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_DROP_HAND_ITEM, RoomUnitDropHandItemComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_GIVE_HANDITEM, RoomUnitGiveHandItemComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_GIVE_HANDITEM_PET, RoomUnitGiveHandItemPetComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_LOOK, RoomUnitLookComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_SIGN, RoomUnitSignComposer);
|
||||
this._composers.set(OutgoingHeader.UNIT_POSTURE, RoomUnitPostureComposer);
|
||||
|
@ -232,4 +232,5 @@ export class OutgoingHeader
|
||||
public static MARKETPLACE_BUY_OFFER = 1603;
|
||||
public static CATALOG_REQUESET_PET_BREEDS = 1756;
|
||||
public static APPROVE_NAME = 2109;
|
||||
public static UNIT_GIVE_HANDITEM_PET = 2768;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '../../../../../../core/communication/messages/IMessageComposer';
|
||||
|
||||
export class RoomUnitGiveHandItemPetComposer implements IMessageComposer<ConstructorParameters<typeof RoomUnitGiveHandItemPetComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof RoomUnitGiveHandItemPetComposer>;
|
||||
|
||||
constructor(unitId: number)
|
||||
{
|
||||
this._data = [ unitId ];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ export * from './RoomUnitActionComposer';
|
||||
export * from './RoomUnitDanceComposer';
|
||||
export * from './RoomUnitDropHandItemComposer';
|
||||
export * from './RoomUnitGiveHandItemComposer';
|
||||
export * from './RoomUnitGiveHandItemPetComposer';
|
||||
export * from './RoomUnitLookComposer';
|
||||
export * from './RoomUnitPostureComposer';
|
||||
export * from './RoomUnitSignComposer';
|
||||
|
@ -86,7 +86,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): 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;
|
||||
|
@ -6,6 +6,7 @@ import { NitroManager } from '../../core/common/NitroManager';
|
||||
import { IConnection } from '../../core/communication/connections/IConnection';
|
||||
import { IMessageComposer } from '../../core/communication/messages/IMessageComposer';
|
||||
import { NitroEvent } from '../../core/events/NitroEvent';
|
||||
import { TextureUtils } from '../../room';
|
||||
import { RoomObjectEvent } from '../../room/events/RoomObjectEvent';
|
||||
import { RoomObjectMouseEvent } from '../../room/events/RoomObjectMouseEvent';
|
||||
import { IRoomInstance } from '../../room/IRoomInstance';
|
||||
@ -3437,22 +3438,39 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
|
||||
return null;
|
||||
}
|
||||
|
||||
public createRoomScreenshot(roomId: number, canvasId: number): void
|
||||
public createRoomScreenshot(roomId: number, canvasId: number = -1, bounds: Rectangle = null): HTMLImageElement
|
||||
{
|
||||
const canvas = this.getRoomInstanceRenderingCanvas(roomId, canvasId);
|
||||
let canvas: IRoomRenderingCanvas = null;
|
||||
|
||||
if(!canvas) return;
|
||||
if(canvasId > -1)
|
||||
{
|
||||
canvas = this.getRoomInstanceRenderingCanvas(this._activeRoomId, canvasId);
|
||||
}
|
||||
else
|
||||
{
|
||||
canvas = this.getActiveRoomInstanceRenderingCanvas();
|
||||
}
|
||||
|
||||
const texture = canvas.getDisplayAsTexture();
|
||||
let texture: RenderTexture = null;
|
||||
|
||||
const base64 = Nitro.instance.renderer.extract.base64(texture);
|
||||
if(bounds)
|
||||
{
|
||||
texture = TextureUtils.generateTexture(canvas.master, bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = canvas.getDisplayAsTexture();
|
||||
}
|
||||
|
||||
const base64 = TextureUtils.generateImageUrl(texture);
|
||||
const image = new Image();
|
||||
|
||||
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
|
||||
|
@ -354,10 +354,15 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
|
||||
const frame = Math.round(this._totalTimeRunning / (60 / this._animationFPS));
|
||||
|
||||
let updateVisuals = false;
|
||||
|
||||
if(frame !== this._lastFrame)
|
||||
{
|
||||
this._lastFrame = frame;
|
||||
|
||||
updateVisuals = true;
|
||||
}
|
||||
|
||||
let spriteCount = 0;
|
||||
|
||||
const objects = this._container.objects;
|
||||
@ -368,7 +373,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
{
|
||||
if(!object) continue;
|
||||
|
||||
spriteCount = (spriteCount + this.renderObject(object, object.instanceId.toString(), time, update, spriteCount));
|
||||
spriteCount = (spriteCount + this.renderObject(object, object.instanceId.toString(), time, update, updateVisuals, spriteCount));
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,9 +399,8 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
}
|
||||
|
||||
this.cleanSprites(spriteCount);
|
||||
}
|
||||
|
||||
if(update) this._canvasUpdated = true;
|
||||
if(update || updateVisuals) this._canvasUpdated = true;
|
||||
|
||||
this._renderTimestamp = this._totalTimeRunning;
|
||||
this._renderedWidth = this._width;
|
||||
@ -430,7 +434,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
this._objectCache.removeObjectCache(identifier);
|
||||
}
|
||||
|
||||
private renderObject(object: IRoomObject, identifier: string, time: number, update: boolean, count: number): number
|
||||
private renderObject(object: IRoomObject, identifier: string, time: number, update: boolean, updateVisuals: boolean, count: number): number
|
||||
{
|
||||
if(!object) return 0;
|
||||
|
||||
@ -458,7 +462,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
return 0;
|
||||
}
|
||||
|
||||
visualization.update(this._geometry, time, (!sortableCache.isEmpty || update), (this._skipObjectUpdate && this._runningSlow));
|
||||
if(updateVisuals) visualization.update(this._geometry, time, (!sortableCache.isEmpty || update), (this._skipObjectUpdate && this._runningSlow));
|
||||
|
||||
if(locationCache.locationChanged) update = true;
|
||||
|
||||
|
4
src/room/utils/NitroRectangle.ts
Normal file
4
src/room/utils/NitroRectangle.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Rectangle } from 'pixi.js';
|
||||
|
||||
export class NitroRectangle extends Rectangle
|
||||
{}
|
@ -3,6 +3,7 @@ export * from './INitroPoint';
|
||||
export * from './IRoomGeometry';
|
||||
export * from './IVector3D';
|
||||
export * from './NitroPoint';
|
||||
export * from './NitroRectangle';
|
||||
export * from './NumberBank';
|
||||
export * from './PointMath';
|
||||
export * from './Rasterizer';
|
||||
|
Loading…
Reference in New Issue
Block a user