Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 1: Line 1:
local p = {};
local p = {};
local heroes_data = mw.loadJsonData("Data:Sandbox.json")
local heroes_data = mw.loadJsonData("Data:HeroData.json")
local attributes_data = mw.loadJsonData("Data:AttributeData.json")
local attributes_data = mw.loadJsonData("Data:AttributeData.json")
local attribute_orders = mw.loadJsonData("Data:StatInfoboxOrder.json")
local attribute_orders = mw.loadJsonData("Data:StatInfoboxOrder.json")
Line 7: Line 7:
local dictionary_module = require('Module:Dictionary')
local dictionary_module = require('Module:Dictionary')
local attribute_module = require('Module:AttributeData')
local attribute_module = require('Module:AttributeData')
-- Maps template-facing stat names to their actual keys in the JSON data.
-- This is primarily used for keys that hold localization strings (e.g., "citadel_weapon_hero_wraith_set_desc")
-- rather than direct display values.
local TEMPLATE_KEY_MAP = {
    WeaponName = "NameKey",
    WeaponDescription = "DescKey"
}


-- returns the table of a specific item, used by external modules
-- returns the table of a specific item, used by external modules
Line 54: Line 62:
     if(hero == nil) then return "Hero Not Found" end
     if(hero == nil) then return "Hero Not Found" end
      
      
    local var_value
     -- Use the map to find the real data key, or default to the key provided by the template.
 
     local stat_key_to_lookup = TEMPLATE_KEY_MAP[hero_stat_key] or hero_stat_key
     -- Special handling for WeaponName and WeaponDescription which use different keys in the JSON data
      
     if hero_stat_key == "WeaponName" then
     -- Generic logic: Check top-level first, then Weapon, then AltFire
        if hero.Weapon and hero.Weapon.NameKey then
    local var_value = hero[stat_key_to_lookup]
            var_value = hero.Weapon.NameKey
    if var_value == nil and hero.Weapon then
        end
        var_value = hero.Weapon[stat_key_to_lookup]
     elseif hero_stat_key == "WeaponDescription" then
    end
        if hero.Weapon and hero.Weapon.DescKey then
    if var_value == nil and hero.Weapon and hero.Weapon.AltFire then
            var_value = hero.Weapon.DescKey
        var_value = hero.Weapon.AltFire[stat_key_to_lookup]
        end
     else
        -- Default logic for other stats
        -- Check top-level first, then Weapon, then AltFire
        var_value = hero[hero_stat_key]
        if var_value == nil and hero.Weapon then
            var_value = hero.Weapon[hero_stat_key]
        end
        if var_value == nil and hero.Weapon and hero.Weapon.AltFire then
            var_value = hero.Weapon.AltFire[hero_stat_key]
        end
     end
     end