From 1da342462d012b105c0c147059ee8b17fa6b0ad1 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Tue, 3 Sep 2024 23:29:58 +0300 Subject: [PATCH] Revert "feat: refactor occupants to not use alt passengers map (#34)" (#37) This reverts commit a30695acd59f0b4852739968ae89bfbd501d3178. --- bindings/src/server/entities/Vehicle.js | 60 ++++++------------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/bindings/src/server/entities/Vehicle.js b/bindings/src/server/entities/Vehicle.js index b8d802e..47d0f49 100644 --- a/bindings/src/server/entities/Vehicle.js +++ b/bindings/src/server/entities/Vehicle.js @@ -1,7 +1,7 @@ import * as alt from 'alt-server'; import {SyncedMetaProxy} from '../../shared/meta.js'; import mp from '../../shared/mp.js'; -import {deg2rad, hashIfNeeded, altSeatToMp, rad2deg, TemporaryContainer} from '../../shared/utils.js'; +import {deg2rad, hashIfNeeded, mpSeatToAlt, rad2deg, TemporaryContainer} from '../../shared/utils.js'; import {_Entity} from './Entity.js'; import {ServerPool} from '../pools/ServerPool'; import {EntityGetterView} from '../../shared/pools/EntityGetterView'; @@ -254,13 +254,22 @@ export class _Vehicle extends _Entity { } getOccupant(id) { - return this.__occupantsMap?.get(id); + if (mpSeatToAlt(id) === 1) return this.alt.driver?.mp; + // TODO: implement in core + + return this.alt.passengers?.[mpSeatToAlt(id)]?.mp; } getOccupants() { - return this.__occupantsMap !== undefined - ? Array.from(this.__occupantsMap.values()) - : []; + // TODO: implement in core + const occupants = []; + const driver = this.alt.driver; + if (driver) occupants.push(driver.mp); + + const passengers = Object.values(this.alt.passengers); + if (passengers?.length) occupants.push(...passengers.map(p => p.mp)); + + return occupants; } // TODO: getPaint @@ -392,44 +401,3 @@ alt.on('vehicleSiren', (vehicle, player, state) => { alt.on('vehicleDestroy', (vehicle) => { mp.events.dispatchLocal('vehicleDeath', vehicle.mp); }); - -alt.on('playerEnteredVehicle', (player, vehicle, seat) => { - let occupants = vehicle.mp.__occupantsMap; - if (!occupants) { - occupants = new Map(); - vehicle.mp.__occupantsMap = occupants; - } - - occupants.set(altSeatToMp(seat), player); -}); - -alt.on('playerLeftVehicle', (player, vehicle, seat) => { - let occupants = vehicle.mp.__occupantsMap; - if (!occupants) { - occupants = new Map(); - vehicle.mp.__occupantsMap = occupants; - } - - occupants.forEach((p, s) => { - if (p === player) { - occupants.delete(s); - } - }); -}); - -alt.on('playerChangedVehicleSeat', (player, vehicle, oldSeat, newSeat) => { - let occupants = vehicle.mp.__occupantsMap; - if (!occupants) { - occupants = new Map(); - vehicle.mp.__occupantsMap = occupants; - } - - occupants.delete(altSeatToMp(oldSeat)); - occupants.set(altSeatToMp(newSeat), player); -}); - -alt.on('removeEntity', (entity) => { - if (entity instanceof alt.Vehicle) { - delete entity.mp.__occupantsMap; - } -});