Modul:Infobox Item: Unterschied zwischen den Versionen

Aus Eco - Deutsches Wiki
Wechseln zu:Navigation, Suche
[unmarkierte Version][unmarkierte Version]
(Fix SkillScroll and Books)
(Copying from EN)
 
(7 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
-- Credit: Die von Pradoxzon erstellte Original-Infobox (jetzt als Infobox_Item bekannt) wurde dann von Nesphit und TreeNuts0 bearbeitet. Fyre (FishAus) und Scotty (ZeelNightwolf) haben das Infobox_Item weiter bearbeitet. Sie wurden dann dupliziert und als Basis für Infobox_Skill, Infobox_Plant und Infobox_Animal verwendet.
+
-- Credit: Original Infobox (now known as Infobox_Item) created by Pradoxzon was then edited by Nesphit and TreeNuts0. Fyre (FishAus) and Scotty (ZeelNightwolf) further edited the Infobox_Item. They then duplicated and used as a base for Infobox_Skill, Infobox_Plant, and Infobox_Animal.
 +
 
 
local p = {}
 
local p = {}
 
+
local Utils = require('Module:Utils')
-- Grabs args from the parent frame
+
local L = require('Module:Localization')
-- Trims and parses the args into a table, then returns the table
 
function norm()
 
    local origArgs = mw.getCurrentFrame():getParent().args
 
    local args = {}
 
   
 
    for k, v in pairs( origArgs ) do
 
        v = mw.text.trim( tostring( v ) )
 
        if v ~= '' then
 
            args[k] = v
 
        end
 
    end
 
   
 
    return args
 
end
 
  
 
-- Build an Item Infobox
 
-- Build an Item Infobox
function itemBox( args, itemData )
+
function itemBox(args, itemData)
 
     -- check that all necessary arguments are passed correctly
 
     -- check that all necessary arguments are passed correctly
 
     if args.name == nil or args.name == '' then
 
     if args.name == nil or args.name == '' then
 
         return '\'name\' must be specified.'
 
         return '\'name\' must be specified.'
 
     end
 
     end
      
+
 
local item = args.name
+
     local item = args.name
local itemTable = itemData.items[item]
+
    local itemTable = itemData.items[item]
 +
 
 +
    if itemTable == nil then
 +
        return item .. ' could not be found in Module:ItemData.'
 +
    end
 +
 
 
     local itemType = itemTable.type
 
     local itemType = itemTable.type
local itemEN = string.sub (itemType, 1, -5)
+
    local itemEN = string.sub(itemType, 1, -5)
local scrollEN = string.sub (itemType, 1, -7)
+
    local itemimagename = string.gsub(itemEN, ' ', '')
local itemimagename = string.gsub(itemEN, ' ', '')
+
 
local scrollimagename = string.gsub(scrollEN, ' ', '')
 
 
if itemTable == nil then
 
return item .. 'Konnte nicht in Modul: ItemData gefunden werden.'
 
end
 
   
 
 
     -- string used to build the infobox
 
     -- string used to build the infobox
 
     local infobox = '{| class=\"infobox\"\n'
 
     local infobox = '{| class=\"infobox\"\n'
   
 
-- 'Name and Image' section
 
-- name of the item
 
infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
 
   
 
-- the item's type (ItemData - group)
 
infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
 
 
if itemTable.group == 'Nahrung' then
 
infobox = infobox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Nahrung\'\'\'\n'
 
-- Items:Food Icon Image
 
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
 
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
 
image = itemimagename .. '_Icon.png'
 
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
 
image = itemimagename .. '_Icon.jpg'
 
end
 
 
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconGreen]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
 
 
elseif itemTable.group == 'Fertigkeitsbücher' then
 
infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
 
-- Items:Skill Book Icon Image
 
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillBook.png|link=https://wiki.play.eco/File:SkillBook.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
 
  
elseif itemTable.group == 'Fertigkeitsbücher' then
+
    -- 'Name and Image' section
infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
+
    -- name of the item
-- Items:Skill Scrolls Icon Image
+
    infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillScroll.png|link=https://wiki.play.eco/File:SkillScroll.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
+
 
 +
    -- the item's type (ItemData - group)
 +
    infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
 +
 
 +
    local text_colour = '#78B1FF'
 +
 
 +
    if itemTable.group == L.t('Food') then
 +
        text_colour = '#85D66B'
 +
    elseif itemTable.group == L.t('Skill Books') or itemTable.group == L.t('Skill Scrolls') then
 +
        text_colour = '#FFCF4D'
 +
    elseif itemTable.group == L.t('Skill Scrolls') then
 +
        text_colour = '#FFCF4D'
 +
    end
 +
 
 +
    infobox = infobox .. text_colour .. ';\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
 +
    local icon = Utils.build_icon(item)
 +
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | '..icon .. '\n'
 +
 
 +
    -- 'Description' section header
 +
    infobox = infobox .. sectionHeader('Description')
 +
 
 +
    if itemTable.description == nil or itemTable.description == '' then
 +
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'' .. L.t('None') .. '\'\'\'\n'
 +
    else
 +
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. itemTable.description .. '\n'
 +
    end
 +
 
 +
    --Crafting
 +
    local craftingRecipes = mw.loadData("Module:CraftingRecipes")
 +
 
 +
    infobox = infobox .. generalSection(item, itemTable, craftingRecipes, args)
 +
 
 +
    infobox = infobox .. IDsSection(itemTable)
 +
 
 +
    -- Tags Header
 +
    if itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
 +
        infobox = infobox .. tagSection(itemTable, itemData)
 +
    end
 +
 
 +
    -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
 +
    if itemTable.group == L.t('Block Items') or itemTable.group == L.t('World Object Items') then
 +
        infobox = infobox .. placementSection(itemTable, itemimagename)
 +
 
 +
        -- Object Form Image
 +
        if itemTable.group == L.t('Block Items') then
 +
            infobox = infobox .. objectFormSection(itemTable, itemimagename)
 +
        end
 +
 
 +
        -- 'Housing' section (if there is a Room Category)
 +
        if itemTable.roomCategory ~= nil then
 +
            infobox = infobox .. housingSection(itemTable)
 +
        end
 +
 
 +
        -- 'Storage' Section (if inventorySlots is not nil)
 +
        if itemTable.inventorySlots ~= nil then
 +
            infobox = infobox .. storageSection(itemTable)
 +
        end
 +
 
 +
        -- 'Power' section (if EngeryType is ``not nil)
 +
        if itemTable.energyType ~= nil then
 +
            infobox = infobox .. powerSection(itemTable)
 +
 
 +
        end
 +
 
 +
        -- 'Fuel' Section (if fuelsUsed by Object)
 +
        if itemTable.fuelsUsed ~= nil then
 +
            infobox = infobox .. fuelsSection(itemTable)
 +
        end
 +
 
 +
        -- 'Fluid' section (if fludisUsed is not nil)
 +
        if itemTable.fluidsUsed ~= nil or itemTable.fluidsProduced ~= nil then
 +
            infobox = infobox .. fluidsSection(itemTable)
 +
        end
 +
    end
 +
 
 +
    -- Road Object header (if group == Road Items)
 +
    if itemTable.group == L.t('Road Items') then
 +
        infobox = infobox .. roadItemsSection(itemTable, itemimagename)
 +
    end
 +
    infobox = infobox .. '|}'
 +
    return infobox
 +
end
 +
 
 +
function sectionHeader(title, count)
 +
    return "|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | '''" .. L.t(title, count) .. "'''\n"
 +
end
 +
 
 +
function sectionRow(label, content, count, unit)
 +
    if unit ~= nil then
 +
        content = tonumber(content)
 +
        unit = L.t(unit, content)
 +
        local lang = mw.getContentLanguage()
 +
        content = lang:formatNum(content)
 +
    else
 +
        unit = ''
 +
    end
 +
    return '|-\n| ' .. L.t(label, count) .. ':\n| style=\"text-align: right; padding: 3px;\" | ' .. content .. unit .. '\n'
 +
end
 +
 
 +
function sectionImage(imageName, suffix)
 +
    local image = checkImage(imageName, suffix)
 +
    return '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
 +
end
 +
 
 +
local function addToSet(set, key)
 +
    set[key] = true
 +
end
 +
 
 +
local function setNotContains(set, key)
 +
    return set[key] == nil
 +
end
 +
 
 +
local function craftingSubSection(title, item, productsOrIngredients, recipes)
 +
    local stations = {}
 +
    local sortStations = {}
 +
    local stationString = ''
 +
    for _, recipeName in ipairs(productsOrIngredients[item]) do
 +
        local currentRecipe = recipes[recipeName]
 +
        if currentRecipe ~= nil then
 +
            if currentRecipe.variants[recipeName] ~= nil then
 +
                local currentStation = currentRecipe.craftStn[1][1]
 +
                if setNotContains(stations, currentStation) then
 +
                    addToSet(stations, currentStation)
 +
                end
 +
            end
 +
        end
 +
    end
 +
 
 +
    if stations then
 +
        for a, _ in pairs(stations) do
 +
            table.insert(sortStations, a)
 +
        end
 +
        table.sort(sortStations)
 +
        for i, n in ipairs(sortStations) do
 +
            stationString = stationString .. ' [[' .. n .. ']]'
 +
            if (n ~= sortStations[#sortStations]) then
 +
                -- add a comma
 +
                stationString = stationString .. ', '
 +
            end
 +
        end
 +
        return sectionRow(title, stationString)
 +
    else
 +
        return sectionRow(title, L.t('N/A'))
 +
    end
 +
end
  
else
+
function generalSection(item, itemTable, craftingRecipes, args)
infobox = infobox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
 
-- Items: Other Icon Image
 
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
 
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
 
image = itemimagename .. '_Icon.png'
 
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
 
image = itemimagename .. '_Icon.jpg'
 
end
 
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
 
end
 
   
 
  -- 'Description' section header
 
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Beschreibung\'\'\'\n'
 
 
if itemTable.description == nil then
 
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'None\'\'\'\n'
 
elseif itemTable.description == '' then
 
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'None\'\'\'\n'
 
else
 
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. itemTable.description .. '\n'
 
end
 
 
 
     -- 'General' section header
 
     -- 'General' section header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
+
    section = sectionHeader('General')
      
+
 
-- -- created at
+
     -- Is a product at these tables
-- local craftingRecipes = require( "Modul:CraftingRecipes" )
+
    if craftingRecipes.products[item] ~= nil and Utils.tableLen(craftingRecipes.products[item]) >= 1 then
-- local recipes = craftingRecipes.recipes
+
        section = section .. craftingSubSection('Created at', item, craftingRecipes.products, craftingRecipes.recipes)
+
    end
-- local function addToSet(set, key)
+
 
-- set[key] = true
+
    -- Is an ingredient at these tables
-- end
+
    if craftingRecipes.ingredients[item] ~= nil and Utils.tableLen(craftingRecipes.ingredients[item]) >= 1 then
+
        section = section .. craftingSubSection('Used at', item, craftingRecipes.ingredients, craftingRecipes.recipes)
-- local function setNotContains(set, key)
+
    end
-- return set[key] == nil
+
 
-- end
+
    -- calories and nutrients (if itemTable.group == 'Food')
+
    if itemTable.group == L.t('Food') then
-- if craftingRecipes.items[item] ~= nil and #craftingRecipes.items[item] >= 1 then
+
        section = section .. sectionRow('Calorie', itemTable.calories, tonumber(itemTable.calories), 'cal')
-- local count = 0
+
        section = section .. '|- valign=\"center\"\n| rowspan=\"4\" | ' .. L.t('Nutrients') .. ':\n'
-- local stations = {}
+
        section = section .. '| style=\"color: red; text-align: right; padding: 3px;\" | ' .. L.t('Carbs') .. ': ' .. itemTable.carbs .. '\n'
-- local sortStations = {}
+
        section = section .. '|- valign=\"center\"\n| style=\"color: orange; text-align: right; padding: 3px;\" | ' .. L.t('Protein') .. ': ' .. itemTable.protein .. '\n'
-- local stationString = ''
+
        section = section .. '|- valign=\"center\"\n| style=\"color: yellow; text-align: right; padding: 3px;\" | ' .. L.t('Fat') .. ': ' .. itemTable.fat .. '\n'
-- local found = false
+
        section = section .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | ' .. L.t('Vitamins') .. ': ' .. itemTable.vitamins .. '\n'
-- for k, v in ipairs( craftingRecipes.items[item] ) do
+
        section = section .. sectionRow('Nutrition Density', L.t('%s per 100 cals'):format(itemTable.density))
-- for num = 1, #recipes[v].numberOfVariants do
+
    end
-- if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
+
 
-- if setNotContains(stations, recipes[v].craftStn[1]) then
+
    -- carried
-- addToSet(stations, recipes[v].craftStn[1])
+
    local carried
-- count = count + 1
+
    if args.carried ~= nil and args.carried ~= '' then
-- end
+
        carried = args.carried
-- if found == false then
+
    else
-- found = true
+
        carried = itemTable.carried
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" |'
+
    end
-- end
+
    section = section .. sectionRow('Carried in', carried)
-- end
+
 
-- end
+
    -- weight
-- end
+
    local weight
+
    if itemTable.weight ~= nil then
-- local track = 0
+
        weight = itemTable.weight
-- if found == true then
+
    else
-- for a, b in pairs(stations) do
+
        weight = '0.0'
-- table.insert(sortStations, a)
+
    end
-- end
+
    section = section .. sectionRow('Weight', weight, nil, 'kg')
-- table.sort(sortStations)
+
 
-- for i, n in ipairs(sortStations) do
+
    -- stack limit
-- stationString = stationString .. ' [[' .. n .. ']]'
+
    if itemTable.maxStack ~= nil then
-- track = track + 1
+
        section = section .. sectionRow('Stack limit', itemTable.maxStack)
-- if track ~= count then -- Changed these line to produce comma if not last table.
+
    end
-- stationString = stationString .. ','
+
 
-- end
+
    -- yield
-- end
+
    if itemTable.yield ~= nil then
-- infobox = infobox .. stationString .. '\n'
+
        section = section .. sectionRow('Improve Gathering', itemTable.yield)
-- else
+
    end
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
+
 
-- end
+
    -- fuel
-- elseif args.created ~= nil and args.created ~= '' then
+
    if itemTable.fuel ~= nil then
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.created .. '\n'
+
        section = section .. sectionRow('Fuel energy', itemTable.fuel, nil, 'J')
-- else
+
    end
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
+
 
-- end
+
    -- currency
 +
    if itemTable.currency ~= nil then
 +
        section = section .. "|- style=\"text-align: center;\"\n| colspan=\"2\" | " .. L.t('Can back a currency') .. "\n"
 +
    end
 +
    return section
 +
end
  
-- calories and nutrients (if itemTable.group == 'Food')
+
function IDsSection(itemTable)
if itemTable.group == 'Nahrung' then
 
infobox = infobox .. '|-\n| Kalorien:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.calories .. '\n|- valign=\"center\"\n| rowspan=\"4\" | Nutrients:\n'
 
infobox = infobox .. '| style=\"color: red; text-align: right; padding: 3px;\" | Kohlenhydrate: ' .. itemTable.carbs .. '\n'
 
infobox = infobox .. '|- valign=\"center\"\n| style=\"color: orange; text-align: right; padding: 3px;\" | Protein: ' .. itemTable.protein .. '\n'
 
infobox = infobox .. '|- valign=\"center\"\n| style=\"color: yellow; text-align: right; padding: 3px;\" | Fett: ' .. itemTable.fat .. '\n'
 
infobox = infobox .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | Vitamine: ' .. itemTable.vitamins .. '\n'
 
infobox = infobox .. '|-\n| Nährstoffdichte:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.density .. ' per 100 cals\n'
 
end
 
 
-- carried
 
if args.carried ~= nil and args.carried ~= '' then
 
infobox = infobox .. '|-\n| Getragen :\n| style=\"text-align: right; padding: 3px;\" | ' .. args.carried .. '\n'
 
else
 
infobox = infobox .. '|-\n| Getragen: \n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.carried .. '\n'
 
end
 
   
 
-- weight
 
if itemTable.weight ~= nil then
 
infobox = infobox .. '|-\n| Gewicht:\n| style="text-align: right; padding: 3px;" | ' .. itemTable.weight .. ' kg\n'
 
else
 
infobox = infobox .. '|-\n| Gewicht:\n| style="text-align: right; padding: 3px;" | 0.00kg\n'
 
end
 
   
 
-- stack limit
 
if itemTable.maxStack ~= nil then
 
infobox = infobox .. '|-\n| Stapellimit:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.maxStack .. '\n'
 
end
 
 
-- yield
 
if itemTable.yield ~= nil then
 
infobox = infobox .. '|-\n| Ertrag verbessern: \n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.yield .. '\n'
 
end
 
 
-- fuel
 
if itemTable.fuel ~= nil then
 
infobox = infobox .. '|-\n| Kraftstoff:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuel .. ' J\n'
 
end
 
   
 
-- currency
 
if itemTable.currency ~= nil then
 
infobox = infobox .. '|-\n| Wird als Währung verwendet:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.currency .. '\n'
 
end
 
 
 
     -- 'IDs' section header
 
     -- 'IDs' section header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'IDs\'\'\'\n'
+
    section = sectionHeader('ID', 2)
   
 
-- item id (type)
 
infobox = infobox .. '|- valign=\"center\"\n| Artikel-ID\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.type .. '\n'
 
   
 
-- id number (type id)
 
infobox = infobox .. '|- valign=\"center\"\n| ID-Nummer:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.typeID .. '\n'
 
  
-- Tags Header
+
    -- item id (type)
if itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
+
    section = section .. sectionRow('Item ID', itemTable.type)
            -- Tags Header
+
 
            infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Tags\'\'\'\n'
+
    -- id number (type id)
            local tags = itemTable.tagGroups
+
    section = section .. sectionRow('ID Number', itemTable.typeID)
            local list = ''
+
 
            -- for each item in the list (a is position, b is value)          
+
    return section
            for a,b in ipairs(tags) do
+
end
            --if not these tags listed here
+
 
                if (b ~='[[Object]]' or b ~= '[[World  Object]]' or b ~= '[[Housing  Object]]') then
+
function tagSection(itemTable, itemData)
                    -- add the tag to the list
+
    -- Tags Header
                    list = list .. b
+
    local tags = itemTable.tagGroups
                end
+
    section = sectionHeader('Tag', Utils.tableLen(tags))
                -- if not the last item in the list
+
    local list = ''
                if (b ~= tags[#tags]) then
+
    -- for each item in the list (a is position, b is value)
                    -- add a comma
+
    for a, b in ipairs(tags) do
                    list = list .. ', '
+
        --if not these tags listed here
                end
+
        if (b ~= L.t('Object') or b ~= L.t('World  Object') or b ~= L.t('Housing  Object')) then
 +
            -- add the tag to the list
 +
            -- HACK: Some tag localisations have spaces in the tag name, but not in the tag data
 +
            local tagLink
 +
            -- Some tags have multiple spaces? Possible data quality issue
 +
            bClean = b:gsub("%s+", " ")
 +
            if itemData.tags[bClean] ~= nil then
 +
                tagLink = L.t('%s Tag'):format(bClean)
 +
            else
 +
                tagLink = L.t('%s Tag'):format(bClean:gsub(' ', ''))
 
             end
 
             end
             -- Now the list is made add it to the infobox
+
 
            infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
+
            list = list .. '[[' .. tagLink .. '|' .. bClean .. ']][[Category:' .. bClean .. ']]'
 +
        end
 +
        -- if not the last item in the list
 +
        if (b ~= tags[#tags]) then
 +
             -- add a comma
 +
            list = list .. ', '
 +
        end
 +
    end
 +
    -- Now the list is made add it to the infobox
 +
    section = section .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
 +
 
 +
    return section
 +
end
 +
 
 +
function placementSection(itemTable, itemImageName)
 +
    section = sectionHeader('World Object')
 +
    -- Object Placed Image
 +
    section = section .. sectionImage(itemImageName, 'Placed')
 +
 
 +
    -- 'Placement' section
 +
    --Placement Header
 +
    section = section .. sectionHeader('Placement')
 +
 
 +
    --Vechile
 +
    if itemTable.mobile ~= nil then
 +
        section = section .. sectionRow('Vehicle/Mobile Object', itemTable.mobile)
 +
    end
 +
 
 +
    --Dimensions
 +
    if itemTable.footprint ~= nil then
 +
        section = section .. sectionRow('Dimensions (X,Y,Z)', itemTable.footprint)
 +
    end
 +
 
 +
    --Material Tier
 +
    if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
 +
        section = section .. sectionRow('Room Material', itemTable.materialTier) .. '[[Category:Tier ' .. itemTable.materialTier .. ']]\n'
 +
    end
 +
 
 +
    --Room Req.
 +
    if itemTable.roomContainReq ~= nil then
 +
        section = section .. sectionRow('Room Required', itemTable.roomContainReq)
 +
    end
 +
 
 +
    --Room Size. Req.
 +
    if itemTable.roomSizeReq ~= nil then
 +
        section = section .. sectionRow('Room Size', itemTable.roomSizeReq, nil, 'm³')
 +
    end
 +
 
 +
    --Room Mat. Req.
 +
    if itemTable.roomMatReq ~= nil then
 +
        section = section .. sectionRow('Room Materials', itemTable.roomMatReq)
 +
    end
 +
    return section
 +
end
 +
 
 +
function objectFormSection(itemTable, itemImageName)
 +
    return sectionImage(itemImageName, 'Form')
 +
end
 +
 
 +
function housingSection(itemTable)
 +
    -- Housing Header
 +
    section = sectionHeader('Housing')
 +
 
 +
    --roomCategory
 +
    section = section .. sectionRow('Room Category', itemTable.roomCategory) .. '[[Category:' .. itemTable.roomCategory .. ']]\n'
 +
 
 +
    if itemTable.roomCategory ~= L.t('Industrial') then
 +
        if itemTable.furnitureType ~= nil then
 +
            --furnitureType
 +
            section = section .. sectionRow('Furniture Type', itemTable.furnitureType) .. '[[Category:' .. itemTable.furnitureType .. ']]\n'
 +
 
 +
            --Value of the object
 +
            section = section .. sectionRow('Value', itemTable.skillValue)
 +
 
 +
            --Dim. Return % of Object
 +
            section = section .. sectionRow('Dim. Return %', itemTable.repeatsDepreciation * 100, nil, '%')
 
         end
 
         end
 +
    end
 +
 +
    if itemTable.roomCategory == L.t('Industrial') then
 +
        section = section .. "|- style=\"background-color: #red; text-align: center;\"\n| colspan=\"2\" | '''" .. L.t('ALL ROOM VALUE LOST') .. "'''\n"
 +
    end
 +
 +
    return section
 +
end
 +
 +
function storageSection(itemTable)
 +
    -- Storage Header
 +
    section = sectionHeader('Storage')
 +
 +
    --Inventory Slots
 +
    section = section .. sectionRow('Inventory Slots', itemTable.inventorySlots)
 +
 +
    --inventoryMaxWeight
 +
    if itemTable.inventoryMaxWeight ~= nil then
 +
        maxWeightKg = itemTable.inventoryMaxWeight / 1000
 +
        section = section .. sectionRow('Inventory Max Weight', maxWeightKg, nil, 'kg')
 +
    else
 +
        section = section .. sectionRow('Inventory Max Weight', L.t('Unlimited'))
 +
    end
 +
 +
    return section
 +
end
 +
 +
function powerSection(itemTable)
 +
    -- Power Header
 +
    section = sectionHeader('Power')
 +
 +
    --EngergyType
 +
    section = section .. sectionRow('Energy Type', itemTable.energyType) .. '[[Category:' .. itemTable.energyType .. ']]\n'
 +
 +
    --Grid Radius
 +
    section = section .. sectionRow('Grid Radius', itemTable.gridRadius, nil, 'm')
 +
 +
    --Energy Produced
 +
    section = section .. sectionRow('Energy Produced', itemTable.energyProduced, nil, 'w')
 +
 +
    --Energy Used
 +
    section = section .. sectionRow('Energy Used', itemTable.energyUsed, nil, 'w')
  
     -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
+
     return section
if itemTable.group == 'Block Items' or itemTable.group == 'World Object Items' then
+
end
infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'World Object\'\'\'\n'
 
 
-- Object Placed Image
 
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
 
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
 
image = itemimagename .. '_Placed.png'
 
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
 
image = itemimagename .. '_Placed.jpg'
 
end
 
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
 
 
 
-- 'Placement' section
 
--Placement Header
 
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Platzierung\'\'\'\n'
 
  
--Vechile
+
function fuelsSection(itemTable)
if itemTable.mobile ~= nil then
+
    -- Fuel Header
infobox = infobox .. '|-\n| Fahrzeug / mobiles Objekt:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.mobile .. '\n'
+
    section = sectionHeader('Fuel')
end
 
 
--Dimensions
 
if itemTable.footprint ~= nil then
 
infobox = infobox .. '|-\n| Maße (X,Y,Z):\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.footprint .. '\n'
 
end
 
 
--Material Tier
 
if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
 
infobox = infobox .. '|-\n| Raummaterial:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '\n'
 
end
 
 
--Room Req.
 
if itemTable.roomContainReq ~= nil then
 
infobox = infobox .. '|-\n| Zimmer erforderlich:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
 
end
 
 
--Room Size. Req.
 
if itemTable.roomSizeReq ~= nil then
 
infobox = infobox .. '|-\n| Raumgröße:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' m³\n'
 
end
 
 
--Room Mat. Req.
 
if itemTable.roomMatReq ~= nil then
 
infobox = infobox .. '|-\n| Raummaterialien:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomMatReq .. '\n'
 
end
 
 
-- Object Form Image
 
if itemTable.group == 'Block Items' then
 
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Form.png|[[Category:Pages_with_missing_form]]'
 
if mw.title.makeTitle('File', itemimagename .. '_Form.png').file.exists then
 
image = itemimagename .. '_Form.png'
 
elseif mw.title.makeTitle('File', itemimagename .. '_Form.jpg').file.exists then
 
image = itemimagename .. '_Form.jpg'
 
end
 
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
 
end
 
  
-- 'Housing' section (if there is a Room Category)
+
    --Fuels Used by Object
if itemTable.roomCategory ~= nil then 
+
    section = section .. sectionRow('Fuels Used', '[[' .. L.t('%s Tag'):format(itemTable.fuelsUsed:gsub('[%[%]]+', '')) .. ']]')
-- Housing Header
 
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Gehäuse\'\'\'\n'
 
   
 
--roomCategory
 
infobox = infobox .. '|-\n| Zimmerkategorie:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
 
  
if itemTable.roomCategory ~= 'Industrial' then
+
    return section
if itemTable.furnitureType ~= nil then
+
end
--furnitureType
 
infobox = infobox .. '|-\n| Möbeltyp:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
 
           
 
--Value of the object
 
infobox = infobox .. '|-\n| Wert:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
 
           
 
--Dim. Return % of Object 
 
infobox = infobox .. '|-\n| Abnehmender Ertrag %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'   
 
end
 
end
 
 
if itemTable.roomCategory == 'Industrial' then
 
infobox = infobox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'Alle Zimmerwert verloren\'\'\'\n'
 
end
 
end
 
-- 'Storage' Section (if inventorySlots is not nil)
 
if itemTable.inventorySlots ~= nil then
 
-- Storage Header
 
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Speicherung\'\'\'\n'
 
  
--Inventory Slots
+
function fluidsSection(itemTable)
infobox = infobox .. '|-\n| Inventarplätze:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.inventorySlots .. '\n'
+
    -- Liquid/Gas Header
+
    section = sectionHeader('Liquid/Gas')
--inventoryMaxWeight
 
if itemTable.inventoryMaxWeight ~= nil then
 
maxWeightKg = itemTable.inventoryMaxWeight/1000
 
infobox = infobox .. '|-\n| Inventar Max. Gewicht:\n| style=\"text-align: right; padding: 3px;\" | ' .. maxWeightKg .. ' Kg\n'
 
else
 
infobox = infobox .. '|-\n| Inventar Max. Gewicht:\n| style=\"text-align: right; padding: 3px;\" |Unbegrenzt \n'
 
end
 
end
 
  
-- 'Power' section (if EngeryType is ``not nil)
+
    --Input (fludisUsed)
if itemTable.energyType ~= nil then
+
    if itemTable.fluidsUsed ~= nil then
-- Power Header
+
        local list = ''
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Leistung\'\'\'\n'
+
        for a, b in ipairs(itemTable.fluidsUsed) do
 +
            local acceptedType = b[1]
 +
            local cRateString = string.gsub(b[2], "%s+", "")
 +
            local consumingRate = tonumber(cRateString)
 +
            list = list .. L.t('%s at %sL'):format(acceptedType, consumingRate)
  
--EngergyType
+
            if (a ~= #itemTable.fluidsUsed) then
infobox = infobox .. '|-\n| Energietyp:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyType .. '\n'
+
                list = list .. ', '
+
            end
--Grid Radius
+
        end
infobox = infobox .. '|-\n| Gitterradius:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.gridRadius .. ' m\n'
+
        section = section .. sectionRow('Input', list)
+
    end
--Energy Produced
 
infobox = infobox .. '|-\n|Energie produziert:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyProduced .. ' J\n'
 
 
--Energy Used
 
infobox = infobox .. '|-\n| Energieverbrauch:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyUsed .. ' J\n'
 
end
 
  
-- 'Fuel' Section (if fuelsUsed by Object)
+
    --Output (liquidProduced)
if itemTable.fuelsUsed ~= nil then
+
    if itemTable.fluidsProduced ~= nil then
-- Fuel Header
+
        local list = ''
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Kraftstoffe\'\'\'\n'
+
        for a, b in ipairs(itemTable.fluidsProduced) do
+
            local producedType = b[1]
--Fuels Used by Object
+
            local pRateString = string.gsub(b[2], "%s+", "")
infobox = infobox .. '|-\n| Verwendete Kraftstoffe:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuelsUsed .. '\n'
+
            local producingRate = tonumber(pRateString)
end
+
            if (producingRate == 0) then
+
                producingRate = 'Rate of Input'
-- 'Fluid' section (if fludisUsed is not nil)   
+
            end
            if itemTable.fluidsUsed ~= nil then
+
            list = list .. L.t('%s at %sL'):format(producedType, producingRate)
            -- Liquid/Gas Header
+
            if (a ~= #itemTable.fluidsProduced) then
                infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Flüssigkeit / Gas\'\'\'\n'
+
                list = list .. ', '
           
+
            end
                --Input (fludisUsed)
+
        end
                infobox = infobox .. '|-\n|Eingang: \n| style=\"text-align: right; padding: 3px;\" | '
+
        section = section .. sectionRow('Output', list)
                    for a,b in ipairs(itemTable.fluidsUsed) do
+
    end
                        local acceptedType =  b[1]
+
 
                        local cRateString = string.gsub(b[2], "%s+", "")
+
    return section
                        local consumingRate = tonumber(cRateString)
+
end
                        infobox = infobox .. acceptedType .. ' at ' .. consumingRate .. ' L'
+
 
                        if (a ~= #itemTable.fluidsUsed) then
+
function roadItemsSection(itemTable, itemImageName)
                            infobox = infobox .. ', '
+
    section = sectionHeader('Road Object')
                        end
+
 
                    end
+
    -- Object Placed Image
                infobox = infobox .. '\n'
+
    section = section .. sectionImage(itemImageName, 'Placed')
+
    return section
--Output (liquidProduced)
+
end
infobox = infobox .. '|-\n| Ausgabe: \n| style=\"text-align: right; padding: 3px;\" | '
+
 
for a,b in ipairs(itemTable.fluidsProduced) do
+
function checkImage(imageName, suffix)
local producedType = b[1]
+
    local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. imageName .. '_' .. suffix .. '.png|[[Category:Pages_with_missing_' .. suffix:lower() .. ']]'
                        local pRateString = string.gsub(b[2], "%s+", "")
+
    if mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.png').file.exists then
                        local producingRate = tonumber(pRateString)
+
        image = imageName .. '_' .. suffix .. '.png'
if (producingRate == 0) then
+
    elseif mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.jpg').file.exists then
producingRate = 'Rate of Input'
+
        image = imageName .. '_' .. suffix .. '.jpg'
end
+
    end
infobox = infobox .. producedType .. ' at ' .. producingRate .. ' L'
+
    return image
if (a ~= #itemTable.fluidsProduced) then
+
end
infobox = infobox .. ', '
 
end
 
end
 
infobox = infobox .. '\n'
 
end
 
end
 
 
-- Road Object header (if group == Road Items)
 
if itemTable.group == 'Road Items' then
 
infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'Road Object\'\'\'\n'
 
 
-- Object Placed Image
 
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
 
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
 
image = itemimagename .. '_Placed.png'
 
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
 
image = itemimagename .. '_Placed.jpg'
 
end
 
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
 
end
 
 
infobox = infobox .. '|}'
 
return infobox
 
end
 
 
  
 
-- Main entry point for the Module
 
-- Main entry point for the Module
function p.ItemMain()
+
function p.ItemMain(frame)
 
     -- get args from the Template
 
     -- get args from the Template
     local args = norm()
+
     local args = Utils.normaliseArgs(frame)
   
+
 
 
     -- get item data
 
     -- get item data
     local itemData = require( "Module:ItemData" )
+
     local itemData = mw.loadData("Module:ItemData")
     return itemBox( args, itemData )
+
     return itemBox(args, itemData)
 
end
 
end
  
 
return p
 
return p

Aktuelle Version vom 16. März 2021, 17:04 Uhr

Dokumentation[Quelltext bearbeiten]

Dieses Modul bietet die Back-End-Funktionalität des Vorlage:Infobox_Item.

Wenn die Vorlage übergeben wird, wird eine Infobox mit Details aus den folgenden Modulen erstellt:

Translating Module[Quelltext bearbeiten]

This Module is a copy of the EN Module of the same name.
RULES FOR TRANSLATING THE LUA MODULES
IF IN DOUBT ASK IN DISCORD
IF ONLY 99.99% SURE ASK IN DISCORD
'string' --Anything using single quotes is a string HARDCODED in this file, these should be translated where appropriate.
'|- Valign \n' -- EXCEPTION if it looks like HTML styling,
local variable -- don't edit or change variable names
speciesTable.idealGrowthRate -- don't edit names of getters or methods

Credit[Quelltext bearbeiten]

Die von Pradoxzon erstellte Original-Infobox (jetzt als Infobox_Item bekannt) wurde von Nesphit und TreeNuts0 bearbeitet. Fyre (FishAus) und Scotty (ZeelNightwolf) haben das Infobox_Item weiter bearbeitet. Sie wurde dann dupliziert und als Basis für Infobox_Skill, Infobox_Plant und Infobox_Animal verwendet.


-- Credit: Original Infobox (now known as Infobox_Item) created by Pradoxzon was then edited by Nesphit and TreeNuts0. Fyre (FishAus) and Scotty (ZeelNightwolf) further edited the Infobox_Item. They then duplicated and used as a base for Infobox_Skill, Infobox_Plant, and Infobox_Animal.

local p = {}
local Utils = require('Module:Utils')
local L = require('Module:Localization')

-- Build an Item Infobox
function itemBox(args, itemData)
    -- check that all necessary arguments are passed correctly
    if args.name == nil or args.name == '' then
        return '\'name\' must be specified.'
    end

    local item = args.name
    local itemTable = itemData.items[item]

    if itemTable == nil then
        return item .. ' could not be found in Module:ItemData.'
    end

    local itemType = itemTable.type
    local itemEN = string.sub(itemType, 1, -5)
    local itemimagename = string.gsub(itemEN, ' ', '')

    -- string used to build the infobox
    local infobox = '{| class=\"infobox\"\n'

    -- 'Name and Image' section
    -- name of the item
    infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'

    -- the item's type (ItemData - group)
    infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '

    local text_colour = '#78B1FF'

    if itemTable.group == L.t('Food') then
        text_colour = '#85D66B'
    elseif itemTable.group == L.t('Skill Books') or itemTable.group == L.t('Skill Scrolls') then
        text_colour = '#FFCF4D'
    elseif itemTable.group == L.t('Skill Scrolls') then
        text_colour = '#FFCF4D'
    end

    infobox = infobox .. text_colour .. ';\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
    local icon = Utils.build_icon(item)
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | '..icon .. '\n'

    -- 'Description' section header
    infobox = infobox .. sectionHeader('Description')

    if itemTable.description == nil or itemTable.description == '' then
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'' .. L.t('None') .. '\'\'\'\n'
    else
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. itemTable.description .. '\n'
    end

    --Crafting
    local craftingRecipes = mw.loadData("Module:CraftingRecipes")

    infobox = infobox .. generalSection(item, itemTable, craftingRecipes, args)

    infobox = infobox .. IDsSection(itemTable)

    -- Tags Header
    if itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
        infobox = infobox .. tagSection(itemTable, itemData)
    end

    -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
    if itemTable.group == L.t('Block Items') or itemTable.group == L.t('World Object Items') then
        infobox = infobox .. placementSection(itemTable, itemimagename)

        -- Object Form Image
        if itemTable.group == L.t('Block Items') then
            infobox = infobox .. objectFormSection(itemTable, itemimagename)
        end

        -- 'Housing' section (if there is a Room Category)
        if itemTable.roomCategory ~= nil then
            infobox = infobox .. housingSection(itemTable)
        end

        -- 'Storage' Section (if inventorySlots is not nil)
        if itemTable.inventorySlots ~= nil then
            infobox = infobox .. storageSection(itemTable)
        end

        -- 'Power' section (if EngeryType is ``not nil)
        if itemTable.energyType ~= nil then
            infobox = infobox .. powerSection(itemTable)

        end

        -- 'Fuel' Section (if fuelsUsed by Object)
        if itemTable.fuelsUsed ~= nil then
            infobox = infobox .. fuelsSection(itemTable)
        end

        -- 'Fluid' section (if fludisUsed is not nil)
        if itemTable.fluidsUsed ~= nil or itemTable.fluidsProduced ~= nil then
            infobox = infobox .. fluidsSection(itemTable)
        end
    end

    -- Road Object header (if group == Road Items)
    if itemTable.group == L.t('Road Items') then
        infobox = infobox .. roadItemsSection(itemTable, itemimagename)
    end
    infobox = infobox .. '|}'
    return infobox
end

function sectionHeader(title, count)
    return "|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | '''" .. L.t(title, count) .. "'''\n"
end

function sectionRow(label, content, count, unit)
    if unit ~= nil then
        content = tonumber(content)
        unit = L.t(unit, content)
        local lang = mw.getContentLanguage()
        content = lang:formatNum(content)
    else
        unit = ''
    end
    return '|-\n| ' .. L.t(label, count) .. ':\n| style=\"text-align: right; padding: 3px;\" | ' .. content .. unit .. '\n'
end

function sectionImage(imageName, suffix)
    local image = checkImage(imageName, suffix)
    return '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
end

local function addToSet(set, key)
    set[key] = true
end

local function setNotContains(set, key)
    return set[key] == nil
end

local function craftingSubSection(title, item, productsOrIngredients, recipes)
    local stations = {}
    local sortStations = {}
    local stationString = ''
    for _, recipeName in ipairs(productsOrIngredients[item]) do
        local currentRecipe = recipes[recipeName]
        if currentRecipe ~= nil then
            if currentRecipe.variants[recipeName] ~= nil then
                local currentStation = currentRecipe.craftStn[1][1]
                if setNotContains(stations, currentStation) then
                    addToSet(stations, currentStation)
                end
            end
        end
    end

    if stations then
        for a, _ in pairs(stations) do
            table.insert(sortStations, a)
        end
        table.sort(sortStations)
        for i, n in ipairs(sortStations) do
            stationString = stationString .. ' [[' .. n .. ']]'
            if (n ~= sortStations[#sortStations]) then
                -- add a comma
                stationString = stationString .. ', '
            end
        end
        return sectionRow(title, stationString)
    else
        return sectionRow(title, L.t('N/A'))
    end
end

function generalSection(item, itemTable, craftingRecipes, args)
    -- 'General' section header
    section = sectionHeader('General')

    -- Is a product at these tables
    if craftingRecipes.products[item] ~= nil and Utils.tableLen(craftingRecipes.products[item]) >= 1 then
        section = section .. craftingSubSection('Created at', item, craftingRecipes.products, craftingRecipes.recipes)
    end

    -- Is an ingredient at these tables
    if craftingRecipes.ingredients[item] ~= nil and Utils.tableLen(craftingRecipes.ingredients[item]) >= 1 then
        section = section .. craftingSubSection('Used at', item, craftingRecipes.ingredients, craftingRecipes.recipes)
    end

    -- calories and nutrients (if itemTable.group == 'Food')
    if itemTable.group == L.t('Food') then
        section = section .. sectionRow('Calorie', itemTable.calories, tonumber(itemTable.calories), 'cal')
        section = section .. '|- valign=\"center\"\n| rowspan=\"4\" | ' .. L.t('Nutrients') .. ':\n'
        section = section .. '| style=\"color: red; text-align: right; padding: 3px;\" | ' .. L.t('Carbs') .. ': ' .. itemTable.carbs .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: orange; text-align: right; padding: 3px;\" | ' .. L.t('Protein') .. ': ' .. itemTable.protein .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: yellow; text-align: right; padding: 3px;\" | ' .. L.t('Fat') .. ': ' .. itemTable.fat .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | ' .. L.t('Vitamins') .. ': ' .. itemTable.vitamins .. '\n'
        section = section .. sectionRow('Nutrition Density', L.t('%s per 100 cals'):format(itemTable.density))
    end

    -- carried
    local carried
    if args.carried ~= nil and args.carried ~= '' then
        carried = args.carried
    else
        carried = itemTable.carried
    end
    section = section .. sectionRow('Carried in', carried)

    -- weight
    local weight
    if itemTable.weight ~= nil then
        weight = itemTable.weight
    else
        weight = '0.0'
    end
    section = section .. sectionRow('Weight', weight, nil, 'kg')

    -- stack limit
    if itemTable.maxStack ~= nil then
        section = section .. sectionRow('Stack limit', itemTable.maxStack)
    end

    -- yield
    if itemTable.yield ~= nil then
        section = section .. sectionRow('Improve Gathering', itemTable.yield)
    end

    -- fuel
    if itemTable.fuel ~= nil then
        section = section .. sectionRow('Fuel energy', itemTable.fuel, nil, 'J')
    end

    -- currency
    if itemTable.currency ~= nil then
        section = section .. "|- style=\"text-align: center;\"\n| colspan=\"2\" | " .. L.t('Can back a currency') .. "\n"
    end
    return section
end

function IDsSection(itemTable)
    -- 'IDs' section header
    section = sectionHeader('ID', 2)

    -- item id (type)
    section = section .. sectionRow('Item ID', itemTable.type)

    -- id number (type id)
    section = section .. sectionRow('ID Number', itemTable.typeID)

    return section
end

function tagSection(itemTable, itemData)
    -- Tags Header
    local tags = itemTable.tagGroups
    section = sectionHeader('Tag', Utils.tableLen(tags))
    local list = ''
    -- for each item in the list (a is position, b is value)
    for a, b in ipairs(tags) do
        --if not these tags listed here
        if (b ~= L.t('Object') or b ~= L.t('World  Object') or b ~= L.t('Housing  Object')) then
            -- add the tag to the list
            -- HACK: Some tag localisations have spaces in the tag name, but not in the tag data
            local tagLink
            -- Some tags have multiple spaces? Possible data quality issue
            bClean = b:gsub("%s+", " ")
            if itemData.tags[bClean] ~= nil then
                tagLink = L.t('%s Tag'):format(bClean)
            else
                tagLink = L.t('%s Tag'):format(bClean:gsub(' ', ''))
            end

            list = list .. '[[' .. tagLink .. '|' .. bClean .. ']][[Category:' .. bClean .. ']]'
        end
        -- if not the last item in the list
        if (b ~= tags[#tags]) then
            -- add a comma
            list = list .. ', '
        end
    end
    -- Now the list is made add it to the infobox
    section = section .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'

    return section
end

function placementSection(itemTable, itemImageName)
    section = sectionHeader('World Object')
    -- Object Placed Image
    section = section .. sectionImage(itemImageName, 'Placed')

    -- 'Placement' section
    --Placement Header
    section = section .. sectionHeader('Placement')

    --Vechile
    if itemTable.mobile ~= nil then
        section = section .. sectionRow('Vehicle/Mobile Object', itemTable.mobile)
    end

    --Dimensions
    if itemTable.footprint ~= nil then
        section = section .. sectionRow('Dimensions (X,Y,Z)', itemTable.footprint)
    end

    --Material Tier
    if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
        section = section .. sectionRow('Room Material', itemTable.materialTier) .. '[[Category:Tier ' .. itemTable.materialTier .. ']]\n'
    end

    --Room Req.
    if itemTable.roomContainReq ~= nil then
        section = section .. sectionRow('Room Required', itemTable.roomContainReq)
    end

    --Room Size. Req.
    if itemTable.roomSizeReq ~= nil then
        section = section .. sectionRow('Room Size', itemTable.roomSizeReq, nil, 'm³')
    end

    --Room Mat. Req.
    if itemTable.roomMatReq ~= nil then
        section = section .. sectionRow('Room Materials', itemTable.roomMatReq)
    end
    return section
end

function objectFormSection(itemTable, itemImageName)
    return sectionImage(itemImageName, 'Form')
end

function housingSection(itemTable)
    -- Housing Header
    section = sectionHeader('Housing')

    --roomCategory
    section = section .. sectionRow('Room Category', itemTable.roomCategory) .. '[[Category:' .. itemTable.roomCategory .. ']]\n'

    if itemTable.roomCategory ~= L.t('Industrial') then
        if itemTable.furnitureType ~= nil then
            --furnitureType
            section = section .. sectionRow('Furniture Type', itemTable.furnitureType) .. '[[Category:' .. itemTable.furnitureType .. ']]\n'

            --Value of the object
            section = section .. sectionRow('Value', itemTable.skillValue)

            --Dim. Return % of Object
            section = section .. sectionRow('Dim. Return %', itemTable.repeatsDepreciation * 100, nil, '%')
        end
    end

    if itemTable.roomCategory == L.t('Industrial') then
        section = section .. "|- style=\"background-color: #red; text-align: center;\"\n| colspan=\"2\" | '''" .. L.t('ALL ROOM VALUE LOST') .. "'''\n"
    end

    return section
end

function storageSection(itemTable)
    -- Storage Header
    section = sectionHeader('Storage')

    --Inventory Slots
    section = section .. sectionRow('Inventory Slots', itemTable.inventorySlots)

    --inventoryMaxWeight
    if itemTable.inventoryMaxWeight ~= nil then
        maxWeightKg = itemTable.inventoryMaxWeight / 1000
        section = section .. sectionRow('Inventory Max Weight', maxWeightKg, nil, 'kg')
    else
        section = section .. sectionRow('Inventory Max Weight', L.t('Unlimited'))
    end

    return section
end

function powerSection(itemTable)
    -- Power Header
    section = sectionHeader('Power')

    --EngergyType
    section = section .. sectionRow('Energy Type', itemTable.energyType) .. '[[Category:' .. itemTable.energyType .. ']]\n'

    --Grid Radius
    section = section .. sectionRow('Grid Radius', itemTable.gridRadius, nil, 'm')

    --Energy Produced
    section = section .. sectionRow('Energy Produced', itemTable.energyProduced, nil, 'w')

    --Energy Used
    section = section .. sectionRow('Energy Used', itemTable.energyUsed, nil, 'w')

    return section
end

function fuelsSection(itemTable)
    -- Fuel Header
    section = sectionHeader('Fuel')

    --Fuels Used by Object
    section = section .. sectionRow('Fuels Used', '[[' .. L.t('%s Tag'):format(itemTable.fuelsUsed:gsub('[%[%]]+', '')) .. ']]')

    return section
end

function fluidsSection(itemTable)
    -- Liquid/Gas Header
    section = sectionHeader('Liquid/Gas')

    --Input (fludisUsed)
    if itemTable.fluidsUsed ~= nil then
        local list = ''
        for a, b in ipairs(itemTable.fluidsUsed) do
            local acceptedType = b[1]
            local cRateString = string.gsub(b[2], "%s+", "")
            local consumingRate = tonumber(cRateString)
            list = list .. L.t('%s at %sL'):format(acceptedType, consumingRate)

            if (a ~= #itemTable.fluidsUsed) then
                list = list .. ', '
            end
        end
        section = section .. sectionRow('Input', list)
    end

    --Output (liquidProduced)
    if itemTable.fluidsProduced ~= nil then
        local list = ''
        for a, b in ipairs(itemTable.fluidsProduced) do
            local producedType = b[1]
            local pRateString = string.gsub(b[2], "%s+", "")
            local producingRate = tonumber(pRateString)
            if (producingRate == 0) then
                producingRate = 'Rate of Input'
            end
            list = list .. L.t('%s at %sL'):format(producedType, producingRate)
            if (a ~= #itemTable.fluidsProduced) then
                list = list .. ', '
            end
        end
        section = section .. sectionRow('Output', list)
    end

    return section
end

function roadItemsSection(itemTable, itemImageName)
    section = sectionHeader('Road Object')

    -- Object Placed Image
    section = section .. sectionImage(itemImageName, 'Placed')
    return section
end

function checkImage(imageName, suffix)
    local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. imageName .. '_' .. suffix .. '.png|[[Category:Pages_with_missing_' .. suffix:lower() .. ']]'
    if mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.png').file.exists then
        image = imageName .. '_' .. suffix .. '.png'
    elseif mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.jpg').file.exists then
        image = imageName .. '_' .. suffix .. '.jpg'
    end
    return image
end

-- Main entry point for the Module
function p.ItemMain(frame)
    -- get args from the Template
    local args = Utils.normaliseArgs(frame)

    -- get item data
    local itemData = mw.loadData("Module:ItemData")
    return itemBox(args, itemData)
end

return p