Module:WeaponsData

From MENACE Official Wiki
Revision as of 07:02, 28 September 2025 by joljaycups (talk | contribs) (Created page with "---@class WeaponsData local WeaponsData = {} --region Dependencies local JsonUtils = require("Module:JsonUtils") --endregion --region Private constants local DATA_FILE = "Modules:Data/Weapons.json" local SCHEMA = { NAME = "name", TYPE = "type", VALUE = "value", RANGE = "range", ACCMOD = "accmod", HPDAMAGE = "hpdamage", APDAMAGE = "apdamage", APEN = "apen", SUPPRESS = "suppression", NUM_HITS = "numHits", ROF = "rof", C...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:WeaponsData/doc

---@class WeaponsData
local WeaponsData = {}

--region Dependencies

local JsonUtils = require("Module:JsonUtils")

--endregion

--region Private constants

local DATA_FILE = "Modules:Data/Weapons.json"

local SCHEMA = {
    NAME = "name",
    TYPE = "type",
    VALUE = "value",
    RANGE = "range",
    ACCMOD = "accmod",
    HPDAMAGE = "hpdamage",
    APDAMAGE = "apdamage",
    APEN = "apen",
    SUPPRESS = "suppression",
    NUM_HITS = "numHits",
    ROF = "rof",
    COST = "cost",
    DESCRIPTION = "description",
    IMAGE = "image"
}

--endregion

--region Private member variables

local weaponsData

--endregion

--region Private methods

local function loadData()
    if not weaponsData then
        local newData = JsonUtils.convertJSONToLuaTable(DATA_FILE)

        --Promote the name to be the key of the main data table
        weaponsData = {}
        for _, weapon in ipairs(newData) do
            weaponsData[weapon[SCHEMA.NAME]] = weapon
        end
    end
end