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.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Module:Infobox Item: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 1: Line 1:
-- 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 = {}
-- Header for the wikitable
function header( args )
    local headerStr = '{| class=\"wikitable mw-collapsible\" style=\"text-align: center;\"\n|-\n'


-- Grabs args from the parent frame
    -- Show or hide the Crafting Station column
-- Trims and parses the args into a table, then returns the table
    if args[1] == '1' then
function norm()
         headerStr = headerStr .. '! Crafting Station !'
    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
     end
      
 
     return args
    -- Item, Level Needed, Materials, Related Specialty
     headerStr = headerStr .. '! colspan=\"4\" | Item !! colspan=\"4\" | Materials !! Level Needed !! Crafting Time <br>(mins) !! Labour Cost || XP Gain !! style="width: 100px" | Related <br> Specialty\n'
 
     return headerStr
end
end


-- Build an Item Infobox
function imagedisp( name )
function itemBox( args, itemData )
    local str = ''
     -- check that all necessary arguments are passed correctly
local image = ''
     if args.name == nil or args.name == '' then
     -- Manual override for image file
        return '\'name\' must be specified.'
     if name then
    end
image = string.gsub(name, ' ', '') .. '_Icon.png'
      
str = str .. ' <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|center|50px|link=' .. name .. '|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> '
local item = args.name
else
local itemTable = itemData.items[item]
image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. name .. '_Icon.png'
str = str .. '[[File:' .. image .. '|frameless|50px|class=iconBlue]]'
end
str = str .. '<br> [[' .. name .. ']]'
return str
end
 
function stationcell( args )
  local str = ''
str = str .. '| ' .. imagedisp(args[1])
return str
end
 
 
function itemcell( args )
     local str = ''
str = str .. '| ' .. imagedisp(args[1])
str = str .. '<br>x' .. args[2] .. '\n'
return str
end
 
function skillreqcell( args )
    local str = ''
str = str .. '| ' .. imagedisp(args[1])
str = str .. '<br> Level ' .. args[2] .. ' \n'
return str
end


if itemTable == nil then
function groupedskillcell( args )
return item .. ' could not be found in Module:ItemData.'
    local str = ''
str = str .. '| ' .. imagedisp(args[1])
if args[2] ~= nil then
str = str .. ' <br> ' .. imagedisp(args[2])
end
end
return str
end


    local itemType = itemTable.type
-- Create a wikitable of recipes
local itemEN = string.sub (itemType, 1, -5)
function p.main( recipes )
local itemimagename = string.gsub(itemEN, ' ', '')
    local rows = ''
      
     -- string used to build the infobox
     --Not relevant for v0.9
     local infobox = '{| class=\"infobox\"\n'
     -- find number of times each Affect by Skill occurs
      
     --local prevSkill = recipes[1].efficiencySkills[1]
-- 'Name and Image' section
    --local skillIndex = {}
-- name of the item
     --local prevSkillnum = 0
infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
--local count = 0
   
    --for num = 1, #recipes do
-- the item's type (ItemData - group)
--if prevSkill ~= recipes[num].efficiencySkills[1] then
infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
--skillIndex[#skillIndex + 1] = prevSkillnum + count
--prevSkillnum = 1
--if #recipes[num].ingredients > 4 then
--count = 1
--else
--count = 0
--end
--prevSkill = recipes[num].efficiencySkills[1]
--else
--prevSkillnum = prevSkillnum + 1
--if #recipes[num].ingredients > 4 then
--count = count + 1
--end
--end
    --end
    --skillIndex[#skillIndex + 1] = prevSkillnum + count
if itemTable.group == 'Food' then
    -- Get each row
infobox = infobox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
    local j = 0
-- Items:Food Icon Image
    local k = 1
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
    for i = 1, #recipes do
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
 
image = itemimagename .. '_Icon.png'
-- get information from the current recipe for building
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
local checkImage = recipes[i].checkImage
image = itemimagename .. '_Icon.jpg'
local craftStn = recipes[i].craftStn
end
local skillNeeds = recipes[i].skillNeeds
--use last variant as this is always the default variant
    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'
local numberOfVariants = recipes[i].numberOfVariants
local products = {{'',''}}
local ingredients = {{'',''}}
elseif itemTable.group == 'Skill Books' then
--loop through variants to select default variant ingredients
infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
for k, v in pairs(recipes[i].variants) do
-- Items:Skill Book Icon Image
--given pairs doesn't guarantee order, check that product matches default variant
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'
if v.products[1][1] == recipes[i].defaultVariant then
ingredients = v.ingredients
elseif itemTable.group == 'Skill Scrolls' then
products = v.products
infobox = infobox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
else
-- Items:Skill Scrolls Icon Image
--handle scenarios where product ~= default variant (for example Refine Tallow)
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'
ingredients = v.ingredients
products = v.products
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
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
end
   
local baseCraftTime = recipes[i].baseCraftTime
  -- 'Description' section header
local baseLaborCost = recipes[i].baseLaborCost
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Description\'\'\'\n'
local baseXPGain = recipes[i].baseXPGain
-- determine the size needed for products to display correctly
local ingrednum = #ingredients
local rowspan = '|'
local rowspanProducts = '|'
if itemTable.description == nil then
--Code to incorporate rowspan for ingrediants and variants here
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'None\'\'\'\n'
local rowspanCount = 0
elseif itemTable.description == '' then
 
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'None\'\'\'\n'
--accomodate both variants and multiple ingredients
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'
   
-- -- created at
-- local craftingRecipes = require( "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
-- if craftingRecipes.items[item] ~= nil and #craftingRecipes.items[item] >= 1 then
-- local count = 0
-- local stations = {}
-- local sortStations = {}
-- local stationString = ''
-- local found = false
-- for k, v in ipairs( craftingRecipes.items[item] ) do
-- 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]) then
-- addToSet(stations, recipes[v].craftStn[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
-- local track = 0
if ingrednum > 4 then
-- if found == true then
rowspanCount = rowspanCount + 2
-- 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
-- elseif args.created ~= nil and args.created ~= '' then
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.created .. '\n'
-- else
-- infobox = infobox .. '|-\n| Created at:\n| style=\"text-align: right; padding: 3px;\" | N/A\n'
-- 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
end
--suspect there will be a bug here for many variants & many ingredients - might need x2 multipler per variant.
-- carried
if(#recipes == 1) then --only add variant rowspans if there is one recipe (i.e. variants will be displayed)
if args.carried ~= nil and args.carried ~= '' then
if tonumber(recipes[i].numberOfVariants) > 1 then
infobox = infobox .. '|-\n| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. args.carried .. '\n'
rowspanCount = rowspanCount + tonumber(recipes[i].numberOfVariants)
else
rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
infobox = infobox .. '|-\n| Carried in:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.carried .. '\n'
end
end
end
   
if rowspanCount > 0 then
-- weight
rowspan = '| rowspan=\"' .. rowspanCount .. '\" '
if itemTable.weight ~= nil then
if(#recipes > 1) then
infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | ' .. itemTable.weight .. ' kg\n'
rowspanProducts = '| rowspan=\"' .. rowspanCount .. '\" '
else
else
infobox = infobox .. '|-\n| Weight:\n| style="text-align: right; padding: 3px;" | 0.00kg\n'
rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
end
end
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 itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
--original rowspan working
            -- Tags Header
--if ingrednum > 4 then
            infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Tags\'\'\'\n'
-- rowspan = '| rowspan=\"2\" '
            local tags = itemTable.tagGroups
--end
            local list = ''
            -- for each item in the list (a is position, b is value)           
-- String to return
            for a,b in ipairs(tags) do
local row = '|-\n'
            --if not these tags listed here
                if (b ~='[[Object]]' or b ~= '[[World  Object]]' or b ~= '[[Housing  Object]]') then
                    -- add the tag to the list
                    list = list .. b
                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
            infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
        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 .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'World Object\'\'\'\n'
-- Object Placed Image
-- Add new row if products or ingredients are passed in with at least 1 item
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
if (products[1] and ingredients[1]) then
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
     
image = itemimagename .. '_Placed.png'
-- Show or hide the Crafting Station column
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
if recipes[i].dispCraftStn == '1' then
image = itemimagename .. '_Placed.jpg'
row = row .. rowspan .. stationcell({craftStn[1]}) .. '\n'
end
end
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
       
 
-- Add the products columns
-- 'Placement' section
local prodnum = #products
--Placement Header
for a = 1, prodnum do
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Placement\'\'\'\n'
if prodnum == 1 then
row = row .. rowspanProducts .. ' colspan=\"4\" '
end
if ((prodnum == 2) or (prodnum == 3 and a == 2)) then
row = row .. rowspanProducts .. ' colspan=\"2\" '
end
row = row .. itemcell({products[a][1], products[a][2]})
end
-- Add the FIRST row of Ingredients column
local numing = ingrednum
if ingrednum > 4 then
numing = 4
end
for b = 1, numing do
if (ingrednum == 1) then
row = row .. '| colspan=\"4\" '
end
if ((ingrednum == 2) or (ingrednum == 3 and b == 2)) then
row = row .. '| colspan=\"2\" '
end
row = row .. itemcell({ingredients[b][2], ingredients[b][3]})
end


--Vechile
-- Add the Skill needed column
if itemTable.mobile ~= nil then
if (skillNeeds[1] ~= '' and skillNeeds[1] ~= nil) then
infobox = infobox .. '|-\n| Vehicle/Mobile Object:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.mobile .. '\n'
row = row .. rowspan .. skillreqcell({skillNeeds[1][1], skillNeeds[1][2]})
end
else
row = row .. rowspan
if ingrednum > 4 then
row = row .. '|'
end
row = row .. ' \'\'None\'\' \n'
end
-- Add the Crafting time column
row = row .. rowspan
if rowspanCount > 1 then
row = row .. '|'
end
if baseCraftTime then
row = row .. baseCraftTime .. '\n'
else
--Dimensions
row = row .. rowspan .. ' \'\'missing\'\' \n'
if itemTable.footprint ~= nil then
infobox = infobox .. '|-\n| Dimensions (X,Y,Z):\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.footprint .. '\n'
end
end
--Material Tier
-- Add the Labour time column
if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
row = row .. rowspan
infobox = infobox .. '|-\n| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '\n'
if rowspanCount > 1 then
row = row .. '|'
end
if baseLaborCost then
row = row .. baseLaborCost .. '\n'
else
row = row .. rowspan .. ' \'\'missing\'\' \n'
end
end
--Room Req.
-- Add the XP gain column
if itemTable.roomContainReq ~= nil then
row = row .. rowspan
infobox = infobox .. '|-\n| Room Required:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
if rowspanCount > 1 then
end
row = row .. '|'
end
--Room Size. Req.
if baseXPGain then
if itemTable.roomSizeReq ~= nil then
row = row .. baseXPGain .. '\n'
infobox = infobox .. '|-\n| Room Size:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' \n'
else
row = row .. rowspan .. ' \'\'missing\'\' \n'
end
end
--Room Mat. Req.
-- not in v0.9
if itemTable.roomMatReq ~= nil then
-- Add the Affect by Skills column IF new skill grouping
infobox = infobox .. '|-\n| Room Materials:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomMatReq .. '\n'
--if j == 0 and (recipes[i].efficiencySkills[1] ~= nil and recipes[i].efficiencySkills[1] ~= 'nil')  then
end
--row = row .. '| rowspan=\"' .. skillIndex[k] .. '\" ' .. groupedskillcell({recipes[i].efficiencySkills[1], recipes[i].speedSkills}) .. '\n'
--elseif (recipes[i].efficiencySkills[1] == nil or recipes[i].efficiencySkills[1] == 'nil') then
-- Object Form Image
--row = row .. '| \n'
if itemTable.group == 'Block Items' then
--end
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Form.png|[[Category:Pages_with_missing_form]]'
--j = j + 1
if mw.title.makeTitle('File', itemimagename .. '_Form.png').file.exists then
--if #ingredients > 4 then
image = itemimagename .. '_Form.png'
--j = j + 1
elseif mw.title.makeTitle('File', itemimagename .. '_Form.jpg').file.exists then
--end
image = itemimagename .. '_Form.jpg'
--if j == skillIndex[k] then
end
--k = k + 1
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
--j = 0
end
--end
 
-- 'Housing' section (if there is a Room Category)
-- Add the SECOND row of ingredients to ingredients column if applicable
if itemTable.roomCategory ~= nil then
if ingrednum > 4 then
-- Housing Header
row = row .. '|-\n'
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
for b = 5, ingrednum do
   
if (ingrednum == 5) then
--roomCategory
row = row .. '| colspan=\"4\" '
infobox = infobox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
end
 
if ((ingrednum == 6) or (ingrednum == 7 and b == 6)) then
if itemTable.roomCategory ~= 'Industrial' then
row = row .. '| colspan=\"2\" '
if itemTable.furnitureType ~= nil then  
--furnitureType
infobox = infobox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
           
--Value of the object
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
end
row = row .. itemcell({ingredients[b][2], ingredients[b][3]})
if itemTable.roomCategory == 'Industrial' then
infobox = infobox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
end
end
end
end
-- 'Storage' Section (if inventorySlots is not nil)
if itemTable.inventorySlots ~= nil then
rows = rows .. row
-- Storage Header
end
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Storage\'\'\'\n'


--Inventory Slots
--Show variants in table if only 1 recipe in list
infobox = infobox .. '|-\n| Inventory Slots:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.inventorySlots .. '\n'
if #recipes == 1 and tonumber(recipes[i].numberOfVariants) > 1 then
for k, v in pairs(recipes[i].variants) do
--inventoryMaxWeight
--start new row for variants
if itemTable.inventoryMaxWeight ~= nil then
row = '|-\n'
maxWeightKg = itemTable.inventoryMaxWeight/1000
--Skip default variant
infobox = infobox .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | ' .. maxWeightKg .. ' Kg\n'
if v.products[1][1] ~= recipes[i].defaultVariant then
else
local prodnum = #products
infobox = infobox .. '|-\n| Inventory Max Weight:\n| style=\"text-align: right; padding: 3px;\" | Unlimited \n'
for a = 1, prodnum do
end
if prodnum == 1 then
end
row = row .. rowspanProducts .. ' colspan=\"4\" '
end
if ((prodnum == 2) or (prodnum == 3 and a == 2)) then
row = row .. rowspanProducts .. ' colspan=\"2\" '
end
row = row .. itemcell({v.products[a][1], v.products[a][2]})
end


-- 'Power' section (if EngeryType is ``not nil)
--will need to cycle ingrediants to fill out complete table
if itemTable.energyType ~= nil then 
--row = row .. itemcell({v.products[1][1], v.products[1][2]})
-- Power Header
local numing = ingrednum
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Power\'\'\'\n'
if ingrednum > 4 then  
 
numing = 4
--EngergyType
end
infobox = infobox .. '|-\n| Energy Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyType .. '\n'
for b = 1, numing do
if (ingrednum == 1) then
--Grid Radius
row = row .. '| colspan=\"4\" '
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 .. ' J\n'
--Energy Used
infobox = infobox .. '|-\n| Energy Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.energyUsed .. ' J\n'
end
 
-- 'Fuel' Section (if fuelsUsed by Object)
if itemTable.fuelsUsed ~= nil then
-- Fuel Header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Fuel\'\'\'\n'
--Fuels Used by Object
infobox = infobox .. '|-\n| Fuels Used:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.fuelsUsed .. '\n'
end
-- 'Fluid' section (if fludisUsed is not nil)   
            if itemTable.fluidsUsed ~= nil then
            -- Liquid/Gas Header
                infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Liquid/Gas\'\'\'\n'
           
                --Input (fludisUsed)
                infobox = infobox .. '|-\n| Input: \n| style=\"text-align: right; padding: 3px;\" | '
                    for a,b in ipairs(itemTable.fluidsUsed) do
                        local acceptedType =  b[1]
                        local cRateString = string.gsub(b[2], "%s+", "")
                        local consumingRate = tonumber(cRateString)
                        infobox = infobox .. acceptedType .. ' at ' .. consumingRate .. ' L'
                        if (a ~= #itemTable.fluidsUsed) then
                            infobox = infobox .. ', '
                        end
                    end
                infobox = infobox .. '\n'
--Output (liquidProduced)
infobox = infobox .. '|-\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
end
infobox = infobox .. producedType .. ' at ' .. producingRate .. ' L'
if ((ingrednum == 2) or (ingrednum == 3 and b == 2)) then
if (a ~= #itemTable.fluidsProduced) then
row = row .. '| colspan=\"2\" '
infobox = infobox .. ', '
end
end
row = row .. itemcell({v.ingredients[b][2], v.ingredients[b][3]})
end
end
infobox = infobox .. '\n'
end
end
end
rows = rows .. row
-- Road Object header (if group == Road Items)
end
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
end
infobox = infobox .. '|}'
return infobox
end
end
 
-- Main entry point for the Module
     -- Return the full wikitable
function p.ItemMain()
return header({recipes[1].dispCraftStn}) .. rows .. '|-\n|}\n'
     -- get args from the Template
    local args = norm()
   
    -- get item data
    local itemData = require( "Module:ItemData" )
    return itemBox( args, itemData )
end
end


return p
return p

Revision as of 04:16, 4 October 2020

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.


local p = {}

-- Header for the wikitable
function header( args )
    local headerStr = '{| class=\"wikitable mw-collapsible\" style=\"text-align: center;\"\n|-\n'

    -- Show or hide the Crafting Station column
    if args[1] == '1' then
        headerStr = headerStr .. '! Crafting Station !'
    end

    -- Item, Level Needed, Materials, Related Specialty
    headerStr = headerStr .. '! colspan=\"4\" | Item !! colspan=\"4\" | Materials !! Level Needed !! Crafting Time <br>(mins) !! Labour Cost || XP Gain !! style="width: 100px" | Related <br> Specialty\n'

    return headerStr
end

function imagedisp( name )
    local str = ''
	local image = ''
    -- Manual override for image file
    if name then
		image = string.gsub(name, ' ', '') .. '_Icon.png'
		str = str .. ' <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|center|50px|link=' .. name .. '|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> '
	else
	image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. name .. '_Icon.png'
		str = str .. '[[File:' .. image .. '|frameless|50px|class=iconBlue]]'
	end
	str = str .. '<br> [[' .. name .. ']]'
	return str
end

function stationcell( args )
  local str = ''
	str = str .. '| ' .. imagedisp(args[1])
	return str
end


function itemcell( args )
    local str = ''
	str = str .. '| ' .. imagedisp(args[1])
	str = str .. '<br>x' .. args[2] .. '\n'
	return str
end

function skillreqcell( args )
    local str = ''
	str = str .. '| ' .. imagedisp(args[1])
	str = str .. '<br> Level ' .. args[2] .. ' \n'
	return str
end

function groupedskillcell( args )
    local str = ''
	str = str .. '| ' .. imagedisp(args[1])
	if args[2] ~= nil then
		str = str .. ' <br> ' .. imagedisp(args[2])
	end
	return str
end

-- Create a wikitable of recipes
function p.main( recipes )
    local rows = ''
	
    --Not relevant for v0.9
    -- find number of times each Affect by Skill occurs
    --local prevSkill = recipes[1].efficiencySkills[1]
    --local skillIndex = {}
    --local prevSkillnum = 0
	--local count = 0
    --for num = 1, #recipes do
		--if prevSkill ~= recipes[num].efficiencySkills[1] then
			--skillIndex[#skillIndex + 1] = prevSkillnum + count
			--prevSkillnum = 1
			--if #recipes[num].ingredients > 4 then
				--count = 1
			--else
				--count = 0
			--end
			--prevSkill = recipes[num].efficiencySkills[1]
		--else
			--prevSkillnum = prevSkillnum + 1
			--if #recipes[num].ingredients > 4 then
				--count = count + 1
			--end
		--end		
    --end
    --skillIndex[#skillIndex + 1] = prevSkillnum + count
	
    -- Get each row
    local j = 0
    local k = 1
    for i = 1, #recipes do

	-- get information from the current recipe for building
		local checkImage = recipes[i].checkImage
		local craftStn = recipes[i].craftStn
		local skillNeeds = recipes[i].skillNeeds
		--use last variant as this is always the default variant
		local numberOfVariants = recipes[i].numberOfVariants
		local products = {{'',''}}
		local ingredients = {{'',''}}
		
		--loop through variants to select default variant ingredients
		for k, v in pairs(recipes[i].variants) do
			--given pairs doesn't guarantee order, check that product matches default variant
			if v.products[1][1] == recipes[i].defaultVariant then
				ingredients = v.ingredients
				products = v.products
			else
				--handle scenarios where product ~= default variant (for example Refine Tallow)
				ingredients = v.ingredients
				products = v.products			
			end
		end
		local baseCraftTime = recipes[i].baseCraftTime
		local baseLaborCost = recipes[i].baseLaborCost
		local baseXPGain = recipes[i].baseXPGain
			
		-- determine the size needed for products to display correctly
		local ingrednum = #ingredients
		local rowspan = '|'
		local rowspanProducts = '|'
		
		--Code to incorporate rowspan for ingrediants and variants here
		local rowspanCount = 0

		--accomodate both variants and multiple ingredients
		
		if ingrednum > 4 then
			rowspanCount = rowspanCount + 2
		end
		--suspect there will be a bug here for many variants & many ingredients - might need x2 multipler per variant.
		if(#recipes == 1) then --only add variant rowspans if there is one recipe (i.e. variants will be displayed)
			if tonumber(recipes[i].numberOfVariants) > 1 then
				rowspanCount = rowspanCount + tonumber(recipes[i].numberOfVariants)
				rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
			end
		end
		if rowspanCount > 0 then
			rowspan = '| rowspan=\"' .. rowspanCount .. '\" '
			if(#recipes > 1) then
				rowspanProducts = '| rowspan=\"' .. rowspanCount .. '\" '
			else
				rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
			end
		end

		
		--original rowspan working
		--if ingrednum > 4 then
		--	rowspan = '| rowspan=\"2\" '
		--end
		
		-- String to return
		local row = '|-\n'
	
		-- Add new row if products or ingredients are passed in with at least 1 item
		if (products[1] and ingredients[1]) then
      	
			-- Show or hide the Crafting Station column
			if recipes[i].dispCraftStn == '1' then
				row = row .. rowspan .. stationcell({craftStn[1]}) .. '\n'
			end
        
			-- Add the products columns
			local prodnum = #products
			for a = 1, prodnum do
				if prodnum == 1 then
					row = row .. rowspanProducts .. ' colspan=\"4\" '
				end
				if ((prodnum == 2) or (prodnum == 3 and a == 2)) then
					row = row .. rowspanProducts .. ' colspan=\"2\" '
				end
				row = row .. itemcell({products[a][1], products[a][2]})
			end
			
			-- Add the FIRST row of Ingredients column	
			local numing = ingrednum
			if ingrednum > 4 then 
				numing = 4
			end
			for b = 1, numing do
				if (ingrednum == 1) then
					row = row .. '| colspan=\"4\" '
				end
				if ((ingrednum == 2) or (ingrednum == 3 and b == 2)) then
					row = row .. '| colspan=\"2\" '
				end
				row = row .. itemcell({ingredients[b][2], ingredients[b][3]})
			end

			-- Add the Skill needed column	
			if (skillNeeds[1] ~= '' and skillNeeds[1] ~= nil) then
				row = row .. rowspan .. skillreqcell({skillNeeds[1][1], skillNeeds[1][2]})
			else
				row = row .. rowspan 
				if ingrednum > 4 then
					row = row .. '|'
				end
				row = row .. ' \'\'None\'\' \n'
			end
			
			-- Add the Crafting time column
			row = row .. rowspan 
			if rowspanCount > 1 then
				row = row .. '|'
			end
			if baseCraftTime then					
				row = row .. baseCraftTime .. '\n'
			else
				
				row = row .. rowspan .. ' \'\'missing\'\' \n'
			end
			
			-- Add the Labour time column
			row = row .. rowspan 
			if rowspanCount > 1 then
				row = row .. '|'
			end
			if baseLaborCost then					
				row = row .. baseLaborCost .. '\n'
			else
				
				row = row .. rowspan .. ' \'\'missing\'\' \n'
			end
			
			-- Add the XP gain column
			row = row .. rowspan 
			if rowspanCount > 1 then
				row = row .. '|'
			end
			if baseXPGain then					
				row = row .. baseXPGain .. '\n'
			else
				
				row = row .. rowspan .. ' \'\'missing\'\' \n'
			end
				
			-- not in v0.9
			-- Add the Affect by Skills column IF new skill grouping
			--if j == 0 and (recipes[i].efficiencySkills[1] ~= nil and recipes[i].efficiencySkills[1] ~= 'nil')  then
				--row = row .. '| rowspan=\"' .. skillIndex[k] .. '\" ' .. groupedskillcell({recipes[i].efficiencySkills[1], recipes[i].speedSkills}) .. '\n'
			--elseif (recipes[i].efficiencySkills[1] == nil or recipes[i].efficiencySkills[1] == 'nil')  then
				--row = row .. '| \n'
			--end
			--j = j + 1
			--if #ingredients > 4 then
				--j = j + 1
			--end
			--if j == skillIndex[k] then
				--k = k + 1
				--j = 0
			--end
				
			-- Add the SECOND row of ingredients to ingredients column if applicable
			if ingrednum > 4 then
				row = row .. '|-\n'
				for b = 5, ingrednum do
					if (ingrednum == 5) then
						row = row .. '| colspan=\"4\" '
					end
					if ((ingrednum == 6) or (ingrednum == 7 and b == 6)) then
						row = row .. '| colspan=\"2\" '
					end
					row = row .. itemcell({ingredients[b][2], ingredients[b][3]})
				end
			end
			
			rows = rows .. row
		end

		--Show variants in table if only 1 recipe in list
		if #recipes == 1 and tonumber(recipes[i].numberOfVariants) > 1 then
			for k, v in pairs(recipes[i].variants) do
				--start new row for variants
				row = '|-\n'
				--Skip default variant
				if v.products[1][1] ~= recipes[i].defaultVariant then
					local prodnum = #products
					for a = 1, prodnum do
						if prodnum == 1 then
							row = row .. rowspanProducts .. ' colspan=\"4\" '
						end
						if ((prodnum == 2) or (prodnum == 3 and a == 2)) then
							row = row .. rowspanProducts .. ' colspan=\"2\" '
						end
						row = row .. itemcell({v.products[a][1], v.products[a][2]})
					end

					--will need to cycle ingrediants to fill out complete table
					--row = row .. itemcell({v.products[1][1], v.products[1][2]})
					local numing = ingrednum
					if ingrednum > 4 then 
						numing = 4
					end
					for b = 1, numing do
						if (ingrednum == 1) then
							row = row .. '| colspan=\"4\" '
						end
							if ((ingrednum == 2) or (ingrednum == 3 and b == 2)) then
							row = row .. '| colspan=\"2\" '
						end
							row = row .. itemcell({v.ingredients[b][2], v.ingredients[b][3]})
					end
					
					
				end
				rows = rows .. row
			end			

		end
	end
		

	
			
    -- Return the full wikitable
	return header({recipes[1].dispCraftStn}) .. rows .. '|-\n|}\n'
end

return p