Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
joljaycups (talk | contribs) No edit summary |
joljaycups (talk | contribs) No edit summary |
||
| Line 63: | Line 63: | ||
--endregion | --endregion | ||
--region Public Methods | --region Public Methods | ||
---@public | ---@public | ||
| Line 69: | Line 70: | ||
---@return table of weapons | ---@return table of weapons | ||
function WeaponsData.getAllWeapons() | function WeaponsData.getAllWeapons() | ||
loadData() | loadData() | ||
| Line 78: | Line 78: | ||
return weaponNames | return weaponNames | ||
end | end | ||
--endregion | |||
Revision as of 09:19, 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 = "Module: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
local function getWeaponFieldByName(weaponName, fieldName)
loadData()
local weapon = weaponsData[weaponName]
if not weapon then
return nil
else
return weapon[fieldName]
end
end
--endregion
--region Public Methods
---@public
---gets and array of all weapons
---
---@return table of weapons
function WeaponsData.getAllWeapons()
loadData()
local weaponNames = {}
for name, _ in pairs(weaponsData) do
table.insert(weaponNames, name)
end
return weaponNames
end
--endregion


