Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
joljaycups (talk | contribs) No edit summary |
joljaycups (talk | contribs) No edit summary |
||
| Line 10: | Line 10: | ||
--region Private constants | --region Private constants | ||
local DATA_FILE = " | local DATA_FILE = "Module:Data/Weapons.json" | ||
local SCHEMA = { | local SCHEMA = { | ||
Revision as of 09:12, 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


