|
|
| Line 24: |
Line 24: |
| end | | end |
| end | | end |
|
| |
|
| |
|
| local function getTitleFromArgs(frame) | | local function getTitleFromArgs(frame) |
| Line 33: |
Line 32: |
| end | | end |
| end | | end |
| | --endregion |
|
| |
|
| | function TestModule.get(frame) |
| | loadData() |
|
| |
|
| local function getPropertyByTitle(frame, property) | | local weaponTitle = frame.args[1] |
| loadData() | | local property = frame.args[2] |
|
| |
|
| local weaponTitle = getTitleFromArgs(frame) | | if not weaponTitle or not property then |
| | return "Error: missing arguments" |
| | end |
|
| |
|
| for _, weapon in ipairs(weaponsData) do | | for _, weapon in ipairs(weaponsData) do |
| if string.lower(weapon.Title) == string.lower(weaponTitle) then | | if weapon.Title and string.lower(weapon.Title) == string.lower(weaponTitle) then |
| return weapon[property] | | return weapon[property] or "Property not found" |
| end | | end |
| end | | end |
| | |
| | return "Weapon not found" |
| end | | end |
| --endregion
| |
|
| |
| function TestModule.getNameByTitle(frame)
| |
| return getPropertyByTitle(frame, "Name")
| |
| end
| |
|
| |
| function TestModule.getPathIDByTitle(frame)
| |
| return getPropertyByTitle(frame, "PathID")
| |
| end
| |
|
| |
| function TestModule.getShortNameByTitle(frame)
| |
| return getPropertyByTitle(frame, "ShortName")
| |
| end
| |
|
| |
| function TestModule.getDescriptionByTitle(frame)
| |
| return getPropertyByTitle(frame, "Description")
| |
| end
| |
|
| |
| function TestModule.getIconByTitle(frame)
| |
| return getPropertyByTitle(frame, "Icon")
| |
| end
| |
|
| |
| function TestModule.getTagsByTitle(frame)
| |
| return getPropertyByTitle(frame, "Tags")
| |
| end
| |
|
| |
| function TestModule.getRarityByTitle(frame)
| |
| return getPropertyByTitle(frame, "Rarity")
| |
| end
| |
|
| |
| function TestModule.getMinCampaignProgressByTitle(frame)
| |
| return getPropertyByTitle(frame, "MinCampaignProgress")
| |
| end
| |
|
| |
| function TestModule.getTradeValueByTitle(frame)
| |
| return getPropertyByTitle(frame, "TradeValue")
| |
| end
| |
|
| |
| function TestModule.getDeployCostsByTitle(frame)
| |
| return getPropertyByTitle(frame, "DeployCosts")
| |
| end
| |
|
| |
| function TestModule.getMinRangeByTitle(frame)
| |
| return getPropertyByTitle(frame, "MinRange")
| |
| end
| |
|
| |
| function TestModule.getIdealRangeByTitle(frame)
| |
| return getPropertyByTitle(frame, "IdealRange")
| |
| end
| |
|
| |
| function TestModule.getMaxRangeByTitle(frame)
| |
| return getPropertyByTitle(frame, "MaxRange")
| |
| end
| |
|
| |
| function TestModule.getAccuracyBonusByTitle(frame)
| |
| return getPropertyByTitle(frame, "AccuracyBonus")
| |
| end
| |
|
| |
| function TestModule.getAccuracyDropoffByTitle(frame)
| |
| return getPropertyByTitle(frame, "AccuracyDropoff")
| |
| end
| |
|
| |
| function TestModule.getDamageByTitle(frame)
| |
| return getPropertyByTitle(frame, "Damage")
| |
| end
| |
|
| |
| function TestModule.getDamageDropoffByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamageDropoff")
| |
| end
| |
|
| |
| function TestModule.getDamagePctCurrentHitpointsByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamagePctCurrentHitpoints")
| |
| end
| |
|
| |
| function TestModule.getDamagePctCurrentHitpointsMinByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamagePctCurrentHitpointsMin")
| |
| end
| |
|
| |
| function TestModule.getDamagePctMaxHitpointsByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamagePctMaxHitpoints")
| |
| end
| |
|
| |
| function TestModule.getDamagePctMaxHitpointsMinByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamagePctMaxHitpointsMin")
| |
| end
| |
|
| |
| function TestModule.getArmorPenetrationByTitle(frame)
| |
| return getPropertyByTitle(frame, "ArmorPenetration")
| |
| end
| |
|
| |
| function TestModule.getArmorPenetrationDropoffByTitle(frame)
| |
| return getPropertyByTitle(frame, "ArmorPenetrationDropoff")
| |
| end
| |
|
| |
| function TestModule.getDamageToArmorDurabilityByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamageToArmorDurability")
| |
| end
| |
|
| |
| function TestModule.getDamageToArmorDurabilityMultByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamageToArmorDurabilityMult")
| |
| end
| |
|
| |
| function TestModule.getDamageToArmorDurabilityDropoffByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamageToArmorDurabilityDropoff")
| |
| end
| |
|
| |
| function TestModule.getDamageToArmorDurabilityDropoffMultByTitle(frame)
| |
| return getPropertyByTitle(frame, "DamageToArmorDurabilityDropoffMult")
| |
| end
| |
|
| |
| function TestModule.getSuppressionByTitle(frame)
| |
| return getPropertyByTitle(frame, "Suppression")
| |
| end
| |
|
| |
| function TestModule.getBlackMarketMaxQuantityByTitle(frame)
| |
| return getPropertyByTitle(frame, "BlackMarketMaxQuantity")
| |
| end
| |
|
| |
|
| return TestModule | | return TestModule |
Documentation for this module may be created at Module:TestModule/doc
---
--- Extracts attributes of weapons from Module:Data/Weapons.json
---
---@module TestModule
local TestModule = {}
--region Dependencies
local JsonUtils = require("Module:JsonUtils")
--endregion
--region Private constants
local DATA_FILE = "Module:Data/Weapons.json"
--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 getTitleFromArgs(frame)
if frame.args then
return frame.args[1] or frame.args.title
else
return frame
end
end
--endregion
function TestModule.get(frame)
loadData()
local weaponTitle = frame.args[1]
local property = frame.args[2]
if not weaponTitle or not property then
return "Error: missing arguments"
end
for _, weapon in ipairs(weaponsData) do
if weapon.Title and string.lower(weapon.Title) == string.lower(weaponTitle) then
return weapon[property] or "Property not found"
end
end
return "Weapon not found"
end
return TestModule