diff --git a/shared/js/enums/audioCategories.js b/shared/js/enums/audioCategories.js index 919bf8815..18af2930b 100644 --- a/shared/js/enums/audioCategories.js +++ b/shared/js/enums/audioCategories.js @@ -1,4 +1,7 @@ -alt.Enums.AudioCategories = Object.freeze({ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + +alt.Enums.AudioCategories = createReverseLookupObject({ X44E21C90: "0x44E21C90", XBAD598C7: "0xBAD598C7", XA4D158B0: "0xA4D158B0", diff --git a/shared/js/enums/baseObjectFilterType.js b/shared/js/enums/baseObjectFilterType.js index 9342d2284..7d6b07fb0 100644 --- a/shared/js/enums/baseObjectFilterType.js +++ b/shared/js/enums/baseObjectFilterType.js @@ -1,4 +1,7 @@ -alt.Enums.BaseObjectFilterType = Object.freeze({ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + +alt.Enums.BaseObjectFilterType = createReverseLookupObject({ PLAYER: 1, VEHICLE: 2, PED: 4, diff --git a/shared/js/enums/blipColor.js b/shared/js/enums/blipColor.js index 67a736459..aa9a7e8e3 100644 --- a/shared/js/enums/blipColor.js +++ b/shared/js/enums/blipColor.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.BlipColor = Object.freeze({ +alt.Enums.BlipColor = createReverseLookupObject({ WHITE: 0, RED: 1, GREEN: 2, diff --git a/shared/js/enums/blipSprite.js b/shared/js/enums/blipSprite.js index 673df3293..606483fb7 100644 --- a/shared/js/enums/blipSprite.js +++ b/shared/js/enums/blipSprite.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.BlipSprite = Object.freeze({ +alt.Enums.BlipSprite = createReverseLookupObject({ HIGHER: 0, LOWER: 1, POLICE_PED: 2, diff --git a/shared/js/enums/configflag.js b/shared/js/enums/configflag.js index 73713b931..d75c21283 100644 --- a/shared/js/enums/configflag.js +++ b/shared/js/enums/configflag.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.ConfigFlag = Object.freeze({ +alt.Enums.ConfigFlag = createReverseLookupObject({ DISABLE_AUTO_WEAPON_SWAP: "DISABLE_AUTO_WEAPON_SWAP", DISABLE_PED_PROP_KNOCK_OFF: "DISABLE_PED_PROP_KNOCK_OFF", DISABLE_IDLE_CAMERA: "DISABLE_IDLE_CAMERA", diff --git a/shared/js/enums/fileEncoding.js b/shared/js/enums/fileEncoding.js index a295d4193..ad9fb00df 100644 --- a/shared/js/enums/fileEncoding.js +++ b/shared/js/enums/fileEncoding.js @@ -1,4 +1,7 @@ -alt.Enums.FileEncoding = Object.freeze({ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + +alt.Enums.FileEncoding = createReverseLookupObject({ UTF8: "utf-8", UTF16: "utf-16", BINARY: "binary" diff --git a/shared/js/enums/gameFont.js b/shared/js/enums/gameFont.js index 34d3ea581..f521d04c3 100644 --- a/shared/js/enums/gameFont.js +++ b/shared/js/enums/gameFont.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.GameFont = Object.freeze({ +alt.Enums.GameFont = createReverseLookupObject({ CHALET_LONDON: 0, HOUSE_SCRIPT: 1, MONOSPACE: 2, diff --git a/shared/js/enums/keycode.js b/shared/js/enums/keycode.js index 3d013db8e..ea784692f 100644 --- a/shared/js/enums/keycode.js +++ b/shared/js/enums/keycode.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.KeyCode = Object.freeze({ +alt.Enums.KeyCode = createReverseLookupObject({ "KEY0": 48, "KEY1": 49, "KEY2": 50, diff --git a/shared/js/enums/locale.js b/shared/js/enums/locale.js index be4a9616d..1137b5825 100644 --- a/shared/js/enums/locale.js +++ b/shared/js/enums/locale.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.Locale = Object.freeze({ +alt.Enums.Locale = createReverseLookupObject({ ARABIC: "ar", BELARUSIAN: "by", CZECH: "cz", diff --git a/shared/js/enums/pedConfigFlag.js b/shared/js/enums/pedConfigFlag.js index e629ed437..5e461c8d7 100644 --- a/shared/js/enums/pedConfigFlag.js +++ b/shared/js/enums/pedConfigFlag.js @@ -1,4 +1,7 @@ -alt.Enums.PedConfigFlag = Object.freeze({ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + +alt.Enums.PedConfigFlag = createReverseLookupObject({ NO_CRITICAL_HITS: 2, DROWNS_IN_WATER: 3, DISABLE_RETICULE_FIXED_LOCKON: 4, diff --git a/shared/js/enums/radioStation.js b/shared/js/enums/radioStation.js index 8c1088420..5420a2d34 100644 --- a/shared/js/enums/radioStation.js +++ b/shared/js/enums/radioStation.js @@ -1,4 +1,7 @@ -alt.Enums.RadioStation = Object.freeze({ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + +alt.Enums.RadioStation = createReverseLookupObject({ LOS_SANTOS_ROCK_RADIO: 0, NON_STOP_POP_FM: 1, RADIO_LOS_SANTOS: 2, diff --git a/shared/js/enums/statName.js b/shared/js/enums/statName.js index 3efc99eba..631fcee79 100644 --- a/shared/js/enums/statName.js +++ b/shared/js/enums/statName.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.StatName = Object.freeze({ +alt.Enums.StatName = createReverseLookupObject({ STAMINA: "stamina", STRENGTH: "strength", LUNG_CAPACITY: "lung_capacity", diff --git a/shared/js/enums/taskTypeIndex.js b/shared/js/enums/taskTypeIndex.js index ca3704965..e9ef04bec 100644 --- a/shared/js/enums/taskTypeIndex.js +++ b/shared/js/enums/taskTypeIndex.js @@ -1,9 +1,12 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // WARNING: values can change after a game update // if R* adds in the middle! // This is up-to-date for b2372 // When changing, update types/client/index.d.ts aswell -alt.Enums.TaskTypeIndex = Object.freeze({ +alt.Enums.TaskTypeIndex = createReverseLookupObject({ HANDS_UP: 0, CLIMB_LADDER: 1, EXIT_VEHICLE: 2, diff --git a/shared/js/enums/vehicleDoorState.js b/shared/js/enums/vehicleDoorState.js index a79c37d98..88ec12cb3 100644 --- a/shared/js/enums/vehicleDoorState.js +++ b/shared/js/enums/vehicleDoorState.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.VehicleDoorState = Object.freeze({ +alt.Enums.VehicleDoorState = createReverseLookupObject({ CLOSED: 0, OPENED_LEVEL_1: 1, OPENED_LEVEL_2: 2, diff --git a/shared/js/enums/vehicleIndicatorLights.js b/shared/js/enums/vehicleIndicatorLights.js index 3bd323d1b..a35e0c121 100644 --- a/shared/js/enums/vehicleIndicatorLights.js +++ b/shared/js/enums/vehicleIndicatorLights.js @@ -1,5 +1,8 @@ +/** @type {typeof import("../helpers/enums.js")} */ +const { createReverseLookupObject } = requireBinding("shared/helpers/enums.js"); + // When changing, update types/shared/index.d.ts aswell -alt.Enums.VehicleIndicatorLights = Object.freeze({ +alt.Enums.VehicleIndicatorLights = createReverseLookupObject({ NONE: 0, BLINK_LEFT: 1, BLINK_RIGHT: 2, diff --git a/shared/js/helpers/enums.js b/shared/js/helpers/enums.js index 4d5ecc240..d969c7ac6 100644 --- a/shared/js/helpers/enums.js +++ b/shared/js/helpers/enums.js @@ -10,3 +10,18 @@ export function createNumericEnum(values) { return Object.freeze(temp); } + +/** + * + * @param {Object} obj + */ +export function createReverseLookupObject(obj) { + const newObj = {}; + + for (const key in obj) { + newObj[obj[key]] = key; + newObj[key] = obj[key]; + } + + return Object.freeze(newObj); +} diff --git a/shared/src/helpers/Template.h b/shared/src/helpers/Template.h index af97b55ff..08b674ba3 100644 --- a/shared/src/helpers/Template.h +++ b/shared/src/helpers/Template.h @@ -204,6 +204,7 @@ namespace js for(auto& [value, key] : values) { obj.Set(key.data(), (int)value); + obj.Set((std::string_view)std::to_string((int)value), key.data()); } ctx.Return(obj); } @@ -217,6 +218,7 @@ namespace js { auto& entry = values[i]; obj.Set(entry.second.data(), (int)entry.first); + obj.Set((std::string_view)std::to_string((int)entry.first), entry.second.data()); } ctx.Return(obj); }