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
[checked revision][checked revision]
No edit summary
(FIX Skill Books)
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.
-- Module:RecipeTable https://wiki.play.eco/en/Module:RecipeTable
 
local p = {}
local p = {}
local Utils = require('Module:Utils')
local L = require('Module:Localization')


-- Build an Item Infobox
local Utils = require("Module:Utils")
function itemBox(args, itemData)
local L = require("Module:Localization")
    -- 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
-- Header for the wikitable
     local itemTable = itemData.items[item]
function header(args)
     local headerStr = '{| class=\"wikitable mw-collapsible\" style=\"text-align: center;\"\n|-\n'


     if itemTable == nil then
    -- Show or hide the Crafting Station column
         return item .. ' could not be found in Module:ItemData.'
     if args[1] == '1' then
         headerStr = headerStr .. '! ' .. L.t('Crafting Station') .. ' !'
     end
     end
    -- Item, Level Needed, Materials, Crafting Time, Labour Cost and XP Gained Specialty
    headerStr = headerStr .. '! colspan=\"4\" | ' .. L.t('Item') .. ' !! colspan=\"4\" | ' .. L.t('Materials') .. ' !! ' .. L.t('Level Needed') .. ' !! ' .. L.t('Crafting Time<br>(mins)') .. ' !! ' .. L.t('Labour Cost') .. ' || ' .. L.t('XP Gained') .. ' !!\n'
    return headerStr
end


    local itemType = itemTable.type
function imagedisp(name, nameEN, style, borderColour)
    local itemEN = string.sub(itemType, 1, -5)
     local borderImageClass = ''
    local itemimagename = string.gsub(itemEN, ' ', '')
     local icon
 
     if borderColour == 'green' then
    -- string used to build the infobox
         borderImageClass = ' borderGreen'
     local infobox = '{| class=\"infobox\"\n'
     elseif borderColour == 'yellow' then
 
         borderImageClass = ' borderYellow'
    -- 'Name and Image' section
    -- name of the item
    infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
 
    -- the item's type (ItemData - group)
    infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
 
     local text_colour = '#78B1FF'
 
     if itemTable.group == L.t('Food') then
        text_colour = '#85D66B'
    elseif itemTable.group == L.t('Skill Books') or itemTable.group == L.t('Skill Scrolls') then
         text_colour = '#FFCF4D'
     elseif itemTable.group == L.t('Skill Scrolls') then
         text_colour = '#FFCF4D'
    end
 
    infobox = infobox .. text_colour .. ';\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
    local icon = Utils.build_icon(item)
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | '..icon .. '\n'
 
    -- 'Description' section header
    infobox = infobox .. sectionHeader('Description')
 
    if itemTable.description == nil or itemTable.description == '' then
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'' .. L.t('None') .. '\'\'\'\n'
    else
        infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. itemTable.description .. '\n'
    end
 
    --Crafting
    local craftingRecipes = mw.loadData("Module:CraftingRecipes")
 
    infobox = infobox .. generalSection(item, itemTable, craftingRecipes, args)
 
    infobox = infobox .. IDsSection(itemTable)
 
    -- Tags Header
    if itemTable.tagGroups ~= nil and itemTable.tagGroups ~= {} then
        infobox = infobox .. tagSection(itemTable, itemData)
     end
     end


     -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
     local iconBG
     if itemTable.group == L.t('Block Items') or itemTable.group == L.t('World Object Items') then
     if style == 'tag' then
         infobox = infobox .. placementSection(itemTable, itemimagename)
         iconBG = 'iconGrey'
 
         icon = L.tag(name) .. 'Tag'
        -- Object Form Image
         name = L.t('%s Tag'):format(name)
         if itemTable.group == L.t('Block Items') then
    elseif style == 'skill' then
            infobox = infobox .. objectFormSection(itemTable, itemimagename)
         iconBG = 'iconBrightBlue'
        end
         icon = nameEN
 
        -- '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


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


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


function sectionRow(label, content, count, unit)
function stationcell(args)
     if unit ~= nil then
     local str = ''
        content = tonumber(content)
     str = str .. '| ' .. imagedisp(args[1], args[2])
        unit = L.t(unit, content)
     return str
        local lang = mw.getContentLanguage()
        content = lang:formatNum(content)
    else
        unit = ''
     end
    return '|-\n| ' .. L.t(label, count) .. ':\n| style=\"text-align: right; padding: 3px;\" | ' .. content .. unit .. '\n'
end
 
function sectionImage(imageName, suffix)
    local image = checkImage(imageName, suffix)
     return '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
end
end


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


local function setNotContains(set, key)
function ingredientcell(args)
     return set[key] == nil
     local str = ''
end
     local borderColour
 
     if args[4] == 'False' then
local function craftingSubSection(title, item, productsOrIngredients, recipes)
         borderColour = 'green'
     local stations = {}
    elseif args[4] == 'True' then
     local sortStations = {}
         borderColour = 'yellow'
    local stationString = ''
    for _, recipeName in ipairs(productsOrIngredients[item]) do
         local currentRecipe = recipes[recipeName]
        if currentRecipe ~= nil then
            if currentRecipe.variants[recipeName] ~= nil then
                local currentStation = currentRecipe.craftStn[1][1]
                if setNotContains(stations, currentStation) then
                    addToSet(stations, currentStation)
                end
            end
         end
     end
     end
 
     if args[1] == 'TAG' then
     if stations then
        style = 'tag'
        for a, _ in pairs(stations) do
            table.insert(sortStations, a)
        end
        table.sort(sortStations)
        for i, n in ipairs(sortStations) do
            stationString = stationString .. ' [[' .. n .. ']]'
            if (n ~= sortStations[#sortStations]) then
                -- add a comma
                stationString = stationString .. ', '
            end
        end
        return sectionRow(title, stationString)
     else
     else
         return sectionRow(title, L.t('N/A'))
         style = nil
     end
     end
    return str .. '| ' .. imagedisp(args[2], args[5], style, borderColour) .. '<br>x' .. args[3] .. '\n'
end
end


function generalSection(item, itemTable, craftingRecipes, args)
function skillreqcell(args)
     -- 'General' section header
     local str = ''
    section = sectionHeader('General')
     str = str .. '| ' .. imagedisp(args[1], args[3], 'skill')
 
     str = str .. '<br> ' .. L.t('Level') .. ' ' .. args[2] .. ' \n'
     -- Is a product at these tables
     return str
    if craftingRecipes.products[item] ~= nil and Utils.tableLen(craftingRecipes.products[item]) >= 1 then
        section = section .. craftingSubSection('Created at', item, craftingRecipes.products, craftingRecipes.recipes)
    end
 
    -- Is an ingredient at these tables
    if craftingRecipes.ingredients[item] ~= nil and Utils.tableLen(craftingRecipes.ingredients[item]) >= 1 then
        section = section .. craftingSubSection('Used at', item, craftingRecipes.ingredients, craftingRecipes.recipes)
    end
 
    -- calories and nutrients (if itemTable.group == 'Food')
     if itemTable.group == L.t('Food') then
        section = section .. sectionRow('Calorie', itemTable.calories, tonumber(itemTable.calories), 'cal')
        section = section .. '|- valign=\"center\"\n| rowspan=\"4\" | ' .. L.t('Nutrients') .. ':\n'
        section = section .. '| style=\"color: red; text-align: right; padding: 3px;\" | ' .. L.t('Carbs') .. ': ' .. itemTable.carbs .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: orange; text-align: right; padding: 3px;\" | ' .. L.t('Protein') .. ': ' .. itemTable.protein .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: yellow; text-align: right; padding: 3px;\" | ' .. L.t('Fat') .. ': ' .. itemTable.fat .. '\n'
        section = section .. '|- valign=\"center\"\n| style=\"color: limegreen; text-align: right; padding: 3px;\" | ' .. L.t('Vitamins') .. ': ' .. itemTable.vitamins .. '\n'
        section = section .. sectionRow('Nutrition Density', L.t('%s per 100 cals'):format(itemTable.density))
    end
 
    -- carried
    local carried
    if args.carried ~= nil and args.carried ~= '' then
        carried = args.carried
    else
        carried = itemTable.carried
    end
    section = section .. sectionRow('Carried in', carried)
 
    -- weight
    local weight
    if itemTable.weight ~= nil then
        weight = itemTable.weight
    else
        weight = '0.0'
    end
    section = section .. sectionRow('Weight', weight, nil, 'kg')
 
    -- stack limit
    if itemTable.maxStack ~= nil then
        section = section .. sectionRow('Stack limit', itemTable.maxStack)
    end
 
    -- yield
    if itemTable.yield ~= nil then
        section = section .. sectionRow('Improve Gathering', itemTable.yield)
    end
 
    -- fuel
    if itemTable.fuel ~= nil then
        section = section .. sectionRow('Fuel energy', itemTable.fuel, nil, 'J')
    end
 
    -- currency
    if itemTable.currency ~= nil then
        section = section .. "|- style=\"text-align: center;\"\n| colspan=\"2\" | " .. L.t('Can back a currency') .. "\n"
    end
     return section
end
end


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


    -- item id (type)
-- Does this even exist anymore?
    section = section .. sectionRow('Item ID', itemTable.type)
--function groupedskillcell( args )
--    local str = ''
-- str = str .. '| ' .. imagedisp(args[1],args[3])
-- if args[2] ~= nil then
-- str = str .. ' <br> ' .. imagedisp(args[2])
-- end
-- return str
--end


    -- id number (type id)
-- Create a wikitable of recipes
     section = section .. sectionRow('ID Number', itemTable.typeID)
function p.main(recipes)
     local rows = ''


     return section
     -- Get each row
end
    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 = {}


function tagSection(itemTable, itemData)
        --loop through variants to select default variant ingredients
    -- Tags Header
        for k, v in pairs(recipes[i].variants) do
    local tags = itemTable.tagGroups
            -- HACK skill books default Recipe does not have Skill Book
    section = sectionHeader('Tag', Utils.tableLen(tags))
            local def = ''
    local list = ''
            if string.sub(k, string.len(k) - 9) == "Skill Book" then
    -- for each item in the list (a is position, b is value)
                 def = string.sub(k, 1, string.len(k) - 11)
    for a, b in ipairs(tags) do
        --if not these tags listed here
        if (b ~= L.t('Object') or b ~= L.t('World  Object') or b ~= L.t('Housing  Object')) then
            -- add the tag to the list
            -- HACK: Some tag localisations have spaces in the tag name, but not in the tag data
            local tagLink
            -- Some tags have multiple spaces? Possible data quality issue
            bClean = b:gsub("%s+", " ")
            if itemData.tags[bClean] ~= nil then
                 tagLink = L.t('%s Tag'):format(bClean)
             else
             else
                 tagLink = L.t('%s Tag'):format(bClean:gsub(' ', ''))
                 def = k
            end
           
            --given pairs doesn't guarantee order, check that product matches default variant
            if def == recipes[i].defaultVariant then
                ingredients = v.ingredients
                products = v.products
             end
             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
    end
        local baseCraftTime = recipes[i].baseCraftTime
    -- Now the list is made add it to the infobox
        local baseLaborCost = recipes[i].baseLaborCost
    section = section .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | ' .. list .. '\n'
        local baseXPGain = recipes[i].baseXPGain
 
    return section
end


function placementSection(itemTable, itemImageName)
        -- determine the size needed for products to display correctly
    section = sectionHeader('World Object')
        local ingrednum = #ingredients
    -- Object Placed Image
        local rowspan = '|'
    section = section .. sectionImage(itemImageName, 'Placed')
        local rowspanProducts = '|'


    -- 'Placement' section
        --Code to incorporate rowspan for ingrediants and variants here
    --Placement Header
        local rowspanCount = 0
    section = section .. sectionHeader('Placement')


    --Vechile
        --accomodate both variants and multiple ingredients
    if itemTable.mobile ~= nil then
        section = section .. sectionRow('Vehicle/Mobile Object', itemTable.mobile)
    end


    --Dimensions
        if ingrednum > 4 then
    if itemTable.footprint ~= nil then
            rowspanCount = rowspanCount + 2
        section = section .. sectionRow('Dimensions (X,Y,Z)', itemTable.footprint)
        end
    end
        --suspect there will be a bug here for many variants & many ingredients - might need x2 multipler per variant.
 
        if (#recipes == 1) then
    --Material Tier
            --only add variant rowspans if there is one recipe (i.e. variants will be displayed)
    if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
            if tonumber(recipes[i].numberOfVariants) > 1 then
        section = section .. sectionRow('Room Material', itemTable.materialTier) .. '[[Category:Tier ' .. itemTable.materialTier .. ']]\n'
                rowspanCount = rowspanCount + tonumber(recipes[i].numberOfVariants)
    end
                rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
 
            end
    --Room Req.
        end
    if itemTable.roomContainReq ~= nil then
        if rowspanCount > 0 then
        section = section .. sectionRow('Room Required', itemTable.roomContainReq)
            rowspan = '| rowspan=\"' .. rowspanCount .. '\" '
    end
            if (#recipes > 1) then
 
                rowspanProducts = '| rowspan=\"' .. rowspanCount .. '\" '
    --Room Size. Req.
             else
    if itemTable.roomSizeReq ~= nil then
                rowspanProducts = '| rowspan=\"' .. rowspanCount - recipes[i].numberOfVariants - 1 .. '\" '
        section = section .. sectionRow('Room Size', itemTable.roomSizeReq, nil, 'm³')
            end
    end
 
    --Room Mat. Req.
    if itemTable.roomMatReq ~= nil then
        section = section .. sectionRow('Room Materials', itemTable.roomMatReq)
    end
    return section
end
 
function objectFormSection(itemTable, itemImageName)
    return sectionImage(itemImageName, 'Form')
end
 
function housingSection(itemTable)
    -- Housing Header
    section = sectionHeader('Housing')
 
    --roomCategory
    section = section .. sectionRow('Room Category', itemTable.roomCategory) .. '[[Category:' .. itemTable.roomCategory .. ']]\n'
 
    if itemTable.roomCategory ~= L.t('Industrial') then
        if itemTable.furnitureType ~= nil then
            --furnitureType
            section = section .. sectionRow('Furniture Type', itemTable.furnitureType) .. '[[Category:' .. itemTable.furnitureType .. ']]\n'
 
             --Value of the object
            section = section .. sectionRow('Value', itemTable.skillValue)
 
            --Dim. Return % of Object
            section = section .. sectionRow('Dim. Return %', itemTable.repeatsDepreciation * 100, nil, '%')
         end
         end
    end


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


    return section
        -- Add new row if products or ingredients are passed in with at least 1 item
end
        if (products[1] and ingredients[1]) then


function storageSection(itemTable)
            -- Show or hide the Crafting Station column
    -- Storage Header
            if recipes[i].dispCraftStn == '1' then
    section = sectionHeader('Storage')
                row = row .. rowspan .. stationcell({ craftStn[1][1], craftStn[1][2] }) .. '\n'
            end


    --Inventory Slots
            -- Add the products columns
    section = section .. sectionRow('Inventory Slots', itemTable.inventorySlots)
            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], products[a][3] })
                if (tonumber(numberOfVariants) > 1) then
                    row = row .. '<i>' .. L.t('Has Variants') .. '</i> \n'
                end
            end


    --inventoryMaxWeight
            -- Add the FIRST row of Ingredients column
    if itemTable.inventoryMaxWeight ~= nil then
            local numing = ingrednum
        maxWeightKg = itemTable.inventoryMaxWeight / 1000
            if ingrednum > 4 then
        section = section .. sectionRow('Inventory Max Weight', maxWeightKg, nil, 'kg')
                numing = 4
    else
            end
        section = section .. sectionRow('Inventory Max Weight', L.t('Unlimited'))
            for b = 1, numing do
    end
                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 .. ingredientcell(ingredients[b])
            end


    return section
            -- Add the Skill needed column
end
            if (skillNeeds[1] ~= '' and skillNeeds[1] ~= nil) then
                row = row .. rowspan .. skillreqcell({ skillNeeds[1][1], skillNeeds[1][2], skillNeeds[1][3] })
            else
                row = row .. rowspan
                if ingrednum > 4 then
                    row = row .. '|'
                end
                row = row .. ' \'\'' .. L.t('None') .. '\'\' \n'
            end


function powerSection(itemTable)
            -- Add the Crafting time column
    -- Power Header
            row = row .. rowspan
    section = sectionHeader('Power')
            if rowspanCount > 1 then
                row = row .. '|'
            end
            if baseCraftTime then
                row = row .. baseCraftTime .. '\n'
            else


    --EngergyType
                row = row .. rowspan .. ' \'\'' .. L.t('Missing') .. '\'\' \n'
    section = section .. sectionRow('Energy Type', itemTable.energyType) .. '[[Category:' .. itemTable.energyType .. ']]\n'
            end


    --Grid Radius
            -- Add the Labour time column
    section = section .. sectionRow('Grid Radius', itemTable.gridRadius, nil, 'm')
            row = row .. rowspan
            if rowspanCount > 1 then
                row = row .. '|'
            end
            if baseLaborCost then
                row = row .. baseLaborCost .. '\n'
            else


    --Energy Produced
                row = row .. rowspan .. ' \'\'' .. L.t('Missing') .. '\'\' \n'
    section = section .. sectionRow('Energy Produced', itemTable.energyProduced, nil, 'w')
            end


    --Energy Used
            -- Add the XP gain column
    section = section .. sectionRow('Energy Used', itemTable.energyUsed, nil, 'w')
            row = row .. rowspan
            if rowspanCount > 1 then
                row = row .. '|'
            end
            if baseXPGain then
                row = row .. baseXPGain .. '\n'
            else


    return section
                row = row .. rowspan .. ' \'\'' .. L.t('Missing') .. '\'\' \n'
end
            end


function fuelsSection(itemTable)
            -- Add the SECOND row of ingredients to ingredients column if applicable
    -- Fuel Header
            if ingrednum > 4 then
    section = sectionHeader('Fuel')
                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 .. ingredientcell(ingredients[b])
                end
            end


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


    return section
        --Show variants in table if only 1 recipe in list
end
        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], v.products[a][3] })
                    end


function fluidsSection(itemTable)
                    --will need to cycle ingrediants to fill out complete table
    -- Liquid/Gas Header
                    --row = row .. itemcell({v.products[1][1], v.products[1][2]})
    section = sectionHeader('Liquid/Gas')
                    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 .. ingredientcell(v.ingredients[b])
                    end


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


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


     --Output (liquidProduced)
     -- Return the full wikitable
     if itemTable.fluidsProduced ~= nil then
     return header({ recipes[1].dispCraftStn }) .. rows .. '|-\n|}\n'
        local list = ''
        for a, b in ipairs(itemTable.fluidsProduced) do
            local producedType = b[1]
            local pRateString = string.gsub(b[2], "%s+", "")
            local producingRate = tonumber(pRateString)
            if (producingRate == 0) then
                producingRate = 'Rate of Input'
            end
            list = list .. L.t('%s at %sL'):format(producedType, producingRate)
            if (a ~= #itemTable.fluidsProduced) then
                list = list .. ', '
            end
        end
        section = section .. sectionRow('Output', list)
    end
 
    return section
end
 
function roadItemsSection(itemTable, itemImageName)
    section = sectionHeader('Road Object')
 
    -- Object Placed Image
    section = section .. sectionImage(itemImageName, 'Placed')
    return section
end
 
function checkImage(imageName, suffix)
    local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. imageName .. '_' .. suffix .. '.png|[[Category:Pages_with_missing_' .. suffix:lower() .. ']]'
    if mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.png').file.exists then
        image = imageName .. '_' .. suffix .. '.png'
    elseif mw.title.makeTitle('File', imageName .. '_' .. suffix .. '.jpg').file.exists then
        image = imageName .. '_' .. suffix .. '.jpg'
    end
    return image
end
 
-- Main entry point for the Module
function p.ItemMain(frame)
    -- get args from the Template
    local args = Utils.normaliseArgs(frame)
 
    -- get item data
    local itemData = mw.loadData("Module:ItemData")
    return itemBox(args, itemData)
end
end


return p
return p

Revision as of 06:47, 19 April 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.


-- Module:RecipeTable https://wiki.play.eco/en/Module:RecipeTable
local p = {}

local Utils = require("Module:Utils")
local L = require("Module:Localization")

-- 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 .. '! ' .. L.t('Crafting Station') .. ' !'
    end
    -- Item, Level Needed, Materials, Crafting Time, Labour Cost and XP Gained Specialty
    headerStr = headerStr .. '! colspan=\"4\" | ' .. L.t('Item') .. ' !! colspan=\"4\" | ' .. L.t('Materials') .. ' !! ' .. L.t('Level Needed') .. ' !! ' .. L.t('Crafting Time<br>(mins)') .. ' !! ' .. L.t('Labour Cost') .. ' || ' .. L.t('XP Gained') .. ' !!\n'
    return headerStr
end

function imagedisp(name, nameEN, style, borderColour)
    local borderImageClass = ''
    local icon
    if borderColour == 'green' then
        borderImageClass = ' borderGreen'
    elseif borderColour == 'yellow' then
        borderImageClass = ' borderYellow'
    end

    local iconBG
    if style == 'tag' then
        iconBG = 'iconGrey'
        icon = L.tag(name) .. 'Tag'
        name = L.t('%s Tag'):format(name)
    elseif style == 'skill' then
        iconBG = 'iconBrightBlue'
        icon = nameEN
    end

    if not icon then
        icon = name
    end

    return Utils.build_icon(icon, name, 'iconRecipe', iconBG, borderImageClass, true) .. '\n[[' .. name .. ']]'
end

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

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

function ingredientcell(args)
    local str = ''
    local borderColour
    if args[4] == 'False' then
        borderColour = 'green'
    elseif args[4] == 'True' then
        borderColour = 'yellow'
    end
    if args[1] == 'TAG' then
        style = 'tag'
    else
        style = nil
    end
    return str .. '| ' .. imagedisp(args[2], args[5], style, borderColour) .. '<br>x' .. args[3] .. '\n'
end

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


-- Does this even exist anymore?
--function groupedskillcell( args )
--    local str = ''
--	str = str .. '| ' .. imagedisp(args[1],args[3])
--	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 = ''

    -- Get each row
    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
            -- HACK skill books default Recipe does not have Skill Book
            local def = ''
            if string.sub(k, string.len(k) - 9) == "Skill Book" then
                def = string.sub(k, 1, string.len(k) - 11)
            else
                def = k
            end
            
            --given pairs doesn't guarantee order, check that product matches default variant
            if def == recipes[i].defaultVariant then
                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

        -- 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][1], craftStn[1][2] }) .. '\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], products[a][3] })
                if (tonumber(numberOfVariants) > 1) then
                    row = row .. '<i>' .. L.t('Has Variants') .. '</i> \n'
                end
            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 .. ingredientcell(ingredients[b])
            end

            -- Add the Skill needed column
            if (skillNeeds[1] ~= '' and skillNeeds[1] ~= nil) then
                row = row .. rowspan .. skillreqcell({ skillNeeds[1][1], skillNeeds[1][2], skillNeeds[1][3] })
            else
                row = row .. rowspan
                if ingrednum > 4 then
                    row = row .. '|'
                end
                row = row .. ' \'\'' .. L.t('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 .. ' \'\'' .. L.t('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 .. ' \'\'' .. L.t('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 .. ' \'\'' .. L.t('Missing') .. '\'\' \n'
            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 .. ingredientcell(ingredients[b])
                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], v.products[a][3] })
                    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 .. ingredientcell(v.ingredients[b])
                    end


                end
                rows = rows .. row
            end
        end
    end

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

return p