Module:ShimmerRecipes

local p = {}

local item = require('Module:Item').go local tr = require('Module:Tr').translate local getSet = require('Module:Iteminfo/idSets').getIdSet local itemNameFromId = require('Module:ItemNames').extract

local currentFrame = mw.getCurrentFrame local na = currentFrame:expandTemplate{ title = 'na' } local lang = 'en'

local function pairsByKeys(t, f)   local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f)   local i = 0      -- iterator variable local iter = function   -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end

local function moons(phase) return currentFrame:expandTemplate{ title = 'moons', args = { phase } } end

-- extra data local extra = { { 1326, 5335, 'Requires Moon Lord to be defeated' }, { 779, 5134, 'Requires Moon Lord to be defeated' }, { 3031, 5364, 'Requires Moon Lord to be defeated' }, { 5364, 3031, 'Requires Moon Lord to be defeated' }, { 71, out = na, [3] = 'Item is consumed, provides 1 Coin Luck' }, { 72, out = na, [3] = 'Item is consumed, provides 100 Coin Luck' }, { 73, out = na, [3] = 'Item is consumed, provides 10,000 Coin Luck' }, { 74, out = na, [3] = 'Item is consumed, completely fills Coin Luck' }, { 3461, 5408, 'Any time during a Full Moon ' .. moons(1) }, { 3461, 5401, 'Any time during a Waning Gibbous ' .. moons(2) }, { 3461, 5403, 'Any time during a Third Quarter ' .. moons(3) }, { 3461, 5402, 'Any time during a Waning Crescent ' .. moons(4) }, { 3461, 5406, 'Any time during a New Moon ' .. moons(5) }, { 3461, 5407, 'Any time during a Waxing Crescent ' .. moons(6) }, { 3461, 5405, 'Any time during a First Quarter ' .. moons(7) }, { 3461, 5404, 'Any time during a Waxing Gibbous ' .. moons(8) }, }

local function getItemLink(id) local name = itemNameFromId('itemNameFromId', id) or '' return item(currentFrame, { name, tr(name, lang), lang = lang, icons = 'no' }) end

local function row(args) local result = '|-\n| ' .. getItemLink(args[1]) if args.out then result = result .. '\n| ' .. args.out else result = result .. '\n| ' .. getItemLink(args[2]) end result = result .. '\n| ' .. args[3] return result end

local function genKeytable(data) local result = {} for k,_ in pairs(data) do		if type(k) == 'number' then result[tr(itemNameFromId('itemNameFromId', k), lang)] = k		end end return result end

function p.gentable(frame) lang = frame.args.lang or currentFrame:expandTemplate{ title = 'lang' } local result = {} result[#result + 1] = '{| class="terraria sortable lined mw-collapsible"' result[#result + 1] = '! Input !! Output !! Notes' local data = getSet('ShimmerTransformToItem') local keyTable = genKeytable(data) for k,v in pairsByKeys(keyTable) do		result[#result + 1] = row{v, data[v], na} end for _,v in pairs(extra) do		result[#result + 1] = row(v) end result[#result + 1] = '|}' return table.concat(result, '\n') end

return p