Module:TestModule: Difference between revisions

From MENACE Official Wiki
Khitrir (talk | contribs)
No edit summary
Khitrir (talk | contribs)
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
---
---
--- Extracts attributes of Weapons from Module:Data/Weapons.json
--- Extracts attributes of weapons from Module:Data/Weapons.json
---
---


Line 15: Line 15:


--region Private member variables
--region Private member variables
local TestModule
local weaponsData
--endregion
--endregion


--region Private methods
--region Private methods
local function loadData()
local function loadData()
     if not TestModule then
     if not weaponsData then
         TestModule = JsonUtils.convertJSONToLuaTable(DATA_FILE)
         weaponsData = JsonUtils.convertJSONToLuaTable(DATA_FILE)
     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 weaponProperty = frame.args[2]


     local weaponTitle = getTitleFromArgs(frame)
     if not weaponTitle or not weaponProperty then
        return "Error: One or more arguments missing"
    end


     for _, weapon in ipairs(TestModule) 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[weaponProperty] or "Error: Property of that name not found"
         end
         end
     end
     end
 
    return "Error: Weapon of that name not found"
end
end
--endregion


function TestModule.getNameByTitle(frame)
    return getPropertyByTitle(frame, "Name")
end


function TestModule.getPathIDByTitle(frame)
function TestModule.getSkillProperty(frame)
    return getPropertyByTitle(frame, "PathID")
    loadData()
end


function TestModule.getShortNameByTitle(frame)
    local weaponTitle = frame.args[1]
    return getPropertyByTitle(frame, "ShortName")
    local skillTitle = frame.args[2]
end
    local skillProperty = frame.args[3]


function TestModule.getDescriptionByTitle(frame)
    if not weaponTitle or not skillTitle or not skillProperty then
    return getPropertyByTitle(frame, "Description")
        return "Error: One or more arguments missing"
end  
    end


function TestModule.getIconByTitle(frame)
    for _, weapon in ipairs(weaponsData) do
    return getPropertyByTitle(frame, "Icon")
        if weapon.Title and string.lower(weapon.Title) == string.lower(weaponTitle) then
end
            for _, skill in ipairs(weapon.SkillsGranted or {}) do
 
                if skill.Title and string.lower(skill.Title) == string.lower(skillTitle) then
function TestModule.getTagsByTitle(frame)
                    return skill[skillProperty]
    return getPropertyByTitle(frame, "Tags")
                end
end
            end
 
            return "Error: Skill of that name not found"
function TestModule.getRarityByTitle(frame)
        end
    return getPropertyByTitle(frame, "Rarity")
    end
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, "Description")
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, "Description")
end  
 
function TestModule.getBlackMarketMaxQuantityByTitle(frame) 
    return getPropertyByTitle(frame, "BlackMarketMaxQuantity")
end  


    return "Error: Weapon of that name not found"
end


return TestModule
return TestModule

Latest revision as of 05:12, 4 May 2026

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 weaponProperty = frame.args[2]

    if not weaponTitle or not weaponProperty then
        return "Error: One or more arguments missing"
    end

    for _, weapon in ipairs(weaponsData) do
        if weapon.Title and string.lower(weapon.Title) == string.lower(weaponTitle) then
            return weapon[weaponProperty] or "Error: Property of that name not found"
        end
    end
   
    return "Error: Weapon of that name not found"
end


function TestModule.getSkillProperty(frame)
    loadData()

    local weaponTitle = frame.args[1]
    local skillTitle = frame.args[2]
    local skillProperty = frame.args[3]

    if not weaponTitle or not skillTitle or not skillProperty then
        return "Error: One or more arguments missing"
    end

    for _, weapon in ipairs(weaponsData) do
        if weapon.Title and string.lower(weapon.Title) == string.lower(weaponTitle) then
            for _, skill in ipairs(weapon.SkillsGranted or {}) do
                if skill.Title and string.lower(skill.Title) == string.lower(skillTitle) then
                    return skill[skillProperty]
                end
            end
            return "Error: Skill of that name not found"
        end
    end

    return "Error: Weapon of that name not found"
end

return TestModule