UNPKG

rock-mod

Version:

Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.

54 lines (53 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RageBaseObjectsManager = void 0; const RageBaseObjectsIterator_1 = require("./RageBaseObjectsIterator"); const RockMod_1 = require("../../../RockMod"); const types_1 = require("../../../net/common/events/types"); class RageBaseObjectsManager { _baseObjects; _baseObjectsType; _iterator; get baseObjects() { return this._baseObjects; } get iterator() { return this._iterator; } constructor(options) { this._baseObjects = new Map(); this._baseObjectsType = options.baseObjectsType; this._iterator = new RageBaseObjectsIterator_1.RageBaseObjectsIterator(this._baseObjects); mp.events.add("entityDestroyed", (mpEntity) => { if (mpEntity.type === this._baseObjectsType) { const baseObject = this.getByID(mpEntity.id); this.unregisterBaseObject(baseObject); } }); } getByID(id) { const baseObject = this.findByID(id); if (!baseObject) { throw new Error(`BaseObject [${this._baseObjectsType}] with id ${id} not found`); } return baseObject; } findByID(id) { const baseObject = this._baseObjects.get(id); return baseObject ?? null; } registerBaseObject(baseObject) { if (this._baseObjects.has(baseObject.id)) { throw new Error(`BaseObject [${this._baseObjectsType}] with id ${baseObject.id} already exists`); } this._baseObjects.set(baseObject.id, baseObject); RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.EntityCreated, baseObject); } unregisterBaseObject(baseObject) { if (!this._baseObjects.delete(baseObject.id)) { throw new Error(`BaseObject [${this._baseObjectsType}] with id ${baseObject.id} not found`); } RockMod_1.RockMod.instance.net.events.emitInternal(types_1.ServerInternalEventName.EntityCreated, baseObject); } } exports.RageBaseObjectsManager = RageBaseObjectsManager;