2024-03-20 02:53:17 +01:00
|
|
|
import { IAssetData, RoomObjectVariable } from '@nitrots/api';
|
|
|
|
import { ObjectTileCursorUpdateMessage, RoomObjectUpdateMessage } from '../../messages';
|
|
|
|
import { RoomObjectLogicBase } from './RoomObjectLogicBase';
|
2021-03-17 03:02:09 +01:00
|
|
|
|
|
|
|
export class TileCursorLogic extends RoomObjectLogicBase
|
|
|
|
{
|
|
|
|
private static CURSOR_VISIBLE_STATE: number = 0;
|
2022-03-03 01:21:30 +01:00
|
|
|
private static CURSOR_HIDDEN_STATE: number = 1;
|
|
|
|
private static CURSOR_HEIGHT_STATE: number = 6;
|
2021-03-17 03:02:09 +01:00
|
|
|
|
|
|
|
private _lastEventId: string;
|
|
|
|
private _isHidden: boolean;
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2022-03-03 01:21:30 +01:00
|
|
|
this._lastEventId = null;
|
|
|
|
this._isHidden = false;
|
2021-03-17 03:02:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public initialize(data: IAssetData): void
|
|
|
|
{
|
2022-11-02 23:44:30 +01:00
|
|
|
if(!this.object) return;
|
2021-03-17 03:02:09 +01:00
|
|
|
|
|
|
|
this.object.model.setValue(RoomObjectVariable.FURNITURE_ALPHA_MULTIPLIER, 1);
|
|
|
|
|
|
|
|
this.object.setState(TileCursorLogic.CURSOR_HIDDEN_STATE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public processUpdateMessage(message: RoomObjectUpdateMessage): void
|
|
|
|
{
|
2022-11-02 23:44:30 +01:00
|
|
|
if(!(message instanceof ObjectTileCursorUpdateMessage)) return;
|
2021-03-17 03:02:09 +01:00
|
|
|
|
2022-11-02 23:44:30 +01:00
|
|
|
if(this._lastEventId && (this._lastEventId === message.sourceEventId)) return;
|
2021-03-17 03:02:09 +01:00
|
|
|
|
2022-11-02 23:44:30 +01:00
|
|
|
if(message.toggleVisibility) this._isHidden = !this._isHidden;
|
2021-03-17 03:02:09 +01:00
|
|
|
|
|
|
|
super.processUpdateMessage(message);
|
|
|
|
|
2022-11-02 23:44:30 +01:00
|
|
|
if(this.object)
|
2021-03-17 03:02:09 +01:00
|
|
|
{
|
2022-11-02 23:44:30 +01:00
|
|
|
if(this._isHidden)
|
2021-03-17 03:02:09 +01:00
|
|
|
{
|
|
|
|
this.object.setState(TileCursorLogic.CURSOR_HIDDEN_STATE, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-02 23:44:30 +01:00
|
|
|
if(!message.visible)
|
2021-03-17 03:02:09 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 22:05:04 +02:00
|
|
|
this._lastEventId = message.sourceEventId;
|
2021-03-17 03:02:09 +01:00
|
|
|
}
|
2021-06-12 22:05:04 +02:00
|
|
|
}
|