Module:HeroData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
initial test
 
Sur (talk | contribs)
m testing
Line 12: Line 12:
end
end


--{{#invoke:ItemData|get_cost|ITEM_NAME}}--
--{{#invoke:HeroData|get_hero_var|HERO_NAME}}--
p.get_cost = function(frame)
p.get_hero_var = function(frame)
local item_name = frame.args[1]
local hero_name = frame.args[1]
local item = get_json_item(item_name)
local hero = get_json_item(hero_name)
if(item == nil) then return "Item Not Found" end
if(hero == nil) then return "Hero Not Found" end
local cost = 0
local var_value = hero["BulletDamage"]
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
return var_value
end
end



Revision as of 23:00, 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}}

4.675


Using hero key

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

Hero Not Found


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

4.675


Round to 2 sig figs

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

4.675


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

4.675


Localize

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

4.675

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

	return var_value
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