Module:Infobox
Jump to navigation
Jump to search
local p = {}
local TableBuilder = require("Module:TableBuilder") local getLanguageCode = require("Module:Languages").getLanguageCode local animateImages = require("Module:Animated")._images local getArgs = require('Module:Arguments').getArgs
function p.block(frame)
local args = getArgs(frame, {inherited = true}) return p._block(args)
end
function p.item(frame)
local args = getArgs(frame, {inherited = true}) return p._item(args)
end
function p.foodItem(frame)
local args = getArgs(frame, {inherited = true}) return p._foodItem(args)
end
function p.mob(frame)
local args = getArgs(frame, {inherited = true}) return p._mob(args)
end
function p.game(frame)
local args = getArgs(frame, {inherited = true}) return p._game(args)
end
function p.mod(frame)
local args = getArgs(frame, {inherited = true}) return p._mod(args)
end
local function infobox(args, type, names)
local data = mw.loadData("Module:Infobox/" .. getLanguageCode())[type] local name = args.name local width = args.width or "200px" local description = args.description local image = args.image or "Blank.png" local imagesize = args.imagesize local imageText if string.match(image, ",") then imageText = animateImages({image, imagesize}) else if imagesize then imageText = "" .. imagesize .. "" else imageText = "File:" .. image .. "" end end
local infobox = TableBuilder.create()
infobox :addClass("wikitable") :css("float", "right") :css("text-align", "left") :css("margin", "0 0 0.5em 1em") :css("padding", "5px") :css("font-size", "90%") :css("position", "relative") :css("clear", "right") :css("overflow", "auto") :css("z-index", "1") :attr("width", width) :addRow() :addHeader() :attr("colspan", 2) :css("font-size", "110%") :css("text-align", "center") :wikitext(name) :done() :done() :addRow() :addHeader() :attr("colspan", 2) :tag("div") :addClass("center") :wikitext(imageText) :done() :done() :done() :addRow() :addHeader() :attr("colspan", 2) :attr("align", "center") :wikitext(description)
for _, name in ipairs(names) do infobox :addRow() :addData() :wikitext("" .. data[name] .. "") :done() :addData() :wikitext(args[name]) end
return infobox
end
function p._block(args)
args.imagesize = args.imagesize or "150px" local infobox = infobox(args, "block", { "type", "drops", "physics", "luminance", "flammable", "generated", "renewable", "stackable", "itemstring" }) return tostring(infobox)
end
function p._item(args)
args.imagesize = args.imagesize or "160px" local infobox = infobox(infobox, "item", { "type", "renewable", "durability", "stackable", "itemstring" }) return tostring(infobox)
end
function p._foodItem(args)
args.imagesize = args.imagesize or "160px" local infobox = infobox(args, "foodItem", { "type", "restores", "cookable", "renewable", "stackable", "itemstring" }) return tostring(infobox)
end
function p._mob(args)
args.imagesize = args.imagesize or "150px" local infobox = infobox(args, "mob", { "health", "armor", "damage", "drops", "entitystring" }) return tostring(infobox)
end
function p._game(args)
args.imagesize = args.imagesize or "150px" local infobox = infobox(args, "game", { "type", "author", "version", "forum", "source" }) return tostring(infobox)
end
function p._mod(args)
args.imagesize = args.imagesize or "150px" local infobox = infobox(args, "mod", { "type", "author", "version", "forum", "source", "luaname" }) return tostring(infobox)
end
return p