Difference between revisions of "Module:Infobox"

From Minetest Wiki
Jump to navigation Jump to search
m (Reverted to data cells but with automatic bold formatting and finished food info)
m (Added mob, game, and mod)
Line 18: Line 18:
 
     local args = getArgs(frame, {inherited = true})
 
     local args = getArgs(frame, {inherited = true})
 
     return p._foodItem(args)
 
     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)
 +
    local name = args.name
 +
    local width = args.width or "200px"
 +
 +
    local description = args.description
 +
    local includewhere = args.includewhere ~= false
 +
    if description and includewhere then
 +
        local wherein = args.wherein or "[[Subgames/Minetest Game|Minetest Game]]"
 +
        description = description .. " in " .. wherein
 +
    end
 +
 +
    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 = "[[File:" .. image .. "|" .. imagesize .. "]]"
 +
        else
 +
            imageText = "[[File:" .. image .. "]]"
 +
        end
 +
    end
 +
 +
    return TableBuilder.create()
 +
        :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)
 +
                :allDone()
 
end
 
end
  
Line 30: Line 106:
 
         name = args.name or args.block_name or "A block",
 
         name = args.name or args.block_name or "A block",
 
         image = args.image,
 
         image = args.image,
         imageSize = "150px",
+
         imagesize = "150px",
 
         description = "A [[Blocks|block]]",
 
         description = "A [[Blocks|block]]",
 
         wherein = args.wherein,
 
         wherein = args.wherein,
Line 51: Line 127:
 
         name = args.name or args.item_name or "An item",
 
         name = args.name or args.item_name or "An item",
 
         image = args.image,
 
         image = args.image,
         imageSize = "160px",
+
         imagesize = "160px",
 
         description = "An [[Items|item]]",
 
         description = "An [[Items|item]]",
 
         wherein = args.wherein,
 
         wherein = args.wherein,
Line 68: Line 144:
 
         name = args.name or args.item_name or "A food",
 
         name = args.name or args.item_name or "A food",
 
         image = args.image,
 
         image = args.image,
         imageSize = "160px",
+
         imagesize = "160px",
 
         description = "A food [[Items|item]]",
 
         description = "A food [[Items|item]]",
 
         wherein = args.wherein,
 
         wherein = args.wherein,
Line 82: Line 158:
 
end
 
end
  
function p.infobox(args)
+
function p._mob(args)
     local name = args.name
+
     local infobox = p.infobox({
    local width = args.width or "200px"
+
        name = args.name or args.mob_name or "A mob",
    local description = args.description .. " in " .. (args.wherein or "[[Subgames/Minetest Game|Minetest Game]]")
+
        image = args.image,
    local image = args.image or "Minetest logo.png"
+
        imagesize = "150px",
    local imageSize = args.imageSize
+
        description = "A [[Mobs|mob]]",
     local imageText
+
        wherein = args.wherein,
     if string.match(image, ",") then
+
        width = args.width
        imageText = animateImages({image, imageSize})
+
     })
    else
+
     addInfoRow(infobox, "Health", args.health or "''?''")
        imageText = "[[File:" .. image .. "|" .. imageSize .. "]]"
+
    addInfoRow(infobox, "Armor", args.armor or "''N/A''")
    end
+
    addInfoRow(infobox, "Damage", args.damage or "''N/A''")
    return TableBuilder.create()
+
    addInfoRow(infobox, "Drops", args.drops or "''N/A''")
        :addClass("wikitable")
+
    addInfoRow(infobox, "Entitystring", args.entitystring or "''?''")
        :css("float", "right")
+
    return tostring(infobox)
        :css("text-align", "left")
+
end
        :css("margin", "0 0 0.5em 1em")
+
 
         :css("padding", "5px")
+
function p._game(args)
         :css("font-size", "90%")
+
    local infobox = p.infobox({
         :css("position", "relative")
+
         name = args.name or "A subgame",
         :css("clear", "right")
+
         image = args.image,
        :css("overflow", "auto")
+
        imagesize = "150px",
        :css("z-index", "1")
+
         description = "A [[Subgames|subgame]]",
        :attr("width", width)
+
         includewhere = false,
        :addRow()
+
        width = args.width
            :addHeader()
+
    })
                :attr("colspan", 2)
+
    addInfoRow(infobox, "Type", args.type or "''?''")
                :css("font-size", "110%")
+
    addInfoRow(infobox, "Author", args.author or "''?''")
                :css("text-align", "center")
+
    addInfoRow(infobox, "Latest version", args.version or "''?''")
                :wikitext(name)
+
    addInfoRow(infobox, "Forum topic", args.forum or "''N/A''")
                :done()
+
    addInfoRow(infobox, "Source code", args.source or "''N/A''")
            :done()
+
    return tostring(infobox)
        :addRow()
+
end
            :addHeader()
+
 
                :attr("colspan", 2)
+
function p._mod(args)
                :tag("div")
+
    local infobox = p.infobox({
                    :addClass("center")
+
        name = args.name or "A mod",
                    :wikitext(imageText)
+
        image = args.image,
                    :done()
+
        imagesize = "150px",
                :done()
+
        description = "A [[Mods|mod]]",
            :done()
+
        includewhere = false,
        :addRow()
+
        width = args.width
            :addHeader()
+
    })
                :attr("colspan", 2)
+
    addInfoRow(infobox, "Type", args.type or "''?''")
                :attr("align", "center")
+
    addInfoRow(infobox, "Author", args.author or "''?''")
                :wikitext(description)
+
    addInfoRow(infobox, "Latest version", args.version or "''?''")
                :allDone()
+
    addInfoRow(infobox, "Forum topic", args.forum or "''N/A''")
 +
    addInfoRow(infobox, "Source code", args.source or "''N/A''")
 +
    addInfoRow(infobox, "Technical name", args.luaname or "''?''")
 +
    return tostring(infobox)
 
end
 
end
  
 
return p
 
return p

Revision as of 16:38, 11 April 2017

local p = {}

local TableBuilder = require("Module:TableBuilder") 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)

   local name = args.name
   local width = args.width or "200px"
   local description = args.description
   local includewhere = args.includewhere ~= false
   if description and includewhere then
       local wherein = args.wherein or "Minetest Game"
       description = description .. " in " .. wherein
   end
   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
   return TableBuilder.create()
       :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)
               :allDone()

end

local function addInfoRow(infobox, name, info)

   local row = infobox:addRow()
   row:addData():wikitext("" .. name .. "")
   row:addData():wikitext(info)

end

function p._block(args)

   local infobox = p.infobox({
       name = args.name or args.block_name or "A block",
       image = args.image,
       imagesize = "150px",
       description = "A block",
       wherein = args.wherein,
       width = args.width
   })
   addInfoRow(infobox, "Type", args.type or args.block_type or "Solid block")
   addInfoRow(infobox, "Drops", args.drops or "Itself")
   addInfoRow(infobox, "Physics", args.physics or "No")
   addInfoRow(infobox, "Luminance", args.luminance or "No")
   addInfoRow(infobox, "Flammable", args.flammable or "No")
   addInfoRow(infobox, "Generated", args.generated or "Yes")
   addInfoRow(infobox, "Renewable", args.renewable or "No")
   addInfoRow(infobox, "Stackable", args.stackable or "Yes (99)")
   addInfoRow(infobox, "Itemstring", args.itemstring or "?")
   return tostring(infobox)

end

function p._item(args)

   local infobox = p.infobox({
       name = args.name or args.item_name or "An item",
       image = args.image,
       imagesize = "160px",
       description = "An item",
       wherein = args.wherein,
       width = args.width
   })
   addInfoRow(infobox, "Type", args.type or args.item_type or "Craftitem")
   addInfoRow(infobox, "Renewable", args.renewable or "No")
   addInfoRow(infobox, "Durability", args.durability or "N/A")
   addInfoRow(infobox, "Stackable", args.stackable or "Yes (99)")
   addInfoRow(infobox, "Itemstring", args.itemstring or "?")
   return tostring(infobox)

end

function p._foodItem(args)

   local infobox = p.infobox({
       name = args.name or args.item_name or "A food",
       image = args.image,
       imagesize = "160px",
       description = "A food item",
       wherein = args.wherein,
       width = args.width
   })
   addInfoRow(infobox, "Type", args.type or args.item_type or "Food")
   addInfoRow(infobox, "Restores", args.restores or "?")
   addInfoRow(infobox, "Cookable", args.cookable or "No")
   addInfoRow(infobox, "Renewable", args.renewable or "No")
   addInfoRow(infobox, "Stackable", args.stackable or "Yes (99)")
   addInfoRow(infobox, "Itemstring", args.itemstring or "?")
   return tostring(infobox)

end

function p._mob(args)

   local infobox = p.infobox({
       name = args.name or args.mob_name or "A mob",
       image = args.image,
       imagesize = "150px",
       description = "A mob",
       wherein = args.wherein,
       width = args.width
   })
   addInfoRow(infobox, "Health", args.health or "?")
   addInfoRow(infobox, "Armor", args.armor or "N/A")
   addInfoRow(infobox, "Damage", args.damage or "N/A")
   addInfoRow(infobox, "Drops", args.drops or "N/A")
   addInfoRow(infobox, "Entitystring", args.entitystring or "?")
   return tostring(infobox)

end

function p._game(args)

   local infobox = p.infobox({
       name = args.name or "A subgame",
       image = args.image,
       imagesize = "150px",
       description = "A subgame",
       includewhere = false,
       width = args.width
   })
   addInfoRow(infobox, "Type", args.type or "?")
   addInfoRow(infobox, "Author", args.author or "?")
   addInfoRow(infobox, "Latest version", args.version or "?")
   addInfoRow(infobox, "Forum topic", args.forum or "N/A")
   addInfoRow(infobox, "Source code", args.source or "N/A")
   return tostring(infobox)

end

function p._mod(args)

   local infobox = p.infobox({
       name = args.name or "A mod",
       image = args.image,
       imagesize = "150px",
       description = "A mod",
       includewhere = false,
       width = args.width
   })
   addInfoRow(infobox, "Type", args.type or "?")
   addInfoRow(infobox, "Author", args.author or "?")
   addInfoRow(infobox, "Latest version", args.version or "?")
   addInfoRow(infobox, "Forum topic", args.forum or "N/A")
   addInfoRow(infobox, "Source code", args.source or "N/A")
   addInfoRow(infobox, "Technical name", args.luaname or "?")
   return tostring(infobox)

end

return p