Module:Sandbox: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 40: | Line 40: | ||
end | end | ||
-- Main function with | -- Find all recipes where this item is used as a component | ||
local function find_recipes(item_name) | |||
local recipes = {} | |||
for _, item in pairs(data) do | |||
if item.Components and type(item.Components) == "table" then | |||
for _, comp_id in ipairs(item.Components) do | |||
local component = data[comp_id] | |||
if component and component.Name == item_name then | |||
table.insert(recipes, item.Name) | |||
break -- Only need to find one match per item | |||
end | |||
end | |||
end | |||
end | |||
return recipes | |||
end | |||
-- Main function with complete item relationship handling | |||
p.generate_infobox = function(frame) | p.generate_infobox = function(frame) | ||
local item_name = frame.args[1] | local item_name = frame.args[1] | ||
| Line 65: | Line 82: | ||
-- Color definitions | -- Color definitions | ||
local colors = { | local colors = { | ||
Weapon = {bg = "#80550F", header = "#C97A03", border = "#C97A03"}, | Weapon = { | ||
Vitality = {bg = "#4D7214", header = "#659818", border = "#659818"}, | bg = "#80550F", header = "#C97A03", border = "#C97A03", | ||
Spirit = {bg = "#623585", header = "#8B56B4", border = "#8B56B4"} | components = {bg = "#9E630C", text = "#DCCFC6"}, | ||
recipes = {bg = "#704A0C", text = "#D1CBC6"} | |||
}, | |||
Vitality = { | |||
bg = "#4D7214", header = "#659818", border = "#659818", | |||
components = {bg = "#203500", text = "#C7C9C6"}, | |||
recipes = {bg = "#436310", text = "#CACFC7"} | |||
}, | |||
Spirit = { | |||
bg = "#623585", header = "#8B56B4", border = "#8B56B4", | |||
components = {bg = "#372248", text = "#C9C7CB"}, | |||
recipes = {bg = "#552D74", text = "#CCC8D2"} | |||
} | |||
} | } | ||
local color = colors[item_type] or colors.Weapon | local color = colors[item_type] or colors.Weapon | ||
-- Process components | -- Process components (what this item is made of) | ||
local component_text = "" | local component_text = "" | ||
if item.Components and type(item.Components) == "table" then | if item.Components and type(item.Components) == "table" and #item.Components > 0 then | ||
local valid_components = {} | local valid_components = {} | ||
for _, comp_id in ipairs(item.Components) do | for _, comp_id in ipairs(item.Components) do | ||
| Line 85: | Line 114: | ||
component_text = string.format( | component_text = string.format( | ||
'|-\n! colspan="4" style="text-align:left; padding:0 12px; font-weight:bold; font-size:16px; font-family:\'Retail Demo Bold\',serif; background-color: %s; color: %s" | COMPONENTS:<br/>%s', | '|-\n! colspan="4" style="text-align:left; padding:0 12px; font-weight:bold; font-size:16px; font-family:\'Retail Demo Bold\',serif; background-color: %s; color: %s" | COMPONENTS:<br/>%s', | ||
color.components.bg, color.components.text, | |||
table.concat(valid_components, "<br/>") | table.concat(valid_components, "<br/>") | ||
) | ) | ||
| Line 92: | Line 120: | ||
end | end | ||
-- Process stats - | -- Process recipes (what items this is used in) | ||
local recipe_text = "" | |||
local recipes = find_recipes(item.Name) | |||
if #recipes > 0 then | |||
local recipe_links = {} | |||
for _, recipe_name in ipairs(recipes) do | |||
table.insert(recipe_links, "{{ItemIcon|" .. recipe_name .. "}}") | |||
end | |||
recipe_text = string.format( | |||
'|-\n! colspan="4" style="text-align:left; padding:0 12px; font-weight:bold; font-size:16px; font-family:\'Retail Demo Bold\',serif; background-color: %s; color: %s" | USED IN:<br/>%s', | |||
color.recipes.bg, color.recipes.text, | |||
table.concat(recipe_links, "<br/>") | |||
) | |||
end | |||
-- Process stats - comprehensive stat handling | |||
local stats = {} | local stats = {} | ||
local stat_config = { | local stat_config = { | ||
| Line 106: | Line 150: | ||
BonusAbilityCharges = {prefix = "+", suffix = " Bonus Charges"}, | BonusAbilityCharges = {prefix = "+", suffix = " Bonus Charges"}, | ||
CooldownReductionOnChargedAbilities = {suffix = "% Charged Ability Cooldown Reduction"}, | CooldownReductionOnChargedAbilities = {suffix = "% Charged Ability Cooldown Reduction"}, | ||
BaseAttackDamagePercent = {suffix = "% Base Attack Damage"} | BaseAttackDamagePercent = {suffix = "% Base Attack Damage"}, | ||
-- Add more stats as needed | |||
} | } | ||
| Line 170: | Line 215: | ||
} | } | ||
-- Add components if | -- Add components section if exists | ||
if component_text ~= "" then | if component_text ~= "" then | ||
table.insert(parts, component_text) | table.insert(parts, component_text) | ||
end | |||
-- Add recipes section if exists | |||
if recipe_text ~= "" then | |||
table.insert(parts, recipe_text) | |||
end | end | ||
-- Add description if it exists | -- Add description if it exists | ||
if item.Description then | if item.Description and item.Description ~= "" then | ||
table.insert(parts, | table.insert(parts, | ||
string.format( | string.format( | ||