Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:HeroData: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m fix outdated use of PageRef for write_default_items()
Sur (talk | contribs)
m use {{PI}} instead of {{Ls}} for level scaling
 
(4 intermediate revisions by 2 users not shown)
Line 139: Line 139:


--If the hero scales with the stat, it returns {{Ss|value}} or {{Ls|value}}, else blank string
--If the hero scales with the stat, it returns {{Ss|value}} or {{Ls|value}}, else blank string
--{{#invoke:HeroData|get_hero_scalar_str_invoke|HERO_NAME|STAT_NAME}}--
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SCALING_TYPE|STAT_NAME}}--
p.get_hero_scalar_str_invoke = function(frame)
p.get_hero_scalar = function(frame)
local hero_name = frame.args[1]
local hero_key = frame.args[1]
local hero_stat_key = frame.args[2]
local scaling_type = frame.args[2]
local hero_data = p.get_json_item(hero_name)
local hero_stat_key = frame.args[3]
if(hero_data == nil) then return "Hero Not Found" end
return p.get_hero_scalar_str(hero_data, hero_stat_key) --surely theres a better way
local hero_data = heroes_data[hero_key]
if(hero_data == nil) then return "Hero " .. hero_key .. " not found." end
local scaling_data = hero_data[scaling_type .. "Scaling"]
if scaling_data == nil then return scaling_type .. "Scaling data not found for hero" .. hero_key end
local scaling_value = scaling_data[hero_stat_key]
if scaling_value == nil then return scaling_type .. "Scaling data does not have key " .. hero_stat_key .. " for hero " .. hero_key end
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
return scaling_str
end
end


-- Retrieve scaling string of a hero's given stat, if it has scaling, else return blank
-- Retrieve scaling string of a hero's given stat, if it has scaling, else return blank
-- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}}
-- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}}
function p.get_hero_scalar_str(scaling_value, scaling_type)
function p.write_scalar_str(scaling_value, scaling_type)
local scaling_abbrevs = {Spirit = "Ss", Level = "Ls"}
local scaling_abbrevs = {Spirit = "Ss", Level = "PI"}
-- Return blank if it doesnt scale
-- Return blank if it doesnt scale
Line 170: Line 181:


-- Retrieve scaling value and type of a hero's given stat, if it has scaling, else return 0
-- Retrieve scaling value and type of a hero's given stat, if it has scaling, else return 0
function p.get_hero_scalar(hero_data, hero_stat_key)
function p.get_hero_scaling_data(hero_data, hero_stat_key)
local scaling_type_full
local scaling_type_full
local scaling_data
local scaling_data
Line 381: Line 392:
-- Add the scaling str if it scales
-- Add the scaling str if it scales
local scaling_data = p.get_hero_scalar(hero_data, stat_name)
local scaling_data = p.get_hero_scaling_data(hero_data, stat_name)
local scaling_strs = ""
local scaling_strs = ""
if (scaling_data ~= nil) then
if (scaling_data ~= nil) then
for scaling_value, scaling_type in pairs(scaling_data) do
for scaling_value, scaling_type in pairs(scaling_data) do
local scaling_str = p.get_hero_scalar_str(scaling_value, scaling_type)
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
scaling_strs = scaling_strs .. scaling_str
scaling_strs = scaling_strs .. scaling_str
Line 482: Line 493:
in_development = hero_data["InDevelopment"]
in_development = hero_data["InDevelopment"]
is_disabled = hero_data["IsDisabled"]
is_disabled = hero_data["IsDisabled"]
if ((not in_development) and (not is_disabled)) then  
if (not is_disabled) then  
--Add the row's stats
--Add the row's stats
Line 517: Line 528:
-- Retrieve scaling val and str if it scales
-- Retrieve scaling val and str if it scales
local scaling_data = p.get_hero_scalar(hero_data, attr_key)
local scaling_data = p.get_hero_scaling_data(hero_data, attr_key)
local scaling_strs = ""
local scaling_strs = ""
if (scaling_data ~= nil) then
if (scaling_data ~= nil) then
for scaling_value, scaling_type in pairs(scaling_data) do
for scaling_value, scaling_type in pairs(scaling_data) do
local scaling_str = p.get_hero_scalar_str(scaling_value, scaling_type)
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
if (scaling_str ~= nil) then
if (scaling_str ~= nil) then