Module:HeroData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m get_hero_var now actually requires stat_name param
Sur (talk | contribs)
m removed unused functions
Line 25: Line 25:
end
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
return p

Revision as of 23:04, 9 September 2024

Module documentation [edit] [purge]

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

  • Page - translates to english
  • Page/en - translates to english
  • Page/es - translates to spanish

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}}

570


Using hero key

{{#invoke:HeroData|get_hero_var|hero_atlas|MaxHealth}}

Hero Not Found


{{#invoke:HeroData|get_hero_var|Abrams|FalloffStartRange}}

20.0000108


Round to 2 sig figs

{{#invoke:HeroData|get_hero_var|Abrams|FalloffStartRange|2}}

20.0000108


{{#invoke:HeroData|get_hero_var|Abrams|WeaponName}}

citadel_weapon_hero_atlas_set


Localize

{{#invoke:HeroData|get_hero_var|Abrams|WeaponName|true}}

citadel_weapon_hero_atlas_set

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:HeroData|get_hero_var|HERO_NAME|STAT_NAME}}--
p.get_hero_var = function(frame)
	local hero_name = frame.args[1]
	local hero_stat_key = frame.args[2]
	
	local hero = get_json_item(hero_name)
	if(hero == nil) then return "Hero Not Found" end
	
	local var_value = hero[hero_stat_key]

	return var_value
end



return p