Module:ItemData: Difference between revisions

created get_property_upgrade
added raw variable for get_prop, get_property_upgrades to get data without suffixes
Line 128: Line 128:
WeaponPowerPerStack = true,
WeaponPowerPerStack = true,
}
}
local function strip_suffix(value)
if type(value) == "number" then
return tostring(value)
end
if type(value) ~= "string" then
return tostring(value)
end
return value:match("[-%d%.]+") or value
end


---------------------------------------- Utility functions
---------------------------------------- Utility functions
Line 265: Line 276:
local item_name = frame.args[1]
local item_name = frame.args[1]
local property = frame.args[2]
local property = frame.args[2]
local raw = frame.args.raw == 'true'
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
Line 278: Line 290:
if prop_value["Value"] ~= nil and prop_value["Scale"] ~= nil and prop_value["Scale"]["Value"] ~= nil and prop_value["Scale"]["Type"] ~= nil then
if prop_value["Value"] ~= nil and prop_value["Scale"] ~= nil and prop_value["Scale"]["Value"] ~= nil and prop_value["Scale"]["Type"] ~= nil then
-- This is a structured attribute with scaling data
-- This is a structured attribute with scaling data
display_value = tostring(prop_value["Value"])
display_value = raw and strip_suffix(prop_value["Value"]) or tostring(prop_value["Value"])
local scale_val = tonumber(prop_value["Scale"]["Value"])
if not raw then
local scale_val = tonumber(prop_value["Scale"]["Value"])
if scale_val ~= 0 then
if scale_val ~= 0 then
local scale_type = prop_value["Scale"]["Type"]
local scale_type = prop_value["Scale"]["Type"]
local rounded_scale_val = util_module.round_to_sig_fig(scale_val, 2)
local rounded_scale_val = util_module.round_to_sig_fig(scale_val, 2)
 
local template_title
local template_title
if scale_type == "power_increase" then
if scale_type == "power_increase" then
template_title = "Template:Boon"
template_title = "Template:Boon"
else
else
template_title = "Template:Ss"
template_title = "Template:Ss"
end
 
local template_args = { [1] = rounded_scale_val }
-- Add a space before the scaling template for proper separation
scaling_str = " " .. mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end
end
local template_args = { [1] = rounded_scale_val }
-- Add a space before the scaling template for proper separation
scaling_str = " " .. mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end
end
else
else
Line 300: Line 313:
local tableValues = {}
local tableValues = {}
for _, v in pairs(prop_value) do
for _, v in pairs(prop_value) do
table.insert(tableValues, tostring(v))
table.insert(tableValues, raw and strip_suffix(v) or tostring(v))
end
end
return table.concat(tableValues, ", ")
return table.concat(tableValues, ", ")
Line 306: Line 319:
else
else
-- This is a simple, non-table property
-- This is a simple, non-table property
display_value = tostring(prop_value)
display_value = raw and strip_suffix(prop_value) or tostring(prop_value)
end
 
if raw then
return display_value
end
end
 
-- Assemble the final string, adding the '%' sign if necessary
-- Assemble the final string, adding the '%' sign if necessary
if percentage_properties[property] == true then
if percentage_properties[property] == true then
Line 316: Line 333:
end
end
end
end


p.get_component_name = function(frame)
p.get_component_name = function(frame)
Line 372: Line 390:
local item_name = frame.args[1]
local item_name = frame.args[1]
local property = frame.args[2]
local property = frame.args[2]
local raw = frame.args.raw == 'true'


local item = get_json_item(item_name)
local item = get_json_item(item_name)
Line 387: Line 406:
local values = {}
local values = {}
for _, v in ipairs(prop_upgrades) do
for _, v in ipairs(prop_upgrades) do
table.insert(values, tostring(v))
table.insert(values, raw and strip_suffix(v) or tostring(v))
end
end


local result = table.concat(values, ", ")
local result = table.concat(values, ", ")
if raw then
return result
end


-- Append % if this property is percentage-based
-- Append % if this property is percentage-based
Line 399: Line 422:
end
end
end
end


return p
return p