Module:WeaponsData: Difference between revisions
From MENACE Official Wiki
joljaycups (talk | contribs) No edit summary |
joljaycups (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
--region Dependencies | --region Dependencies | ||
local JsonUtils = require("Module:JsonUtils") | local JsonUtils = require("Module:JsonUtils") | ||
--endregion | --endregion | ||
| Line 70: | Line 68: | ||
local function formatWeaponRow(weapon) | local function formatWeaponRow(weapon) | ||
local row = {} | local row = {} | ||
-- Add table row start | -- Add table row start | ||
table.insert(row, "|-") | table.insert(row, "|-") | ||
-- Name/Title with link | -- Name/Title with link | ||
table.insert(row, string.format("| [[%s]]", weapon.Title or "")) | table.insert(row, string.format("| [[%s]]", weapon.Title or "")) | ||
-- ShortName | -- ShortName | ||
table.insert(row, string.format("| %s", weapon.ShortName or "")) | table.insert(row, string.format("| %s", weapon.ShortName or "")) | ||
-- Range (using MaxRange) | -- Range (using MaxRange) | ||
table.insert(row, string.format("| %d", weapon.MaxRange or 0)) | table.insert(row, string.format("| %d", weapon.MaxRange or 0)) | ||
-- Damage | -- Damage | ||
table.insert(row, string.format("| %.1f", weapon.Damage or 0)) | table.insert(row, string.format("| %.1f", weapon.Damage or 0)) | ||
-- Armor Damage (DamageToArmorDurability) | -- Armor Damage (DamageToArmorDurability) | ||
table.insert(row, string.format("| %.1f", weapon.DamageToArmorDurability or 0)) | table.insert(row, string.format("| %.1f", weapon.DamageToArmorDurability or 0)) | ||
-- Armor Penetration | -- Armor Penetration | ||
table.insert(row, string.format("| %.1f", weapon.ArmorPenetration or 0)) | table.insert(row, string.format("| %.1f", weapon.ArmorPenetration or 0)) | ||
-- Suppression | -- Suppression | ||
table.insert(row, string.format("| %.1f", weapon.Suppression or 0)) | table.insert(row, string.format("| %.1f", weapon.Suppression or 0)) | ||
-- Trade Value | -- Trade Value | ||
table.insert(row, string.format("| %d", weapon.TradeValue or 0)) | table.insert(row, string.format("| %d", weapon.TradeValue or 0)) | ||
-- Accuracy Modifier (AccuracyBonus) | -- Accuracy Modifier (AccuracyBonus) | ||
table.insert(row, string.format("| %.1f", weapon.AccuracyBonus or 0)) | table.insert(row, string.format("| %.1f", weapon.AccuracyBonus or 0)) | ||
return table.concat(row, "\n") | return table.concat(row, "\n") | ||
end | end | ||
--endregion | |||
-- | --region Public methods | ||
-- | ---Returns a wiki table row for a weapon by Name field | ||
- | ---@param weaponName string The Name identifier of the weapon (e.g., "weapon.generic_assault_rifle_tier1_ARC_762") | ||
---@return string The formatted wiki table row | |||
--- | function WeaponsData.getWeaponRow(weaponName) | ||
---@return table | |||
function WeaponsData. | |||
loadData() | loadData() | ||
-- Find the weapon by Name | |||
for | for _, weapon in ipairs(weaponsData) do | ||
if weapon.Name == weaponName then | |||
return formatWeaponRow(weapon) | |||
end | |||
end | end | ||
return | |||
return "Weapon not found: " .. (weaponName or "nil") | |||
end | end | ||
--- | ---Returns a wiki table row for a weapon by Title field | ||
---@param weaponTitle string The Title of the weapon (e.g., "R14A2 ARC") | |||
--- | ---@return string The formatted wiki table row | ||
---@return string | function WeaponsData.getWeaponRowByTitle(weaponTitle) | ||
function WeaponsData. | loadData() | ||
-- Find the weapon by Title | |||
for _, weapon in ipairs(weaponsData) do | |||
if weapon.Title == weaponTitle then | |||
return formatWeaponRow(weapon) | |||
end | |||
end | |||
return "Weapon not found: " .. (weaponTitle or "nil") | |||
end | end | ||
---Returns a wiki table row for | ---Returns a wiki table row for the first weapon (for testing) | ||
---@return string The formatted wiki table row | ---@return string The formatted wiki table row | ||
function WeaponsData. | function WeaponsData.getFirstWeaponRow() | ||
loadData() | loadData() | ||
if #weaponsData > 0 then | |||
return formatWeaponRow(weaponsData[1]) | |||
end | |||
return "No weapons found in data" | |||
end | |||
-- | ---Returns a complete wiki table with all weapons | ||
---@return string The complete wiki table | |||
function WeaponsData.getAllWeaponsTable() | |||
loadData() | |||
local tableRows = {} | |||
-- Add table header | |||
table.insert(tableRows, '{| class="wikitable sortable"') | |||
table.insert(tableRows, '|-') | |||
table.insert(tableRows, '! Name !! Type !! Range !! Damage !! Armor Dmg !! Armor Pen !! Suppression !! Trade Value !! Accuracy') | |||
-- Add each weapon as a row | |||
for _, weapon in ipairs(weaponsData) do | for _, weapon in ipairs(weaponsData) do | ||
table.insert(tableRows, formatWeaponRow(weapon)) | |||
end | end | ||
return | -- Close table | ||
table.insert(tableRows, '|}') | |||
return table.concat(tableRows, "\n") | |||
end | end | ||
Revision as of 06:30, 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
weaponsData = JsonUtils.convertJSONToLuaTable(DATA_FILE)
end
end
--[[local function getTitle(NAME)
loadDate()
return SCHEMA.TITLE
end]]
---Formats a single weapon as a wiki table row
---@param weapon table The weapon data
---@return string The formatted table row
local function formatWeaponRow(weapon)
local row = {}
-- Add table row start
table.insert(row, "|-")
-- Name/Title with link
table.insert(row, string.format("| [[%s]]", weapon.Title or ""))
-- ShortName
table.insert(row, string.format("| %s", weapon.ShortName or ""))
-- Range (using MaxRange)
table.insert(row, string.format("| %d", weapon.MaxRange or 0))
-- Damage
table.insert(row, string.format("| %.1f", weapon.Damage or 0))
-- Armor Damage (DamageToArmorDurability)
table.insert(row, string.format("| %.1f", weapon.DamageToArmorDurability or 0))
-- Armor Penetration
table.insert(row, string.format("| %.1f", weapon.ArmorPenetration or 0))
-- Suppression
table.insert(row, string.format("| %.1f", weapon.Suppression or 0))
-- Trade Value
table.insert(row, string.format("| %d", weapon.TradeValue or 0))
-- Accuracy Modifier (AccuracyBonus)
table.insert(row, string.format("| %.1f", weapon.AccuracyBonus or 0))
return table.concat(row, "\n")
end
--endregion
--region Public methods
---Returns a wiki table row for a weapon by Name field
---@param weaponName string The Name identifier of the weapon (e.g., "weapon.generic_assault_rifle_tier1_ARC_762")
---@return string The formatted wiki table row
function WeaponsData.getWeaponRow(weaponName)
loadData()
-- Find the weapon by Name
for _, weapon in ipairs(weaponsData) do
if weapon.Name == weaponName then
return formatWeaponRow(weapon)
end
end
return "Weapon not found: " .. (weaponName or "nil")
end
---Returns a wiki table row for a weapon by Title field
---@param weaponTitle string The Title of the weapon (e.g., "R14A2 ARC")
---@return string The formatted wiki table row
function WeaponsData.getWeaponRowByTitle(weaponTitle)
loadData()
-- Find the weapon by Title
for _, weapon in ipairs(weaponsData) do
if weapon.Title == weaponTitle then
return formatWeaponRow(weapon)
end
end
return "Weapon not found: " .. (weaponTitle or "nil")
end
---Returns a wiki table row for the first weapon (for testing)
---@return string The formatted wiki table row
function WeaponsData.getFirstWeaponRow()
loadData()
if #weaponsData > 0 then
return formatWeaponRow(weaponsData[1])
end
return "No weapons found in data"
end
---Returns a complete wiki table with all weapons
---@return string The complete wiki table
function WeaponsData.getAllWeaponsTable()
loadData()
local tableRows = {}
-- Add table header
table.insert(tableRows, '{| class="wikitable sortable"')
table.insert(tableRows, '|-')
table.insert(tableRows, '! Name !! Type !! Range !! Damage !! Armor Dmg !! Armor Pen !! Suppression !! Trade Value !! Accuracy')
-- Add each weapon as a row
for _, weapon in ipairs(weaponsData) do
table.insert(tableRows, formatWeaponRow(weapon))
end
-- Close table
table.insert(tableRows, '|}')
return table.concat(tableRows, "\n")
end
--endregion
return WeaponsData


