Module:HeroData: Difference between revisionsGive feedback
m category data moved to attribute data; utils_module>util_module; attributes_module>attribute_module |
m temp save, unfinished write_infobox |
||
| Line 76: | Line 76: | ||
end | end | ||
--{{#invoke:HeroData| | --HERO_NAME in english | ||
p. | --{{#invoke:HeroData|write_infobox|HERO_NAME}}-- | ||
p.write_infobox = function(frame) | |||
-- Get hero data | |||
hero_name = frame.args[1] | hero_name = frame.args[1] | ||
hero_data = p.get_json_item(hero_name) | |||
if(hero_data == nil) then return "Hero Not Found" end | |||
-- Attributes to include in the infobox call | |||
local infobox_attributes = { | |||
Weapon = {"DPS", "ClipSize", "RoundsPerSecond", "ReloadTime"}, | |||
Vitality = {"MaxHealth", "BulletResist", "SpiritResist", "MoveSpeed"} | |||
} | |||
-- Declarations and initializations | |||
local category_data = attribute_module.get_category_data() | |||
local stats | |||
local stat_data | |||
local alternate_name | |||
local stat_value | |||
local label | |||
local postfix | |||
local templateArgs = {} | local templateArgs = {} | ||
for stat_name, stat_value in pairs( | -- Iterate attribute categories | ||
for _, category in ipairs(infobox_attributes) do | |||
stats = attributes_data[category] | |||
if (stats ~= nil) then -- Ensure the category is in the hero data | |||
-- Iterate attributes to be called by infobox | |||
for _, stat_name in ipairs(infobox_attributes[category]) do | |||
stat_data = stats[stat_name] | |||
alternate_name = stat_data["alternate_name"] | |||
-- gets the stat's value if its under either its alternate name or real name | |||
stat_value = hero_data[alternate_name] | |||
if (stat_value == nil) then | |||
stat_value = hero_data[stat_name] | |||
if (stat_value == nil) then | |||
stat_value = 0 --default to 0 if not present | |||
end | |||
end | |||
--Round value to 3 significant figures | |||
stat_value = util_module.round_to_sig_fig(stat_value, 3) | |||
-- get label and postfix | |||
label = util_module.call_lang(stat_data["label"]) | |||
postfix = stat_data["postfix"] | |||
if (postfix == nil) then | |||
postfix = "" | |||
else | |||
postfix = util_module.call_lang(postfix) | |||
end | |||
end | |||
end | |||
end | |||
for stat_name, stat_value in pairs(hero_data) do | |||
if (type(stat_value) ~= "table") then -- skips complex nested tables | if (type(stat_value) ~= "table") then -- skips complex nested tables | ||
templateArgs[stat_name] = stat_value | templateArgs[stat_name] = stat_value | ||