Module:ItemData: Difference between revisionsGive feedback
proper item_type output instead of codenames |
Updated module to support new scaling format |
||
| Line 130: | Line 130: | ||
--check Data:ItemData.json for properties | --check Data:ItemData.json for properties | ||
p.get_prop = function(frame) | p.get_prop = function(frame) | ||
local item_name = frame.args[1] | local item_name = frame.args[1] | ||
local property = frame.args[2] | local property = frame.args[2] | ||
local item = get_json_item(item_name) | local item = get_json_item(item_name) | ||
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end | if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end | ||
if(type( | |||
for | local prop_value = item[property] | ||
local tableValues = table.insert(tableValues, v) | if (prop_value == nil) then return nil end | ||
-- Handle properties that are tables (either scaled attributes or simple lists) | |||
if(type(prop_value) == "table") then | |||
-- Check if the property is a structured attribute with scaling data | |||
if prop_value["Value"] ~= nil and prop_value["Scale"] ~= nil and prop_value["Scale"]["Value"] ~= nil and prop_value["Scale"]["Type"] ~= nil then | |||
local base_val = tostring(prop_value["Value"]) | |||
local scale_val = tonumber(prop_value["Scale"]["Value"]) | |||
local scale_type = prop_value["Scale"]["Type"] | |||
-- Return only the base value if the scaling amount is zero | |||
if scale_val == 0 then | |||
return base_val | |||
end | |||
-- Use the shared utility module to round the scaling value to 2 significant figures for a cleaner display | |||
local rounded_scale_val = util_module.round_to_sig_fig(scale_val, 2) | |||
-- Select the appropriate display template based on the scaling type | |||
local template_title | |||
if scale_type == "power_increase" then | |||
template_title = "Template:Boon" | |||
else | |||
-- Default to Spirit Scaling for other types (e.g., "spirit") | |||
template_title = "Template:Ss" | |||
end | |||
-- Prepare arguments and expand the chosen template | |||
local template_args = { [1] = rounded_scale_val } | |||
local scaling_str = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args } | |||
-- Combine the base value with the formatted scaling string | |||
return base_val .. " " .. scaling_str | |||
else | |||
-- Handle properties that are simple lists (e.g., TargetTypes, Components) | |||
local tableValues = {} | |||
for _, v in pairs(prop_value) do | |||
table.insert(tableValues, tostring(v)) | |||
end | |||
return table.concat(tableValues, ", ") | |||
end | end | ||
end | end | ||
return | |||
-- Handle non-table properties by returning the value directly | |||
return prop_value | |||
end | end | ||