nitro-renderer/src/room/object/RoomObjectModel.ts

54 lines
987 B
TypeScript
Raw Normal View History

2022-10-30 07:08:37 +01:00
import { IRoomObjectModel } from '../../api';
2021-03-17 03:02:09 +01:00
export class RoomObjectModel implements IRoomObjectModel
{
private _map: Map<string, unknown>;
private _updateCounter: number;
constructor()
{
2022-03-03 01:21:30 +01:00
this._map = new Map();
2021-03-17 03:02:09 +01:00
this._updateCounter = 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
{
2022-10-30 07:08:37 +01:00
if (this._map.has(key))
2021-11-07 08:02:41 +01:00
{
2022-10-30 07:08:37 +01:00
if (this._map.get(key) === value) return;
2021-11-07 08:02:41 +01:00
}
2021-03-17 03:02:09 +01:00
this._map.set(key, (value as T));
this._updateCounter++;
}
public removeKey(key: string): void
{
2022-10-30 07:08:37 +01:00
if (!key) return;
2021-03-17 03:02:09 +01:00
this._map.delete(key);
this._updateCounter++;
}
public get updateCounter(): number
{
return this._updateCounter;
}
2021-11-07 08:02:41 +01:00
}