Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
joljaycups (talk | contribs) No edit summary |
joljaycups (talk | contribs) No edit summary |
||
| Line 99: | Line 99: | ||
--endregion | --endregion | ||
return WeaponsData | |||
Revision as of 05:40, 3 October 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",
SHORTNAME = "ShortName",
DESCRIPTION = "Description",
ICON = "Icon",
TAGS = "Tags",
RARITY = "Rarity",
TRADEVALUE = "TradeValue",
APEN = "IconEquipment",
SUPPRESS = "IconSkillBar",
NUM_HITS = "DeployCosts",
ROF = "SkillsGranted",
COST = "MinRange",
IDEALRANGE = "IdealRange",
IMAGE = "MaxRange",
ACCURACYBONUS = "AccuracyBonus",
ACCURACYDROPOFF = "AccuracyDropoff",
DAMAGE = "Damage",
DAMAGEDROPOFF = "DamageDropoff",
DAMAGEPCTCURRENTHITPOINTS = "DamagePctCurrentHitpoints",
DAMAGEPCTCURRENTHITPOINTSMIN = "DamagePctCurrentHitpointsMin",
DAMAGEPCTMAXHITPOINTS = "DamagePctMaxHitpoints",
DAMAGEPCTMAXHITPOINTSMIN = "DamagePctMaxHitpointsMin",
ARMORPENETRATION = "ArmorPenetration",
ARMORPENETRATIONDROPOFF = "ArmorPenetrationDropoff",
DAMAGETOARMORDURABILITY = "DamageToArmorDurability",
DAMAGETOARMORDURABILITYMULT = "DamageToArmorDurabilityMult",
DAMAGETOARMORDURABILITY_DROPOFF = "DamageToArmorDurabilityDropoff",
DAMAGETOARMORDURABILITYDROPOFFMULT = "DamageToArmorDurabilityDropoffMult",
SUPPRESSION = "Suppression"
}
--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 getTitle(NAME)
loadDate()
return SCHEMA.TITLE
end
--endregion
--region Public Methods
---@public
---gets a table 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
---@public
---prints a row of the table given a name
---
---@return string of table row
function WeaponsData.printRow(weapon)
local weaponsTable = WeaponsData.getAllWeapons()
local tableRow = weaponsTable[weapon[SCHEMA.TITLE]] + "|" + weaponsTable[weapon[SCHEMA.SHORTNAME]] + "|" + weaponsTable[weapon[SCHEMA.DAMAGE]] + "|" + weaponsTable[weapon[SCHEMA.TRADEVALUE]]
return tableRow
end
--endregion
return WeaponsData


