Module:ItemData: Difference between revisions

Jump to navigation Jump to search
Pull item type from lang files
added spirit scaling function (WIP)
Line 1: Line 1:
local p = {};
local lang = require "Module:Lang"
local lang = require "Module:Lang"
 
local util_module = require "Module:Utilities"
local p = {};
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")


Line 127: Line 127:
end
end


--Get spirit scaling for a property
--{{#invoke:ItemData|get_scalar|ITEM_NAME|PROPERTY|sig_figs_or_localize}}--
p.get_scalar = function(frame)
local item_name = frame.args[1]
local property = frame.args[2]
local sig_figs_or_localize = frame.args[3]
local item = get_json_item(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
local scaling_data = item[scaling_type .. "Scaling"]
if scaling_data == nil then return scaling_type .. "Scaling data not found for hero" .. item end
local scaling_value = scaling_data[property]
if scaling_value == nil then return scaling_type .. "Scaling data does not have key " .. property .. " for item " .. item end
--round
if (sig_figs_or_localize ~= nil and tonumber(sig_figs_or_localize) ~= nil) then
scaling_value = util_module.round_to_sig_fig(scaling_value, sig_figs_or_localize)
if (scaling_value == nil) then return "get_hero_scalar() error with rounding" end
end
local scaling_str = p.write_scalar_str(scaling_value)
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
return scaling_str
end
-- Retrieve spirit scaling of an hero's given property, if it has scaling, else return blank
-- Scaling string meaning the expanded template {{Ss|scalar}}
function p.write_scalar_str(scaling_value)
-- Return blank if it doesnt scale
if (scaling_value == 0) then return "" end
-- Round it
scaling_value = util_module.round_to_sig_fig(scaling_value, 3)
--The item has a spirit scaling value with this property
local template_title = "Template:Ss"
local template_args = {}
template_args["1"] = scaling_value --store in 1st arg for {{{1}}} to grab it from {{SS}} or {{LS}} template
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
return template_call
end


p.get_component_name = function(frame)
p.get_component_name = function(frame)