Module:Item
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Item/doc
local p = {}
local lib = require('Module:Feature')
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrapper = {'Template:Item'}
})
return p._main(args)
end
function p._main(args)
local item = args[1] or args.name or "Unknown"
local size = args[2] or args.size or 30
local count = args.count or args.x or nil
local type = args.type or "Item"
local text = args.text or item
local link = args.link or lib.ternary(item == "Unknown", "", item)
local blueprint = tostring(args.blueprint) == "1"
local notext = tostring(args.notext) == "1"
local white = tostring(args.white) == "1"
local suffix = args.suffix and (" " .. args.suffix) or ""
local lcType = type:lower()
if (lcType == "weapon") then suffix = " Icon"
elseif (lcType == "map") then suffix = " Icon"
elseif (lcType == "survivor") then suffix = " Icon"
elseif (lcType == "zombie") then suffix = " Icon"
elseif (lcType == "gamemode") then suffix = " Icon"
end
if (white) then suffix = suffix .. " White" end
item = lib.sanitizeFileName(item)
local file = "[[File:" .. type .. " " .. item .. suffix .. ".png|" .. size .. "x" .. size .. "px|alt=" .. item .. "|link=" .. link .. "]]"
local icon = nil
local corner_size = math.floor(tonumber(size) / 2.5)
local offset = 0
if (corner_size > 21) then
offset = 0
elseif (corner_size > 8) then
offset = math.floor((corner_size - 22) / 2)
else
offset = -6
end
--if (blueprint) then
-- icon = "[[File:Icon Furnishing Blueprint.png|" .. corner_size .. "x" .. corner_size .. "px|link=" .. link .. "]]"
--end
if (lib.isEmpty(item)) then
return ""
end
local outerClass = lib.ternary(type:lower() == 'item', 'item', 'item ' .. type:lower())
local result = mw.html.create():tag('span'):addClass(outerClass)
local item_image = result:tag("span")
:addClass("item-image")
:css({
display = "inline-block",
width = size .. "px",
height = size .. "px",
position = "relative"
})
:wikitext(file)
if (icon ~= nil) then
item_image:tag("span")
:css({
position = "absolute",
top = offset .. "px",
left = "0px",
width = corner_size .. "px",
height = corner_size .. "px"
})
:wikitext(icon)
end
if (newline) then
result:addClass('newline')
result:tag('br'):addClass('hidden')
end
local item_text = result:tag('span'):addClass('item-text')
if (not notext) then
if (lib.isEmpty(link)) then
item_text:wikitext(' ' .. text)
else
item_text:wikitext((newline and '' or ' ') .. '[[' .. link .. '|' .. text .. ']]')
end
end
if (count) then
item_text:wikitext((notext and '' or ' ') .. '×' .. count)
end
if (note) then
item_text:tag('small'):wikitext(((notext and not count) and '' or ' '),'(', note, ')')
end
if (ref) then
item_text:wikitext(ref)
end
return tostring(result);
end
return p