Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
mNo edit summary |
joljaycups (talk | contribs) No edit summary |
||
| Line 13: | Line 13: | ||
local SCHEMA = { | local SCHEMA = { | ||
NAME = " | NAME = "Name", | ||
SHORTNAME = "ShortName", | |||
DESCRIPTION = "Description", | |||
ICON = "Icon", | |||
TAGS = "Tags", | |||
RARITY = "Rarity", | |||
TRADEVALUE = "TradeValue", | |||
APEN = " | APEN = "IconEquipment", | ||
SUPPRESS = " | SUPPRESS = "IconSkillBar", | ||
NUM_HITS = " | NUM_HITS = "DeployCosts", | ||
ROF = " | ROF = "SkillsGranted", | ||
COST = " | COST = "MinRange", | ||
IDEALRANGE = "IdealRange", | |||
IMAGE = " | 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" | |||
} | } | ||
| Line 51: | Line 66: | ||
end | end | ||
local function | local function getTitle(NAME) | ||
loadDate() | |||
return SCHEMA.TITLE | |||
end | end | ||
| Line 66: | Line 75: | ||
--region Public Methods | --region Public Methods | ||
---@public | ---@public | ||
---gets | ---gets a table of all weapons | ||
--- | --- | ||
---@return table of weapons | ---@return table of weapons | ||
| Line 77: | Line 86: | ||
end | end | ||
return weaponNames | 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 | end | ||
--endregion | --endregion | ||
Revision as of 05:36, 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


