Editing Module:RecipeTable

From Eco - English Wiki

Your changes will be displayed to readers once an authorized user accepts them. (help)

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
-- Module:RecipeTable https://wiki.play.eco/en/Module:RecipeTable
local p = {}
local p = {}
local Utils = require("Module:Utils")
local Utils = require("Module:Utils")
local L = require("Module:Localization")
local L = require("Module:Localization")
Line 14: Line 16:
     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'
     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
     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
end


function stationcell(args)
function stationcell(args)
     local str = ''
     local str = ''
     str = str .. '| [[' .. args[1] ..']] '
     str = str .. '| ' .. imagedisp(args[1], args[2])
     return str
     return str
end
end
Line 24: Line 52:
function itemcell(args)
function itemcell(args)
     local str = ''
     local str = ''
     str = str .. '| [[' .. args[1] .. ']] ' .. 'x' .. args[2] .. '\n'
     str = str .. '| ' .. imagedisp(args[1], args[3])
    str = str .. '<br>x' .. args[2] .. '\n'
     return str
     return str
end
end
Line 39: Line 68:
         style = 'tag'
         style = 'tag'
     else
     else
         style = nil
         style = skill
     end
     end
     str = str .. '| [['
     return str .. '| ' .. imagedisp(args[2], args[5], style, borderColour) .. '<br>x' .. args[3] .. '\n'
    if args[1] == 'TAG' then
        str = str .. args[2] .. ' Tag' 
    else
        str = str .. args[2]
    end
    str = str .. ']]'
    str = str .. ' x' .. args[3] .. '\n'
    return str
end
end


function skillreqcell(args)
function skillreqcell(args)
     local str = ''
     local str = ''
     str = str .. '| [[' .. args[1] .. ']] ' .. '<br> ' .. L.t('Level') .. ' ' .. args[2] .. ' \n'
     str = str .. '| ' .. imagedisp(args[1], args[3], 'skill')
    str = str .. '<br> ' .. L.t('Level') .. ' ' .. args[2] .. ' \n'
     return str
     return str
end
end
Line 62: Line 84:
--function groupedskillcell( args )
--function groupedskillcell( args )
--    local str = ''
--    local str = ''
-- str = str .. '| ' .. args[1] .. ' ' .. args[3]
-- str = str .. '| ' .. imagedisp(args[1],args[3])
-- if args[2] ~= nil then
-- if args[2] ~= nil then
-- str = str .. ' <br> ' .. args[2]
-- str = str .. ' <br> ' .. imagedisp(args[2])
-- end
-- end
-- return str
-- return str
Line 72: Line 94:
function p.main(recipes)
function p.main(recipes)
     local rows = ''
     local rows = ''
     -- Get each row
     -- Get each row
     for i = 1, #recipes do
     for i = 1, #recipes do
Line 80: Line 103:
         --use last variant as this is always the default variant
         --use last variant as this is always the default variant
         local numberOfVariants = recipes[i].numberOfVariants
         local numberOfVariants = recipes[i].numberOfVariants
         local products = {}
         local products = { { '', '', '' } }
         local ingredients = {}
         local ingredients = { { '', '' } }


         --loop through variants to select default variant ingredients
         --loop through variants to select default variant ingredients
if numberOfVariants == 1 then
         for k, v in pairs(recipes[i].variants) do
            ingredients = recipes[i].variants[1].ingredients
            --given pairs doesn't guarantee order, check that product matches default variant
            products = recipes[i].variants[1].products
            if k == recipes[i].defaultVariant then
         else
                ingredients = v.ingredients
        --loop through variants to select default variant ingredients
                products = v.products
            for k, v in pairs(recipes[i].variants) do      
                --given pairs doesn't guarantee order, check that product matches default variant
                if k == recipes[i].defaultVariant then
                    ingredients = v.ingredients
                    products = v.products
                end
             end
             end
         end
         end
Line 136: Line 153:
         -- Add new row if products or ingredients are passed in with at least 1 item
         -- Add new row if products or ingredients are passed in with at least 1 item
         if (products[1] and ingredients[1]) then
         if (products[1] and ingredients[1]) then
            local station = craftStn[1]


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


Line 236: Line 251:


             rows = rows .. row
             rows = rows .. row
           
         end
         end


Line 282: Line 296:
     -- Return the full wikitable
     -- Return the full wikitable
     return header({ recipes[1].dispCraftStn }) .. rows .. '|-\n|}\n'
     return header({ recipes[1].dispCraftStn }) .. rows .. '|-\n|}\n'
end
function p.testrender()
  local crafting_recipes = require("Module:GetRecipes")
  return crafting_recipes.renderTable('Campfire', nil, nil, nil)
end
end


return p
return p
Please note that all contributions to Eco - English Wiki are considered to be released under the CC BY-NC-SA 4.0 (see Eco:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)

Template used on this page: