ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:Infobox Item: Difference between revisions

From Eco - English Wiki
[checked revision][unchecked revision]
m (Use mw.loadData to load static data once per page)
(Refactor infobox)
Line 3: Line 3:
local p = {}
local p = {}
local Utils = require('Module:Utils')
local Utils = require('Module:Utils')
local L = require('Module:Localization')


-- 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
 
  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: '
 
  if itemTable.group == 'Food' then
    infobox = infobox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
    -- Items:Food Icon Image
    local image = checkImage(itemimagename, 'Icon')
 
    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 == 'Skill Books' 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 == 'Skill Scrolls' then
    infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
    -- Items:Skill Scrolls Icon Image
    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'
 
  else
    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 .. sectionHeader('Description')
 
  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
 
  --Crafting
  local craftingRecipes = mw.loadData( "Module:CraftingRecipes" )
 
  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 == 'Block Items' or itemTable.group == 'World Object Items' then
    infobox = infobox .. placementSection(itemTable, itemimagename)
 
    -- Object Form Image
    if itemTable.group == '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
      
  end
local item = args.name
 
local itemTable = itemData.items[item]
  -- Road Object header (if group == Road Items)
  if itemTable.group == 'Road Items' then
     infobox = infobox .. roadItemsSection(itemTable, itemimagename)
  end
  infobox = infobox .. '|}'
  return infobox
end
 
local function addToSet(set, key)
  set[key] = true
end
 
local function setNotContains(set, key)
  return set[key] == nil
end
 
function generalSection(itemTable, craftingRecipes)
-- 'General' section header
  section = sectionHeader('General')
 
  local recipes = craftingRecipes.recipes
 


if itemTable == nil then
  -- Is a product at these tables
return item .. ' could not be found in Module:ItemData.'
  if craftingRecipes.products[item] ~= nil and #craftingRecipes.products[item] >= 1 then
end
    local count = 0
    local stations = {}
    local sortStations = {}
    local stationString = ''
    local found = false
    for k, v in ipairs( craftingRecipes.products[item] ) do
      if recipes[v] ~= nil then
        for num = 1, #recipes[v].numberOfVariants do
          if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
            if setNotContains(stations, recipes[v].craftStn[1][1]) then
              addToSet(stations, recipes[v].craftStn[1][1])
              count = count + 1
            end
            if found == false then
              found = true
              infobox = infobox .. '|-\n| Created At:\n| style=\"text-align: right; padding: 3px;\" |'
            end
          end
        end
      end
    end


     local itemType = itemTable.type
     local track = 0
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: '
if itemTable.group == 'Food' then
infobox = infobox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\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 == 'Skill Books' 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 == 'Skill Scrolls' then
infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- Items:Skill Scrolls Icon Image
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'
else
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\" | \'\'\'Description\'\'\'\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
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
   
--Crafting
local craftingRecipes = mw.loadData( "Module:CraftingRecipes" )
local recipes = craftingRecipes.recipes
local function addToSet(set, key)
set[key] = true
end
local function setNotContains(set, key)
return set[key] == nil
end
-- Is a product at these tables
if craftingRecipes.products[item] ~= nil and #craftingRecipes.products[item] >= 1 then
local count = 0
local stations = {}
local sortStations = {}
local stationString = ''
local found = false
for k, v in ipairs( craftingRecipes.products[item] ) do
if recipes[v] ~= nil then
for num = 1, #recipes[v].numberOfVariants do
if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
if setNotContains(stations, recipes[v].craftStn[1][1]) then
addToSet(stations, recipes[v].craftStn[1][1])
count = count + 1
end
if found == false then
found = true
infobox = infobox .. '|-\n| Created At:\n| style=\"text-align: right; padding: 3px;\" |'
end
end
end
end
end
local track = 0
if found == true then
for a, b in pairs(stations) do
table.insert(sortStations, a)
end
table.sort(sortStations)
for i, n in ipairs(sortStations) do
stationString = stationString .. ' [[' .. n .. ']]'
track = track + 1
if track ~= count then -- Changed these line to produce comma if not last table.
stationString = stationString .. ','
end
end
infobox = infobox .. stationString .. '\n'
else
infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
end
end
-- Is an ingredient at these tables
if craftingRecipes.ingredients[item] ~= nil and #craftingRecipes.ingredients[item] >= 1 then
local count = 0
local stations = {}
local sortStations = {}
local stationString = ''
local found = false
for k, v in ipairs( craftingRecipes.ingredients[item] ) do
if recipes[v] ~= nil then
for num = 1, #recipes[v].numberOfVariants do
if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
if setNotContains(stations, recipes[v].craftStn[1][1]) then
addToSet(stations, recipes[v].craftStn[1][1])
count = count + 1
end
if found == false then
found = true
infobox = infobox .. '|-\n| Used At:\n| style=\"text-align: right; padding: 3px;\" |'
end
end
end
end
end
local track = 0
if found == true then
for a, b in pairs(stations) do
table.insert(sortStations, a)
end
table.sort(sortStations)
for i, n in ipairs(sortStations) do
stationString = stationString .. ' [[' .. n .. ']]'
track = track + 1
if track ~= count then -- Changed these line to produce comma if not last table.
stationString = stationString .. ','
end
end
infobox = infobox .. stationString .. '\n'
else
infobox = infobox .. '|-\n| Used at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
end
end
-- calories and nutrients (if itemTable.group == 'Food')
if itemTable.group == 'Food' then
infobox = infobox .. '|-\n| Calories:\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;\" | Carbs: ' .. 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;\" | Fat: ' .. itemTable.fat .. '\n'
infobox = infobox .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | Vitamins: ' .. itemTable.vitamins .. '\n'
infobox = infobox .. '|-\n| Nutrition Density:\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| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.carried .. '\n'
else
infobox = infobox .. '|-\n| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.carried .. '\n'
end
   
-- weight
if itemTable.weight ~= nil then
infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | ' .. itemTable.weight .. ' kg\n'
else
infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | 0.00kg\n'
end
   
-- stack limit
if itemTable.maxStack ~= nil then
infobox = infobox .. '|-\n| Stack limit:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.maxStack .. '\n'
end
-- yield
if itemTable.yield ~= nil then
infobox = infobox .. '|-\n| Improve Gathering: \n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.yield .. '\n'
end
-- fuel
if itemTable.fuel ~= nil then
infobox = infobox .. '|-\n| Fuel energy:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuel .. ' J\n'
end
   
-- currency
if itemTable.currency ~= nil then
infobox = infobox .. '|-\n| Used as Currency:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.currency .. '\n'
end
    -- 'IDs' section header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'IDs\'\'\'\n'
   
-- item id (type)
infobox = infobox .. '|- valign=\"center\"\n| Item ID:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.type .. '\n'
   
-- id number (type id)
infobox = infobox .. '|- valign=\"center\"\n| ID Number:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.typeID .. '\n'


-- Tags Header
    if found == true then
if itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
      for a, b in pairs(stations) do
            -- Tags Header
        table.insert(sortStations, a)
            infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Tags\'\'\'\n'
      end
            local tags = itemTable.tagGroups
      table.sort(sortStations)
            local list = ''
      for i, n in ipairs(sortStations) do
            -- for each item in the list (a is position, b is value)          
        stationString = stationString .. ' [[' .. n .. ']]'
            for a,b in ipairs(tags) do
        track = track + 1
            --if not these tags listed here
        if track ~= count then -- Changed these line to produce comma if not last table.
                if (b ~='Object' or b ~= 'World  Object' or b ~= 'Housing  Object') then
          stationString = stationString .. ','
                    -- add the tag to the list
        end
                    -- HACK: Some tag localisations have spaces in the tag name, but not in the tag data
      end
                    local tagLink
      infobox = infobox .. stationString .. '\n'
                    -- Some tags have multiple spaces? Possible data quality issue
    else
                    bClean = b:gsub("%s+", " ")
      infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
                    if itemData.tags[bClean] ~= nil then
    end
                        tagLink = bClean .. 'Tag'
  end
                    else
                        tagLink = bClean:gsub(' ', '') .. 'Tag'
                    end


                    list = list .. '[[' .. tagLink ..'|' .. bClean ..']][[Category:' .. bClean .. ']]'
  -- Is an ingredient at these tables
                end
  if craftingRecipes.ingredients[item] ~= nil and #craftingRecipes.ingredients[item] >= 1 then
                -- if not the last item in the list
    local count = 0
                if (b ~= tags[#tags]) then
    local stations = {}
                    -- add a comma
    local sortStations = {}
                    list = list .. ', '
    local stationString = ''
                end
    local found = false
    for k, v in ipairs( craftingRecipes.ingredients[item] ) do
      if recipes[v] ~= nil then
        for num = 1, #recipes[v].numberOfVariants do
          if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
            if setNotContains(stations, recipes[v].craftStn[1][1]) then
              addToSet(stations, recipes[v].craftStn[1][1])
              count = count + 1
            end
            if found == false then
              found = true
              infobox = infobox .. '|-\n| Used At:\n| style=\"text-align: right; padding: 3px;\" |'
             end
             end
            -- Now the list is made add it to the infobox
          end
            infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
        end
      end
    end
 
    local track = 0
 
    if found == true then
      for a, b in pairs(stations) do
        table.insert(sortStations, a)
      end
      table.sort(sortStations)
      for i, n in ipairs(sortStations) do
        stationString = stationString .. ' [[' .. n .. ']]'
        track = track + 1
        if track ~= count then -- Changed these line to produce comma if not last table.
          stationString = stationString .. ','
         end
         end
      end
      infobox = infobox .. stationString .. '\n'
    else
      infobox = infobox .. '|-\n| Used at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
    end
  end
  -- calories and nutrients (if itemTable.group == 'Food')
  if itemTable.group == 'Food' then
    infobox = infobox .. '|-\n| Calories:\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;\" | Carbs: ' .. 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;\" | Fat: ' .. itemTable.fat .. '\n'
    infobox = infobox .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | Vitamins: ' .. itemTable.vitamins .. '\n'
    infobox = infobox .. '|-\n| Nutrition Density:\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| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.carried .. '\n'
  else
    infobox = infobox .. '|-\n| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.carried .. '\n'
  end
  -- weight
  if itemTable.weight ~= nil then
    infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | ' .. itemTable.weight .. ' kg\n'
  else
    infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | 0.00kg\n'
  end


    -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
  -- stack limit
if itemTable.group == 'Block Items' or itemTable.group == 'World Object Items' then
  if itemTable.maxStack ~= nil then
infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'World Object\'\'\'\n'
    infobox = infobox .. '|-\n| Stack limit:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.maxStack .. '\n'
  end
-- 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\" | \'\'\'Placement\'\'\'\n'


--Vechile
  -- yield
if itemTable.mobile ~= nil then
  if itemTable.yield ~= nil then
infobox = infobox .. '|-\n| Vehicle/Mobile Object:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.mobile .. '\n'
    infobox = infobox .. '|-\n| Improve Gathering: \n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.yield .. '\n'
end
  end
--Dimensions
if itemTable.footprint ~= nil then
infobox = infobox .. '|-\n| Dimensions (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| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '[[Category:Tier '.. itemTable.materialTier ..']]\n'
end
--Room Req.
if itemTable.roomContainReq ~= nil then
infobox = infobox .. '|-\n| Room Required:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
end
--Room Size. Req.
if itemTable.roomSizeReq ~= nil then
infobox = infobox .. '|-\n| Room Size:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' m³\n'
end
--Room Mat. Req.
if itemTable.roomMatReq ~= nil then
infobox = infobox .. '|-\n| Room Materials:\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)
  -- fuel
if itemTable.roomCategory ~= nil then
  if itemTable.fuel ~= nil then
-- Housing Header
     infobox = infobox .. '|-\n| Fuel energy:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuel .. ' J\n'
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
  end
      
--roomCategory
infobox = infobox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '[[Category:' .. itemTable.roomCategory .. ']]\n'


if itemTable.roomCategory ~= 'Industrial' then
  -- currency
if itemTable.furnitureType ~= nil then  
  if itemTable.currency ~= nil then
--furnitureType
    infobox = infobox .. '|-\n| Used as Currency:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.currency .. '\n'
infobox = infobox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '[[Category:' .. itemTable.furnitureType .. ']]\n'
  end
           
  return section
--Value of the object
end
infobox = infobox .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
           
--Dim. Return % of Object 
infobox = infobox .. '|-\n| Dim. Return %:\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\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\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\" | \'\'\'Storage\'\'\'\n'


--Inventory Slots
function sectionHeader(title, count)
infobox = infobox .. '|-\n| Inventory Slots:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.inventorySlots .. '\n'
  return [[|- style="background-color: #4688C0; text-align: center;"\n| colspan="2" | ''']] .. L.t(title, count) .. [['''\n]]
end
--inventoryMaxWeight
if itemTable.inventoryMaxWeight ~= nil then
maxWeightKg = itemTable.inventoryMaxWeight/1000
infobox = infobox .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | ' .. maxWeightKg .. ' Kg\n'
else
infobox = infobox .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | Unlimited \n'
end
end


-- 'Power' section (if EngeryType is ``not nil)
function IDsSection(itemTable)
if itemTable.energyType ~= nil then 
  -- 'IDs' section header
-- Power Header
  section = sectionHeader('ID', 2)
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Power\'\'\'\n'


--EngergyType
  -- item id (type)
infobox = infobox .. '|-\n| Energy Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyType .. '[[Category:' .. itemTable.energyType .. ']]\n'
  section = section .. '|- valign=\"center\"\n| Item ID:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.type .. '\n'
--Grid Radius
infobox = infobox .. '|-\n| Grid Radius:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.gridRadius .. ' m\n'
--Energy Produced
infobox = infobox .. '|-\n| Energy Produced:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyProduced .. 'W\n'
--Energy Used
infobox = infobox .. '|-\n| Energy Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyUsed .. 'W\n'
end


-- 'Fuel' Section (if fuelsUsed by Object)
  -- id number (type id)
if itemTable.fuelsUsed ~= nil then
  section = section .. '|- valign=\"center\"\n| ID Number:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.typeID .. '\n'
-- Fuel Header
 
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Fuel\'\'\'\n'
  return section
end
--Fuels Used by Object
 
infobox = infobox .. '|-\n| Fuels Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuelsUsed .. '\n'
function tagSection(itemTable, itemData)
end
  -- Tags Header
  local tags = itemTable.tagGroups
-- 'Fluid' section (if fludisUsed is not nil)   
  section = sectionHeader('Tag', Utils.tableLen(tags))
            if itemTable.fluidsUsed ~= nil or itemTable.fluidsProduced ~= nil then  
  local list = ''
            -- Liquid/Gas Header
  -- for each item in the list (a is position, b is value)           
                infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Liquid/Gas\'\'\'\n'
  for a,b in ipairs(tags) do
           
    --if not these tags listed here
                --Input (fludisUsed)
    if (b ~=L.t('Object') or b ~= L.t('World  Object') or b ~= L.t('Housing  Object')) then
                if itemTable.fluidsUsed ~= nil then
      -- add the tag to the list
                infobox = infobox .. '|-\n| Input: \n| style=\"text-align: right; padding: 3px;\" | '  
      -- HACK: Some tag localisations have spaces in the tag name, but not in the tag data
                if itemTable.fluidsUsed ~= nil then
      local tagLink
                    for a,b in ipairs(itemTable.fluidsUsed) do
      -- Some tags have multiple spaces? Possible data quality issue
                        local acceptedType = b[1]
      bClean = b:gsub("%s+", " ")
                        local cRateString = string.gsub(b[2], "%s+", "")
      if itemData.tags[bClean] ~= nil then
                        local consumingRate = tonumber(cRateString)
        tagLink = bClean .. L.t('Tag')
                        infobox = infobox .. acceptedType .. ' at ' .. consumingRate .. ' L'
      else
                        if (a ~= #itemTable.fluidsUsed) then
        tagLink = bClean:gsub(' ', '') .. L.t('Tag')
                            infobox = infobox .. ', '
      end
                        end
 
                    end
      list = list .. '[[' .. tagLink ..'|' .. bClean ..']][[Category:' .. bClean .. ']]'
                end
    end
                infobox = infobox .. '\n'
    -- if not the last item in the list
            end
    if (b ~= tags[#tags]) then
      -- add a comma
--Output (liquidProduced)
      list = list .. ', '
if itemTable.fluidsProduced ~= nil then
    end
infobox = infobox .. '|-\n| Output: \n| style=\"text-align: right; padding: 3px;\" | '
  end
for a,b in ipairs(itemTable.fluidsProduced) do
  -- Now the list is made add it to the infobox
local producedType = b[1]
  section = section .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
                        local pRateString = string.gsub(b[2], "%s+", "")
 
                        local producingRate = tonumber(pRateString)
  return section
if (producingRate == 0) then
end
producingRate = 'Rate of Input'
 
end
function placementSection(itemTable, itemImageName)
infobox = infobox .. producedType .. ' at ' .. producingRate .. ' L'
  section = sectionHeader('World Object')
if (a ~= #itemTable.fluidsProduced) then
-- Object Placed Image
infobox = infobox .. ', '
  local image = checkImage(itemImageName, 'Placed')
end
  section = section .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
end
 
infobox = infobox .. '\n'
  -- 'Placement' section
end
  --Placement Header
end
  section = section .. sectionHeader('Placement')
end
 
  --Vechile
-- Road Object header (if group == Road Items)
  if itemTable.mobile ~= nil then
if itemTable.group == 'Road Items' then
    section = section .. '|-\n| Vehicle/Mobile Object:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.mobile .. '\n'
infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'Road Object\'\'\'\n'
  end
 
-- Object Placed Image
  --Dimensions
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
  if itemTable.footprint ~= nil then
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
    section = section .. '|-\n| Dimensions (X,Y,Z):\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.footprint .. '\n'
image = itemimagename .. '_Placed.png'
  end
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
 
image = itemimagename .. '_Placed.jpg'
  --Material Tier
end
  if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
    section = section .. '|-\n| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '[[Category:Tier '.. itemTable.materialTier ..']]\n'
end
  end
 
infobox = infobox .. '|}'
  --Room Req.
return infobox
  if itemTable.roomContainReq ~= nil then
end
    section = section .. '|-\n| Room Required:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
  end
 
  --Room Size. Req.
  if itemTable.roomSizeReq ~= nil then
    section = section .. '|-\n| Room Size:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' m³\n'
  end
 
  --Room Mat. Req.
  if itemTable.roomMatReq ~= nil then
    section = section .. '|-\n| Room Materials:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomMatReq .. '\n'
  end
  return section
end
 
function objectFormSection(itemTable, itemImageName)
  local image = checkImage(itemImageName, '_Form')
  return '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
end
 
function housingSection(itemTable)
-- Housing Header
  section = sectionHeader('Housing')
 
  --roomCategory
  section = section .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '[[Category:' .. itemTable.roomCategory .. ']]\n'
 
  if section.roomCategory ~= 'Industrial' then
    if section.furnitureType ~= nil then
      --furnitureType
      section = section .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '[[Category:' .. itemTable.furnitureType .. ']]\n'
 
      --Value of the object
      section = section .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
 
      --Dim. Return % of Object 
      section = section .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'   
    end
  end
 
  if itemTable.roomCategory == 'Industrial' then
    section = section .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
  end
 
  return section
end
 
function storageSection(itemTable)
  -- Storage Header
  section = sectionHeader('Storage')
 
  --Inventory Slots
  section = section .. '|-\n| Inventory Slots:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.inventorySlots .. '\n'
 
  --inventoryMaxWeight
  if itemTable.inventoryMaxWeight ~= nil then
    maxWeightKg = itemTable.inventoryMaxWeight/1000
    section = section .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | ' .. maxWeightKg .. ' Kg\n'
  else
    section = section .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | Unlimited \n'
  end
 
  return section
end
 
 
function powerSection(itemTable)
  -- Power Header
  section = sectionHeader('Power')
 
  --EngergyType
  section = section .. '|-\n| Energy Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyType .. '[[Category:' .. itemTable.energyType .. ']]\n'
 
  --Grid Radius
  section = section .. '|-\n| Grid Radius:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.gridRadius .. ' m\n'
 
  --Energy Produced
  section = section .. '|-\n| Energy Produced:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyProduced .. 'W\n'
 
  --Energy Used
  section = section .. '|-\n| Energy Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyUsed .. 'W\n'
 
  return section
end
 
function fuelsSection(itemTable)
  -- Fuel Header
  section = sectionHeader('Fuel')
 
  --Fuels Used by Object
  section = section .. '|-\n| Fuels Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuelsUsed .. '\n'
 
  return section
end
 
function fluidsSection(itemTable)
-- Liquid/Gas Header
  section = sectionHeader('Liquid/Gas')
 
--Input (fludisUsed)
  if itemTable.fluidsUsed ~= nil then
    section = section .. '|-\n| Input: \n| style=\"text-align: right; padding: 3px;\" | '
    if itemTable.fluidsUsed ~= nil then
      for a,b in ipairs(itemTable.fluidsUsed) do
        local acceptedType =  b[1]
        local cRateString = string.gsub(b[2], "%s+", "")
        local consumingRate = tonumber(cRateString)
        section = section .. acceptedType .. ' at ' .. consumingRate .. ' L'
        if (a ~= #itemTable.fluidsUsed) then
          section = section .. ', '
        end
      end
    end
    section = section .. '\n'
  end
 
--Output (liquidProduced)
  if itemTable.fluidsProduced ~= nil then
    section = section .. '|-\n| Output: \n| style=\"text-align: right; padding: 3px;\" | '
    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
      section = section .. producedType .. ' at ' .. producingRate .. ' L'
      if (a ~= #itemTable.fluidsProduced) then
        section = section .. ', '
      end
    end
    section = section .. '\n'
  end
 
 
return section
end
 
function roadItemsSection(itemTable, itemImageName)
  section = sectionHeader('Road Object')
 
  -- Object Placed Image
  local image = checkImage(itemImageName, 'Placed')
  section = section .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
  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
-- Main entry point for the Module
function p.ItemMain(frame)
function p.ItemMain(frame)
    -- get args from the Template
  -- get args from the Template
    local args = Utils.normaliseArgs(frame)
  local args = Utils.normaliseArgs(frame)
   
 
    -- get item data
  -- get item data
    local itemData = mw.loadData( "Module:ItemData" )
  local itemData = mw.loadData( "Module:ItemData" )
    return itemBox( args, itemData )
  return itemBox( args, itemData )
end
end


return p
return p

Revision as of 00:50, 1 March 2021

Documentation

This module provides the back end functionality of the Template:Infobox_Item.

If the template is passed an Infobox will be made using details from the following Modules:

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.


-- 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: '

  if itemTable.group == 'Food' then
    infobox = infobox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
    -- Items:Food Icon Image
    local image = checkImage(itemimagename, 'Icon')

    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 == 'Skill Books' 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 == 'Skill Scrolls' then
    infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
    -- Items:Skill Scrolls Icon Image
    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'

  else
    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 .. sectionHeader('Description')

  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

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

  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 == 'Block Items' or itemTable.group == 'World Object Items' then
    infobox = infobox .. placementSection(itemTable, itemimagename)				

    -- Object Form Image
    if itemTable.group == '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 == 'Road Items' then
    infobox = infobox .. roadItemsSection(itemTable, itemimagename)
  end
  infobox = infobox .. '|}'
  return infobox
end

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

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

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

  local recipes = craftingRecipes.recipes


  -- Is a product at these tables
  if craftingRecipes.products[item] ~= nil and #craftingRecipes.products[item] >= 1 then
    local count = 0
    local stations = {}
    local sortStations = {}
    local stationString = ''
    local found = false
    for k, v in ipairs( craftingRecipes.products[item] ) do
      if recipes[v] ~= nil then
        for num = 1, #recipes[v].numberOfVariants do	
          if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
            if setNotContains(stations, recipes[v].craftStn[1][1]) then
              addToSet(stations, recipes[v].craftStn[1][1])
              count = count + 1
            end	
            if found == false then
              found = true
              infobox = infobox .. '|-\n| Created At:\n| style=\"text-align: right; padding: 3px;\" |'
            end
          end
        end
      end
    end

    local track = 0

    if found == true then
      for a, b in pairs(stations) do
        table.insert(sortStations, a)
      end
      table.sort(sortStations)
      for i, n in ipairs(sortStations) do				
        stationString = stationString .. ' [[' .. n .. ']]'
        track = track + 1
        if track ~= count then -- Changed these line to produce comma if not last table.
          stationString = stationString .. ','
        end
      end
      infobox = infobox .. stationString .. '\n'		
    else
      infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
    end
  end

  -- Is an ingredient at these tables
  if craftingRecipes.ingredients[item] ~= nil and #craftingRecipes.ingredients[item] >= 1 then
    local count = 0
    local stations = {}
    local sortStations = {}
    local stationString = ''
    local found = false
    for k, v in ipairs( craftingRecipes.ingredients[item] ) do
      if recipes[v] ~= nil then
        for num = 1, #recipes[v].numberOfVariants do	
          if (recipes[v].variants[v] ~= nil and recipes[v].numberOfVariants <= tostring(1)) then
            if setNotContains(stations, recipes[v].craftStn[1][1]) then
              addToSet(stations, recipes[v].craftStn[1][1])
              count = count + 1
            end	
            if found == false then
              found = true
              infobox = infobox .. '|-\n| Used At:\n| style=\"text-align: right; padding: 3px;\" |'
            end
          end
        end
      end
    end

    local track = 0

    if found == true then
      for a, b in pairs(stations) do
        table.insert(sortStations, a)
      end
      table.sort(sortStations)
      for i, n in ipairs(sortStations) do				
        stationString = stationString .. ' [[' .. n .. ']]'
        track = track + 1
        if track ~= count then -- Changed these line to produce comma if not last table.
          stationString = stationString .. ','
        end
      end
      infobox = infobox .. stationString .. '\n'		
    else
      infobox = infobox .. '|-\n| Used at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
    end
  end

  -- calories and nutrients (if itemTable.group == 'Food')
  if itemTable.group == 'Food' then
    infobox = infobox .. '|-\n| Calories:\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;\" | Carbs: ' .. 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;\" | Fat: ' .. itemTable.fat .. '\n'
    infobox = infobox .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | Vitamins: ' .. itemTable.vitamins .. '\n'
    infobox = infobox .. '|-\n| Nutrition Density:\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| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.carried .. '\n'
  else
    infobox = infobox .. '|-\n| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.carried .. '\n'
  end

  -- weight
  if itemTable.weight ~= nil then
    infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | ' .. itemTable.weight .. ' kg\n'
  else
    infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | 0.00kg\n'
  end

  -- stack limit
  if itemTable.maxStack ~= nil then
    infobox = infobox .. '|-\n| Stack limit:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.maxStack .. '\n'
  end

  -- yield 
  if itemTable.yield ~= nil then
    infobox = infobox .. '|-\n| Improve Gathering: \n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.yield .. '\n'
  end 	

  -- fuel
  if itemTable.fuel ~= nil then
    infobox = infobox .. '|-\n| Fuel energy:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuel .. ' J\n'
  end

  -- currency
  if itemTable.currency ~= nil then
    infobox = infobox .. '|-\n| Used as Currency:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.currency .. '\n'
  end
  return section
end

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

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

  -- item id (type)
  section = section .. '|- valign=\"center\"\n| Item ID:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.type .. '\n'

  -- id number (type id)
  section = section .. '|- valign=\"center\"\n| ID Number:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.typeID .. '\n'

  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 = bClean .. L.t('Tag')
      else
        tagLink = bClean:gsub(' ', '') .. L.t('Tag')
      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
  local image = checkImage(itemImageName, 'Placed')
  section = section .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'

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

  --Vechile
  if itemTable.mobile ~= nil then
    section = section .. '|-\n| Vehicle/Mobile Object:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.mobile .. '\n'
  end			

  --Dimensions 
  if itemTable.footprint ~= nil then
    section = section .. '|-\n| Dimensions (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
    section = section .. '|-\n| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '[[Category:Tier '.. itemTable.materialTier ..']]\n'
  end

  --Room Req.
  if itemTable.roomContainReq ~= nil then
    section = section .. '|-\n| Room Required:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
  end	

  --Room Size. Req.
  if itemTable.roomSizeReq ~= nil then
    section = section .. '|-\n| Room Size:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' m³\n'
  end

  --Room Mat. Req.
  if itemTable.roomMatReq ~= nil then
    section = section .. '|-\n| Room Materials:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomMatReq .. '\n'
  end	
  return section
end

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

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

  --roomCategory
  section = section .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '[[Category:' .. itemTable.roomCategory .. ']]\n'

  if section.roomCategory ~= 'Industrial' then
    if section.furnitureType ~= nil then 
      --furnitureType
      section = section .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '[[Category:' .. itemTable.furnitureType .. ']]\n'

      --Value of the object
      section = section .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'

      --Dim. Return % of Object  
      section = section .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'    
    end
  end

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

  return section
end

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

  --Inventory Slots
  section = section .. '|-\n| Inventory Slots:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.inventorySlots .. '\n'

  --inventoryMaxWeight
  if itemTable.inventoryMaxWeight ~= nil then
    maxWeightKg = itemTable.inventoryMaxWeight/1000
    section = section .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | ' .. maxWeightKg .. ' Kg\n'
  else
    section = section .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | Unlimited \n'
  end

  return section
end


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

  --EngergyType 
  section = section .. '|-\n| Energy Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyType .. '[[Category:' .. itemTable.energyType .. ']]\n'

  --Grid Radius
  section = section .. '|-\n| Grid Radius:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.gridRadius .. ' m\n'

  --Energy Produced
  section = section .. '|-\n| Energy Produced:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyProduced .. 'W\n'

  --Energy Used
  section = section .. '|-\n| Energy Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyUsed .. 'W\n'	

  return section
end

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

  --Fuels Used by Object
  section = section .. '|-\n| Fuels Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuelsUsed .. '\n'

  return section
end

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

--Input (fludisUsed) 
  if itemTable.fluidsUsed ~= nil then
    section = section .. '|-\n| Input: \n| style=\"text-align: right; padding: 3px;\" | ' 
    if itemTable.fluidsUsed ~= nil then
      for a,b in ipairs(itemTable.fluidsUsed) do
        local acceptedType =  b[1]
        local cRateString = string.gsub(b[2], "%s+", "")
        local consumingRate = tonumber(cRateString)
        section = section .. acceptedType .. ' at ' .. consumingRate .. ' L'
        if (a ~= #itemTable.fluidsUsed) then
          section = section .. ', '
        end
      end
    end
    section = section .. '\n'
  end

--Output (liquidProduced)
  if itemTable.fluidsProduced ~= nil then
    section = section .. '|-\n| Output: \n| style=\"text-align: right; padding: 3px;\" | '
    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
      section = section .. producedType .. ' at ' .. producingRate .. ' L'
      if (a ~= #itemTable.fluidsProduced) then
        section = section .. ', '
      end
    end
    section = section .. '\n'
  end


return section
end

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

  -- Object Placed Image
  local image = checkImage(itemImageName, 'Placed')
  section = section .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
  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