You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
export class RoomFloorHole
|
||||
{
|
||||
private _x: number;
|
||||
private _y: number;
|
||||
private _width: number;
|
||||
private _height: number;
|
||||
|
||||
constructor(x: number, y: number, width: number, height: number)
|
||||
{
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
public get x(): number
|
||||
{
|
||||
return this._x;
|
||||
}
|
||||
|
||||
public get y(): number
|
||||
{
|
||||
return this._y;
|
||||
}
|
||||
|
||||
public get width(): number
|
||||
{
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public get height(): number
|
||||
{
|
||||
return this._height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { IRoomMapData } from '@nitrots/api';
|
||||
|
||||
export class RoomMapData implements IRoomMapData
|
||||
{
|
||||
private _width: number;
|
||||
private _height: number;
|
||||
private _wallHeight: number;
|
||||
private _fixedWallsHeight: number;
|
||||
private _tileMap: { height: number }[][];
|
||||
private _holeMap: { id: number, x: number, y: number, width: number, height: number }[];
|
||||
private _doors: { x: number, y: number, z: number, dir: number }[];
|
||||
private _dimensions: { minX: number, maxX: number, minY: number, maxY: number };
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._width = 0;
|
||||
this._height = 0;
|
||||
this._wallHeight = 0;
|
||||
this._fixedWallsHeight = 0;
|
||||
this._tileMap = [];
|
||||
this._holeMap = [];
|
||||
this._doors = [];
|
||||
this._dimensions = {
|
||||
minX: 0,
|
||||
maxX: 0,
|
||||
minY: 0,
|
||||
maxY: 0
|
||||
};
|
||||
}
|
||||
|
||||
public get width(): number
|
||||
{
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public set width(width: number)
|
||||
{
|
||||
this._width = width;
|
||||
}
|
||||
|
||||
public get height(): number
|
||||
{
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public set height(height: number)
|
||||
{
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
public get wallHeight(): number
|
||||
{
|
||||
return this._wallHeight;
|
||||
}
|
||||
|
||||
public set wallHeight(wallHeight: number)
|
||||
{
|
||||
this._wallHeight = wallHeight;
|
||||
}
|
||||
|
||||
public get fixedWallsHeight(): number
|
||||
{
|
||||
return this._fixedWallsHeight;
|
||||
}
|
||||
|
||||
public set fixedWallsHeight(fixedWallsHeight: number)
|
||||
{
|
||||
this._fixedWallsHeight = fixedWallsHeight;
|
||||
}
|
||||
|
||||
public get tileMap(): { height: number }[][]
|
||||
{
|
||||
return this._tileMap;
|
||||
}
|
||||
|
||||
public get holeMap(): { id: number, x: number, y: number, width: number, height: number }[]
|
||||
{
|
||||
return this._holeMap;
|
||||
}
|
||||
|
||||
public get doors(): { x: number, y: number, z: number, dir: number }[]
|
||||
{
|
||||
return this._doors;
|
||||
}
|
||||
|
||||
public get dimensions(): { minX: number, maxX: number, minY: number, maxY: number }
|
||||
{
|
||||
return this._dimensions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IVector3D } from '@nitrots/api';
|
||||
|
||||
export class RoomMapMaskData
|
||||
{
|
||||
private _masks: { id: string, type: string, category: string, locations: IVector3D[] }[];
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._masks = [];
|
||||
}
|
||||
|
||||
public get masks(): { id: string, type: string, category: string, locations: IVector3D[] }[]
|
||||
{
|
||||
return this._masks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import { IRoomObjectController, IRoomObjectEventHandler, IRoomObjectModel, IRoomObjectMouseHandler, IRoomObjectUpdateMessage, IRoomObjectVisualization, IVector3D } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { RoomObjectModel } from './RoomObjectModel';
|
||||
|
||||
export class RoomObject implements IRoomObjectController
|
||||
{
|
||||
private static OBJECT_COUNTER: number = 0;
|
||||
|
||||
private _id: number;
|
||||
private _instanceId: number;
|
||||
private _type: string;
|
||||
private _model: IRoomObjectModel = new RoomObjectModel();
|
||||
|
||||
private _location: IVector3D = new Vector3d();
|
||||
private _direction: IVector3D = new Vector3d();
|
||||
private _states: number[] = [];
|
||||
|
||||
private _visualization: IRoomObjectVisualization = null;
|
||||
private _logic: IRoomObjectEventHandler = null;
|
||||
private _pendingLogicMessages: IRoomObjectUpdateMessage[] = [];
|
||||
|
||||
private _updateCounter: number = 0;
|
||||
private _isReady: boolean = false;
|
||||
|
||||
constructor(id: number, stateCount: number, type: string)
|
||||
{
|
||||
this._id = id;
|
||||
this._instanceId = RoomObject.OBJECT_COUNTER++;
|
||||
this._type = type;
|
||||
|
||||
let i = (stateCount - 1);
|
||||
|
||||
while(i >= 0)
|
||||
{
|
||||
this._states[i] = 0;
|
||||
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._pendingLogicMessages = [];
|
||||
|
||||
this.setVisualization(null);
|
||||
this.setLogic(null);
|
||||
|
||||
if(this._model) this._model.dispose();
|
||||
}
|
||||
|
||||
public getLocation(): IVector3D
|
||||
{
|
||||
return this._location;
|
||||
}
|
||||
|
||||
public setLocation(vector: IVector3D): void
|
||||
{
|
||||
if(!vector) return;
|
||||
|
||||
if((vector.x === this._location.x) && (vector.y === this._location.y) && (vector.z === this._location.z)) return;
|
||||
|
||||
this._location.x = vector.x;
|
||||
this._location.y = vector.y;
|
||||
this._location.z = vector.z;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public getDirection(): IVector3D
|
||||
{
|
||||
return this._direction;
|
||||
}
|
||||
|
||||
public setDirection(vector: IVector3D): void
|
||||
{
|
||||
if(!vector) return;
|
||||
|
||||
if((vector.x === this._direction.x) && (vector.y === this._direction.y) && (vector.z === this._direction.z)) return;
|
||||
|
||||
this._direction.x = (((vector.x % 360) + 360) % 360);
|
||||
this._direction.y = (((vector.y % 360) + 360) % 360);
|
||||
this._direction.z = (((vector.z % 360) + 360) % 360);
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public getState(index: number = 0): number
|
||||
{
|
||||
if((index >= 0) && (index < this._states.length))
|
||||
{
|
||||
return this._states[index];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public setState(state: number, index: number = 0): boolean
|
||||
{
|
||||
if((index >= 0) && (index < this._states.length))
|
||||
{
|
||||
if(this._states[index] !== state)
|
||||
{
|
||||
this._states[index] = state;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public setVisualization(visualization: IRoomObjectVisualization): void
|
||||
{
|
||||
if(this._visualization === visualization) return;
|
||||
|
||||
if(this._visualization) this._visualization.dispose();
|
||||
|
||||
this._visualization = visualization;
|
||||
|
||||
if(this._visualization) this._visualization.object = this;
|
||||
}
|
||||
|
||||
public setLogic(logic: IRoomObjectEventHandler): void
|
||||
{
|
||||
if(this._logic === logic) return;
|
||||
|
||||
const eventHandler = this._logic;
|
||||
|
||||
if(eventHandler)
|
||||
{
|
||||
this._logic = null;
|
||||
|
||||
eventHandler.setObject(null);
|
||||
}
|
||||
|
||||
this._logic = logic;
|
||||
|
||||
if(this._logic)
|
||||
{
|
||||
this._logic.setObject(this);
|
||||
|
||||
while(this._pendingLogicMessages.length)
|
||||
{
|
||||
const message = this._pendingLogicMessages.shift();
|
||||
|
||||
this._logic.processUpdateMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: IRoomObjectUpdateMessage): void
|
||||
{
|
||||
if(this._logic) return this._logic.processUpdateMessage(message);
|
||||
|
||||
this._pendingLogicMessages.push(message);
|
||||
}
|
||||
|
||||
public tearDown(): void
|
||||
{
|
||||
if(this._logic) this._logic.tearDown();
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get instanceId(): number
|
||||
{
|
||||
return this._instanceId;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get model(): IRoomObjectModel
|
||||
{
|
||||
return this._model;
|
||||
}
|
||||
|
||||
public get visualization(): IRoomObjectVisualization
|
||||
{
|
||||
return this._visualization;
|
||||
}
|
||||
|
||||
public get mouseHandler(): IRoomObjectMouseHandler
|
||||
{
|
||||
return this._logic as IRoomObjectMouseHandler;
|
||||
}
|
||||
|
||||
public get logic(): IRoomObjectEventHandler
|
||||
{
|
||||
return this._logic;
|
||||
}
|
||||
|
||||
public get location(): IVector3D
|
||||
{
|
||||
return this._location;
|
||||
}
|
||||
|
||||
public get direction(): IVector3D
|
||||
{
|
||||
return this._direction;
|
||||
}
|
||||
|
||||
public get updateCounter(): number
|
||||
{
|
||||
return this._updateCounter;
|
||||
}
|
||||
|
||||
public set updateCounter(count: number)
|
||||
{
|
||||
this._updateCounter = count;
|
||||
}
|
||||
|
||||
public get isReady(): boolean
|
||||
{
|
||||
return this._isReady;
|
||||
}
|
||||
|
||||
public set isReady(flag: boolean)
|
||||
{
|
||||
this._isReady = flag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { IRoomObjectModel } from '@nitrots/api';
|
||||
|
||||
export class RoomObjectModel implements IRoomObjectModel
|
||||
{
|
||||
private _map: Map<string, unknown> = new Map();
|
||||
private _updateCounter: number = 0;
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._map.clear();
|
||||
|
||||
this._updateCounter = 0;
|
||||
}
|
||||
|
||||
public getValue<T>(key: string): T
|
||||
{
|
||||
const existing = this._map.get(key);
|
||||
|
||||
return (existing as T);
|
||||
}
|
||||
|
||||
public setValue<T>(key: string, value: T): void
|
||||
{
|
||||
if(this._map.has(key))
|
||||
{
|
||||
if(this._map.get(key) === value) return;
|
||||
}
|
||||
|
||||
this._map.set(key, (value as T));
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public removeKey(key: string): void
|
||||
{
|
||||
if(!key) return;
|
||||
|
||||
this._map.delete(key);
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get updateCounter(): number
|
||||
{
|
||||
return this._updateCounter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { IVector3D } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
|
||||
export class RoomPlaneBitmapMaskData
|
||||
{
|
||||
public static WINDOW: string = 'window';
|
||||
public static HOLE: string = 'hole';
|
||||
|
||||
private _loc: Vector3d;
|
||||
private _type: string;
|
||||
private _category: string;
|
||||
|
||||
constructor(type: string, loc: IVector3D, category: string)
|
||||
{
|
||||
this.type = type;
|
||||
this.loc = loc;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public get loc(): IVector3D
|
||||
{
|
||||
return this._loc;
|
||||
}
|
||||
|
||||
public set loc(k: IVector3D)
|
||||
{
|
||||
if(!this._loc) this._loc = new Vector3d();
|
||||
|
||||
this._loc.assign(k);
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public set type(type: string)
|
||||
{
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public get category(): string
|
||||
{
|
||||
return this._category;
|
||||
}
|
||||
|
||||
public set category(category: string)
|
||||
{
|
||||
this._category = category;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._loc = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { IVector3D } from '@nitrots/api';
|
||||
import { RoomMapMaskData } from './RoomMapMaskData';
|
||||
import { RoomPlaneBitmapMaskData } from './RoomPlaneBitmapMaskData';
|
||||
|
||||
export class RoomPlaneBitmapMaskParser
|
||||
{
|
||||
private _masks: Map<string, RoomPlaneBitmapMaskData>;
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._masks = new Map();
|
||||
}
|
||||
|
||||
public get maskCount(): number
|
||||
{
|
||||
return this._masks.size;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._masks)
|
||||
{
|
||||
this.reset();
|
||||
|
||||
this._masks = null;
|
||||
}
|
||||
}
|
||||
|
||||
public initialize(k: RoomMapMaskData): boolean
|
||||
{
|
||||
if(!k) return false;
|
||||
|
||||
this._masks.clear();
|
||||
|
||||
if(k.masks.length)
|
||||
{
|
||||
for(const mask of k.masks)
|
||||
{
|
||||
if(!mask) continue;
|
||||
|
||||
const location = mask.locations.length ? mask.locations[0] : null;
|
||||
|
||||
if(!location) continue;
|
||||
|
||||
this._masks.set(mask.id, new RoomPlaneBitmapMaskData(mask.type, location, mask.category));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public reset(): void
|
||||
{
|
||||
for(const mask of this._masks.values())
|
||||
{
|
||||
if(!mask) continue;
|
||||
|
||||
mask.dispose();
|
||||
}
|
||||
|
||||
this._masks.clear();
|
||||
}
|
||||
|
||||
public addMask(k: string, _arg_2: string, _arg_3: IVector3D, _arg_4: string): void
|
||||
{
|
||||
const mask = new RoomPlaneBitmapMaskData(_arg_2, _arg_3, _arg_4);
|
||||
|
||||
this._masks.delete(k);
|
||||
this._masks.set(k, mask);
|
||||
}
|
||||
|
||||
public removeMask(k: string): boolean
|
||||
{
|
||||
const existing = this._masks.get(k);
|
||||
|
||||
if(existing)
|
||||
{
|
||||
this._masks.delete(k);
|
||||
|
||||
existing.dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public getXML(): RoomMapMaskData
|
||||
{
|
||||
const data = new RoomMapMaskData();
|
||||
|
||||
for(const [key, mask] of this._masks.entries())
|
||||
{
|
||||
if(!mask) continue;
|
||||
|
||||
const type = this.getMaskType(mask);
|
||||
const category = this.getMaskCategory(mask);
|
||||
const location = this.getMaskLocation(mask);
|
||||
|
||||
if(type && category && location)
|
||||
{
|
||||
const newMask: any = {
|
||||
id: key,
|
||||
type: type,
|
||||
category: category,
|
||||
locations: [
|
||||
{
|
||||
x: location.x,
|
||||
y: location.y,
|
||||
z: location.z
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data.masks.push(newMask);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public getMaskLocation(mask: RoomPlaneBitmapMaskData): IVector3D
|
||||
{
|
||||
if(!mask) return null;
|
||||
|
||||
return mask.loc;
|
||||
}
|
||||
|
||||
public getMaskType(mask: RoomPlaneBitmapMaskData): string
|
||||
{
|
||||
if(!mask) return null;
|
||||
|
||||
return mask.type;
|
||||
}
|
||||
|
||||
public getMaskCategory(mask: RoomPlaneBitmapMaskData): string
|
||||
{
|
||||
if(!mask) return null;
|
||||
|
||||
return mask.category;
|
||||
}
|
||||
|
||||
public get masks(): Map<string, RoomPlaneBitmapMaskData>
|
||||
{
|
||||
return this._masks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { IVector3D } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { RoomPlaneMaskData } from './RoomPlaneMaskData';
|
||||
|
||||
export class RoomPlaneData
|
||||
{
|
||||
public static PLANE_UNDEFINED: number = 0;
|
||||
public static PLANE_FLOOR: number = 1;
|
||||
public static PLANE_WALL: number = 2;
|
||||
public static PLANE_LANDSCAPE: number = 3;
|
||||
public static PLANE_BILLBOARD: number = 4;
|
||||
|
||||
private _type: number = 0;
|
||||
private _loc: Vector3d = null;
|
||||
private _leftSide: Vector3d = null;
|
||||
private _rightSide: Vector3d = null;
|
||||
private _normal: Vector3d = null;
|
||||
private _normalDirection: Vector3d = null;
|
||||
private _secondaryNormals: Vector3d[];
|
||||
private _masks: RoomPlaneMaskData[];
|
||||
|
||||
constructor(k: number, _arg_2: IVector3D, _arg_3: IVector3D, _arg_4: IVector3D, _arg_5: IVector3D[])
|
||||
{
|
||||
let _local_6: number;
|
||||
let _local_7: number;
|
||||
let _local_8: number;
|
||||
let _local_9: number;
|
||||
let _local_10: number;
|
||||
let _local_11: number;
|
||||
let _local_12: IVector3D;
|
||||
let _local_13: Vector3d;
|
||||
this._secondaryNormals = [];
|
||||
this._masks = [];
|
||||
this._loc = new Vector3d();
|
||||
this._loc.assign(_arg_2);
|
||||
this._leftSide = new Vector3d();
|
||||
this._leftSide.assign(_arg_3);
|
||||
this._rightSide = new Vector3d();
|
||||
this._rightSide.assign(_arg_4);
|
||||
this._type = k;
|
||||
if(((!(_arg_3 == null)) && (!(_arg_4 == null))))
|
||||
{
|
||||
this._normal = Vector3d.crossProduct(_arg_3, _arg_4);
|
||||
_local_6 = 0;
|
||||
_local_7 = 0;
|
||||
_local_8 = 0;
|
||||
_local_9 = 0;
|
||||
_local_10 = 0;
|
||||
if(((!(this.normal.x == 0)) || (!(this.normal.y == 0))))
|
||||
{
|
||||
_local_9 = this.normal.x;
|
||||
_local_10 = this.normal.y;
|
||||
_local_6 = (360 + ((Math.atan2(_local_10, _local_9) / Math.PI) * 180));
|
||||
if(_local_6 >= 360)
|
||||
{
|
||||
_local_6 = (_local_6 - 360);
|
||||
}
|
||||
_local_9 = Math.sqrt(((this.normal.x * this.normal.x) + (this.normal.y * this.normal.y)));
|
||||
_local_10 = this.normal.z;
|
||||
_local_7 = (360 + ((Math.atan2(_local_10, _local_9) / Math.PI) * 180));
|
||||
if(_local_7 >= 360)
|
||||
{
|
||||
_local_7 = (_local_7 - 360);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.normal.z < 0)
|
||||
{
|
||||
_local_7 = 90;
|
||||
}
|
||||
else
|
||||
{
|
||||
_local_7 = 270;
|
||||
}
|
||||
}
|
||||
this._normalDirection = new Vector3d(_local_6, _local_7, _local_8);
|
||||
}
|
||||
if(((!(_arg_5 == null)) && (_arg_5.length > 0)))
|
||||
{
|
||||
_local_11 = 0;
|
||||
while(_local_11 < _arg_5.length)
|
||||
{
|
||||
_local_12 = _arg_5[_local_11];
|
||||
if(((!(_local_12 == null)) && (_local_12.length > 0)))
|
||||
{
|
||||
_local_13 = new Vector3d();
|
||||
_local_13.assign(_local_12);
|
||||
_local_13.multiply((1 / _local_13.length));
|
||||
this._secondaryNormals.push(_local_13);
|
||||
}
|
||||
_local_11++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get loc(): IVector3D
|
||||
{
|
||||
return this._loc;
|
||||
}
|
||||
|
||||
public get leftSide(): IVector3D
|
||||
{
|
||||
return this._leftSide;
|
||||
}
|
||||
|
||||
public get rightSide(): IVector3D
|
||||
{
|
||||
return this._rightSide;
|
||||
}
|
||||
|
||||
public get normal(): IVector3D
|
||||
{
|
||||
return this._normal;
|
||||
}
|
||||
|
||||
public get normalDirection(): IVector3D
|
||||
{
|
||||
return this._normalDirection;
|
||||
}
|
||||
|
||||
public get secondaryNormalCount(): number
|
||||
{
|
||||
return this._secondaryNormals.length;
|
||||
}
|
||||
|
||||
public get maskCount(): number
|
||||
{
|
||||
return this._masks.length;
|
||||
}
|
||||
|
||||
public getSecondaryNormal(k: number): IVector3D
|
||||
{
|
||||
if(((k < 0) || (k >= this.secondaryNormalCount)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
const _local_2: Vector3d = new Vector3d();
|
||||
_local_2.assign((this._secondaryNormals[k] as IVector3D));
|
||||
return _local_2;
|
||||
}
|
||||
|
||||
public addMask(k: number, _arg_2: number, _arg_3: number, _arg_4: number): void
|
||||
{
|
||||
const _local_5: RoomPlaneMaskData = new RoomPlaneMaskData(k, _arg_2, _arg_3, _arg_4);
|
||||
this._masks.push(_local_5);
|
||||
}
|
||||
|
||||
private getMask(k: number): RoomPlaneMaskData
|
||||
{
|
||||
if(((k < 0) || (k >= this.maskCount)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this._masks[k];
|
||||
}
|
||||
|
||||
public getMaskLeftSideLoc(k: number): number
|
||||
{
|
||||
const _local_2: RoomPlaneMaskData = this.getMask(k);
|
||||
if(_local_2 != null)
|
||||
{
|
||||
return _local_2.leftSideLoc;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public getMaskRightSideLoc(k: number): number
|
||||
{
|
||||
const _local_2: RoomPlaneMaskData = this.getMask(k);
|
||||
if(_local_2 != null)
|
||||
{
|
||||
return _local_2.rightSideLoc;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public getMaskLeftSideLength(k: number): number
|
||||
{
|
||||
const _local_2: RoomPlaneMaskData = this.getMask(k);
|
||||
if(_local_2 != null)
|
||||
{
|
||||
return _local_2.leftSideLength;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public getMaskRightSideLength(k: number): number
|
||||
{
|
||||
const _local_2: RoomPlaneMaskData = this.getMask(k);
|
||||
if(_local_2 != null)
|
||||
{
|
||||
return _local_2.rightSideLength;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
export class RoomPlaneMaskData
|
||||
{
|
||||
private _leftSideLoc: number = 0;
|
||||
private _rightSideLoc: number = 0;
|
||||
private _leftSideLength: number = 0;
|
||||
private _rightSideLength: number = 0;
|
||||
|
||||
constructor(k: number, _arg_2: number, _arg_3: number, _arg_4: number)
|
||||
{
|
||||
this._leftSideLoc = k;
|
||||
this._rightSideLoc = _arg_2;
|
||||
this._leftSideLength = _arg_3;
|
||||
this._rightSideLength = _arg_4;
|
||||
}
|
||||
|
||||
public get leftSideLoc(): number
|
||||
{
|
||||
return this._leftSideLoc;
|
||||
}
|
||||
|
||||
public get rightSideLoc(): number
|
||||
{
|
||||
return this._rightSideLoc;
|
||||
}
|
||||
|
||||
public get leftSideLength(): number
|
||||
{
|
||||
return this._leftSideLength;
|
||||
}
|
||||
|
||||
public get rightSideLength(): number
|
||||
{
|
||||
return this._rightSideLength;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
import { IVector3D } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { Point } from 'pixi.js';
|
||||
|
||||
export class RoomWallData
|
||||
{
|
||||
public static WALL_DIRECTION_VECTORS: Vector3d[] = [
|
||||
new Vector3d(1, 0, 0),
|
||||
new Vector3d(0, 1, 0),
|
||||
new Vector3d(-1, 0, 0),
|
||||
new Vector3d(0, -1, 0)
|
||||
];
|
||||
|
||||
public static WALL_NORMAL_VECTORS: Vector3d[] = [
|
||||
new Vector3d(0, 1, 0),
|
||||
new Vector3d(-1, 0, 0),
|
||||
new Vector3d(0, -1, 0),
|
||||
new Vector3d(1, 0, 0)
|
||||
];
|
||||
|
||||
private _corners: Point[];
|
||||
private _endPoints: Point[];
|
||||
private _directions: number[];
|
||||
private _lengths: number[];
|
||||
private _leftTurns: boolean[];
|
||||
private _borders: boolean[];
|
||||
private _hideWalls: boolean[];
|
||||
private _manuallyLeftCut: boolean[];
|
||||
private _manuallyRightCut: boolean[];
|
||||
private _addDuplicates: boolean;
|
||||
private _count: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._corners = [];
|
||||
this._endPoints = [];
|
||||
this._directions = [];
|
||||
this._lengths = [];
|
||||
this._leftTurns = [];
|
||||
this._borders = [];
|
||||
this._hideWalls = [];
|
||||
this._manuallyLeftCut = [];
|
||||
this._manuallyRightCut = [];
|
||||
this._addDuplicates = false;
|
||||
this._count = 0;
|
||||
}
|
||||
|
||||
public addWall(k: Point, _arg_2: number, _arg_3: number, _arg_4: boolean, _arg_5: boolean): void
|
||||
{
|
||||
if(((this._addDuplicates) || (this.checkIsNotDuplicate(k, _arg_2, _arg_3, _arg_4, _arg_5))))
|
||||
{
|
||||
this._corners.push(k);
|
||||
this._directions.push(_arg_2);
|
||||
this._lengths.push(_arg_3);
|
||||
this._borders.push(_arg_4);
|
||||
this._leftTurns.push(_arg_5);
|
||||
this._hideWalls.push(false);
|
||||
this._manuallyLeftCut.push(false);
|
||||
this._manuallyRightCut.push(false);
|
||||
this._count++;
|
||||
}
|
||||
}
|
||||
|
||||
private checkIsNotDuplicate(k: Point, _arg_2: number, _arg_3: number, _arg_4: boolean, _arg_5: boolean): boolean
|
||||
{
|
||||
let _local_6 = 0;
|
||||
|
||||
while(_local_6 < this._count)
|
||||
{
|
||||
if(((((((this._corners[_local_6].x == k.x) && (this._corners[_local_6].y == k.y)) && (this._directions[_local_6] == _arg_2)) && (this._lengths[_local_6] == _arg_3)) && (this._borders[_local_6] == _arg_4)) && (this._leftTurns[_local_6] == _arg_5)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_local_6++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public get count(): number
|
||||
{
|
||||
return this._count;
|
||||
}
|
||||
|
||||
public getCorner(k: number): Point
|
||||
{
|
||||
return this._corners[k];
|
||||
}
|
||||
|
||||
public getEndPoint(k: number): Point
|
||||
{
|
||||
this.calculateWallEndPoints();
|
||||
return this._endPoints[k];
|
||||
}
|
||||
|
||||
public getLength(k: number): number
|
||||
{
|
||||
return this._lengths[k];
|
||||
}
|
||||
|
||||
public getDirection(k: number): number
|
||||
{
|
||||
return this._directions[k];
|
||||
}
|
||||
|
||||
public getBorder(k: number): boolean
|
||||
{
|
||||
return this._borders[k];
|
||||
}
|
||||
|
||||
public getHideWall(k: number): boolean
|
||||
{
|
||||
return this._hideWalls[k];
|
||||
}
|
||||
|
||||
public getLeftTurn(k: number): boolean
|
||||
{
|
||||
return this._leftTurns[k];
|
||||
}
|
||||
|
||||
public getManuallyLeftCut(k: number): boolean
|
||||
{
|
||||
return this._manuallyLeftCut[k];
|
||||
}
|
||||
|
||||
public getManuallyRightCut(k: number): boolean
|
||||
{
|
||||
return this._manuallyRightCut[k];
|
||||
}
|
||||
|
||||
public setHideWall(k: number, _arg_2: boolean): void
|
||||
{
|
||||
this._hideWalls[k] = _arg_2;
|
||||
}
|
||||
|
||||
public setLength(k: number, _arg_2: number): void
|
||||
{
|
||||
if(_arg_2 < this._lengths[k])
|
||||
{
|
||||
this._lengths[k] = _arg_2;
|
||||
this._manuallyRightCut[k] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public moveCorner(k: number, _arg_2: number): void
|
||||
{
|
||||
let _local_3: IVector3D;
|
||||
if(((_arg_2 > 0) && (_arg_2 < this._lengths[k])))
|
||||
{
|
||||
const corner = this._corners[k];
|
||||
|
||||
_local_3 = RoomWallData.WALL_DIRECTION_VECTORS[this.getDirection(k)];
|
||||
this._corners[k] = new Point((corner.x + (_arg_2 * _local_3.x)), (corner.y + (_arg_2 * _local_3.y)));
|
||||
this._lengths[k] = (this._lengths[k] - _arg_2);
|
||||
this._manuallyLeftCut[k] = true;
|
||||
}
|
||||
}
|
||||
|
||||
private calculateWallEndPoints(): void
|
||||
{
|
||||
let k: number;
|
||||
let _local_2: Point;
|
||||
let _local_3: Point;
|
||||
let _local_4: IVector3D;
|
||||
let _local_5: number;
|
||||
if(this._endPoints.length != this.count)
|
||||
{
|
||||
this._endPoints = [];
|
||||
k = 0;
|
||||
while(k < this.count)
|
||||
{
|
||||
_local_2 = this.getCorner(k);
|
||||
_local_3 = new Point(_local_2.x, _local_2.y);
|
||||
_local_4 = RoomWallData.WALL_DIRECTION_VECTORS[this.getDirection(k)];
|
||||
_local_5 = this.getLength(k);
|
||||
_local_3.x = (_local_3.x + (_local_4.x * _local_5));
|
||||
_local_3.y = (_local_3.y + (_local_4.y * _local_5));
|
||||
this._endPoints.push(_local_3);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export * from './RoomFloorHole';
|
||||
export * from './RoomMapData';
|
||||
export * from './RoomMapMaskData';
|
||||
export * from './RoomObject';
|
||||
export * from './RoomObjectModel';
|
||||
export * from './RoomPlaneBitmapMaskData';
|
||||
export * from './RoomPlaneBitmapMaskParser';
|
||||
export * from './RoomPlaneData';
|
||||
export * from './RoomPlaneMaskData';
|
||||
export * from './RoomPlaneParser';
|
||||
export * from './RoomWallData';
|
||||
export * from './logic';
|
||||
export * from './logic/furniture';
|
||||
export * from './visualization';
|
||||
export * from './visualization/avatar';
|
||||
export * from './visualization/avatar/additions';
|
||||
export * from './visualization/data';
|
||||
export * from './visualization/furniture';
|
||||
export * from './visualization/pet';
|
||||
export * from './visualization/room';
|
||||
export * from './visualization/room/mask';
|
||||
export * from './visualization/room/utils';
|
||||
@@ -0,0 +1,504 @@
|
||||
|
||||
import { AvatarAction, IRoomGeometry, IRoomObjectModel, IVector3D, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent, RoomObjectMouseEvent, RoomObjectMoveEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { GetTickerTime, Vector3d } from '@nitrots/utils';
|
||||
import { ObjectAvatarCarryObjectUpdateMessage, ObjectAvatarChatUpdateMessage, ObjectAvatarDanceUpdateMessage, ObjectAvatarEffectUpdateMessage, ObjectAvatarExpressionUpdateMessage, ObjectAvatarFigureUpdateMessage, ObjectAvatarFlatControlUpdateMessage, ObjectAvatarGestureUpdateMessage, ObjectAvatarMutedUpdateMessage, ObjectAvatarOwnMessage, ObjectAvatarPlayerValueUpdateMessage, ObjectAvatarPlayingGameUpdateMessage, ObjectAvatarPostureUpdateMessage, ObjectAvatarSelectedMessage, ObjectAvatarSignUpdateMessage, ObjectAvatarSleepUpdateMessage, ObjectAvatarTypingUpdateMessage, ObjectAvatarUpdateMessage, ObjectAvatarUseObjectUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
||||
import { MovingObjectLogic } from './MovingObjectLogic';
|
||||
|
||||
export class AvatarLogic extends MovingObjectLogic
|
||||
{
|
||||
private static MAX_HAND_ID: number = 999999999;
|
||||
private static MAX_HAND_USE_ID: number = 999;
|
||||
private static EFFECT_TYPE_SPLASH: number = 28;
|
||||
private static EFFECT_SPLASH_LENGTH: number = 500;
|
||||
private static EFFECT_TYPE_SWIM: number = 29;
|
||||
private static EFFECT_TYPE_SPLASH_DARK: number = 184;
|
||||
private static EFFECT_TYPE_SWIM_DARK: number = 185;
|
||||
|
||||
private _selected: boolean;
|
||||
private _reportedLocation: IVector3D;
|
||||
private _effectChangeTimeStamp: number;
|
||||
private _newEffect: number;
|
||||
private _blinkingStartTimestamp: number;
|
||||
private _blinkingEndTimestamp: number;
|
||||
private _talkingEndTimestamp: number;
|
||||
private _talkingPauseStartTimestamp: number;
|
||||
private _talkingPauseEndTimestamp: number;
|
||||
private _carryObjectStartTimestamp: number;
|
||||
private _carryObjectEndTimestamp: number;
|
||||
private _allowUseCarryObject: boolean;
|
||||
private _animationEndTimestamp: number;
|
||||
private _signEndTimestamp: number;
|
||||
private _gestureEndTimestamp: number;
|
||||
private _numberValueEndTimestamp: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._selected = false;
|
||||
this._reportedLocation = null;
|
||||
this._effectChangeTimeStamp = 0;
|
||||
this._newEffect = 0;
|
||||
this._blinkingStartTimestamp = GetTickerTime() + this.randomBlinkStartTimestamp();
|
||||
this._blinkingEndTimestamp = 0;
|
||||
this._talkingEndTimestamp = 0;
|
||||
this._talkingPauseStartTimestamp = 0;
|
||||
this._talkingPauseEndTimestamp = 0;
|
||||
this._carryObjectStartTimestamp = 0;
|
||||
this._carryObjectEndTimestamp = 0;
|
||||
this._allowUseCarryObject = false;
|
||||
this._animationEndTimestamp = 0;
|
||||
this._signEndTimestamp = 0;
|
||||
this._gestureEndTimestamp = 0;
|
||||
this._numberValueEndTimestamp = 0;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectMouseEvent.CLICK, RoomObjectMouseEvent.DOUBLE_CLICK, RoomObjectMoveEvent.POSITION_CHANGED, RoomObjectMouseEvent.MOUSE_ENTER, RoomObjectMouseEvent.MOUSE_LEAVE, RoomObjectFurnitureActionEvent.MOUSE_BUTTON, RoomObjectFurnitureActionEvent.MOUSE_ARROW];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._selected && this.object)
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectMoveEvent(RoomObjectMoveEvent.OBJECT_REMOVED, this.object));
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
|
||||
this._reportedLocation = null;
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(this._selected && this.object)
|
||||
{
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const location = this.object.getLocation();
|
||||
|
||||
if(((!this._reportedLocation || (this._reportedLocation.x !== location.x)) || (this._reportedLocation.y !== location.y)) || (this._reportedLocation.z !== location.z))
|
||||
{
|
||||
if(!this._reportedLocation) this._reportedLocation = new Vector3d();
|
||||
|
||||
this._reportedLocation.assign(location);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectMoveEvent(RoomObjectMoveEvent.POSITION_CHANGED, this.object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(model) this.updateModel(this.time, model);
|
||||
}
|
||||
|
||||
private updateModel(time: number, model: IRoomObjectModel): void
|
||||
{
|
||||
if(this._talkingEndTimestamp > 0)
|
||||
{
|
||||
if(time > this._talkingEndTimestamp)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 0);
|
||||
|
||||
this._talkingEndTimestamp = 0;
|
||||
this._talkingPauseStartTimestamp = 0;
|
||||
this._talkingPauseEndTimestamp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!this._talkingPauseEndTimestamp && !this._talkingPauseStartTimestamp)
|
||||
{
|
||||
this._talkingPauseStartTimestamp = time + this.randomTalkingPauseStartTimestamp();
|
||||
this._talkingPauseEndTimestamp = this._talkingPauseStartTimestamp + this.randomTalkingPauseEndTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
if((this._talkingPauseStartTimestamp > 0) && (time > this._talkingPauseStartTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 0);
|
||||
|
||||
this._talkingPauseStartTimestamp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((this._talkingPauseEndTimestamp > 0) && (time > this._talkingPauseEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 1);
|
||||
|
||||
this._talkingPauseEndTimestamp = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((this._animationEndTimestamp > 0) && (time > this._animationEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_EXPRESSION, 0);
|
||||
|
||||
this._animationEndTimestamp = 0;
|
||||
}
|
||||
|
||||
if((this._gestureEndTimestamp > 0) && (time > this._gestureEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_GESTURE, 0);
|
||||
|
||||
this._gestureEndTimestamp = 0;
|
||||
}
|
||||
|
||||
if((this._signEndTimestamp > 0) && (time > this._signEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_SIGN, -1);
|
||||
|
||||
this._signEndTimestamp = 0;
|
||||
}
|
||||
|
||||
if(this._carryObjectEndTimestamp > 0)
|
||||
{
|
||||
if(time > this._carryObjectEndTimestamp)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_CARRY_OBJECT, 0);
|
||||
model.setValue(RoomObjectVariable.FIGURE_USE_OBJECT, 0);
|
||||
|
||||
this._carryObjectStartTimestamp = 0;
|
||||
this._carryObjectEndTimestamp = 0;
|
||||
this._allowUseCarryObject = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(this._allowUseCarryObject)
|
||||
{
|
||||
if((time - this._carryObjectStartTimestamp) > 5000)
|
||||
{
|
||||
if(((time - this._carryObjectStartTimestamp) % 10000) < 1000)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_USE_OBJECT, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_USE_OBJECT, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((this._blinkingStartTimestamp > -1) && (time > this._blinkingStartTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_BLINK, 1);
|
||||
|
||||
this._blinkingStartTimestamp = time + this.randomBlinkStartTimestamp();
|
||||
this._blinkingEndTimestamp = time + this.randomBlinkEndTimestamp();
|
||||
}
|
||||
|
||||
if((this._blinkingEndTimestamp > 0) && (time > this._blinkingEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_BLINK, 0);
|
||||
|
||||
this._blinkingEndTimestamp = 0;
|
||||
}
|
||||
|
||||
if((this._effectChangeTimeStamp > 0) && (time > this._effectChangeTimeStamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_EFFECT, this._newEffect);
|
||||
|
||||
this._effectChangeTimeStamp = 0;
|
||||
}
|
||||
|
||||
if((this._numberValueEndTimestamp > 0) && (time > this._numberValueEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_NUMBER_VALUE, 0);
|
||||
|
||||
this._numberValueEndTimestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message || !this.object) return;
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
if(message instanceof ObjectAvatarPostureUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_POSTURE, message.postureType);
|
||||
model.setValue(RoomObjectVariable.FIGURE_POSTURE_PARAMETER, message.parameter);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarChatUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 1);
|
||||
|
||||
this._talkingEndTimestamp = (this.time + (message.numberOfWords * 1000));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarTypingUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_IS_TYPING, message.isTyping ? 1 : 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarMutedUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_IS_MUTED, (message.isMuted ? 1 : 0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarPlayingGameUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_IS_PLAYING_GAME, (message.isPlayingGame ? 1 : 0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.HEAD_DIRECTION, message.headDirection);
|
||||
model.setValue(RoomObjectVariable.FIGURE_CAN_STAND_UP, message.canStandUp);
|
||||
model.setValue(RoomObjectVariable.FIGURE_VERTICAL_OFFSET, message.baseY);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarGestureUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_GESTURE, message.gesture);
|
||||
|
||||
this._gestureEndTimestamp = (this.time + 3000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarExpressionUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_EXPRESSION, message.expressionType);
|
||||
|
||||
this._animationEndTimestamp = AvatarAction.getExpressionTimeout(model.getValue<number>(RoomObjectVariable.FIGURE_EXPRESSION));
|
||||
|
||||
if(this._animationEndTimestamp > -1) this._animationEndTimestamp += this.time;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarDanceUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_DANCE, message.danceStyle);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarSleepUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_SLEEP, message.isSleeping ? 1 : 0);
|
||||
|
||||
if(message.isSleeping) this._blinkingStartTimestamp = -1;
|
||||
else this._blinkingStartTimestamp = (this.time + this.randomBlinkStartTimestamp());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarPlayerValueUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_NUMBER_VALUE, message.value);
|
||||
|
||||
this._numberValueEndTimestamp = (this.time + 3000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarEffectUpdateMessage)
|
||||
{
|
||||
this.updateAvatarEffect(message.effect, message.delayMilliseconds, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarCarryObjectUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_CARRY_OBJECT, message.itemType);
|
||||
model.setValue(RoomObjectVariable.FIGURE_USE_OBJECT, 0);
|
||||
|
||||
if(message.itemType === 0)
|
||||
{
|
||||
this._carryObjectStartTimestamp = 0;
|
||||
this._carryObjectEndTimestamp = 0;
|
||||
this._allowUseCarryObject = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._carryObjectStartTimestamp = this.time;
|
||||
|
||||
if(message.itemType < AvatarLogic.MAX_HAND_ID)
|
||||
{
|
||||
this._carryObjectEndTimestamp = 0;
|
||||
this._allowUseCarryObject = message.itemType <= AvatarLogic.MAX_HAND_USE_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._carryObjectEndTimestamp = this._carryObjectStartTimestamp + 1500;
|
||||
this._allowUseCarryObject = false;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarUseObjectUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_USE_OBJECT, message.itemType);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarSignUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_SIGN, message.signType);
|
||||
|
||||
this._signEndTimestamp = (this.time + 5000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarFlatControlUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_FLAT_CONTROL, message.level);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarFigureUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE, message.figure);
|
||||
model.setValue(RoomObjectVariable.GENDER, message.gender);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarSelectedMessage)
|
||||
{
|
||||
this._selected = message.selected;
|
||||
this._reportedLocation = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarOwnMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.OWN_USER, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private updateAvatarEffect(effect: number, delay: number, model: IRoomObjectModel): void
|
||||
{
|
||||
if(effect === AvatarLogic.EFFECT_TYPE_SPLASH)
|
||||
{
|
||||
this._effectChangeTimeStamp = (GetTickerTime() + AvatarLogic.EFFECT_SPLASH_LENGTH);
|
||||
this._newEffect = AvatarLogic.EFFECT_TYPE_SWIM;
|
||||
}
|
||||
|
||||
else if(effect === AvatarLogic.EFFECT_TYPE_SPLASH_DARK)
|
||||
{
|
||||
this._effectChangeTimeStamp = (GetTickerTime() + AvatarLogic.EFFECT_SPLASH_LENGTH);
|
||||
this._newEffect = AvatarLogic.EFFECT_TYPE_SWIM_DARK;
|
||||
}
|
||||
|
||||
else if(model.getValue<number>(RoomObjectVariable.FIGURE_EFFECT) === AvatarLogic.EFFECT_TYPE_SWIM)
|
||||
{
|
||||
this._effectChangeTimeStamp = (GetTickerTime() + AvatarLogic.EFFECT_SPLASH_LENGTH);
|
||||
this._newEffect = effect;
|
||||
|
||||
effect = AvatarLogic.EFFECT_TYPE_SPLASH;
|
||||
}
|
||||
|
||||
else if(model.getValue<number>(RoomObjectVariable.FIGURE_EFFECT) === AvatarLogic.EFFECT_TYPE_SWIM_DARK)
|
||||
{
|
||||
this._effectChangeTimeStamp = (GetTickerTime() + AvatarLogic.EFFECT_SPLASH_LENGTH);
|
||||
this._newEffect = effect;
|
||||
|
||||
effect = AvatarLogic.EFFECT_TYPE_SPLASH_DARK;
|
||||
}
|
||||
|
||||
else if(delay === 0)
|
||||
{
|
||||
this._effectChangeTimeStamp = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
this._effectChangeTimeStamp = (GetTickerTime() + delay);
|
||||
this._newEffect = effect;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
model.setValue(RoomObjectVariable.FIGURE_EFFECT, effect);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
let eventType: string = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.MOUSE_CLICK:
|
||||
eventType = RoomObjectMouseEvent.CLICK;
|
||||
break;
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
eventType = RoomObjectMouseEvent.DOUBLE_CLICK;
|
||||
break;
|
||||
case MouseEventType.ROLL_OVER:
|
||||
eventType = RoomObjectMouseEvent.MOUSE_ENTER;
|
||||
|
||||
if(this.object.model) this.object.model.setValue(RoomObjectVariable.FIGURE_HIGHLIGHT, 1);
|
||||
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_BUTTON, this.object));
|
||||
break;
|
||||
case MouseEventType.ROLL_OUT:
|
||||
eventType = RoomObjectMouseEvent.MOUSE_LEAVE;
|
||||
|
||||
if(this.object.model) this.object.model.setValue(RoomObjectVariable.FIGURE_HIGHLIGHT, 0);
|
||||
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_ARROW, this.object));
|
||||
break;
|
||||
}
|
||||
|
||||
if(eventType && this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectMouseEvent(eventType, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown));
|
||||
}
|
||||
|
||||
private randomTalkingPauseStartTimestamp(): number
|
||||
{
|
||||
return 100 + (Math.random() * 200);
|
||||
}
|
||||
|
||||
private randomTalkingPauseEndTimestamp(): number
|
||||
{
|
||||
return 75 + (Math.random() * 75);
|
||||
}
|
||||
|
||||
private randomBlinkStartTimestamp(): number
|
||||
{
|
||||
return 4500 + (Math.random() * 1000);
|
||||
}
|
||||
|
||||
private randomBlinkEndTimestamp(): number
|
||||
{
|
||||
return 50 + (Math.random() * 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import { IRoomObjectController, IRoomObjectUpdateMessage, IVector3D, RoomObjectVariable } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { ObjectMoveUpdateMessage } from '../../messages';
|
||||
import { RoomObjectLogicBase } from './RoomObjectLogicBase';
|
||||
|
||||
export class MovingObjectLogic extends RoomObjectLogicBase
|
||||
{
|
||||
public static DEFAULT_UPDATE_INTERVAL: number = 500;
|
||||
private static TEMP_VECTOR: Vector3d = new Vector3d();
|
||||
|
||||
private _liftAmount: number;
|
||||
|
||||
private _location: Vector3d;
|
||||
private _locationDelta: Vector3d;
|
||||
private _lastUpdateTime: number;
|
||||
private _changeTime: number;
|
||||
private _updateInterval: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._liftAmount = 0;
|
||||
|
||||
this._location = new Vector3d();
|
||||
this._locationDelta = new Vector3d();
|
||||
this._lastUpdateTime = 0;
|
||||
this._changeTime = 0;
|
||||
this._updateInterval = MovingObjectLogic.DEFAULT_UPDATE_INTERVAL;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._liftAmount = 0;
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
const locationOffset = this.getLocationOffset();
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(model)
|
||||
{
|
||||
if(locationOffset)
|
||||
{
|
||||
if(this._liftAmount !== locationOffset.z)
|
||||
{
|
||||
this._liftAmount = locationOffset.z;
|
||||
|
||||
model.setValue(RoomObjectVariable.FURNITURE_LIFT_AMOUNT, this._liftAmount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this._liftAmount !== 0)
|
||||
{
|
||||
this._liftAmount = 0;
|
||||
|
||||
model.setValue(RoomObjectVariable.FURNITURE_LIFT_AMOUNT, this._liftAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((this._locationDelta.length > 0) || locationOffset)
|
||||
{
|
||||
const vector = MovingObjectLogic.TEMP_VECTOR;
|
||||
|
||||
let difference = (this.time - this._changeTime);
|
||||
|
||||
if(difference === (this._updateInterval >> 1)) difference++;
|
||||
|
||||
if(difference > this._updateInterval) difference = this._updateInterval;
|
||||
|
||||
if(this._locationDelta.length > 0)
|
||||
{
|
||||
vector.assign(this._locationDelta);
|
||||
vector.multiply((difference / this._updateInterval));
|
||||
vector.add(this._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
vector.assign(this._location);
|
||||
}
|
||||
|
||||
if(locationOffset) vector.add(locationOffset);
|
||||
|
||||
this.object.setLocation(vector);
|
||||
|
||||
if(difference === this._updateInterval)
|
||||
{
|
||||
this._locationDelta.x = 0;
|
||||
this._locationDelta.y = 0;
|
||||
this._locationDelta.z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this._lastUpdateTime = this.time;
|
||||
}
|
||||
|
||||
public setObject(object: IRoomObjectController): void
|
||||
{
|
||||
super.setObject(object);
|
||||
|
||||
if(object) this._location.assign(object.getLocation());
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: IRoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message.location) this._location.assign(message.location);
|
||||
|
||||
if(message instanceof ObjectMoveUpdateMessage) return this.processMoveMessage(message);
|
||||
}
|
||||
|
||||
private processMoveMessage(message: ObjectMoveUpdateMessage): void
|
||||
{
|
||||
if(!message || !this.object || !message.location) return;
|
||||
|
||||
this._changeTime = this._lastUpdateTime;
|
||||
|
||||
this._locationDelta.assign(message.targetLocation);
|
||||
this._locationDelta.subtract(this._location);
|
||||
}
|
||||
|
||||
protected getLocationOffset(): IVector3D
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected get lastUpdateTime(): number
|
||||
{
|
||||
return this._lastUpdateTime;
|
||||
}
|
||||
|
||||
protected set updateInterval(interval: number)
|
||||
{
|
||||
if(interval <= 0) interval = 1;
|
||||
|
||||
this._updateInterval = interval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
import { IAssetData, IRoomGeometry, IRoomObjectModel, IVector3D, MouseEventType, PetFigureData, PetType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectMouseEvent, RoomObjectMoveEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { ObjectAvatarChatUpdateMessage, ObjectAvatarExperienceUpdateMessage, ObjectAvatarFigureUpdateMessage, ObjectAvatarPetGestureUpdateMessage, ObjectAvatarPostureUpdateMessage, ObjectAvatarSelectedMessage, ObjectAvatarSleepUpdateMessage, ObjectAvatarUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
||||
import { MovingObjectLogic } from './MovingObjectLogic';
|
||||
|
||||
export class PetLogic extends MovingObjectLogic
|
||||
{
|
||||
private _selected: boolean;
|
||||
private _reportedLocation: IVector3D;
|
||||
private _postureIndex: number;
|
||||
private _gestureIndex: number;
|
||||
private _headDirectionDelta: number;
|
||||
private _directions: number[];
|
||||
|
||||
private _talkingEndTimestamp: number;
|
||||
private _gestureEndTimestamp: number;
|
||||
private _expressionEndTimestamp: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._selected = false;
|
||||
this._reportedLocation = null;
|
||||
this._postureIndex = 0;
|
||||
this._gestureIndex = 0;
|
||||
this._headDirectionDelta = 0;
|
||||
this._directions = [];
|
||||
|
||||
this._talkingEndTimestamp = 0;
|
||||
this._gestureEndTimestamp = 0;
|
||||
this._expressionEndTimestamp = 0;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectMouseEvent.CLICK, RoomObjectMoveEvent.POSITION_CHANGED];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
if(!asset) return;
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.model)
|
||||
{
|
||||
const directions = asset.logic.model.directions;
|
||||
|
||||
if(directions && directions.length)
|
||||
{
|
||||
for(const direction of directions) this._directions.push(direction);
|
||||
|
||||
this._directions.sort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.setValue(RoomObjectVariable.PET_ALLOWED_DIRECTIONS, this._directions);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._selected && this.object)
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectMoveEvent(RoomObjectMoveEvent.OBJECT_REMOVED, this.object));
|
||||
}
|
||||
|
||||
this._directions = null;
|
||||
this._reportedLocation = null;
|
||||
}
|
||||
|
||||
public update(totalTimeRunning: number): void
|
||||
{
|
||||
super.update(totalTimeRunning);
|
||||
|
||||
if(this._selected && this.object)
|
||||
{
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const location = this.object.getLocation();
|
||||
|
||||
if(((!this._reportedLocation || (this._reportedLocation.x !== location.x)) || (this._reportedLocation.y !== location.y)) || (this._reportedLocation.z !== location.z))
|
||||
{
|
||||
if(!this._reportedLocation) this._reportedLocation = new Vector3d();
|
||||
|
||||
this._reportedLocation.assign(location);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectMoveEvent(RoomObjectMoveEvent.POSITION_CHANGED, this.object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.object && this.object.model) this.updateModel(totalTimeRunning, this.object.model);
|
||||
}
|
||||
|
||||
private updateModel(time: number, model: IRoomObjectModel): void
|
||||
{
|
||||
if((this._gestureEndTimestamp > 0) && (time > this._gestureEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_GESTURE, null);
|
||||
|
||||
this._gestureEndTimestamp = 0;
|
||||
}
|
||||
|
||||
if(this._talkingEndTimestamp > 0)
|
||||
{
|
||||
if(time > this._talkingEndTimestamp)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 0);
|
||||
|
||||
this._talkingEndTimestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if((this._expressionEndTimestamp > 0) && (time > this._expressionEndTimestamp))
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_EXPRESSION, 0);
|
||||
|
||||
this._expressionEndTimestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message || !this.object) return;
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
if(message instanceof ObjectAvatarUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.HEAD_DIRECTION, message.headDirection);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarFigureUpdateMessage)
|
||||
{
|
||||
const petFigureData = new PetFigureData(message.figure);
|
||||
|
||||
model.setValue(RoomObjectVariable.FIGURE, message.figure);
|
||||
model.setValue(RoomObjectVariable.RACE, message.subType);
|
||||
model.setValue(RoomObjectVariable.PET_PALETTE_INDEX, petFigureData.paletteId);
|
||||
model.setValue(RoomObjectVariable.PET_COLOR, petFigureData.color);
|
||||
model.setValue(RoomObjectVariable.PET_TYPE, petFigureData.typeId);
|
||||
model.setValue(RoomObjectVariable.PET_CUSTOM_LAYER_IDS, petFigureData.customLayerIds);
|
||||
model.setValue(RoomObjectVariable.PET_CUSTOM_PARTS_IDS, petFigureData.customPartIds);
|
||||
model.setValue(RoomObjectVariable.PET_CUSTOM_PALETTE_IDS, petFigureData.customPaletteIds);
|
||||
model.setValue(RoomObjectVariable.PET_IS_RIDING, (message.isRiding ? 1 : 0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarPostureUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_POSTURE, message.postureType);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarChatUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_TALK, 1);
|
||||
|
||||
this._talkingEndTimestamp = this.time + (message.numberOfWords * 1000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarSleepUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_SLEEP, message.isSleeping ? 1 : 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarPetGestureUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_GESTURE, message.gesture);
|
||||
|
||||
this._gestureEndTimestamp = this.time + 3000;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarSelectedMessage)
|
||||
{
|
||||
this._selected = message.selected;
|
||||
this._reportedLocation = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectAvatarExperienceUpdateMessage)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FIGURE_EXPERIENCE_TIMESTAMP, this.time);
|
||||
model.setValue(RoomObjectVariable.FIGURE_GAINED_EXPERIENCE, message.gainedExperience);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
let eventType: string = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.MOUSE_CLICK:
|
||||
eventType = RoomObjectMouseEvent.CLICK;
|
||||
break;
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
break;
|
||||
case MouseEventType.MOUSE_DOWN: {
|
||||
const petType = this.object.model.getValue<number>(RoomObjectVariable.PET_TYPE);
|
||||
|
||||
if(petType === PetType.MONSTERPLANT)
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_DOWN, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(eventType && this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectMouseEvent(eventType, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
import { IRoomGeometry, IRoomObjectModel, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { RoomObjectEvent, RoomObjectMouseEvent, RoomObjectTileMouseEvent, RoomObjectWallMouseEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { ColorConverter, Vector3d } from '@nitrots/utils';
|
||||
import { Point } from 'pixi.js';
|
||||
import { ObjectRoomColorUpdateMessage, ObjectRoomFloorHoleUpdateMessage, ObjectRoomMapUpdateMessage, ObjectRoomMaskUpdateMessage, ObjectRoomPlanePropertyUpdateMessage, ObjectRoomPlaneVisibilityUpdateMessage, ObjectRoomUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
||||
import { RoomMapData } from '../RoomMapData';
|
||||
import { RoomPlaneBitmapMaskData } from '../RoomPlaneBitmapMaskData';
|
||||
import { RoomPlaneBitmapMaskParser } from '../RoomPlaneBitmapMaskParser';
|
||||
import { RoomPlaneData } from '../RoomPlaneData';
|
||||
import { RoomPlaneParser } from '../RoomPlaneParser';
|
||||
import { RoomObjectLogicBase } from './RoomObjectLogicBase';
|
||||
|
||||
export class RoomLogic extends RoomObjectLogicBase
|
||||
{
|
||||
private _planeParser: RoomPlaneParser;
|
||||
private _planeBitmapMaskParser: RoomPlaneBitmapMaskParser;
|
||||
private _color: number;
|
||||
private _light: number;
|
||||
private _originalColor: number;
|
||||
private _originalLight: number;
|
||||
private _targetColor: number;
|
||||
private _targetLight: number;
|
||||
private _colorChangedTime: number;
|
||||
private _colorTransitionLength: number;
|
||||
private _lastHoleUpdate: number;
|
||||
private _needsMapUpdate: boolean;
|
||||
private _skipColorTransition: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._planeParser = new RoomPlaneParser();
|
||||
this._planeBitmapMaskParser = new RoomPlaneBitmapMaskParser();
|
||||
this._color = 0xFFFFFF;
|
||||
this._light = 0xFF;
|
||||
this._originalColor = 0xFFFFFF;
|
||||
this._originalLight = 0xFF;
|
||||
this._targetColor = 0xFFFFFF;
|
||||
this._targetLight = 0xFF;
|
||||
this._colorChangedTime = 0;
|
||||
this._colorTransitionLength = 1500;
|
||||
this._lastHoleUpdate = 0;
|
||||
this._needsMapUpdate = false;
|
||||
this._skipColorTransition = false;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectMouseEvent.MOUSE_MOVE, RoomObjectMouseEvent.CLICK];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
super.dispose();
|
||||
|
||||
if(this._planeParser)
|
||||
{
|
||||
this._planeParser.dispose();
|
||||
|
||||
this._planeParser = null;
|
||||
}
|
||||
|
||||
if(this._planeBitmapMaskParser)
|
||||
{
|
||||
this._planeBitmapMaskParser.dispose();
|
||||
|
||||
this._planeBitmapMaskParser = null;
|
||||
}
|
||||
}
|
||||
|
||||
public initialize(roomMap: RoomMapData): void
|
||||
{
|
||||
if(!roomMap || !this.object) return;
|
||||
|
||||
if(!(roomMap instanceof RoomMapData)) return;
|
||||
|
||||
if(!this._planeParser.initializeFromMapData(roomMap)) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_MAP_DATA, roomMap);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_BACKGROUND_COLOR, 0xFFFFFF);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_FLOOR_VISIBILITY, 1);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_WALL_VISIBILITY, 1);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_LANDSCAPE_VISIBILITY, 1);
|
||||
|
||||
this._skipColorTransition = (GetConfiguration().getValue<boolean>('room.color.skip.transition') === true);
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
this.updateBackgroundColor(time);
|
||||
|
||||
if(this._needsMapUpdate)
|
||||
{
|
||||
if(this._lastHoleUpdate && (time - this._lastHoleUpdate) < 5) return;
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(model)
|
||||
{
|
||||
const mapData = this._planeParser.getMapData();
|
||||
|
||||
model.setValue(RoomObjectVariable.ROOM_MAP_DATA, mapData);
|
||||
model.setValue(RoomObjectVariable.ROOM_FLOOR_HOLE_UPDATE_TIME, time);
|
||||
|
||||
this._planeParser.initializeFromMapData(mapData);
|
||||
}
|
||||
|
||||
this._lastHoleUpdate = 0;
|
||||
this._needsMapUpdate = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private updateBackgroundColor(k: number): void
|
||||
{
|
||||
if(!this.object || !this._colorChangedTime) return;
|
||||
|
||||
let color = this._color;
|
||||
let newColor = this._light;
|
||||
|
||||
if((k - this._colorChangedTime) >= this._colorTransitionLength)
|
||||
{
|
||||
color = this._targetColor;
|
||||
newColor = this._targetLight;
|
||||
|
||||
this._colorChangedTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
let _local_7 = ((this._originalColor >> 16) & 0xFF);
|
||||
let _local_8 = ((this._originalColor >> 8) & 0xFF);
|
||||
let _local_9 = (this._originalColor & 0xFF);
|
||||
|
||||
const _local_10 = ((this._targetColor >> 16) & 0xFF);
|
||||
const _local_11 = ((this._targetColor >> 8) & 0xFF);
|
||||
const _local_12 = (this._targetColor & 0xFF);
|
||||
const _local_13 = ((k - this._colorChangedTime) / this._colorTransitionLength);
|
||||
|
||||
_local_7 = (_local_7 + ((_local_10 - _local_7) * _local_13));
|
||||
_local_8 = (_local_8 + ((_local_11 - _local_8) * _local_13));
|
||||
_local_9 = (_local_9 + ((_local_12 - _local_9) * _local_13));
|
||||
|
||||
color = (((_local_7 << 16) + (_local_8 << 8)) + _local_9);
|
||||
newColor = (this._originalLight + ((this._targetLight - this._originalLight) * _local_13));
|
||||
|
||||
this._color = color;
|
||||
this._light = newColor;
|
||||
}
|
||||
|
||||
let _local_5 = ColorConverter.rgbToHSL(color);
|
||||
|
||||
_local_5 = ((_local_5 & 0xFFFF00) + newColor);
|
||||
color = ColorConverter.hslToRGB(_local_5);
|
||||
|
||||
if(this.object.model) this.object.model.setValue(RoomObjectVariable.ROOM_BACKGROUND_COLOR, color);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message || !this.object) return;
|
||||
|
||||
const model = this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
if(message instanceof ObjectRoomUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomMaskUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomMaskUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomPlaneVisibilityUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomPlaneVisibilityUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomPlanePropertyUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomPlanePropertyUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomFloorHoleUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomFloorHoleUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomColorUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomColorUpdateMessage(message, model);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectRoomMapUpdateMessage)
|
||||
{
|
||||
this.onObjectRoomMapUpdateMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
private onObjectRoomUpdateMessage(message: ObjectRoomUpdateMessage, model: IRoomObjectModel): void
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectRoomUpdateMessage.ROOM_FLOOR_UPDATE:
|
||||
model.setValue(RoomObjectVariable.ROOM_FLOOR_TYPE, message.value);
|
||||
return;
|
||||
case ObjectRoomUpdateMessage.ROOM_WALL_UPDATE:
|
||||
model.setValue(RoomObjectVariable.ROOM_WALL_TYPE, message.value);
|
||||
return;
|
||||
case ObjectRoomUpdateMessage.ROOM_LANDSCAPE_UPDATE:
|
||||
model.setValue(RoomObjectVariable.ROOM_LANDSCAPE_TYPE, message.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private onObjectRoomMaskUpdateMessage(message: ObjectRoomMaskUpdateMessage, _arg_2: IRoomObjectModel): void
|
||||
{
|
||||
let maskType: string = null;
|
||||
let update = false;
|
||||
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectRoomMaskUpdateMessage.ADD_MASK:
|
||||
maskType = RoomPlaneBitmapMaskData.WINDOW;
|
||||
|
||||
if(message.maskCategory === ObjectRoomMaskUpdateMessage.HOLE) maskType = RoomPlaneBitmapMaskData.HOLE;
|
||||
|
||||
this._planeBitmapMaskParser.addMask(message.maskId, message.maskType, message.maskLocation, maskType);
|
||||
|
||||
update = true;
|
||||
break;
|
||||
case ObjectRoomMaskUpdateMessage.REMOVE_MASK:
|
||||
update = this._planeBitmapMaskParser.removeMask(message.maskId);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(update) _arg_2.setValue(RoomObjectVariable.ROOM_PLANE_MASK_XML, this._planeBitmapMaskParser.getXML());
|
||||
}
|
||||
|
||||
private onObjectRoomPlaneVisibilityUpdateMessage(message: ObjectRoomPlaneVisibilityUpdateMessage, model: IRoomObjectModel): void
|
||||
{
|
||||
let visible = 0;
|
||||
|
||||
if(message.visible) visible = 1;
|
||||
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectRoomPlaneVisibilityUpdateMessage.FLOOR_VISIBILITY:
|
||||
model.setValue(RoomObjectVariable.ROOM_FLOOR_VISIBILITY, visible);
|
||||
return;
|
||||
case ObjectRoomPlaneVisibilityUpdateMessage.WALL_VISIBILITY:
|
||||
model.setValue(RoomObjectVariable.ROOM_WALL_VISIBILITY, visible);
|
||||
model.setValue(RoomObjectVariable.ROOM_LANDSCAPE_VISIBILITY, visible);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private onObjectRoomPlanePropertyUpdateMessage(message: ObjectRoomPlanePropertyUpdateMessage, model: IRoomObjectModel): void
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectRoomPlanePropertyUpdateMessage.FLOOR_THICKNESS:
|
||||
model.setValue(RoomObjectVariable.ROOM_FLOOR_THICKNESS, message.value);
|
||||
return;
|
||||
case ObjectRoomPlanePropertyUpdateMessage.WALL_THICKNESS:
|
||||
model.setValue(RoomObjectVariable.ROOM_WALL_THICKNESS, message.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private onObjectRoomFloorHoleUpdateMessage(message: ObjectRoomFloorHoleUpdateMessage, model: IRoomObjectModel): void
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectRoomFloorHoleUpdateMessage.ADD:
|
||||
this._planeParser.addFloorHole(message.id, message.x, message.y, message.width, message.height);
|
||||
this._needsMapUpdate = true;
|
||||
return;
|
||||
case ObjectRoomFloorHoleUpdateMessage.REMOVE:
|
||||
this._planeParser.removeFloorHole(message.id);
|
||||
this._needsMapUpdate = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this._lastHoleUpdate = this.time;
|
||||
}
|
||||
|
||||
private onObjectRoomColorUpdateMessage(message: ObjectRoomColorUpdateMessage, model: IRoomObjectModel): void
|
||||
{
|
||||
if(!message || !model) return;
|
||||
|
||||
this._originalColor = this._color;
|
||||
this._originalLight = this._light;
|
||||
this._targetColor = message.color;
|
||||
this._targetLight = message.light;
|
||||
this._colorChangedTime = this.time;
|
||||
|
||||
if(this._skipColorTransition)
|
||||
this._colorTransitionLength = 0;
|
||||
else
|
||||
this._colorTransitionLength = 1500;
|
||||
|
||||
model.setValue(RoomObjectVariable.ROOM_COLORIZE_BG_ONLY, message.backgroundOnly);
|
||||
}
|
||||
|
||||
private onObjectRoomMapUpdateMessage(message: ObjectRoomMapUpdateMessage): void
|
||||
{
|
||||
if(!message || !message.mapData) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_MAP_DATA, message.mapData);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_FLOOR_HOLE_UPDATE_TIME, this.time);
|
||||
|
||||
this._planeParser.initializeFromMapData(message.mapData);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object || !this.object.model) return;
|
||||
|
||||
const tag = event.spriteTag;
|
||||
|
||||
let planeId = 0;
|
||||
|
||||
if(tag && (tag.indexOf('@') >= 0))
|
||||
{
|
||||
planeId = parseInt(tag.substr(tag.indexOf('@') + 1));
|
||||
}
|
||||
|
||||
if((planeId < 1) || (planeId > this._planeParser.planeCount))
|
||||
{
|
||||
if(event.type === MouseEventType.ROLL_OUT)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_PLANE, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
planeId--;
|
||||
|
||||
let planePosition: Point = null;
|
||||
|
||||
const planeLocation = this._planeParser.getPlaneLocation(planeId);
|
||||
const planeLeftSide = this._planeParser.getPlaneLeftSide(planeId);
|
||||
const planeRightSide = this._planeParser.getPlaneRightSide(planeId);
|
||||
const planeNormalDirection = this._planeParser.getPlaneNormalDirection(planeId);
|
||||
const planeType = this._planeParser.getPlaneType(planeId);
|
||||
|
||||
if(((((planeLocation == null) || (planeLeftSide == null)) || (planeRightSide == null)) || (planeNormalDirection == null))) return;
|
||||
|
||||
const leftSideLength = planeLeftSide.length;
|
||||
const rightSideLength = planeRightSide.length;
|
||||
|
||||
if(((leftSideLength == 0) || (rightSideLength == 0))) return;
|
||||
|
||||
const screenX = event.screenX;
|
||||
const screenY = event.screenY;
|
||||
const screenPoint = new Point(screenX, screenY);
|
||||
|
||||
planePosition = geometry.getPlanePosition(screenPoint, planeLocation, planeLeftSide, planeRightSide);
|
||||
|
||||
if(!planePosition)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_PLANE, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const _local_18 = Vector3d.product(planeLeftSide, (planePosition.x / leftSideLength));
|
||||
|
||||
_local_18.add(Vector3d.product(planeRightSide, (planePosition.y / rightSideLength)));
|
||||
_local_18.add(planeLocation);
|
||||
|
||||
const tileX = _local_18.x;
|
||||
const tileY = _local_18.y;
|
||||
const tileZ = _local_18.z;
|
||||
|
||||
if(((((planePosition.x >= 0) && (planePosition.x < leftSideLength)) && (planePosition.y >= 0)) && (planePosition.y < rightSideLength)))
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_X, tileX);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_Y, tileY);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_Z, tileZ);
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_PLANE, (planeId + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.ROOM_SELECTED_PLANE, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let eventType: string = null;
|
||||
|
||||
if((event.type === MouseEventType.MOUSE_MOVE) || (event.type === MouseEventType.ROLL_OVER)) eventType = RoomObjectMouseEvent.MOUSE_MOVE;
|
||||
else if((event.type === MouseEventType.MOUSE_CLICK)) eventType = RoomObjectMouseEvent.CLICK;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.MOUSE_MOVE:
|
||||
case MouseEventType.ROLL_OVER:
|
||||
case MouseEventType.MOUSE_CLICK: {
|
||||
let newEvent: RoomObjectEvent = null;
|
||||
|
||||
if(planeType === RoomPlaneData.PLANE_FLOOR)
|
||||
{
|
||||
newEvent = new RoomObjectTileMouseEvent(eventType, this.object, event.eventId, tileX, tileY, tileZ, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
}
|
||||
|
||||
else if((planeType === RoomPlaneData.PLANE_WALL) || (planeType === RoomPlaneData.PLANE_LANDSCAPE))
|
||||
{
|
||||
let direction = 90;
|
||||
|
||||
if(planeNormalDirection)
|
||||
{
|
||||
direction = (planeNormalDirection.x + 90);
|
||||
|
||||
if(direction > 360) direction -= 360;
|
||||
}
|
||||
|
||||
const _local_27 = ((planeLeftSide.length * planePosition.x) / leftSideLength);
|
||||
const _local_28 = ((planeRightSide.length * planePosition.y) / rightSideLength);
|
||||
|
||||
newEvent = new RoomObjectWallMouseEvent(eventType, this.object, event.eventId, planeLocation, planeLeftSide, planeRightSide, _local_27, _local_28, direction, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
}
|
||||
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(newEvent);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import { IEventDispatcher, IRoomGeometry, IRoomObjectController, IRoomObjectEventHandler, IRoomObjectUpdateMessage } from '@nitrots/api';
|
||||
import { RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
|
||||
export class RoomObjectLogicBase implements IRoomObjectEventHandler
|
||||
{
|
||||
private _events: IEventDispatcher = null;
|
||||
private _object: IRoomObjectController = null;
|
||||
private _time: number = 0;
|
||||
|
||||
public initialize(data: unknown): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._object = null;
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
this._time = time;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: IRoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message || !this._object) return;
|
||||
|
||||
this._object.setLocation(message.location);
|
||||
this._object.setDirection(message.direction);
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected mergeTypes(k: string[], _arg_2: string[]): string[]
|
||||
{
|
||||
const types = k.concat();
|
||||
|
||||
for(const type of _arg_2)
|
||||
{
|
||||
if(!type || (types.indexOf(type) >= 0)) continue;
|
||||
|
||||
types.push(type);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public setObject(object: IRoomObjectController): void
|
||||
{
|
||||
if(this._object === object) return;
|
||||
|
||||
if(this._object)
|
||||
{
|
||||
this._object.setLogic(null);
|
||||
}
|
||||
|
||||
if(!object)
|
||||
{
|
||||
this.dispose();
|
||||
|
||||
this._object = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._object = object;
|
||||
this._object.setLogic(this);
|
||||
}
|
||||
|
||||
public tearDown(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public get object(): IRoomObjectController
|
||||
{
|
||||
return this._object;
|
||||
}
|
||||
|
||||
public get eventDispatcher(): IEventDispatcher
|
||||
{
|
||||
return this._events;
|
||||
}
|
||||
|
||||
public set eventDispatcher(events: IEventDispatcher)
|
||||
{
|
||||
this._events = events;
|
||||
}
|
||||
|
||||
public get widget(): string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public get time(): number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { ObjectVisibilityUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
||||
import { RoomObjectLogicBase } from './RoomObjectLogicBase';
|
||||
|
||||
export class SelectionArrowLogic extends RoomObjectLogicBase
|
||||
{
|
||||
public initialize(data: IAssetData): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ALPHA_MULTIPLIER, 1);
|
||||
|
||||
this.object.setState(1, 0);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!(message instanceof ObjectVisibilityUpdateMessage)) return;
|
||||
|
||||
if(this.object)
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectVisibilityUpdateMessage.ENABLED:
|
||||
this.object.setState(0, 0);
|
||||
return;
|
||||
case ObjectVisibilityUpdateMessage.DISABLED:
|
||||
this.object.setState(1, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { ObjectTileCursorUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
||||
import { RoomObjectLogicBase } from './RoomObjectLogicBase';
|
||||
|
||||
export class TileCursorLogic extends RoomObjectLogicBase
|
||||
{
|
||||
private static CURSOR_VISIBLE_STATE: number = 0;
|
||||
private static CURSOR_HIDDEN_STATE: number = 1;
|
||||
private static CURSOR_HEIGHT_STATE: number = 6;
|
||||
|
||||
private _lastEventId: string;
|
||||
private _isHidden: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._lastEventId = null;
|
||||
this._isHidden = false;
|
||||
}
|
||||
|
||||
public initialize(data: IAssetData): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ALPHA_MULTIPLIER, 1);
|
||||
|
||||
this.object.setState(TileCursorLogic.CURSOR_HIDDEN_STATE, 0);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!(message instanceof ObjectTileCursorUpdateMessage)) return;
|
||||
|
||||
if(this._lastEventId && (this._lastEventId === message.sourceEventId)) return;
|
||||
|
||||
if(message.toggleVisibility) this._isHidden = !this._isHidden;
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(this.object)
|
||||
{
|
||||
if(this._isHidden)
|
||||
{
|
||||
this.object.setState(TileCursorLogic.CURSOR_HIDDEN_STATE, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!message.visible)
|
||||
{
|
||||
this.object.setState(TileCursorLogic.CURSOR_HIDDEN_STATE, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.TILE_CURSOR_HEIGHT, message.height);
|
||||
|
||||
this.object.setState((message.height > 0.8) ? TileCursorLogic.CURSOR_HEIGHT_STATE : TileCursorLogic.CURSOR_VISIBLE_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._lastEventId = message.sourceEventId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectBadgeAssetEvent, RoomObjectEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectGroupBadgeUpdateMessage, ObjectSelectedMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureBadgeDisplayLogic } from './FurnitureBadgeDisplayLogic';
|
||||
|
||||
export class FurnitureAchievementResolutionLogic extends FurnitureBadgeDisplayLogic
|
||||
{
|
||||
public static STATE_RESOLUTION_NOT_STARTED: number = 0;
|
||||
public static STATE_RESOLUTION_IN_PROGRESS: number = 1;
|
||||
public static STATE_RESOLUTION_ACHIEVED: number = 2;
|
||||
public static STATE_RESOLUTION_FAILED: number = 3;
|
||||
private static ACH_NOT_SET: string = 'ach_0';
|
||||
private static BADGE_VISIBLE_IN_STATE: number = 2;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_OPEN, RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_ENGRAVING, RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_FAILED, RoomObjectBadgeAssetEvent.LOAD_BADGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectGroupBadgeUpdateMessage)
|
||||
{
|
||||
if(message.assetName !== 'loading_icon')
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BADGE_VISIBLE_IN_STATE, FurnitureAchievementResolutionLogic.BADGE_VISIBLE_IN_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
if(message instanceof ObjectSelectedMessage)
|
||||
{
|
||||
if(!this.eventDispatcher || !this.object) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU, this.object));
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
let event: RoomObjectEvent = null;
|
||||
|
||||
switch(this.object.getState(0))
|
||||
{
|
||||
case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_NOT_STARTED:
|
||||
case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_IN_PROGRESS:
|
||||
event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_OPEN, this.object);
|
||||
break;
|
||||
case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_ACHIEVED:
|
||||
event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_ENGRAVING, this.object);
|
||||
break;
|
||||
case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_FAILED:
|
||||
event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_FAILED, this.object);
|
||||
break;
|
||||
}
|
||||
|
||||
if(event) this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
protected updateBadge(badgeId: string): void
|
||||
{
|
||||
if(badgeId === FurnitureAchievementResolutionLogic.ACH_NOT_SET) return;
|
||||
|
||||
super.updateBadge(badgeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { RoomObjectVariable, StringDataType } from '@nitrots/api';
|
||||
import { RoomObjectBadgeAssetEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, ObjectGroupBadgeUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureBadgeDisplayLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.BADGE_DISPLAY_ENGRAVING, RoomObjectBadgeAssetEvent.LOAD_BADGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!this.object) return;
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const data = message.data;
|
||||
|
||||
if(data instanceof StringDataType) this.updateBadge(data.getValue(1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectGroupBadgeUpdateMessage)
|
||||
{
|
||||
if(message.assetName !== 'loading_icon')
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BADGE_ASSET_NAME, message.assetName);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BADGE_IMAGE_STATUS, 1);
|
||||
|
||||
this.update(GetTickerTime());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.BADGE_DISPLAY_ENGRAVING, this.object));
|
||||
}
|
||||
|
||||
protected updateBadge(badgeId: string): void
|
||||
{
|
||||
if(badgeId === '') return;
|
||||
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BADGE_IMAGE_STATUS, -1);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectBadgeAssetEvent(RoomObjectBadgeAssetEvent.LOAD_BADGE, this.object, badgeId, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomToObjectOwnAvatarMoveEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureChangeStateWhenStepOnLogic extends FurnitureLogic
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this.onRoomToObjectOwnAvatarMoveEvent = this.onRoomToObjectOwnAvatarMoveEvent.bind(this);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(this.eventDispatcher) this.eventDispatcher.addEventListener(RoomToObjectOwnAvatarMoveEvent.ROAME_MOVE_TO, this.onRoomToObjectOwnAvatarMoveEvent);
|
||||
}
|
||||
|
||||
public tearDown(): void
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.removeEventListener(RoomToObjectOwnAvatarMoveEvent.ROAME_MOVE_TO, this.onRoomToObjectOwnAvatarMoveEvent);
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private onRoomToObjectOwnAvatarMoveEvent(event: RoomToObjectOwnAvatarMoveEvent): void
|
||||
{
|
||||
if(!event || !this.object) return;
|
||||
|
||||
const location = this.object.getLocation();
|
||||
const targetLocation = event.targetLocation;
|
||||
|
||||
if(!targetLocation) return;
|
||||
|
||||
let sizeX = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_SIZE_X);
|
||||
let sizeY = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_SIZE_Y);
|
||||
|
||||
const direction = (((Math.floor(this.object.getDirection().x) + 45) % 360) / 90);
|
||||
|
||||
if((direction === 1) || (direction === 3)) [sizeX, sizeY] = [sizeY, sizeX];
|
||||
|
||||
if(((targetLocation.x >= location.x) && (targetLocation.x < (location.x + sizeX))) && ((targetLocation.y >= location.y) && (targetLocation.y < (location.y + sizeY))))
|
||||
{
|
||||
this.object.setState(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.object.setState(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureClothingChangeLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.CLOTHING_CHANGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
const furniData = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
this.updateClothingData(furniData);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage) message.data && this.updateClothingData(message.data.getLegacyString());
|
||||
}
|
||||
|
||||
private updateClothingData(furnitureData: string): void
|
||||
{
|
||||
if(!furnitureData || !furnitureData.length) return;
|
||||
|
||||
const [boyClothing, girlClothing] = furnitureData.split(',');
|
||||
|
||||
if(boyClothing && boyClothing.length) this.object.model.setValue<string>(RoomObjectVariable.FURNITURE_CLOTHING_BOY, boyClothing);
|
||||
if(girlClothing && girlClothing.length) this.object.model.setValue<string>(RoomObjectVariable.FURNITURE_CLOTHING_GIRL, girlClothing);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOTHING_CHANGE, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { IRoomGeometry, MouseEventType } from '@nitrots/api';
|
||||
import { RoomObjectEvent, RoomObjectStateChangedEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureCounterClockLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectStateChangedEvent.STATE_CHANGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
let objectEvent: RoomObjectEvent = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
switch(event.spriteTag)
|
||||
{
|
||||
case 'start_stop':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 1);
|
||||
break;
|
||||
case 'reset':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.eventDispatcher && objectEvent)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(objectEvent);
|
||||
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureCrackableLogic extends FurnitureLogic
|
||||
{
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!this.object) return;
|
||||
|
||||
if(this.object.model.getValue(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
this.object.model.setValue(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, RoomWidgetEnumItemExtradataParameter.CRACKABLE_FURNI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { RoomWidgetEnum } from '@nitrots/api';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureCraftingGizmoLogic extends FurnitureLogic
|
||||
{
|
||||
public get widget(): string
|
||||
{
|
||||
return RoomWidgetEnum.CRAFTING;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureCreditLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.CREDITFURNI
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
let creditValue = 0;
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.credits && (asset.logic.credits !== '') && (asset.logic.credits.length > 0)) creditValue = parseInt(asset.logic.credits);
|
||||
}
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_CREDIT_VALUE, creditValue);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CREDITFURNI, this.object));
|
||||
|
||||
super.useObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { RoomObjectPlaySoundIdEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureCuckooClockLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private _state: number = 1;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectPlaySoundIdEvent.PLAY_SOUND_AT_PITCH];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
if((this._state !== -1) && (message.state !== this._state))
|
||||
{
|
||||
this.dispatchSoundEvent(this.object.location.z);
|
||||
}
|
||||
|
||||
this._state = message.state;
|
||||
}
|
||||
}
|
||||
|
||||
private dispatchSoundEvent(height: number): void
|
||||
{
|
||||
const pitch = Math.pow(2, (height - 1.2));
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectPlaySoundIdEvent(RoomObjectPlaySoundIdEvent.PLAY_SOUND_AT_PITCH, this.object, 'FURNITURE_cuckoo_clock', pitch));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureCustomStackHeightLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.STACK_HEIGHT
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(this.object && this.object.model) this.object.model.setValue(RoomObjectVariable.FURNITURE_ALWAYS_STACKABLE, 1);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.STACK_HEIGHT, this.object));
|
||||
|
||||
super.useObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { IRoomGeometry, MouseEventType } from '@nitrots/api';
|
||||
import { RoomObjectEvent, RoomObjectFurnitureActionEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureDiceLogic extends FurnitureLogic
|
||||
{
|
||||
private _noTags: boolean;
|
||||
private _noTagsLastStateActivate: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._noTags = false;
|
||||
this._noTagsLastStateActivate = false;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectFurnitureActionEvent.DICE_ACTIVATE, RoomObjectFurnitureActionEvent.DICE_OFF];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
let objectEvent: RoomObjectEvent = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
if(this._noTags)
|
||||
{
|
||||
if(((!(this._noTagsLastStateActivate)) || (this.object.getState(0) === 0)) || (this.object.getState(0) === 100))
|
||||
{
|
||||
objectEvent = new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.DICE_ACTIVATE, this.object);
|
||||
|
||||
this._noTagsLastStateActivate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
objectEvent = new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.DICE_OFF, this.object);
|
||||
|
||||
this._noTagsLastStateActivate = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(((event.spriteTag === 'activate') || (this.object.getState(0) === 0)) || (this.object.getState(0) === 100))
|
||||
{
|
||||
objectEvent = new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.DICE_ACTIVATE, this.object);
|
||||
}
|
||||
|
||||
else if(event.spriteTag === 'deactivate')
|
||||
{
|
||||
objectEvent = new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.DICE_OFF, this.object);
|
||||
}
|
||||
}
|
||||
|
||||
if(objectEvent && this.eventDispatcher) this.eventDispatcher.dispatchEvent(objectEvent);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureEcotronBoxLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.ECOTRONBOX
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ECOTRONBOX, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { IAssetData, IRoomGeometry, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureEditableInternalLinkLogic extends FurnitureLogic
|
||||
{
|
||||
private _showStateOnceRendered: boolean;
|
||||
private _updateCount: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._showStateOnceRendered = false;
|
||||
this._updateCount = 0;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.INERNAL_LINK];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.action)
|
||||
{
|
||||
if(asset.logic.action.startState === 1) this._showStateOnceRendered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(!this._showStateOnceRendered) return;
|
||||
|
||||
this._updateCount++;
|
||||
|
||||
if(this._showStateOnceRendered && (this._updateCount > 20))
|
||||
{
|
||||
this.setAutomaticStateIndex(1);
|
||||
|
||||
this._showStateOnceRendered = false;
|
||||
}
|
||||
}
|
||||
|
||||
private setAutomaticStateIndex(state: number): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
if(this.object.model)
|
||||
{
|
||||
this.object.model.setValue<number>(RoomObjectVariable.FURNITURE_AUTOMATIC_STATE_INDEX, state);
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry) return;
|
||||
|
||||
if(event.type === MouseEventType.DOUBLE_CLICK)
|
||||
{
|
||||
this.setAutomaticStateIndex(0);
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.INERNAL_LINK, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureEditableRoomLinkLogic extends FurnitureLogic
|
||||
{
|
||||
private _timer: any;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.ROOM_LINK];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.action)
|
||||
{
|
||||
if(asset.logic.action.link && (asset.logic.action.link !== '') && (asset.logic.action.link.length > 0))
|
||||
{
|
||||
(this.object && this.object.model && this.object.model.setValue<string>(RoomObjectVariable.FURNITURE_INTERNAL_LINK, asset.logic.action.link));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._timer)
|
||||
{
|
||||
clearTimeout(this._timer);
|
||||
|
||||
this._timer = null;
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private setAutomaticStateIndex(state: number): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
if(this.object.model)
|
||||
{
|
||||
this.object.model.setValue<number>(RoomObjectVariable.FURNITURE_AUTOMATIC_STATE_INDEX, state);
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
this.setAutomaticStateIndex(1);
|
||||
|
||||
if(this._timer)
|
||||
{
|
||||
clearTimeout(this._timer);
|
||||
|
||||
this._timer = null;
|
||||
}
|
||||
|
||||
this._timer = setTimeout(() =>
|
||||
{
|
||||
this.setAutomaticStateIndex(0);
|
||||
|
||||
this._timer = null;
|
||||
}, 2500);
|
||||
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ROOM_LINK, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureEffectBoxLogic extends FurnitureLogic
|
||||
{
|
||||
private _timer: any;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.EFFECTBOX_OPEN_DIALOG];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.EFFECTBOX_OPEN_DIALOG, this.object));
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.EFFECT_BOX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureExternalImageLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.EXTERNAL_IMAGE
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(!asset) return;
|
||||
|
||||
if(this.object && this.object.model)
|
||||
{
|
||||
let maskType = '';
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.maskType && (asset.logic.maskType !== '') && (asset.logic.maskType.length > 0)) maskType = asset.logic.maskType;
|
||||
}
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_USES_PLANE_MASK, 0);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_PLANE_MASK_TYPE, maskType);
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.EXTERNAL_IMAGE, this.object));
|
||||
|
||||
super.useObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { IAssetData, IParticleSystem, IRoomGeometry, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectEvent, RoomObjectStateChangedEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureFireworksLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectStateChangedEvent.STATE_CHANGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.particleSystems && asset.logic.particleSystems.length)
|
||||
{
|
||||
this.object.model.setValue<IParticleSystem[]>(RoomObjectVariable.FURNITURE_FIREWORKS_DATA, asset.logic.particleSystems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
let objectEvent: RoomObjectEvent = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
switch(event.spriteTag)
|
||||
{
|
||||
case 'start_stop':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 1);
|
||||
break;
|
||||
case 'reset':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.eventDispatcher && objectEvent)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(objectEvent);
|
||||
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectFloorHoleEvent } from '@nitrots/events';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureFloorHoleLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private static STATE_HOLE: number = 0;
|
||||
|
||||
private _currentState: number;
|
||||
private _currentLocation: Vector3d;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._currentState = -1;
|
||||
this._currentLocation = null;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectFloorHoleEvent.ADD_HOLE, RoomObjectFloorHoleEvent.REMOVE_HOLE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._currentState === FurnitureFloorHoleLogic.STATE_HOLE)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFloorHoleEvent(RoomObjectFloorHoleEvent.REMOVE_HOLE, this.object));
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
this.handleAutomaticStateUpdate();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!this.object) return;
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
this.handleStateUpdate(this.object.getState(0));
|
||||
}
|
||||
|
||||
const location = this.object.getLocation();
|
||||
|
||||
if(!this._currentLocation)
|
||||
{
|
||||
this._currentLocation = new Vector3d();
|
||||
}
|
||||
else
|
||||
{
|
||||
if((location.x !== this._currentLocation.x) || (location.y !== this._currentLocation.y))
|
||||
{
|
||||
if(this._currentState === FurnitureFloorHoleLogic.STATE_HOLE)
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectFloorHoleEvent(RoomObjectFloorHoleEvent.ADD_HOLE, this.object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._currentLocation.assign(location);
|
||||
}
|
||||
|
||||
private handleStateUpdate(state: number): void
|
||||
{
|
||||
if(state === this._currentState) return;
|
||||
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
if(state === FurnitureFloorHoleLogic.STATE_HOLE)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFloorHoleEvent(RoomObjectFloorHoleEvent.ADD_HOLE, this.object));
|
||||
}
|
||||
|
||||
else if(this._currentState === FurnitureFloorHoleLogic.STATE_HOLE)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFloorHoleEvent(RoomObjectFloorHoleEvent.REMOVE_HOLE, this.object));
|
||||
}
|
||||
}
|
||||
|
||||
this._currentState = state;
|
||||
}
|
||||
|
||||
private handleAutomaticStateUpdate(): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
const model = this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
const stateIndex = model.getValue<number>(RoomObjectVariable.FURNITURE_AUTOMATIC_STATE_INDEX);
|
||||
|
||||
if(!isNaN(stateIndex)) this.handleStateUpdate((stateIndex % 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { ContextMenuEnum, IAssetData, RoomObjectVariable, StringDataType } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureFriendFurniLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private static readonly STATE_UNINITIALIZED: number = -1;
|
||||
private static readonly STATE_UNLOCKED: number = 0;
|
||||
private static readonly STATE_LOCKED: number = 1;
|
||||
|
||||
private _state: number = -1;
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(this.object) this.object.model.setValue(RoomObjectVariable.FURNITURE_FRIENDFURNI_ENGRAVING, this.engravingDialogType);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const data = (message.data as StringDataType);
|
||||
|
||||
if(data)
|
||||
{
|
||||
this._state = data.state;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._state = message.state;
|
||||
}
|
||||
}
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.FRIEND_FURNITURE_ENGRAVING];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
if(this._state === FurnitureFriendFurniLogic.STATE_LOCKED)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.FRIEND_FURNITURE_ENGRAVING, this.object));
|
||||
}
|
||||
else
|
||||
{
|
||||
super.useObject();
|
||||
}
|
||||
}
|
||||
|
||||
public get engravingDialogType(): number
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ((this._state === FurnitureFriendFurniLogic.STATE_UNLOCKED) ? ContextMenuEnum.FRIEND_FURNITURE : ContextMenuEnum.DUMMY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureGuildCustomizedLogic } from './FurnitureGuildCustomizedLogic';
|
||||
|
||||
export class FurnitureGroupForumTerminalLogic extends FurnitureGuildCustomizedLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.INERNAL_LINK
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
protected updateGroupId(id: string): void
|
||||
{
|
||||
super.updateGroupId(id);
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_INTERNAL_LINK, `groupforum/${id}`);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.INERNAL_LINK, this.object));
|
||||
|
||||
super.useObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { IRoomGeometry, MouseEventType, RoomObjectVariable, StringDataType } from '@nitrots/api';
|
||||
import { RoomObjectBadgeAssetEvent, RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, ObjectGroupBadgeUpdateMessage, ObjectSelectedMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureGuildCustomizedLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public static GROUPID_KEY: number = 1;
|
||||
public static BADGE_KEY: number = 2;
|
||||
public static COLOR1_KEY: number = 3;
|
||||
public static COLOR2_KEY: number = 4;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectBadgeAssetEvent.LOAD_BADGE,
|
||||
RoomObjectWidgetRequestEvent.GUILD_FURNI_CONTEXT_MENU,
|
||||
RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const data = message.data;
|
||||
|
||||
if(data instanceof StringDataType)
|
||||
{
|
||||
this.updateGroupId(data.getValue(FurnitureGuildCustomizedLogic.GROUPID_KEY));
|
||||
this.updateBadge(data.getValue(FurnitureGuildCustomizedLogic.BADGE_KEY));
|
||||
this.updateColors(data.getValue(FurnitureGuildCustomizedLogic.COLOR1_KEY), data.getValue(FurnitureGuildCustomizedLogic.COLOR2_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
else if(message instanceof ObjectGroupBadgeUpdateMessage)
|
||||
{
|
||||
if(message.assetName !== 'loading_icon')
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_ASSET_NAME, message.assetName);
|
||||
|
||||
this.update(GetTickerTime());
|
||||
}
|
||||
}
|
||||
|
||||
else if(message instanceof ObjectSelectedMessage)
|
||||
{
|
||||
if(!message.selected)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU, this.object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected updateGroupId(id: string): void
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_GUILD_ID, parseInt(id));
|
||||
}
|
||||
|
||||
private updateBadge(badge: string): void
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectBadgeAssetEvent(RoomObjectBadgeAssetEvent.LOAD_BADGE, this.object, badge, true));
|
||||
}
|
||||
|
||||
public updateColors(color1: string, color2: string): void
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_COLOR_1, parseInt(color1, 16));
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_COLOR_2, parseInt(color2, 16));
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.MOUSE_CLICK:
|
||||
this.openContextMenu();
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
private openContextMenu(): void
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.GUILD_FURNI_CONTEXT_MENU, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { RoomObjectFurnitureActionEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureHabboWheelLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectFurnitureActionEvent.USE_HABBOWHEEL];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.USE_HABBOWHEEL, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureHighScoreLogic extends FurnitureLogic
|
||||
{
|
||||
private static SHOW_WIDGET_IN_STATE = 1;
|
||||
|
||||
private _state = -1;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
return [RoomObjectWidgetRequestEvent.HIGH_SCORE_DISPLAY, RoomObjectWidgetRequestEvent.HIDE_HIGH_SCORE_DISPLAY];
|
||||
}
|
||||
|
||||
public tearDown(): void
|
||||
{
|
||||
if(this.object.model.getValue(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.HIDE_HIGH_SCORE_DISPLAY, this.object));
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(this.object.model.getValue(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) !== 1) return;
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
if(message.state === FurnitureHighScoreLogic.SHOW_WIDGET_IN_STATE)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.HIGH_SCORE_DISPLAY, this.object));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.HIDE_HIGH_SCORE_DISPLAY, this.object));
|
||||
}
|
||||
|
||||
this._state = message.state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { IRoomGeometry, MouseEventType } from '@nitrots/api';
|
||||
import { RoomObjectEvent, RoomObjectStateChangedEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureHockeyScoreLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectStateChangedEvent.STATE_CHANGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
let objectEvent: RoomObjectEvent = null;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
switch(event.spriteTag)
|
||||
{
|
||||
case 'off':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 3);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MouseEventType.MOUSE_CLICK:
|
||||
switch(event.spriteTag)
|
||||
{
|
||||
case 'inc':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 2);
|
||||
break;
|
||||
case 'dec':
|
||||
objectEvent = new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 1);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.eventDispatcher && objectEvent)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(objectEvent);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, 3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { FriendFurniEngravingWidgetType } from '@nitrots/api';
|
||||
import { FurnitureFriendFurniLogic } from './FurnitureFriendFurniLogic';
|
||||
|
||||
export class FurnitureHweenLovelockLogic extends FurnitureFriendFurniLogic
|
||||
{
|
||||
public get engravingDialogType(): number
|
||||
{
|
||||
return FriendFurniEngravingWidgetType.HABBOWEEN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { LegacyDataType } from '@nitrots/api';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureIceStormLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private _nextState: number;
|
||||
private _nextStateExtra: number;
|
||||
private _nextStateTimestamp: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._nextState = 0;
|
||||
this._nextStateTimestamp = 0;
|
||||
}
|
||||
|
||||
public update(totalTimeRunning: number): void
|
||||
{
|
||||
if((this._nextStateTimestamp > 0) && (totalTimeRunning >= this._nextStateTimestamp))
|
||||
{
|
||||
this._nextStateTimestamp = 0;
|
||||
|
||||
const data = new LegacyDataType();
|
||||
|
||||
data.setString(this._nextState.toString());
|
||||
|
||||
super.processUpdateMessage(new ObjectDataUpdateMessage(this._nextState, data, this._nextStateExtra));
|
||||
}
|
||||
|
||||
super.update(totalTimeRunning);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
this.processUpdate(message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
private processUpdate(message: ObjectDataUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
const state = ~~(message.state / 1000);
|
||||
const time = ~~(message.state % 1000);
|
||||
|
||||
if(!time)
|
||||
{
|
||||
this._nextStateTimestamp = 0;
|
||||
|
||||
const data = new LegacyDataType();
|
||||
|
||||
data.setString(state.toString());
|
||||
|
||||
super.processUpdateMessage(new ObjectDataUpdateMessage(state, data, message.extra));
|
||||
}
|
||||
else
|
||||
{
|
||||
this._nextState = state;
|
||||
this._nextStateExtra = message.extra;
|
||||
this._nextStateTimestamp = this.time + time;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import { IAssetData, IRoomGeometry, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureInternalLinkLogic extends FurnitureLogic
|
||||
{
|
||||
private _showStateOnceRendered: boolean = false;
|
||||
private _updateCount: number = 0;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.INERNAL_LINK
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.action)
|
||||
{
|
||||
this.object.model.setValue<string>(RoomObjectVariable.FURNITURE_INTERNAL_LINK, asset.logic.action.link);
|
||||
|
||||
if(asset.logic.action.startState === 1) this._showStateOnceRendered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(!this._showStateOnceRendered) return;
|
||||
|
||||
this._updateCount++;
|
||||
|
||||
if(this._showStateOnceRendered && (this._updateCount === 20))
|
||||
{
|
||||
this.setAutomaticStateIndex(1);
|
||||
|
||||
this._showStateOnceRendered = false;
|
||||
}
|
||||
}
|
||||
|
||||
private setAutomaticStateIndex(state: number): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
if(this.object.model)
|
||||
{
|
||||
this.object.model.setValue<number>(RoomObjectVariable.FURNITURE_AUTOMATIC_STATE_INDEX, state);
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry) return;
|
||||
|
||||
if((event.type === MouseEventType.DOUBLE_CLICK) && this._showStateOnceRendered)
|
||||
{
|
||||
this.setAutomaticStateIndex(0);
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.INERNAL_LINK, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent, RoomObjectStateChangedEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureJukeboxLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private _disposeEventsAllowed: boolean = false;
|
||||
private _isInitialized: boolean = false;
|
||||
private _currentState: number = -1;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectFurnitureActionEvent.JUKEBOX_START,
|
||||
RoomObjectFurnitureActionEvent.JUKEBOX_MACHINE_STOP,
|
||||
RoomObjectFurnitureActionEvent.JUKEBOX_DISPOSE,
|
||||
RoomObjectFurnitureActionEvent.JUKEBOX_INIT,
|
||||
RoomObjectWidgetRequestEvent.JUKEBOX_PLAYLIST_EDITOR
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this.requestDispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) !== 1) return;
|
||||
|
||||
if(!this._isInitialized) this.requestInit();
|
||||
|
||||
this.object.model.setValue<string>(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, RoomWidgetEnumItemExtradataParameter.JUKEBOX);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const state = this.object.getState(0);
|
||||
|
||||
if(state !== this._currentState)
|
||||
{
|
||||
this._currentState = state;
|
||||
|
||||
if(state === 1) this.requestPlayList();
|
||||
else if(state === 0) this.requestStopPlaying();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private requestInit(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this._disposeEventsAllowed = true;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.JUKEBOX_INIT, this.object));
|
||||
|
||||
this._isInitialized = true;
|
||||
}
|
||||
|
||||
private requestPlayList(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this._disposeEventsAllowed = true;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.JUKEBOX_START, this.object));
|
||||
}
|
||||
|
||||
private requestStopPlaying(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.JUKEBOX_MACHINE_STOP, this.object));
|
||||
}
|
||||
|
||||
private requestDispose(): void
|
||||
{
|
||||
if(!this._disposeEventsAllowed || !this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.JUKEBOX_DISPOSE, this.object));
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.JUKEBOX_PLAYLIST_EDITOR, this.object));
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object, -1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
import { IAssetData, IRoomGeometry, IRoomObjectController, IRoomObjectModel, IVector3D, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { RoomObjectMouseEvent, RoomObjectRoomAdEvent, RoomObjectStateChangedEvent, RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, ObjectHeightUpdateMessage, ObjectItemDataUpdateMessage, ObjectMoveUpdateMessage, ObjectSelectedMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { MovingObjectLogic } from '../MovingObjectLogic';
|
||||
|
||||
export class FurnitureLogic extends MovingObjectLogic
|
||||
{
|
||||
private static BOUNCING_STEPS: number = -1;
|
||||
private static BOUNCING_Z: number = -1;
|
||||
|
||||
private _sizeX: number;
|
||||
private _sizeY: number;
|
||||
private _sizeZ: number;
|
||||
private _centerX: number;
|
||||
private _centerY: number;
|
||||
private _centerZ: number;
|
||||
|
||||
private _directions: number[];
|
||||
|
||||
private _mouseOver: boolean;
|
||||
|
||||
private _locationOffset: IVector3D;
|
||||
private _bouncingStep: number;
|
||||
private _storedRotateMessage: RoomObjectUpdateMessage;
|
||||
private _directionInitialized: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._sizeX = 0;
|
||||
this._sizeY = 0;
|
||||
this._sizeZ = 0;
|
||||
this._centerX = 0;
|
||||
this._centerY = 0;
|
||||
this._centerZ = 0;
|
||||
|
||||
this._directions = [];
|
||||
|
||||
this._mouseOver = false;
|
||||
|
||||
this._locationOffset = new Vector3d();
|
||||
this._bouncingStep = 0;
|
||||
this._storedRotateMessage = null;
|
||||
this._directionInitialized = false;
|
||||
|
||||
if(FurnitureLogic.BOUNCING_STEPS === -1)
|
||||
{
|
||||
FurnitureLogic.BOUNCING_STEPS = GetConfiguration().getValue<number>('furni.rotation.bounce.steps', 8);
|
||||
}
|
||||
|
||||
if(FurnitureLogic.BOUNCING_Z === -1)
|
||||
{
|
||||
FurnitureLogic.BOUNCING_Z = GetConfiguration().getValue<number>('furni.rotation.bounce.height', 0.0625);
|
||||
}
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectStateChangedEvent.STATE_CHANGE,
|
||||
RoomObjectMouseEvent.CLICK,
|
||||
RoomObjectMouseEvent.MOUSE_DOWN,
|
||||
RoomObjectMouseEvent.MOUSE_DOWN_LONG,
|
||||
RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_SHOW,
|
||||
RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_HIDE,
|
||||
RoomObjectRoomAdEvent.ROOM_AD_FURNI_DOUBLE_CLICK,
|
||||
RoomObjectRoomAdEvent.ROOM_AD_FURNI_CLICK];
|
||||
|
||||
if(this.widget) types.push(RoomObjectWidgetRequestEvent.OPEN_WIDGET, RoomObjectWidgetRequestEvent.CLOSE_WIDGET);
|
||||
|
||||
if(this.contextMenu) types.push(RoomObjectWidgetRequestEvent.OPEN_FURNI_CONTEXT_MENU, RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU);
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
if(!asset) return;
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.model)
|
||||
{
|
||||
const dimensions = asset.logic.model.dimensions;
|
||||
|
||||
if(dimensions)
|
||||
{
|
||||
this._sizeX = dimensions.x;
|
||||
this._sizeY = dimensions.y;
|
||||
this._sizeZ = dimensions.z;
|
||||
|
||||
this._centerX = (this._sizeX / 2);
|
||||
this._centerY = (this._sizeY / 2);
|
||||
this._centerZ = (this._sizeZ / 2);
|
||||
}
|
||||
|
||||
const directions = asset.logic.model.directions;
|
||||
|
||||
if(directions && directions.length)
|
||||
{
|
||||
for(const direction of directions) this._directions.push(direction);
|
||||
|
||||
this._directions.sort((a, b) => (a - b));
|
||||
}
|
||||
}
|
||||
|
||||
if(asset.logic.customVars)
|
||||
{
|
||||
const variables = asset.logic.customVars.variables;
|
||||
|
||||
if(variables && variables.length)
|
||||
{
|
||||
model.setValue(RoomObjectVariable.FURNITURE_CUSTOM_VARIABLES, variables);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.setValue(RoomObjectVariable.FURNITURE_SIZE_X, this._sizeX);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_SIZE_Y, this._sizeY);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_SIZE_Z, this._sizeZ);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_CENTER_X, this._centerX);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_CENTER_Y, this._centerY);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_CENTER_Z, this._centerZ);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_ALLOWED_DIRECTIONS, this._directions);
|
||||
model.setValue(RoomObjectVariable.FURNITURE_ALPHA_MULTIPLIER, 1);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._storedRotateMessage = null;
|
||||
this._directions = null;
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public setObject(object: IRoomObjectController): void
|
||||
{
|
||||
super.setObject(object);
|
||||
|
||||
if(object && object.getLocation().length) this._directionInitialized = true;
|
||||
}
|
||||
|
||||
protected getAdClickUrl(model: IRoomObjectModel): string
|
||||
{
|
||||
return model.getValue<string>(RoomObjectVariable.FURNITURE_AD_URL);
|
||||
}
|
||||
|
||||
protected handleAdClick(objectId: number, objectType: string, clickUrl: string): void
|
||||
{
|
||||
if(!this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_FURNI_CLICK, this.object));
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(this._bouncingStep > 0)
|
||||
{
|
||||
this._bouncingStep++;
|
||||
|
||||
if(this._bouncingStep > FurnitureLogic.BOUNCING_STEPS) this._bouncingStep = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
this.processDataUpdateMessage(message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectHeightUpdateMessage)
|
||||
{
|
||||
this.processObjectHeightUpdateMessage(message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectItemDataUpdateMessage)
|
||||
{
|
||||
this.processItemDataUpdateMessage(message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._mouseOver = false;
|
||||
|
||||
if(message.location && message.direction)
|
||||
{
|
||||
if(!(message instanceof ObjectMoveUpdateMessage))
|
||||
{
|
||||
const direction = this.object.getDirection();
|
||||
const location = this.object.getLocation();
|
||||
|
||||
if((direction.x !== message.direction.x) && this._directionInitialized)
|
||||
{
|
||||
if((location.x === message.location.x) && (location.y === message.location.y) && (location.z === message.location.z))
|
||||
{
|
||||
this._bouncingStep = 1;
|
||||
this._storedRotateMessage = new RoomObjectUpdateMessage(message.location, message.direction);
|
||||
|
||||
message = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._directionInitialized = true;
|
||||
}
|
||||
|
||||
if(message instanceof ObjectSelectedMessage)
|
||||
{
|
||||
if(this.contextMenu && this.eventDispatcher && this.object)
|
||||
{
|
||||
const eventType = (message.selected) ? RoomObjectWidgetRequestEvent.OPEN_FURNI_CONTEXT_MENU : RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(eventType, this.object));
|
||||
}
|
||||
}
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
private processDataUpdateMessage(message: ObjectDataUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
this.object.setState(message.state, 0);
|
||||
|
||||
if(message.data) message.data.writeRoomObjectModel(this.object.model);
|
||||
|
||||
if(message.extra !== null) this.object.model.setValue(RoomObjectVariable.FURNITURE_EXTRAS, message.extra.toString());
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_STATE_UPDATE_TIME, this.lastUpdateTime);
|
||||
}
|
||||
|
||||
private processObjectHeightUpdateMessage(message: ObjectHeightUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_SIZE_Z, message.height);
|
||||
}
|
||||
|
||||
private processItemDataUpdateMessage(message: ObjectItemDataUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ITEMDATA, message.data);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
const adUrl = this.getAdClickUrl(this.object.model);
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.MOUSE_MOVE:
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_MOVE, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
mouseEvent.localX = event.localX;
|
||||
mouseEvent.localY = event.localY;
|
||||
mouseEvent.spriteOffsetX = event.spriteOffsetX;
|
||||
mouseEvent.spriteOffsetY = event.spriteOffsetY;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
}
|
||||
return;
|
||||
case MouseEventType.ROLL_OVER:
|
||||
if(!this._mouseOver)
|
||||
{
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
if(adUrl && (adUrl.indexOf('http') === 0))
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_SHOW, this.object));
|
||||
}
|
||||
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_ENTER, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
mouseEvent.localX = event.localX;
|
||||
mouseEvent.localY = event.localY;
|
||||
mouseEvent.spriteOffsetX = event.spriteOffsetX;
|
||||
mouseEvent.spriteOffsetY = event.spriteOffsetY;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
}
|
||||
|
||||
this._mouseOver = true;
|
||||
}
|
||||
return;
|
||||
case MouseEventType.ROLL_OUT:
|
||||
if(this._mouseOver)
|
||||
{
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
if(adUrl && (adUrl.indexOf('http') === 0))
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_HIDE, this.object));
|
||||
}
|
||||
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_LEAVE, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
mouseEvent.localX = event.localX;
|
||||
mouseEvent.localY = event.localY;
|
||||
mouseEvent.spriteOffsetX = event.spriteOffsetX;
|
||||
mouseEvent.spriteOffsetY = event.spriteOffsetY;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
}
|
||||
|
||||
this._mouseOver = false;
|
||||
}
|
||||
return;
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
this.useObject();
|
||||
return;
|
||||
case MouseEventType.MOUSE_CLICK:
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.CLICK, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
mouseEvent.localX = event.localX;
|
||||
mouseEvent.localY = event.localY;
|
||||
mouseEvent.spriteOffsetX = event.spriteOffsetX;
|
||||
mouseEvent.spriteOffsetY = event.spriteOffsetY;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
|
||||
if(adUrl && (adUrl.indexOf('http') === 0))
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_HIDE, this.object));
|
||||
}
|
||||
|
||||
if(adUrl && adUrl.length) this.handleAdClick(this.object.id, this.object.type, adUrl);
|
||||
}
|
||||
return;
|
||||
case MouseEventType.MOUSE_DOWN:
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_DOWN, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
}
|
||||
return;
|
||||
case MouseEventType.MOUSE_DOWN_LONG:
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_DOWN_LONG, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(mouseEvent);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected getLocationOffset(): IVector3D
|
||||
{
|
||||
if(this._bouncingStep <= 0) return null;
|
||||
|
||||
this._locationOffset.x = 0;
|
||||
this._locationOffset.y = 0;
|
||||
|
||||
if(this._bouncingStep <= (FurnitureLogic.BOUNCING_STEPS / 2))
|
||||
{
|
||||
this._locationOffset.z = FurnitureLogic.BOUNCING_Z * this._bouncingStep;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this._bouncingStep <= FurnitureLogic.BOUNCING_STEPS)
|
||||
{
|
||||
if(this._storedRotateMessage)
|
||||
{
|
||||
super.processUpdateMessage(this._storedRotateMessage);
|
||||
|
||||
this._storedRotateMessage = null;
|
||||
}
|
||||
|
||||
this._locationOffset.z = FurnitureLogic.BOUNCING_Z * (FurnitureLogic.BOUNCING_STEPS - this._bouncingStep);
|
||||
}
|
||||
}
|
||||
|
||||
return this._locationOffset;
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
const clickUrl = this.getAdClickUrl(this.object.model);
|
||||
|
||||
if(clickUrl && clickUrl.length)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_FURNI_DOUBLE_CLICK, this.object, null, clickUrl));
|
||||
}
|
||||
|
||||
if(this.widget) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.OPEN_WIDGET, this.object));
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object));
|
||||
}
|
||||
|
||||
public tearDown(): void
|
||||
{
|
||||
if(this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
if(this.widget) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_WIDGET, this.object));
|
||||
|
||||
if(this.contextMenu) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU, this.object));
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { FriendFurniEngravingWidgetType } from '@nitrots/api';
|
||||
import { FurnitureFriendFurniLogic } from './FurnitureFriendFurniLogic';
|
||||
|
||||
export class FurnitureLoveLockLogic extends FurnitureFriendFurniLogic
|
||||
{
|
||||
public get engravingDialogType(): number
|
||||
{
|
||||
return FriendFurniEngravingWidgetType.LOVE_LOCK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { MapDataType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureMannequinLogic extends FurnitureLogic
|
||||
{
|
||||
private static GENDER: string = 'GENDER';
|
||||
private static FIGURE: string = 'FIGURE';
|
||||
private static OUTFIT_NAME: string = 'OUTFIT_NAME';
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.MANNEQUIN];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
message.data.writeRoomObjectModel(this.object.model);
|
||||
|
||||
this.processObjectData();
|
||||
}
|
||||
}
|
||||
|
||||
private processObjectData(): void
|
||||
{
|
||||
if(!this.object || !this.object.model) return;
|
||||
|
||||
const data = new MapDataType();
|
||||
|
||||
data.initializeFromRoomObjectModel(this.object.model);
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_MANNEQUIN_GENDER, data.getValue(FurnitureMannequinLogic.GENDER));
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_MANNEQUIN_FIGURE, data.getValue(FurnitureMannequinLogic.FIGURE));
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_MANNEQUIN_NAME, data.getValue(FurnitureMannequinLogic.OUTFIT_NAME));
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.MANNEQUIN, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureMonsterplantSeedLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG, this.object));
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.MONSTERPLANT_SEED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureMultiHeightLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(this.object && this.object.model) this.object.model.setValue(RoomObjectVariable.FURNITURE_IS_VARIABLE_HEIGHT, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { IRoomGeometry, MouseEventType } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureMultiStateLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectFurnitureActionEvent.MOUSE_BUTTON, RoomObjectFurnitureActionEvent.MOUSE_ARROW];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.ROLL_OVER:
|
||||
this.eventDispatcher && this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_BUTTON, this.object));
|
||||
break;
|
||||
case MouseEventType.ROLL_OUT:
|
||||
this.eventDispatcher && this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_ARROW, this.object));
|
||||
break;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureMysteryBoxLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.MYSTERYBOX_OPEN_DIALOG];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.MYSTERYBOX_OPEN_DIALOG, this.object));
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.MYSTERY_BOX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureMysteryTrophyLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.MYSTERYTROPHY_OPEN_DIALOG];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.MYSTERYTROPHY_OPEN_DIALOG, this.object));
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.MYSTERY_TROPHY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { RoomObjectFurnitureActionEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureOneWayDoorLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectFurnitureActionEvent.ENTER_ONEWAYDOOR];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.ENTER_ONEWAYDOOR, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurniturePetCustomizationLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.PET_PRODUCT_MENU];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!this.object) return;
|
||||
|
||||
if(this.object.model.getValue(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
this.object.model.setValue(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, RoomWidgetEnumItemExtradataParameter.USABLE_PRODUCT);
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.PET_PRODUCT_MENU, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurniturePlaceholderLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.PLACEHOLDER
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.PLACEHOLDER, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { IAssetData, IAssetLogicPlanetSystem, RoomObjectVariable } from '@nitrots/api';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurniturePlanetSystemLogic extends FurnitureLogic
|
||||
{
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.planetSystems)
|
||||
{
|
||||
this.object.model.setValue<IAssetLogicPlanetSystem[]>(RoomObjectVariable.FURNITURE_PLANETSYSTEM_DATA, asset.logic.planetSystems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import { IAssetData, IParticleSystem, IRoomGeometry, MapDataType, MouseEventType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent, RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, ObjectModelDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurniturePresentLogic extends FurnitureLogic
|
||||
{
|
||||
private static MESSAGE: string = 'MESSAGE';
|
||||
private static PRODUCT_CODE: string = 'PRODUCT_CODE';
|
||||
private static EXTRA_PARAM: string = 'EXTRA_PARAM';
|
||||
private static PURCHASER_NAME: string = 'PURCHASER_NAME';
|
||||
private static PURCHASER_FIGURE: string = 'PURCHASER_FIGURE';
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.PRESENT
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.particleSystems && asset.logic.particleSystems.length)
|
||||
{
|
||||
this.object.model.setValue<IParticleSystem[]>(RoomObjectVariable.FURNITURE_FIREWORKS_DATA, asset.logic.particleSystems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
message.data.writeRoomObjectModel(this.object.model);
|
||||
|
||||
this.updateStuffData();
|
||||
}
|
||||
|
||||
if(message instanceof ObjectModelDataUpdateMessage)
|
||||
{
|
||||
if(message.numberKey === RoomObjectVariable.FURNITURE_DISABLE_PICKING_ANIMATION)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_DISABLE_PICKING_ANIMATION, message.numberValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateStuffData(): void
|
||||
{
|
||||
if(!this.object || !this.object.model) return;
|
||||
|
||||
const stuffData = new MapDataType();
|
||||
|
||||
stuffData.initializeFromRoomObjectModel(this.object.model);
|
||||
|
||||
const message = stuffData.getValue(FurniturePresentLogic.MESSAGE);
|
||||
const data = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
if(!message && (typeof data === 'string'))
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_DATA, data.substr(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_DATA, stuffData.getValue(FurniturePresentLogic.MESSAGE));
|
||||
}
|
||||
|
||||
this.writeToModel(RoomObjectVariable.FURNITURE_TYPE_ID, stuffData.getValue(FurniturePresentLogic.PRODUCT_CODE));
|
||||
this.writeToModel(RoomObjectVariable.FURNITURE_PURCHASER_NAME, stuffData.getValue(FurniturePresentLogic.PURCHASER_NAME));
|
||||
this.writeToModel(RoomObjectVariable.FURNITURE_PURCHASER_FIGURE, stuffData.getValue(FurniturePresentLogic.PURCHASER_FIGURE));
|
||||
}
|
||||
|
||||
private writeToModel(key: string, value: string): void
|
||||
{
|
||||
if(!value) return;
|
||||
|
||||
this.object.model.setValue(key, value);
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.ROLL_OVER:
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_BUTTON, this.object));
|
||||
break;
|
||||
case MouseEventType.ROLL_OUT:
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.MOUSE_ARROW, this.object));
|
||||
break;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.PRESENT, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurniturePurchaseableClothingLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG,
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG, this.object));
|
||||
}
|
||||
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.PURCHASABLE_CLOTHING;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import { LegacyDataType } from '@nitrots/api';
|
||||
import { Vector3d } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, ObjectMoveUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { MovingObjectLogic } from '../MovingObjectLogic';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurniturePushableLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private static ANIMATION_NOT_MOVING: number = 0;
|
||||
private static ANIMATION_MOVING: number = 1;
|
||||
private static MAX_ANIMATION_COUNT: number = 10;
|
||||
|
||||
private _oldLocation: Vector3d;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this.updateInterval = MovingObjectLogic.DEFAULT_UPDATE_INTERVAL;
|
||||
this._oldLocation = new Vector3d();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
const isMoveMessage = (message instanceof ObjectMoveUpdateMessage);
|
||||
|
||||
if(this.object && !isMoveMessage && message.location)
|
||||
{
|
||||
const location = this.object.getLocation();
|
||||
const difference = Vector3d.dif(message.location, location);
|
||||
|
||||
if(difference)
|
||||
{
|
||||
if((Math.abs(difference.x) < 2) && (Math.abs(difference.y) < 2))
|
||||
{
|
||||
let prevLocation = location;
|
||||
|
||||
if((Math.abs(difference.x) > 1) || (Math.abs(difference.y) > 1))
|
||||
{
|
||||
prevLocation = Vector3d.sum(location, Vector3d.product(difference, 0.5));
|
||||
}
|
||||
|
||||
super.processUpdateMessage(new ObjectMoveUpdateMessage(prevLocation, message.location, message.direction));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(message.location && !isMoveMessage) super.processUpdateMessage(new ObjectMoveUpdateMessage(message.location, message.location, message.direction));
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
if(message.state > 0)
|
||||
{
|
||||
this.updateInterval = MovingObjectLogic.DEFAULT_UPDATE_INTERVAL / this.getUpdateIntervalValue(message.state);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updateInterval = 1;
|
||||
}
|
||||
|
||||
this.handleDataUpdate(message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(isMoveMessage && message.isSlide) this.updateInterval = MovingObjectLogic.DEFAULT_UPDATE_INTERVAL;
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
protected getUpdateIntervalValue(value: number)
|
||||
{
|
||||
return (value / FurniturePushableLogic.MAX_ANIMATION_COUNT);
|
||||
}
|
||||
|
||||
protected getAnimationValue(value: number)
|
||||
{
|
||||
return (value % FurniturePushableLogic.MAX_ANIMATION_COUNT);
|
||||
}
|
||||
|
||||
private handleDataUpdate(message: ObjectDataUpdateMessage): void
|
||||
{
|
||||
const animation = this.getAnimationValue(message.state);
|
||||
|
||||
if(animation !== message.state)
|
||||
{
|
||||
const legacyStuff = new LegacyDataType();
|
||||
|
||||
legacyStuff.setString(animation.toString());
|
||||
|
||||
message = new ObjectDataUpdateMessage(animation, legacyStuff, message.extra);
|
||||
}
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
this._oldLocation.assign(this.object.getLocation());
|
||||
|
||||
super.update(time);
|
||||
|
||||
if(Vector3d.dif(this.object.getLocation(), this._oldLocation).length !== 0) return;
|
||||
|
||||
if(this.object.getState(0) !== FurniturePushableLogic.ANIMATION_NOT_MOVING) this.object.setState(FurniturePushableLogic.ANIMATION_NOT_MOVING, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { RoomObjectStateChangedEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureRandomStateLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectStateChangedEvent.STATE_RANDOM
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_RANDOM, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ContextMenuEnum } from '@nitrots/api';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureRandomTeleportLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public get contextMenu(): string
|
||||
{
|
||||
return ContextMenuEnum.RANDOM_TELEPORT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnum } from '@nitrots/api';
|
||||
import { RoomObjectDataRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureRentableSpaceLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectDataRequestEvent.RODRE_CURRENT_USER_ID,
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(this.object && this.object.model)
|
||||
{
|
||||
if(!this.object.model.getValue<number>(RoomObjectVariable.SESSION_CURRENT_USER_ID))
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectDataRequestEvent(RoomObjectDataRequestEvent.RODRE_CURRENT_USER_ID, this.object));
|
||||
}
|
||||
|
||||
const renterId = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA)['renterId'];
|
||||
const userId = this.object.model.getValue<number>(RoomObjectVariable.SESSION_CURRENT_USER_ID);
|
||||
|
||||
if(renterId)
|
||||
{
|
||||
if(parseInt(renterId) === userId) this.object.setState(2, 0);
|
||||
else this.object.setState(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.object.setState(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get widget(): string
|
||||
{
|
||||
return RoomWidgetEnum.RENTABLESPACE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import { IRoomGeometry, MouseEventType, NumberDataType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectHSLColorEnableEvent, RoomObjectWidgetRequestEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureRoomBackgroundColorLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
|
||||
private _roomColorUpdated: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._roomColorUpdated = false;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.BACKGROUND_COLOR,
|
||||
RoomObjectHSLColorEnableEvent.ROOM_BACKGROUND_COLOR
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._roomColorUpdated)
|
||||
{
|
||||
if(this.eventDispatcher && this.object)
|
||||
{
|
||||
const realRoomObject = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT);
|
||||
|
||||
if(realRoomObject === 1)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectHSLColorEnableEvent(RoomObjectHSLColorEnableEvent.ROOM_BACKGROUND_COLOR, this.object, false, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
this._roomColorUpdated = false;
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
message.data.writeRoomObjectModel(this.object.model);
|
||||
|
||||
const realRoomObject = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT);
|
||||
|
||||
if(realRoomObject === 1) this.processColorUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private processColorUpdate(): void
|
||||
{
|
||||
if(!this.object || !this.object.model) return;
|
||||
|
||||
const numberData = new NumberDataType();
|
||||
|
||||
numberData.initializeFromRoomObjectModel(this.object.model);
|
||||
|
||||
const state = numberData.getValue(0);
|
||||
const hue = numberData.getValue(1);
|
||||
const saturation = numberData.getValue(2);
|
||||
const lightness = numberData.getValue(3);
|
||||
|
||||
if((state > -1) && (hue > -1) && (saturation > -1) && (lightness > -1))
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ROOM_BACKGROUND_COLOR_HUE, hue);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ROOM_BACKGROUND_COLOR_SATURATION, saturation);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_ROOM_BACKGROUND_COLOR_LIGHTNESS, lightness);
|
||||
|
||||
this.object.setState(state, 0);
|
||||
|
||||
if(this.eventDispatcher)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectHSLColorEnableEvent(RoomObjectHSLColorEnableEvent.ROOM_BACKGROUND_COLOR, this.object, (state === 1), hue, saturation, lightness));
|
||||
}
|
||||
|
||||
this._roomColorUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry || !this.object) return;
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case MouseEventType.DOUBLE_CLICK:
|
||||
(this.eventDispatcher && this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.BACKGROUND_COLOR, this.object)));
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { IRoomObjectModel } from '@nitrots/api';
|
||||
import { FurnitureRoomBrandingLogic } from './FurnitureRoomBrandingLogic';
|
||||
|
||||
export class FurnitureRoomBackgroundLogic extends FurnitureRoomBrandingLogic
|
||||
{
|
||||
protected getAdClickUrl(model: IRoomObjectModel): string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { IRoomObjectModel, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectRoomAdEvent } from '@nitrots/events';
|
||||
import { HabboWebTools } from '@nitrots/utils';
|
||||
import { FurnitureRoomBrandingLogic } from './FurnitureRoomBrandingLogic';
|
||||
|
||||
export class FurnitureRoomBillboardLogic extends FurnitureRoomBrandingLogic
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._hasClickUrl = true;
|
||||
}
|
||||
|
||||
protected getAdClickUrl(model: IRoomObjectModel): string
|
||||
{
|
||||
return model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_URL);
|
||||
}
|
||||
|
||||
protected handleAdClick(objectId: number, objectType: string, clickUrl: string): void
|
||||
{
|
||||
if(clickUrl.indexOf('http') === 0)
|
||||
{
|
||||
HabboWebTools.openWebPage(clickUrl);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_FURNI_CLICK, this.object, '', clickUrl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { IAssetData, IRoomGeometry, MapDataType, MouseEventType, RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { RoomObjectRoomAdEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { ObjectAdUpdateMessage, ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureRoomBrandingLogic extends FurnitureLogic
|
||||
{
|
||||
public static STATE: string = 'state';
|
||||
public static IMAGEURL_KEY: string = 'imageUrl';
|
||||
public static CLICKURL_KEY: string = 'clickUrl';
|
||||
public static OFFSETX_KEY: string = 'offsetX';
|
||||
public static OFFSETY_KEY: string = 'offsetY';
|
||||
public static OFFSETZ_KEY: string = 'offsetZ';
|
||||
|
||||
protected _disableFurnitureSelection: boolean;
|
||||
protected _hasClickUrl: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._disableFurnitureSelection = true;
|
||||
this._hasClickUrl = false;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectRoomAdEvent.ROOM_AD_LOAD_IMAGE];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(this._disableFurnitureSelection)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_SELECTION_DISABLED, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage) this.processAdDataUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectAdUpdateMessage) this.processAdUpdate(message);
|
||||
}
|
||||
|
||||
private processAdDataUpdateMessage(message: ObjectDataUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
const objectData = new MapDataType();
|
||||
|
||||
objectData.initializeFromRoomObjectModel(this.object.model);
|
||||
|
||||
const state = parseInt(objectData.getValue(FurnitureRoomBrandingLogic.STATE));
|
||||
|
||||
if(!isNaN(state) && (this.object.getState(0) !== state)) this.object.setState(state, 0);
|
||||
|
||||
const imageUrl = objectData.getValue(FurnitureRoomBrandingLogic.IMAGEURL_KEY);
|
||||
const existingUrl = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_URL);
|
||||
|
||||
if(!existingUrl || (existingUrl !== imageUrl))
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_URL, imageUrl);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_STATUS, 0);
|
||||
|
||||
this.downloadBackground();
|
||||
}
|
||||
|
||||
const clickUrl = objectData.getValue(FurnitureRoomBrandingLogic.CLICKURL_KEY);
|
||||
|
||||
if(clickUrl)
|
||||
{
|
||||
const existingUrl = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_URL);
|
||||
|
||||
if(!existingUrl || existingUrl !== clickUrl)
|
||||
{
|
||||
if(this.object.model) this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_URL, clickUrl);
|
||||
}
|
||||
}
|
||||
|
||||
const offsetX = parseInt(objectData.getValue(FurnitureRoomBrandingLogic.OFFSETX_KEY));
|
||||
const offsetY = parseInt(objectData.getValue(FurnitureRoomBrandingLogic.OFFSETY_KEY));
|
||||
const offsetZ = parseInt(objectData.getValue(FurnitureRoomBrandingLogic.OFFSETZ_KEY));
|
||||
|
||||
if(!isNaN(offsetX)) this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_OFFSET_X, offsetX);
|
||||
if(!isNaN(offsetY)) this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_OFFSET_Y, offsetY);
|
||||
if(!isNaN(offsetZ)) this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_OFFSET_Z, offsetZ);
|
||||
|
||||
let options = (((FurnitureRoomBrandingLogic.IMAGEURL_KEY + '=') + ((imageUrl !== null) ? imageUrl : '')) + '\t');
|
||||
|
||||
if(this._hasClickUrl) options = (options + (((FurnitureRoomBrandingLogic.CLICKURL_KEY + '=') + ((clickUrl !== null) ? clickUrl : '')) + '\t'));
|
||||
|
||||
options = (options + (((FurnitureRoomBrandingLogic.OFFSETX_KEY + '=') + offsetX) + '\t'));
|
||||
options = (options + (((FurnitureRoomBrandingLogic.OFFSETY_KEY + '=') + offsetY) + '\t'));
|
||||
options = (options + (((FurnitureRoomBrandingLogic.OFFSETZ_KEY + '=') + offsetZ) + '\t'));
|
||||
|
||||
this.object.model.setValue(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, (RoomWidgetEnumItemExtradataParameter.BRANDING_OPTIONS + options));
|
||||
}
|
||||
|
||||
private processAdUpdate(message: ObjectAdUpdateMessage): void
|
||||
{
|
||||
if(!message || !this.object) return;
|
||||
|
||||
switch(message.type)
|
||||
{
|
||||
case ObjectAdUpdateMessage.IMAGE_LOADED:
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_STATUS, 1);
|
||||
break;
|
||||
case ObjectAdUpdateMessage.IMAGE_LOADING_FAILED:
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_STATUS, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry) return;
|
||||
|
||||
if((event.type === MouseEventType.MOUSE_MOVE) || (event.type === MouseEventType.DOUBLE_CLICK)) return;
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
|
||||
private async downloadBackground(): Promise<void>
|
||||
{
|
||||
const model = this.object && this.object.model;
|
||||
|
||||
if(!model) return;
|
||||
|
||||
const imageUrl = model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_URL);
|
||||
const imageStatus = model.getValue<number>(RoomObjectVariable.FURNITURE_BRANDING_IMAGE_STATUS);
|
||||
|
||||
if(!imageUrl || (imageUrl === '') || (imageStatus === 1)) return;
|
||||
|
||||
const asset = GetAssetManager();
|
||||
|
||||
if(!asset) return;
|
||||
|
||||
const texture = asset.getTexture(imageUrl);
|
||||
|
||||
if(!texture)
|
||||
{
|
||||
const status = await asset.downloadAsset(imageUrl);
|
||||
|
||||
if(!status)
|
||||
{
|
||||
this.processUpdateMessage(new ObjectAdUpdateMessage(ObjectAdUpdateMessage.IMAGE_LOADING_FAILED));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.processUpdateMessage(new ObjectAdUpdateMessage(ObjectAdUpdateMessage.IMAGE_LOADED));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectDimmerStateUpdateEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureRoomDimmerLogic extends FurnitureLogic
|
||||
{
|
||||
private _roomColorUpdated: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._roomColorUpdated = false;
|
||||
}
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.DIMMER,
|
||||
RoomObjectWidgetRequestEvent.WIDGET_REMOVE_DIMMER,
|
||||
RoomObjectDimmerStateUpdateEvent.DIMMER_STATE
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._roomColorUpdated)
|
||||
{
|
||||
if(this.eventDispatcher && this.object)
|
||||
{
|
||||
const realRoomObject = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT);
|
||||
|
||||
if(realRoomObject === 1)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectDimmerStateUpdateEvent(this.object, 0, 1, 1, 0xFFFFFF, 0xFF));
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.WIDGET_REMOVE_DIMMER, this.object));
|
||||
}
|
||||
|
||||
this._roomColorUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
if(message.data)
|
||||
{
|
||||
const extra = message.data.getLegacyString();
|
||||
|
||||
const realRoomObject = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT);
|
||||
|
||||
if(realRoomObject === 1) this.processDimmerData(extra);
|
||||
|
||||
super.processUpdateMessage(new ObjectDataUpdateMessage(this.getStateFromDimmerData(extra), message.data));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
private getStateFromDimmerData(data: string): number
|
||||
{
|
||||
if(!data) return 0;
|
||||
|
||||
const parts = data.split(',');
|
||||
|
||||
if(parts.length >= 5) return (parseInt(parts[0]) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private processDimmerData(data: string): void
|
||||
{
|
||||
if(!data) return;
|
||||
|
||||
const parts = data.split(',');
|
||||
|
||||
if(parts.length >= 5)
|
||||
{
|
||||
const state = this.getStateFromDimmerData(data);
|
||||
const presetId = parseInt(parts[1]);
|
||||
const effectId = parseInt(parts[2]);
|
||||
const color = parts[3];
|
||||
|
||||
let colorCode = parseInt(color.substr(1), 16);
|
||||
let brightness = parseInt(parts[4]);
|
||||
|
||||
if(!state)
|
||||
{
|
||||
colorCode = 0xFFFFFF;
|
||||
brightness = 0xFF;
|
||||
}
|
||||
|
||||
if(this.eventDispatcher && this.object)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectDimmerStateUpdateEvent(this.object, state, presetId, effectId, colorCode, brightness));
|
||||
|
||||
this._roomColorUpdated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.DIMMER, this.object));
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
// if(this.object && this.object.model)
|
||||
// {
|
||||
// const realRoomObject = this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT);
|
||||
|
||||
// if(realRoomObject === 1)
|
||||
// {
|
||||
// const data = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
// if(data && data.length > 0)
|
||||
// {
|
||||
// this.object.model.setValue(RoomObjectVariable.FURNITURE_DATA, '');
|
||||
|
||||
// this.processDimmerData(data);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureScoreLogic extends FurnitureLogic
|
||||
{
|
||||
private static UPDATE_INTERVAL: number = 50;
|
||||
private static MAX_UPDATE_TIME: number = 3000;
|
||||
|
||||
private _score: number;
|
||||
private _scoreIncreaser: number;
|
||||
private _scoreTimer: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._score = 0;
|
||||
this._scoreIncreaser = 50;
|
||||
this._scoreTimer = 0;
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
if(message instanceof ObjectDataUpdateMessage) return this.updateScore(message.state);
|
||||
|
||||
super.processUpdateMessage(message);
|
||||
}
|
||||
|
||||
private updateScore(count: number): void
|
||||
{
|
||||
this._score = count;
|
||||
|
||||
const currentScore = this.object.getState(0);
|
||||
|
||||
if(this._score !== currentScore)
|
||||
{
|
||||
let difference = (this._score - currentScore);
|
||||
|
||||
if(difference < 0) difference = -(difference);
|
||||
|
||||
if((difference * FurnitureScoreLogic.UPDATE_INTERVAL) > FurnitureScoreLogic.MAX_UPDATE_TIME) this._scoreIncreaser = (FurnitureScoreLogic.MAX_UPDATE_TIME / difference);
|
||||
else this._scoreIncreaser = FurnitureScoreLogic.UPDATE_INTERVAL;
|
||||
|
||||
this._scoreTimer = GetTickerTime();
|
||||
}
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
const currentScore = this.object.getState(0);
|
||||
|
||||
if((currentScore !== this._score) && (time >= (this._scoreTimer + this._scoreIncreaser)))
|
||||
{
|
||||
const _local_3 = (time - this._scoreTimer);
|
||||
let _local_4 = (_local_3 / this._scoreIncreaser);
|
||||
let _local_5 = 1;
|
||||
|
||||
if(this._score < currentScore) _local_5 = -1;
|
||||
|
||||
if(_local_4 > (_local_5 * (this._score - currentScore))) _local_4 = (_local_5 * (this._score - currentScore));
|
||||
|
||||
this.object.setState((currentScore + (_local_5 * _local_4)), 0);
|
||||
|
||||
this._scoreTimer = (time - (_local_3 - (_local_4 * this._scoreIncreaser)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureSongDiskLogic extends FurnitureLogic
|
||||
{
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
const extras = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_EXTRAS);
|
||||
const diskId = parseInt(extras);
|
||||
|
||||
this.object.model.setValue<string>(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, (RoomWidgetEnumItemExtradataParameter.SONGDISK + diskId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectSamplePlaybackEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureSoundBlockLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private static HIGHEST_SEMITONE: number = 12;
|
||||
private static LOWEST_SEMITONE: number = -12;
|
||||
private static STATE_UNINITIALIZED: number = -1;
|
||||
|
||||
private _state: number = -1;
|
||||
private _sampleId: number = -1;
|
||||
private _noPitch: boolean = false;
|
||||
private _lastLocZ: number = 0;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectSamplePlaybackEvent.ROOM_OBJECT_INITIALIZED,
|
||||
RoomObjectSamplePlaybackEvent.ROOM_OBJECT_DISPOSED,
|
||||
RoomObjectSamplePlaybackEvent.PLAY_SAMPLE,
|
||||
RoomObjectSamplePlaybackEvent.CHANGE_PITCH
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.soundSample)
|
||||
{
|
||||
this._sampleId = asset.logic.soundSample.id;
|
||||
this._noPitch = asset.logic.soundSample.noPitch;
|
||||
}
|
||||
}
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_SOUNDBLOCK_RELATIVE_ANIMATION_SPEED, 1);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._state !== FurnitureSoundBlockLogic.STATE_UNINITIALIZED)
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectSamplePlaybackEvent(RoomObjectSamplePlaybackEvent.ROOM_OBJECT_DISPOSED, this.object, this._sampleId));
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage) this.updateSoundBlockMessage(message);
|
||||
}
|
||||
|
||||
private updateSoundBlockMessage(message: ObjectDataUpdateMessage): void
|
||||
{
|
||||
if(!message) return;
|
||||
|
||||
const model = this.object && this.object.model;
|
||||
const location = this.object && this.object.location;
|
||||
|
||||
if(!model || !location) return;
|
||||
|
||||
if(this._state === FurnitureSoundBlockLogic.STATE_UNINITIALIZED && model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
this._lastLocZ = location.z;
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectSamplePlaybackEvent(RoomObjectSamplePlaybackEvent.ROOM_OBJECT_INITIALIZED, this.object, this._sampleId, this.getPitchForHeight(location.z)));
|
||||
}
|
||||
|
||||
if(this._state !== FurnitureSoundBlockLogic.STATE_UNINITIALIZED && model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) === 1)
|
||||
{
|
||||
if(this._lastLocZ !== location.z)
|
||||
{
|
||||
this._lastLocZ = location.z;
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectSamplePlaybackEvent(RoomObjectSamplePlaybackEvent.CHANGE_PITCH, this.object, this._sampleId, this.getPitchForHeight(location.z)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(this._state !== FurnitureSoundBlockLogic.STATE_UNINITIALIZED && message.state !== this._state)
|
||||
{
|
||||
this.playSoundAt(location.z);
|
||||
}
|
||||
|
||||
this._state = message.state;
|
||||
}
|
||||
|
||||
private playSoundAt(height: number): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
const pitch: number = this.getPitchForHeight(height);
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_SOUNDBLOCK_RELATIVE_ANIMATION_SPEED, pitch);
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectSamplePlaybackEvent(RoomObjectSamplePlaybackEvent.PLAY_SAMPLE, this.object, this._sampleId, pitch));
|
||||
}
|
||||
|
||||
private getPitchForHeight(height: number): number
|
||||
{
|
||||
if(this._noPitch) return 1;
|
||||
|
||||
let heightScaled: number = (height * 2);
|
||||
|
||||
if(heightScaled > FurnitureSoundBlockLogic.HIGHEST_SEMITONE)
|
||||
{
|
||||
heightScaled = Math.min(0, (FurnitureSoundBlockLogic.LOWEST_SEMITONE + ((heightScaled - FurnitureSoundBlockLogic.HIGHEST_SEMITONE) - 1)));
|
||||
}
|
||||
|
||||
return Math.pow(2, (heightScaled / 12));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { RoomObjectVariable, RoomWidgetEnumItemExtradataParameter } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent } from '@nitrots/events';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureSoundMachineLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private _disposeEventsAllowed: boolean = false;
|
||||
private _isInitialized: boolean = false;
|
||||
private _currentState: number = -1;
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectFurnitureActionEvent.SOUND_MACHINE_START,
|
||||
RoomObjectFurnitureActionEvent.SOUND_MACHINE_STOP,
|
||||
RoomObjectFurnitureActionEvent.SOUND_MACHINE_DISPOSE,
|
||||
RoomObjectFurnitureActionEvent.SOUND_MACHINE_INIT
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this.requestDispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_REAL_ROOM_OBJECT) !== 1) return;
|
||||
|
||||
if(!this._isInitialized) this.requestInit();
|
||||
|
||||
this.object.model.setValue<string>(RoomWidgetEnumItemExtradataParameter.INFOSTAND_EXTRA_PARAM, RoomWidgetEnumItemExtradataParameter.JUKEBOX);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const state = this.object.getState(0);
|
||||
|
||||
if(state !== this._currentState)
|
||||
{
|
||||
this._currentState = state;
|
||||
|
||||
if(state === 1) this.requestPlayList();
|
||||
else if(state === 0) this.requestStopPlaying();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private requestInit(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this._disposeEventsAllowed = true;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.SOUND_MACHINE_INIT, this.object));
|
||||
|
||||
this._isInitialized = true;
|
||||
}
|
||||
|
||||
private requestPlayList(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this._disposeEventsAllowed = true;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.SOUND_MACHINE_START, this.object));
|
||||
}
|
||||
|
||||
private requestStopPlaying(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.SOUND_MACHINE_STOP, this.object));
|
||||
}
|
||||
|
||||
private requestDispose(): void
|
||||
{
|
||||
if(!this._disposeEventsAllowed || !this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.SOUND_MACHINE_DISPOSE, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectFurnitureActionEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { ObjectItemDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureStickieLogic extends FurnitureLogic
|
||||
{
|
||||
private static STICKIE_COLORS: string[] = ['9CCEFF', 'FF9CFF', '9CFF9C', 'FFFF33'];
|
||||
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.STICKIE,
|
||||
RoomObjectFurnitureActionEvent.STICKIE
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
this.updateColor();
|
||||
|
||||
if(this.object) this.object.model.setValue(RoomObjectVariable.FURNITURE_IS_STICKIE, '');
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectItemDataUpdateMessage)
|
||||
{
|
||||
this.eventDispatcher && this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.STICKIE, this.object));
|
||||
}
|
||||
|
||||
this.updateColor();
|
||||
}
|
||||
|
||||
protected updateColor(): void
|
||||
{
|
||||
if(!this.object) return;
|
||||
|
||||
const furnitureData = this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
let colorIndex = FurnitureStickieLogic.STICKIE_COLORS.indexOf(furnitureData);
|
||||
|
||||
if(colorIndex < 0) colorIndex = 3;
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_COLOR, (colorIndex + 1));
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectFurnitureActionEvent(RoomObjectFurnitureActionEvent.STICKIE, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureTrophyLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [RoomObjectWidgetRequestEvent.TROPHY];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.TROPHY, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { RoomObjectVariable, VoteDataType } from '@nitrots/api';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureVoteCounterLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
private static UPDATE_INTERVAL: number = 33;
|
||||
private static MAX_UPDATE_TIME: number = 1000;
|
||||
|
||||
private _total: number;
|
||||
private _lastUpdate: number;
|
||||
private _interval: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._total = 0;
|
||||
this._lastUpdate = 0;
|
||||
this._interval = 33;
|
||||
}
|
||||
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const stuffData = (message.data as VoteDataType);
|
||||
|
||||
if(!stuffData) return;
|
||||
|
||||
this.updateTotal(stuffData.result);
|
||||
}
|
||||
}
|
||||
|
||||
private updateTotal(k: number): void
|
||||
{
|
||||
this._total = k;
|
||||
|
||||
if(!this._lastUpdate)
|
||||
{
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_VOTE_COUNTER_COUNT, k);
|
||||
|
||||
this._lastUpdate = GetTickerTime();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(this._total !== this.currentTotal)
|
||||
{
|
||||
const difference = Math.abs((this._total - this.currentTotal));
|
||||
|
||||
if((difference * FurnitureVoteCounterLogic.UPDATE_INTERVAL) > FurnitureVoteCounterLogic.MAX_UPDATE_TIME)
|
||||
{
|
||||
this._interval = (FurnitureVoteCounterLogic.MAX_UPDATE_TIME / difference);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._interval = FurnitureVoteCounterLogic.UPDATE_INTERVAL;
|
||||
}
|
||||
|
||||
this._lastUpdate = GetTickerTime();
|
||||
}
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(this.object)
|
||||
{
|
||||
if((this.currentTotal !== this._total) && (time >= (this._lastUpdate + this._interval)))
|
||||
{
|
||||
const _local_2 = (time - this._lastUpdate);
|
||||
let _local_3 = (_local_2 / this._interval);
|
||||
let _local_4 = 1;
|
||||
|
||||
if(this._total < this.currentTotal) _local_4 = -1;
|
||||
|
||||
if(_local_3 > (_local_4 * (this._total - this.currentTotal))) _local_3 = (_local_4 * (this._total - this.currentTotal));
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_VOTE_COUNTER_COUNT, (this.currentTotal + (_local_4 * _local_3)));
|
||||
|
||||
this._lastUpdate = (time - (_local_2 - (_local_3 * this._interval)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private get currentTotal(): number
|
||||
{
|
||||
return this.object.model.getValue<number>(RoomObjectVariable.FURNITURE_VOTE_COUNTER_COUNT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { RoomObjectVariable, VoteDataType } from '@nitrots/api';
|
||||
import { ObjectDataUpdateMessage, RoomObjectUpdateMessage } from '../../../messages';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureVoteMajorityLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
||||
{
|
||||
super.processUpdateMessage(message);
|
||||
|
||||
if(!this.object) return;
|
||||
|
||||
if(message instanceof ObjectDataUpdateMessage)
|
||||
{
|
||||
const data = message.data;
|
||||
|
||||
if(data instanceof VoteDataType) this.object.model.setValue(RoomObjectVariable.FURNITURE_VOTE_MAJORITY_RESULT, data.result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { IRoomGeometry, MouseEventType } from '@nitrots/api';
|
||||
import { RoomObjectStateChangedEvent, RoomSpriteMouseEvent } from '@nitrots/events';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureWelcomeGiftLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void
|
||||
{
|
||||
if(!event || !geometry) return;
|
||||
|
||||
if(event.type === MouseEventType.DOUBLE_CLICK)
|
||||
{
|
||||
if(this.eventDispatcher) this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object));
|
||||
}
|
||||
|
||||
super.mouseEvent(event, geometry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
||||
import { FurnitureMultiStateLogic } from './FurnitureMultiStateLogic';
|
||||
|
||||
export class FurnitureWindowLogic extends FurnitureMultiStateLogic
|
||||
{
|
||||
public initialize(asset: IAssetData): void
|
||||
{
|
||||
super.initialize(asset);
|
||||
|
||||
let maskType = '';
|
||||
|
||||
if(asset.logic)
|
||||
{
|
||||
if(asset.logic.maskType && (asset.logic.maskType !== '') && (asset.logic.maskType.length > 0)) maskType = asset.logic.maskType;
|
||||
}
|
||||
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_USES_PLANE_MASK, 1);
|
||||
this.object.model.setValue(RoomObjectVariable.FURNITURE_PLANE_MASK_TYPE, maskType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { RoomObjectVariable } from '@nitrots/api';
|
||||
import { RoomObjectDataRequestEvent, RoomObjectWidgetRequestEvent } from '@nitrots/events';
|
||||
import { FurnitureLogic } from './FurnitureLogic';
|
||||
|
||||
export class FurnitureYoutubeLogic extends FurnitureLogic
|
||||
{
|
||||
public getEventTypes(): string[]
|
||||
{
|
||||
const types = [
|
||||
RoomObjectWidgetRequestEvent.YOUTUBE,
|
||||
RoomObjectDataRequestEvent.RODRE_URL_PREFIX
|
||||
];
|
||||
|
||||
return this.mergeTypes(super.getEventTypes(), types);
|
||||
}
|
||||
|
||||
public update(time: number): void
|
||||
{
|
||||
super.update(time);
|
||||
|
||||
if(!this.object.model.getValue<string>(RoomObjectVariable.SESSION_URL_PREFIX))
|
||||
{
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectDataRequestEvent(RoomObjectDataRequestEvent.RODRE_URL_PREFIX, this.object));
|
||||
}
|
||||
}
|
||||
|
||||
public useObject(): void
|
||||
{
|
||||
if(!this.object || !this.eventDispatcher) return;
|
||||
|
||||
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.YOUTUBE, this.object));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
export * from './FurnitureAchievementResolutionLogic';
|
||||
export * from './FurnitureBadgeDisplayLogic';
|
||||
export * from './FurnitureChangeStateWhenStepOnLogic';
|
||||
export * from './FurnitureClothingChangeLogic';
|
||||
export * from './FurnitureCounterClockLogic';
|
||||
export * from './FurnitureCrackableLogic';
|
||||
export * from './FurnitureCraftingGizmoLogic';
|
||||
export * from './FurnitureCreditLogic';
|
||||
export * from './FurnitureCuckooClockLogic';
|
||||
export * from './FurnitureCustomStackHeightLogic';
|
||||
export * from './FurnitureDiceLogic';
|
||||
export * from './FurnitureEcotronBoxLogic';
|
||||
export * from './FurnitureEditableInternalLinkLogic';
|
||||
export * from './FurnitureEditableRoomLinkLogic';
|
||||
export * from './FurnitureEffectBoxLogic';
|
||||
export * from './FurnitureExternalImageLogic';
|
||||
export * from './FurnitureFireworksLogic';
|
||||
export * from './FurnitureFloorHoleLogic';
|
||||
export * from './FurnitureFriendFurniLogic';
|
||||
export * from './FurnitureGroupForumTerminalLogic';
|
||||
export * from './FurnitureGuildCustomizedLogic';
|
||||
export * from './FurnitureHabboWheelLogic';
|
||||
export * from './FurnitureHighScoreLogic';
|
||||
export * from './FurnitureHockeyScoreLogic';
|
||||
export * from './FurnitureHweenLovelockLogic';
|
||||
export * from './FurnitureIceStormLogic';
|
||||
export * from './FurnitureInternalLinkLogic';
|
||||
export * from './FurnitureJukeboxLogic';
|
||||
export * from './FurnitureLogic';
|
||||
export * from './FurnitureLoveLockLogic';
|
||||
export * from './FurnitureMannequinLogic';
|
||||
export * from './FurnitureMonsterplantSeedLogic';
|
||||
export * from './FurnitureMultiHeightLogic';
|
||||
export * from './FurnitureMultiStateLogic';
|
||||
export * from './FurnitureMysteryBoxLogic';
|
||||
export * from './FurnitureMysteryTrophyLogic';
|
||||
export * from './FurnitureOneWayDoorLogic';
|
||||
export * from './FurniturePetCustomizationLogic';
|
||||
export * from './FurniturePlaceholderLogic';
|
||||
export * from './FurniturePlanetSystemLogic';
|
||||
export * from './FurniturePresentLogic';
|
||||
export * from './FurniturePurchaseableClothingLogic';
|
||||
export * from './FurniturePushableLogic';
|
||||
export * from './FurnitureRandomStateLogic';
|
||||
export * from './FurnitureRandomTeleportLogic';
|
||||
export * from './FurnitureRentableSpaceLogic';
|
||||
export * from './FurnitureRoomBackgroundColorLogic';
|
||||
export * from './FurnitureRoomBackgroundLogic';
|
||||
export * from './FurnitureRoomBillboardLogic';
|
||||
export * from './FurnitureRoomBrandingLogic';
|
||||
export * from './FurnitureRoomDimmerLogic';
|
||||
export * from './FurnitureScoreLogic';
|
||||
export * from './FurnitureSongDiskLogic';
|
||||
export * from './FurnitureSoundBlockLogic';
|
||||
export * from './FurnitureSoundMachineLogic';
|
||||
export * from './FurnitureStickieLogic';
|
||||
export * from './FurnitureTrophyLogic';
|
||||
export * from './FurnitureVoteCounterLogic';
|
||||
export * from './FurnitureVoteMajorityLogic';
|
||||
export * from './FurnitureWelcomeGiftLogic';
|
||||
export * from './FurnitureWindowLogic';
|
||||
export * from './FurnitureYoutubeLogic';
|
||||
@@ -0,0 +1,8 @@
|
||||
export * from './AvatarLogic';
|
||||
export * from './MovingObjectLogic';
|
||||
export * from './PetLogic';
|
||||
export * from './RoomLogic';
|
||||
export * from './RoomObjectLogicBase';
|
||||
export * from './SelectionArrowLogic';
|
||||
export * from './TileCursorLogic';
|
||||
export * from './furniture';
|
||||
@@ -0,0 +1,355 @@
|
||||
import { AlphaTolerance, IRoomObjectSprite, RoomObjectSpriteType } from '@nitrots/api';
|
||||
import { BLEND_MODES, Filter, Texture } from 'pixi.js';
|
||||
|
||||
export class RoomObjectSprite implements IRoomObjectSprite
|
||||
{
|
||||
private static SPRITE_COUNTER: number = 0;
|
||||
|
||||
private _id: number = RoomObjectSprite.SPRITE_COUNTER++;
|
||||
private _name: string = '';
|
||||
private _type: string = '';
|
||||
private _spriteType: number = RoomObjectSpriteType.DEFAULT;
|
||||
private _texture: Texture = null;
|
||||
|
||||
private _width: number = 0;
|
||||
private _height: number = 0;
|
||||
private _offsetX: number = 0;
|
||||
private _offsetY: number = 0;
|
||||
private _flipH: boolean = false;
|
||||
private _flipV: boolean = false;
|
||||
private _direction: number = 0;
|
||||
|
||||
private _alpha: number = 255;
|
||||
private _blendMode: BLEND_MODES = 'normal';
|
||||
private _color: number = 0xFFFFFF;
|
||||
private _relativeDepth: number = 0;
|
||||
private _varyingDepth: boolean = false;
|
||||
private _libraryAssetName: string = '';
|
||||
private _clickHandling: boolean = false;
|
||||
private _visible: boolean = true;
|
||||
private _tag: string = '';
|
||||
private _posture: string = null;
|
||||
private _alphaTolerance: number = AlphaTolerance.MATCH_OPAQUE_PIXELS;
|
||||
private _filters: Filter[] = [];
|
||||
|
||||
private _updateCounter: number = 0;
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._texture = null;
|
||||
this._width = 0;
|
||||
this._height = 0;
|
||||
}
|
||||
|
||||
public increaseUpdateCounter(): void
|
||||
{
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public set id(id: number)
|
||||
{
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public set name(name: string)
|
||||
{
|
||||
if(this._name === name) return;
|
||||
|
||||
this._name = name;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public set type(type: string)
|
||||
{
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public get spriteType(): number
|
||||
{
|
||||
return this._spriteType;
|
||||
}
|
||||
|
||||
public set spriteType(type: number)
|
||||
{
|
||||
this._spriteType = type;
|
||||
}
|
||||
|
||||
public get texture(): Texture
|
||||
{
|
||||
return this._texture;
|
||||
}
|
||||
|
||||
public set texture(texture: Texture)
|
||||
{
|
||||
if(this._texture === texture) return;
|
||||
|
||||
if(texture)
|
||||
{
|
||||
this._width = texture.width;
|
||||
this._height = texture.height;
|
||||
}
|
||||
|
||||
this._texture = texture;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get width(): number
|
||||
{
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public get height(): number
|
||||
{
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public get offsetX(): number
|
||||
{
|
||||
return this._offsetX;
|
||||
}
|
||||
|
||||
public set offsetX(x: number)
|
||||
{
|
||||
if(this._offsetX === x) return;
|
||||
|
||||
this._offsetX = x;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get offsetY(): number
|
||||
{
|
||||
return this._offsetY;
|
||||
}
|
||||
|
||||
public set offsetY(y: number)
|
||||
{
|
||||
if(this._offsetY === y) return;
|
||||
|
||||
this._offsetY = y;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get flipH(): boolean
|
||||
{
|
||||
return this._flipH;
|
||||
}
|
||||
|
||||
public set flipH(flip: boolean)
|
||||
{
|
||||
if(this._flipH === flip) return;
|
||||
|
||||
this._flipH = flip;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get flipV(): boolean
|
||||
{
|
||||
return this._flipV;
|
||||
}
|
||||
|
||||
public set flipV(flip: boolean)
|
||||
{
|
||||
if(this._flipV === flip) return;
|
||||
|
||||
this._flipV = flip;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get direction(): number
|
||||
{
|
||||
return this._direction;
|
||||
}
|
||||
|
||||
public set direction(direction: number)
|
||||
{
|
||||
this._direction = direction;
|
||||
}
|
||||
|
||||
public get alpha(): number
|
||||
{
|
||||
return this._alpha;
|
||||
}
|
||||
|
||||
public set alpha(alpha: number)
|
||||
{
|
||||
alpha = (alpha & 0xFF);
|
||||
|
||||
if(this._alpha === alpha) return;
|
||||
|
||||
this._alpha = alpha;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get blendMode(): BLEND_MODES
|
||||
{
|
||||
return this._blendMode;
|
||||
}
|
||||
|
||||
public set blendMode(blend: BLEND_MODES)
|
||||
{
|
||||
if(this._blendMode === blend) return;
|
||||
|
||||
this._blendMode = blend;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get color(): number
|
||||
{
|
||||
return this._color;
|
||||
}
|
||||
|
||||
public set color(color: number)
|
||||
{
|
||||
color = (color & 0xFFFFFF);
|
||||
|
||||
if(this._color === color) return;
|
||||
|
||||
this._color = color;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get relativeDepth(): number
|
||||
{
|
||||
return this._relativeDepth;
|
||||
}
|
||||
|
||||
public set relativeDepth(depth: number)
|
||||
{
|
||||
if(this._relativeDepth === depth) return;
|
||||
|
||||
this._relativeDepth = depth;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get varyingDepth(): boolean
|
||||
{
|
||||
return this._varyingDepth;
|
||||
}
|
||||
|
||||
public set varyingDepth(flag: boolean)
|
||||
{
|
||||
if(flag === this._varyingDepth) return;
|
||||
|
||||
this._varyingDepth = flag;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get libraryAssetName(): string
|
||||
{
|
||||
return this._libraryAssetName;
|
||||
}
|
||||
|
||||
public set libraryAssetName(value: string)
|
||||
{
|
||||
this._libraryAssetName = value;
|
||||
}
|
||||
|
||||
public get clickHandling(): boolean
|
||||
{
|
||||
return this._clickHandling;
|
||||
}
|
||||
|
||||
public set clickHandling(flag: boolean)
|
||||
{
|
||||
this._clickHandling = flag;
|
||||
}
|
||||
|
||||
public get visible(): boolean
|
||||
{
|
||||
return this._visible;
|
||||
}
|
||||
|
||||
public set visible(visible: boolean)
|
||||
{
|
||||
if(this._visible === visible) return;
|
||||
|
||||
this._visible = visible;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get tag(): string
|
||||
{
|
||||
return this._tag;
|
||||
}
|
||||
|
||||
public set tag(tag: string)
|
||||
{
|
||||
if(this._tag === tag) return;
|
||||
|
||||
this._tag = tag;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get posture(): string
|
||||
{
|
||||
return this._posture;
|
||||
}
|
||||
|
||||
public set posture(posture: string)
|
||||
{
|
||||
if(this._posture === posture) return;
|
||||
|
||||
this._posture = posture;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get alphaTolerance(): number
|
||||
{
|
||||
return this._alphaTolerance;
|
||||
}
|
||||
|
||||
public set alphaTolerance(tolerance: number)
|
||||
{
|
||||
if(this._alphaTolerance === tolerance) return;
|
||||
|
||||
this._alphaTolerance = tolerance;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get filters(): Filter[]
|
||||
{
|
||||
return this._filters;
|
||||
}
|
||||
|
||||
public set filters(filters: Filter[])
|
||||
{
|
||||
this._filters = filters;
|
||||
|
||||
this._updateCounter++;
|
||||
}
|
||||
|
||||
public get updateCounter(): number
|
||||
{
|
||||
return this._updateCounter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
import { IGraphicAssetCollection, IObjectVisualizationData, IRoomGeometry, IRoomObjectController, IRoomObjectSprite, IRoomObjectSpriteVisualization, RoomObjectSpriteData } from '@nitrots/api';
|
||||
import { TextureUtils } from '@nitrots/utils';
|
||||
import { Container, Point, Rectangle, Sprite, Texture } from 'pixi.js';
|
||||
import { RoomObjectSprite } from './RoomObjectSprite';
|
||||
|
||||
export class RoomObjectSpriteVisualization implements IRoomObjectSpriteVisualization
|
||||
{
|
||||
private static VISUALIZATION_COUNTER: number = 0;
|
||||
|
||||
private _id: number = RoomObjectSpriteVisualization.VISUALIZATION_COUNTER++;
|
||||
private _object: IRoomObjectController = null;
|
||||
private _asset: IGraphicAssetCollection = null;
|
||||
private _sprites: IRoomObjectSprite[] = [];
|
||||
|
||||
protected _scale: number = -1;
|
||||
|
||||
private _updateObjectCounter: number = -1;
|
||||
private _updateModelCounter: number = -1;
|
||||
private _updateSpriteCounter: number = -1;
|
||||
|
||||
public initialize(data: IObjectVisualizationData): boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public update(geometry: IRoomGeometry, time: number, update: boolean, skipUpdate: boolean): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
protected reset(): void
|
||||
{
|
||||
this._scale = -1;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._sprites)
|
||||
{
|
||||
while(this._sprites.length)
|
||||
{
|
||||
const sprite = (this._sprites[0] as RoomObjectSprite);
|
||||
|
||||
if(sprite) sprite.dispose();
|
||||
|
||||
this._sprites.shift();
|
||||
}
|
||||
|
||||
this._sprites = null;
|
||||
}
|
||||
|
||||
this._object = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
public getSprite(index: number): IRoomObjectSprite
|
||||
{
|
||||
if((index >= 0) && (index < this._sprites.length)) return this._sprites[index];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getSpriteList(): RoomObjectSpriteData[]
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public createSprite(): IRoomObjectSprite
|
||||
{
|
||||
return this.createSpriteAtIndex(this._sprites.length);
|
||||
}
|
||||
|
||||
public createSpriteAtIndex(index: number): IRoomObjectSprite
|
||||
{
|
||||
const sprite = new RoomObjectSprite();
|
||||
|
||||
if(index >= this._sprites.length)
|
||||
{
|
||||
this._sprites.push(sprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._sprites.splice(index, 0, sprite);
|
||||
}
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
protected createSprites(count: number): void
|
||||
{
|
||||
while(this._sprites.length > count)
|
||||
{
|
||||
const sprite = this._sprites[(this._sprites.length - 1)] as RoomObjectSprite;
|
||||
|
||||
if(sprite) sprite.dispose();
|
||||
|
||||
this._sprites.pop();
|
||||
}
|
||||
|
||||
while(this._sprites.length < count)
|
||||
{
|
||||
this._sprites.push(new RoomObjectSprite());
|
||||
}
|
||||
}
|
||||
|
||||
public get image(): Texture
|
||||
{
|
||||
return this.getImage();
|
||||
}
|
||||
|
||||
public getImage(): Texture
|
||||
{
|
||||
const boundingRectangle = this.getBoundingRectangle();
|
||||
|
||||
if((boundingRectangle.width * boundingRectangle.height) === 0) return null;
|
||||
|
||||
const spriteCount = this.totalSprites;
|
||||
const spriteList: IRoomObjectSprite[] = [];
|
||||
|
||||
let index = 0;
|
||||
|
||||
while(index < spriteCount)
|
||||
{
|
||||
const objectSprite = this.getSprite(index);
|
||||
|
||||
if(objectSprite && objectSprite.visible && objectSprite.texture) spriteList.push(objectSprite);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
spriteList.sort((a, b) =>
|
||||
{
|
||||
return b.relativeDepth - a.relativeDepth;
|
||||
});
|
||||
|
||||
const container = new Container();
|
||||
|
||||
index = 0;
|
||||
|
||||
while(index < spriteList.length)
|
||||
{
|
||||
const objectSprite = spriteList[index];
|
||||
const texture = objectSprite.texture;
|
||||
|
||||
if(texture)
|
||||
{
|
||||
const sprite = new Sprite(texture);
|
||||
|
||||
sprite.alpha = (objectSprite.alpha / 255);
|
||||
sprite.tint = objectSprite.color;
|
||||
sprite.x = objectSprite.offsetX;
|
||||
sprite.y = objectSprite.offsetY;
|
||||
sprite.blendMode = objectSprite.blendMode;
|
||||
sprite.filters = objectSprite.filters;
|
||||
|
||||
if(objectSprite.flipH) sprite.scale.x = -1;
|
||||
|
||||
if(objectSprite.flipV) sprite.scale.y = -1;
|
||||
|
||||
container.addChild(sprite);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return TextureUtils.generateTexture({
|
||||
target: container
|
||||
});
|
||||
}
|
||||
|
||||
public getBoundingRectangle(): Rectangle
|
||||
{
|
||||
const totalSprites = this.totalSprites;
|
||||
const rectangle = new Rectangle();
|
||||
|
||||
let iterator = 0;
|
||||
|
||||
while(iterator < totalSprites)
|
||||
{
|
||||
const sprite = this.getSprite(iterator);
|
||||
|
||||
if(sprite && sprite.texture && sprite.visible)
|
||||
{
|
||||
const offsetX = ((sprite.flipH) ? (-(sprite.width) + sprite.offsetX) : sprite.offsetX);
|
||||
const offsetY = ((sprite.flipV) ? (-(sprite.height) + sprite.offsetY) : sprite.offsetY);
|
||||
const point = new Point(offsetX, offsetY);
|
||||
|
||||
if(iterator === 0)
|
||||
{
|
||||
rectangle.x = point.x;
|
||||
rectangle.y = point.y;
|
||||
rectangle.width = sprite.width;
|
||||
rectangle.height = sprite.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(point.x < rectangle.x) rectangle.x = point.x;
|
||||
|
||||
if(point.y < rectangle.y) rectangle.y = point.y;
|
||||
|
||||
if((point.x + sprite.width) > rectangle.right) rectangle.width = ((point.x + sprite.width) - rectangle.x);
|
||||
|
||||
if((point.y + sprite.height) > rectangle.bottom) rectangle.height = ((point.y + sprite.height) - rectangle.y);
|
||||
}
|
||||
}
|
||||
|
||||
iterator++;
|
||||
}
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
public get instanceId(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get object(): IRoomObjectController
|
||||
{
|
||||
return this._object;
|
||||
}
|
||||
|
||||
public set object(object: IRoomObjectController)
|
||||
{
|
||||
this._object = object;
|
||||
}
|
||||
|
||||
public get asset(): IGraphicAssetCollection
|
||||
{
|
||||
return this._asset;
|
||||
}
|
||||
|
||||
public set asset(asset: IGraphicAssetCollection)
|
||||
{
|
||||
if(this._asset) this._asset.removeReference();
|
||||
|
||||
this._asset = asset;
|
||||
|
||||
if(this._asset) this._asset.addReference();
|
||||
}
|
||||
|
||||
public get sprites(): IRoomObjectSprite[]
|
||||
{
|
||||
return this._sprites;
|
||||
}
|
||||
|
||||
public get totalSprites(): number
|
||||
{
|
||||
return this._sprites.length;
|
||||
}
|
||||
|
||||
public get updateObjectCounter(): number
|
||||
{
|
||||
return this._updateObjectCounter;
|
||||
}
|
||||
|
||||
public set updateObjectCounter(count: number)
|
||||
{
|
||||
this._updateObjectCounter = count;
|
||||
}
|
||||
|
||||
public get updateModelCounter(): number
|
||||
{
|
||||
return this._updateModelCounter;
|
||||
}
|
||||
|
||||
public set updateModelCounter(count: number)
|
||||
{
|
||||
this._updateModelCounter = count;
|
||||
}
|
||||
|
||||
public get updateSpriteCounter(): number
|
||||
{
|
||||
return this._updateSpriteCounter;
|
||||
}
|
||||
|
||||
public set updateSpriteCounter(count: number)
|
||||
{
|
||||
this._updateSpriteCounter = count;
|
||||
}
|
||||
|
||||
public get spriteCount(): number
|
||||
{
|
||||
return this._sprites.length;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
import { AvatarScaleType, IAssetData, IAvatarEffectListener, IAvatarImage, IAvatarImageListener, IObjectVisualizationData } from '@nitrots/api';
|
||||
import { GetAvatarRenderManager } from '@nitrots/avatar';
|
||||
|
||||
export class AvatarVisualizationData implements IObjectVisualizationData
|
||||
{
|
||||
public initialize(asset: IAssetData): boolean
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
}
|
||||
|
||||
public createAvatarImage(figure: string, size: number, gender: string = null, avatarListener: IAvatarImageListener = null, effectListener: IAvatarEffectListener = null): IAvatarImage
|
||||
{
|
||||
let avatarImage: IAvatarImage = null;
|
||||
|
||||
if(size > 48) avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.LARGE, gender, avatarListener, effectListener);
|
||||
else avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.SMALL, gender, avatarListener, effectListener);
|
||||
|
||||
return avatarImage;
|
||||
}
|
||||
|
||||
public get layerCount(): number
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { IRoomObjectSprite } from '@nitrots/api';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IExpressionAddition } from './IExpressionAddition';
|
||||
|
||||
export class ExpressionAddition implements IExpressionAddition
|
||||
{
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _type: number,
|
||||
private _visualization: AvatarVisualization)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get visualization(): AvatarVisualization
|
||||
{
|
||||
return this._visualization;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { ExpressionAddition } from './ExpressionAddition';
|
||||
import { FloatingHeartAddition } from './FloatingHeartAddition';
|
||||
import { IExpressionAddition } from './IExpressionAddition';
|
||||
|
||||
export class ExpressionAdditionFactory
|
||||
{
|
||||
public static WAVE: number = 1;
|
||||
public static BLOW: number = 2;
|
||||
public static LAUGH: number = 3;
|
||||
public static CRY: number = 4;
|
||||
public static IDLE: number = 5;
|
||||
|
||||
public static getExpressionAddition(id: number, type: number, visualization: AvatarVisualization): IExpressionAddition
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case this.BLOW: return new FloatingHeartAddition(id, this.BLOW, visualization);
|
||||
default: return new ExpressionAddition(id, type, visualization);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import { AvatarAction, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { ExpressionAddition } from './ExpressionAddition';
|
||||
|
||||
export class FloatingHeartAddition extends ExpressionAddition
|
||||
{
|
||||
private static DELAY_BEFORE_ANIMATION: number = 300;
|
||||
private static STATE_DELAY: number = 0;
|
||||
private static STATE_FADE_IN: number = 1;
|
||||
private static STATE_FLOAT: number = 2;
|
||||
private static STATE_COMPLETE: number = 3;
|
||||
|
||||
private _asset: Texture = null;
|
||||
private _startTime: number = GetTickerTime();
|
||||
private _delta: number = 0;
|
||||
private _offsetY: number = 0;
|
||||
private _scale: number = 0;
|
||||
private _state: number = 0;
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
this._scale = scale;
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
|
||||
if(scale < 48)
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_blowkiss_small');
|
||||
|
||||
if((this.visualization.angle === 90) || (this.visualization.angle === 270))
|
||||
{
|
||||
offsetX = 0;
|
||||
}
|
||||
|
||||
else if((this.visualization.angle === 135) || (this.visualization.angle === 180) || (this.visualization.angle === 225))
|
||||
{
|
||||
offsetX = 6;
|
||||
}
|
||||
|
||||
else offsetX = -6;
|
||||
|
||||
this._offsetY = -38;
|
||||
|
||||
additionScale = 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_blowkiss');
|
||||
|
||||
if((this.visualization.angle === 90) || (this.visualization.angle === 270))
|
||||
{
|
||||
offsetX = -3;
|
||||
}
|
||||
|
||||
else if((this.visualization.angle === 135) || (this.visualization.angle === 180) || (this.visualization.angle === 225))
|
||||
{
|
||||
offsetX = 22;
|
||||
}
|
||||
|
||||
else offsetX = -30;
|
||||
|
||||
this._offsetY = -70;
|
||||
}
|
||||
|
||||
if(this.visualization.posture === AvatarAction.POSTURE_SIT)
|
||||
{
|
||||
this._offsetY += (additionScale / 2);
|
||||
}
|
||||
|
||||
else if(this.visualization.posture === AvatarAction.POSTURE_LAY)
|
||||
{
|
||||
this._offsetY += additionScale;
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = this._offsetY;
|
||||
sprite.relativeDepth = -0.02;
|
||||
sprite.alpha = 0;
|
||||
|
||||
const delta = this._delta;
|
||||
|
||||
this.animate(sprite);
|
||||
|
||||
this._delta = delta;
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(!sprite) return false;
|
||||
|
||||
if(this._asset) sprite.texture = this._asset;
|
||||
|
||||
if(this._state === FloatingHeartAddition.STATE_DELAY)
|
||||
{
|
||||
if((GetTickerTime() - this._startTime) < FloatingHeartAddition.DELAY_BEFORE_ANIMATION) return false;
|
||||
|
||||
this._state = FloatingHeartAddition.STATE_FADE_IN;
|
||||
|
||||
sprite.alpha = 0;
|
||||
sprite.visible = true;
|
||||
|
||||
this._delta = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this._state === FloatingHeartAddition.STATE_FADE_IN)
|
||||
{
|
||||
this._delta += 0.1;
|
||||
|
||||
sprite.offsetY = this._offsetY;
|
||||
sprite.alpha = (Math.pow(this._delta, 0.9) * 255);
|
||||
|
||||
if(this._delta >= 1)
|
||||
{
|
||||
sprite.alpha = 255;
|
||||
|
||||
this._delta = 0;
|
||||
this._state = FloatingHeartAddition.STATE_FLOAT;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this._state === FloatingHeartAddition.STATE_FLOAT)
|
||||
{
|
||||
const alpha = Math.pow(this._delta, 0.9);
|
||||
|
||||
this._delta += 0.05;
|
||||
|
||||
const offset = ((this._scale < 48) ? -30 : -40);
|
||||
|
||||
sprite.offsetY = (this._offsetY + (((this._delta < 1) ? alpha : 1) * offset));
|
||||
sprite.alpha = ((1 - alpha) * 255);
|
||||
|
||||
if(sprite.alpha <= 0)
|
||||
{
|
||||
sprite.visible = false;
|
||||
|
||||
this._state = FloatingHeartAddition.STATE_COMPLETE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { AvatarAction, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class FloatingIdleZAddition implements IAvatarAddition
|
||||
{
|
||||
private static DELAY_BEFORE_ANIMATION: number = 2000;
|
||||
private static DELAY_PER_FRAME: number = 2000;
|
||||
private static STATE_DELAY: number = 0;
|
||||
private static STATE_FRAME_A: number = 1;
|
||||
private static STATE_FRAME_B: number = 2;
|
||||
|
||||
private _asset: Texture = null;
|
||||
private _startTime: number = GetTickerTime();
|
||||
private _offsetY: number = 0;
|
||||
private _scale: number = 0;
|
||||
private _state: number = 0;
|
||||
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _visualization: AvatarVisualization)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
private getSpriteAssetName(state: number): string
|
||||
{
|
||||
let side = 'left';
|
||||
|
||||
if((this._visualization.angle === 135) || (this._visualization.angle === 180) || (this._visualization.angle === 225) || (this._visualization.angle === 270)) side = 'right';
|
||||
|
||||
return ('avatar_addition_user_idle_' + side + '_' + state + ((this._scale < 48) ? '_small' : ''));
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
this._scale = scale;
|
||||
this._asset = GetAssetManager().getTexture(this.getSpriteAssetName((this._state === FloatingIdleZAddition.STATE_FRAME_A) ? 1 : 2));
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
|
||||
if(scale < 48)
|
||||
{
|
||||
if((this._visualization.angle === 135) || (this._visualization.angle === 180) || (this._visualization.angle === 225) || (this._visualization.angle === 270))
|
||||
{
|
||||
offsetX = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
offsetX = -16;
|
||||
}
|
||||
|
||||
this._offsetY = -38;
|
||||
|
||||
additionScale = 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((this._visualization.angle === 135) || (this._visualization.angle === 180) || (this._visualization.angle === 225) || (this._visualization.angle === 270))
|
||||
{
|
||||
offsetX = 22;
|
||||
}
|
||||
else
|
||||
{
|
||||
offsetX = -30;
|
||||
}
|
||||
|
||||
this._offsetY = -70;
|
||||
}
|
||||
|
||||
if(this._visualization.posture === AvatarAction.POSTURE_SIT)
|
||||
{
|
||||
this._offsetY += (additionScale / 2);
|
||||
}
|
||||
|
||||
else if(this._visualization.posture === AvatarAction.POSTURE_LAY)
|
||||
{
|
||||
this._offsetY += (additionScale - (0.3 * additionScale));
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = this._offsetY;
|
||||
sprite.relativeDepth = -0.02;
|
||||
sprite.alpha = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(!sprite) return false;
|
||||
|
||||
const totalTimeRunning = GetTickerTime();
|
||||
|
||||
if(this._state === FloatingIdleZAddition.STATE_DELAY)
|
||||
{
|
||||
if((totalTimeRunning - this._startTime) >= FloatingIdleZAddition.DELAY_BEFORE_ANIMATION)
|
||||
{
|
||||
this._state = FloatingIdleZAddition.STATE_FRAME_A;
|
||||
this._startTime = totalTimeRunning;
|
||||
this._asset = GetAssetManager().getTexture(this.getSpriteAssetName(1));
|
||||
}
|
||||
}
|
||||
|
||||
if(this._state === FloatingIdleZAddition.STATE_FRAME_A)
|
||||
{
|
||||
if((totalTimeRunning - this._startTime) >= FloatingIdleZAddition.DELAY_PER_FRAME)
|
||||
{
|
||||
this._state = FloatingIdleZAddition.STATE_FRAME_B;
|
||||
this._startTime = totalTimeRunning;
|
||||
this._asset = GetAssetManager().getTexture(this.getSpriteAssetName(2));
|
||||
}
|
||||
}
|
||||
|
||||
if(this._state === FloatingIdleZAddition.STATE_FRAME_B)
|
||||
{
|
||||
if((totalTimeRunning - this._startTime) >= FloatingIdleZAddition.DELAY_PER_FRAME)
|
||||
{
|
||||
this._state = FloatingIdleZAddition.STATE_FRAME_A;
|
||||
this._startTime = totalTimeRunning;
|
||||
this._asset = GetAssetManager().getTexture(this.getSpriteAssetName(1));
|
||||
}
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
sprite.alpha = 255;
|
||||
sprite.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.visible = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { AlphaTolerance, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetTexturePool } from '@nitrots/utils';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class GameClickTargetAddition implements IAvatarAddition
|
||||
{
|
||||
private static WIDTH: number = 46;
|
||||
private static HEIGHT: number = 60;
|
||||
private static OFFSET_X: number = -23;
|
||||
private static OFFSET_Y: number = -48;
|
||||
|
||||
private _asset: Texture = null;
|
||||
|
||||
constructor(
|
||||
private _id: number)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
if(this._asset)
|
||||
{
|
||||
GetTexturePool().putTexture(this._asset);
|
||||
|
||||
this._asset = null;
|
||||
}
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
if(!this._asset) this._asset = GetTexturePool().getTexture(GameClickTargetAddition.WIDTH, GameClickTargetAddition.HEIGHT);
|
||||
|
||||
sprite.visible = true;
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = GameClickTargetAddition.OFFSET_X;
|
||||
sprite.offsetY = GameClickTargetAddition.OFFSET_Y;
|
||||
sprite.alphaTolerance = AlphaTolerance.MATCH_ALL_PIXELS;
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { AvatarAction, AvatarGuideStatus, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class GuideStatusBubbleAddition implements IAvatarAddition
|
||||
{
|
||||
private _asset: Texture = null;
|
||||
private _relativeDepth: number = 0;
|
||||
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _visualization: AvatarVisualization,
|
||||
private _status: number)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
sprite.visible = true;
|
||||
sprite.relativeDepth = this._relativeDepth;
|
||||
sprite.alpha = 255;
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
this._asset = GetAssetManager().getTexture((this._status === AvatarGuideStatus.GUIDE) ? 'avatar_addition_user_guide_bubble' : 'avatar_addition_user_guide_requester_bubble');
|
||||
|
||||
if(scale < 48)
|
||||
{
|
||||
offsetX = -19;
|
||||
offsetY = -80;
|
||||
additionScale = 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
offsetX = -19;
|
||||
offsetY = -120;
|
||||
}
|
||||
|
||||
if(this._visualization.posture === AvatarAction.POSTURE_SIT)
|
||||
{
|
||||
offsetY += (additionScale / 2);
|
||||
}
|
||||
|
||||
else if(this._visualization.posture === AvatarAction.POSTURE_LAY)
|
||||
{
|
||||
offsetY += scale;
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = offsetY;
|
||||
sprite.relativeDepth = (-0.02 + 0);
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(this._asset && sprite)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get relativeDepth(): number
|
||||
{
|
||||
return this._relativeDepth;
|
||||
}
|
||||
|
||||
public set relativeDepth(depth: number)
|
||||
{
|
||||
this._relativeDepth = depth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { IRoomObjectSprite } from '@nitrots/api';
|
||||
|
||||
export interface IAvatarAddition
|
||||
{
|
||||
dispose(): void;
|
||||
update(sprite: IRoomObjectSprite, scale: number): void;
|
||||
animate(sprite: IRoomObjectSprite): boolean;
|
||||
id: number;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export interface IExpressionAddition extends IAvatarAddition
|
||||
{
|
||||
type: number;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { AvatarAction, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class MutedBubbleAddition implements IAvatarAddition
|
||||
{
|
||||
private _asset: Texture = null;
|
||||
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _visualization: AvatarVisualization)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
if(scale < 48)
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_muted_small');
|
||||
|
||||
additionScale = 32;
|
||||
offsetX = -12;
|
||||
offsetY = -66;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_muted');
|
||||
|
||||
offsetX = -15;
|
||||
offsetY = -110;
|
||||
}
|
||||
|
||||
if(this._visualization.posture === AvatarAction.POSTURE_SIT) offsetY += (additionScale / 2);
|
||||
else if(this._visualization.posture === AvatarAction.POSTURE_LAY) offsetY += scale;
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.visible = true;
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = offsetY;
|
||||
sprite.relativeDepth = -0.02;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(this._asset && sprite)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import { AvatarAction, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class NumberBubbleAddition implements IAvatarAddition
|
||||
{
|
||||
private _asset: Texture = null;
|
||||
private _scale: number = 0;
|
||||
private _numberValueFadeDirection: number = 0;
|
||||
private _numberValueMoving: boolean = false;
|
||||
private _numberValueMoveCounter: number = 0;
|
||||
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _number: number,
|
||||
private _visualization: AvatarVisualization)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
this._scale = scale;
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
if(this._number > 0)
|
||||
{
|
||||
if(scale < 48)
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_number_' + this._number + '_small');
|
||||
|
||||
additionScale = 32;
|
||||
offsetX = -6;
|
||||
offsetY = -52;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_number_' + this._number);
|
||||
|
||||
offsetX = -8;
|
||||
offsetY = -105;
|
||||
}
|
||||
|
||||
if(this._visualization.posture === AvatarAction.POSTURE_SIT)
|
||||
{
|
||||
offsetY += (additionScale / 2);
|
||||
}
|
||||
|
||||
else if(this._visualization.posture === AvatarAction.POSTURE_LAY)
|
||||
{
|
||||
offsetY += scale;
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.visible = true;
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = offsetY;
|
||||
sprite.relativeDepth = -0.01;
|
||||
sprite.alpha = 0;
|
||||
|
||||
this._numberValueFadeDirection = 1;
|
||||
this._numberValueMoving = true;
|
||||
this._numberValueMoveCounter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(sprite.visible) this._numberValueFadeDirection = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(!sprite) return false;
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
}
|
||||
|
||||
let alpha = sprite.alpha;
|
||||
let didAnimate = false;
|
||||
|
||||
if(this._numberValueMoving)
|
||||
{
|
||||
this._numberValueMoveCounter++;
|
||||
|
||||
if(this._numberValueMoveCounter < 10) return false;
|
||||
|
||||
if(this._numberValueFadeDirection < 0)
|
||||
{
|
||||
if(this._scale < 48)
|
||||
{
|
||||
sprite.offsetY -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.offsetY -= 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
let count = 4;
|
||||
|
||||
if(this._scale < 48) count = 8;
|
||||
|
||||
if(!(this._numberValueMoveCounter % count))
|
||||
{
|
||||
sprite.offsetY--;
|
||||
|
||||
didAnimate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this._numberValueFadeDirection > 0)
|
||||
{
|
||||
if(alpha < 255) alpha += 32;
|
||||
|
||||
if(alpha >= 255)
|
||||
{
|
||||
alpha = 255;
|
||||
|
||||
this._numberValueFadeDirection = 0;
|
||||
}
|
||||
|
||||
sprite.alpha = alpha;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this._numberValueFadeDirection < 0)
|
||||
{
|
||||
if(alpha >= 0) alpha -= 32;
|
||||
|
||||
if(alpha <= 0)
|
||||
{
|
||||
this._numberValueFadeDirection = 0;
|
||||
this._numberValueMoving = false;
|
||||
|
||||
alpha = 0;
|
||||
|
||||
sprite.visible = false;
|
||||
}
|
||||
|
||||
sprite.alpha = alpha;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return didAnimate;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { AvatarAction, IRoomObjectSprite } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { AvatarVisualization } from '../AvatarVisualization';
|
||||
import { IAvatarAddition } from './IAvatarAddition';
|
||||
|
||||
export class TypingBubbleAddition implements IAvatarAddition
|
||||
{
|
||||
private _asset: Texture = null;
|
||||
private _relativeDepth: number = 0;
|
||||
|
||||
constructor(
|
||||
private _id: number,
|
||||
private _visualization: AvatarVisualization)
|
||||
{}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._visualization = null;
|
||||
this._asset = null;
|
||||
}
|
||||
|
||||
public update(sprite: IRoomObjectSprite, scale: number): void
|
||||
{
|
||||
if(!sprite) return;
|
||||
|
||||
sprite.visible = true;
|
||||
sprite.relativeDepth = this._relativeDepth;
|
||||
sprite.alpha = 255;
|
||||
|
||||
let additionScale = 64;
|
||||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
if(scale < 48)
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_typing_small');
|
||||
|
||||
offsetX = 3;
|
||||
offsetY = -42;
|
||||
|
||||
additionScale = 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._asset = GetAssetManager().getTexture('avatar_addition_user_typing');
|
||||
|
||||
offsetX = 14;
|
||||
offsetY = -83;
|
||||
}
|
||||
|
||||
if(this._visualization.posture === AvatarAction.POSTURE_SIT)
|
||||
{
|
||||
offsetY += (additionScale / 2);
|
||||
}
|
||||
|
||||
else if(this._visualization.posture === AvatarAction.POSTURE_LAY)
|
||||
{
|
||||
offsetY += scale;
|
||||
}
|
||||
|
||||
if(this._asset)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
sprite.offsetX = offsetX;
|
||||
sprite.offsetY = offsetY;
|
||||
sprite.relativeDepth = (-0.02 + 0);
|
||||
}
|
||||
}
|
||||
|
||||
public animate(sprite: IRoomObjectSprite): boolean
|
||||
{
|
||||
if(this._asset && sprite)
|
||||
{
|
||||
sprite.texture = this._asset;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get relativeDepth(): number
|
||||
{
|
||||
return this._relativeDepth;
|
||||
}
|
||||
|
||||
public set relativeDepth(depth: number)
|
||||
{
|
||||
this._relativeDepth = depth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export * from './ExpressionAddition';
|
||||
export * from './ExpressionAdditionFactory';
|
||||
export * from './FloatingHeartAddition';
|
||||
export * from './FloatingIdleZAddition';
|
||||
export * from './GameClickTargetAddition';
|
||||
export * from './GuideStatusBubbleAddition';
|
||||
export * from './IAvatarAddition';
|
||||
export * from './IExpressionAddition';
|
||||
export * from './MutedBubbleAddition';
|
||||
export * from './NumberBubbleAddition';
|
||||
export * from './TypingBubbleAddition';
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './AvatarVisualization';
|
||||
export * from './AvatarVisualizationData';
|
||||
export * from './additions';
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user