Module:HeroData
Also see:
- Module:HeroData/nav - For nav box purposes
- Module:HeroData/release - For determining the release status of a hero
Overview
This module provides functions to create hero infoboxes, statboxes, or retrieve hero information using the data uploaded to Data:HeroData.json.
Both will automatically be translated depending on the language selected. If called on
See Template:Lang for more
Functions
get_hero_var
Retrieve a hero variable's value, such as Abram's MaxHealth
Parameters
- hero_name - Name of the hero in english, or key of the hero. Preferred and recommended to use hero key, as its much more efficient. Search for the key in Data:HeroData.json
- hero_var - Key of the hero's variable, see Data:HeroData.json
- sig_figs_or_localize - OPTIONAL, # of sig figs to round to if retrieving a float, or "true" if its a string that should be localized. See Localizable values section.
Note: Recommended to use hero key where possible, i.e. hero_atlas as its O(1) time complexity instead of hero name (Abrams) which is O(N).
Examples
From wikitext:
Using hero name in english
{{#invoke:HeroData|get_hero_var|Abrams|MaxHealth}}
Script error: The function "get_hero_var" does not exist.
Using hero key
{{#invoke:HeroData|get_hero_var|hero_atlas|MaxHealth}}
Script error: The function "get_hero_var" does not exist.
{{#invoke:HeroData|get_hero_var|Abrams|FalloffStartRange}}
Script error: The function "get_hero_var" does not exist.
Round to 2 sig figs
{{#invoke:HeroData|get_hero_var|Abrams|FalloffStartRange|2}}
Script error: The function "get_hero_var" does not exist.
{{#invoke:HeroData|get_hero_var|Abrams|WeaponName}}
Script error: The function "get_hero_var" does not exist.
Localize
{{#invoke:HeroData|get_hero_var|Abrams|WeaponName|true}}
Script error: The function "get_hero_var" does not exist.
Notes
Only usable on variables that are integers, strings, or floats (meaning not dictionaries/hashes or arrays/lists).
If using sig_figs parameter, ensure the value is a float.
If using localize parameter, ensure the value is a string. See Data:HeroData.json, you will notice that hero_astro's "Lore" variable has the value "hero_astro_lore". This key is then sent to Module:Lang which checks for it in Data:Lang_en.json (or a different language).
get_list_elem
Retrieve a specified element from a list
Parameters
- hero_name - Name of the hero in english, or hero key. Preferred and recommended to use hero key, as its much more efficient. Search for the key in Data:HeroData.json
- hero_var - Key of the hero's variable, see Data:HeroData.json
- number - Index to retrieve from the list. 1 for 1st element, 2 for 2nd element, etc.
- localize - OPTIONAL - "true" if its a string that should be localized. See Localizable values section.
Example
From wikitext:
Using hero name in english
{{#invoke:HeroData|get_list_elem|Abrams|WeaponTypes|2}}
Script error: The function "get_list_elem" does not exist.
Using hero key
{{#invoke:HeroData|get_list_elem|hero_atlas|WeaponTypes|2}}
Script error: The function "get_list_elem" does not exist.
{{#invoke:HeroData|get_list_elem|Abrams|WeaponTypes|2|true}}
Script error: The function "get_list_elem" does not exist.
write_infobox
Writes a Template:Infobox_hero template call for a given hero
Parameters
- hero_name – Name of the hero, in english
Example
From wikitext:
{{#invoke:HeroData|write_infobox|HERO_NAME}}
Which outputs Script error: The function "write_infobox" does not exist.
write_stat_infoboxes
Writes all 3 Template:Infobox_stat template calls (Weapon, Vitality, Spirit) for a given hero
Parameters
- hero_name – Name of the hero, in english
Example
From wikitext:
{{#invoke:HeroData|write_stat_infoboxes|HERO_NAME}}
Which outputs Script error: The function "write_stat_infoboxes" does not exist.
write_hero_comparison_table
Writes the Hero Comparison table for a specific Level and Spirit Power
Parameters
- level - Number of Levels / Power Increases
- spirit_power - Amount of Spirit power
Both parameters are optional, as if both are 0 or not provided, the outputted table will be at base and will also include the level/SS scaling in each cell along with the base value, rather than the scaled value.
Example
From wikitext:
{{#invoke:HeroData|write_hero_comparison_table|LEVEL|SPIRITPOWER}}
Which outputs Script error: The function "write_hero_comparison_table" does not exist.
Localizable values
Localizable values as of writing this:
- Lore
- Playstyle
- Role
- WeaponDescription
- WeaponName
- elements in WeaponTypes
- elements in RecommendedItems
local p = {};
local data = mw.loadJsonData("Data:HeroData.json")
-- returns the table of a specific item
function get_json_item(name)
for i,v in pairs(data) do
if (v["Name"] == name) then
return v
end
end
return nil
end
--{{#invoke:ItemData|get_cost|ITEM_NAME}}--
p.get_cost = function(frame)
local item_name = frame.args[1]
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
local cost = 0
local cur_item = item
repeat
cost = cost + cur_item["Cost"]
if(cur_item["Components"] == nil) then
break
end
cur_item = data[cur_item["Components"][1]]
until cur_item == nil
return cost
end
--{{#invoke:ItemData|get_type|ITEM_NAME}}--
p.get_type = function(frame)
local item_name = frame.args[1]
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if (item["Slot"] == "Weapon") then
return "Weapon"
elseif (item["Slot"] == "Armor") then
return "Vitality"
elseif (item["Slot"] == "Tech") then
return "Spirit"
else
return nil
end
end
--{{#invoke:ItemData|is_active|ITEM_NAME}}--
p.is_active = function(frame)
local item_name = frame.args[1]
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if (item["Activation"] == "Passive") then
return false
else
return true
end
end
--{{#invoke:ItemData|get_prop|ITEM_NAME|PROPERTY}}--
--check Data:ItemData.json for properties
p.get_prop = function(frame)
local item_name = frame.args[1]
local property = frame.args[2]
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
return item[property]
end
return p