Module:ItemInfoBox: Difference between revisions
From Alundra
Created page with "local p = {} local function GenItemProperty(args, label, property, prefix, suffix) local value = args[property] if value == nil or value == "" then return "" end prefix = prefix or "" suffix = suffix or "" return string.format( '<div style="display:flex; padding-right:10px"><div>%s</div><div style="flex-grow:1;text-align:right;">%s%s%s</div></div>', label, prefix, value, suffix ) end functio..." |
No edit summary |
||
| Line 22: | Line 22: | ||
function p.render(frame) | function p.render(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local newBlockSet = false -- usage of loops | |||
local out = "" | local out = "" | ||
| Line 61: | Line 63: | ||
file or "" | file or "" | ||
) | ) | ||
end | |||
end | |||
newBlockSet = false | |||
for i = 1, 10 do | |||
local text = args["anim" .. i .. "_text"] | |||
local file = args["anim" .. i .. "_file"] | |||
if file and file ~= "" then | |||
if newBlockSet == false then | |||
out = out .. '<hr/>' | |||
newBlockSet = true | |||
end | |||
if text and text ~= "" then | |||
out = out .. string.format('<div>%s</div>', text) | |||
end | |||
out = out .. string.format('<div>[[File:%s]]</div>', file) | |||
end | end | ||
end | end | ||
Revision as of 10:39, 17 May 2026
Documentation for this module may be created at Module:ItemInfoBox/doc
local p = {}
local function GenItemProperty(args, label, property, prefix, suffix)
local value = args[property]
if value == nil or value == "" then
return ""
end
prefix = prefix or ""
suffix = suffix or ""
return string.format(
'<div style="display:flex; padding-right:10px"><div>%s</div><div style="flex-grow:1;text-align:right;">%s%s%s</div></div>',
label,
prefix,
value,
suffix
)
end
function p.render(frame)
local args = frame:getParent().args
local newBlockSet = false -- usage of loops
local out = ""
local image = args["image"]
if image and image ~= "" then
out = out .. string.format(
'<div style="text-align:center;margin-bottom:0.5rem;">[[File:%s|center|64px]]</div><hr/>',
image
)
end
out = out .. GenItemProperty(args, "Stack size", "stacksize")
out = out .. GenItemProperty(args, "Damage", "damage")
out = out .. GenItemProperty(args, "Damage charged", "damage_charged")
out = out .. GenItemProperty(args, "Damage reduction", "damage_reduction")
out = out .. GenItemProperty(args, "Health", "health")
out = out .. GenItemProperty(args, "Mana", "mana")
out = out .. GenItemProperty(args, "Price", "price", "", " [[File:Coin_Gold.png]]")
local info = args["info"]
if info and info ~= "" then
out = out .. string.format('<div>%s</div>', info)
end
local itemText = args["item_text"]
if itemText and itemText ~= "" then
out = out .. string.format('<hr/><div>%s</div>', itemText)
end
for i = 1, 10 do
local name = args["sound" .. i .. "_name"]
local file = args["sound" .. i .. "_file"]
if name and name ~= "" then
out = out .. string.format(
'<div style="display:flex;justify-content:space-between;"><div>%s</div><div>[[File:%s]]</div></div>',
name,
file or ""
)
end
end
newBlockSet = false
for i = 1, 10 do
local text = args["anim" .. i .. "_text"]
local file = args["anim" .. i .. "_file"]
if file and file ~= "" then
if newBlockSet == false then
out = out .. '<hr/>'
newBlockSet = true
end
if text and text ~= "" then
out = out .. string.format('<div>%s</div>', text)
end
out = out .. string.format('<div>[[File:%s]]</div>', file)
end
end
return out
end
return p