Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
local heroes_data = mw.loadJsonData("Data: | 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 | ||
-- 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 | |||
-- | |||
-- Generic logic: Check top-level first, then Weapon, then AltFire | |||
local var_value = hero[stat_key_to_lookup] | |||
if var_value == nil and hero.Weapon then | |||
var_value = hero.Weapon[stat_key_to_lookup] | |||
end | |||
if var_value == nil and hero.Weapon and hero.Weapon.AltFire then | |||
var_value = hero.Weapon.AltFire[stat_key_to_lookup] | |||
end | end | ||