Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
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..." |
joljaycups (talk | contribs) No edit summary |
||
| Line 49: | Line 49: | ||
end | end | ||
end | end | ||
end | |||
--region Public Methods | |||
---@public | |||
---gets and array of all weapons | |||
--- | |||
---@return table of weapons | |||
function WeaponsData.getAllWeapons() | |||
loadData() | |||
local weapons = {} | |||
for name, _ in pairs(weaponsData) do | |||
table.insert(weapons, name) | |||
end | |||
return weapons | |||
end | end | ||
Revision as of 07:07, 28 September 2025
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
--region Public Methods
---@public
---gets and array of all weapons
---
---@return table of weapons
function WeaponsData.getAllWeapons()
loadData()
local weapons = {}
for name, _ in pairs(weaponsData) do
table.insert(weapons, name)
end
return weapons
end


