FANDOM


-- Generates a list of puzzles for a navbox
 
local p = {}
 
local data
local ret = {}
 
local function processRow( puzzle, game )
	if game and puzzle.game ~= game then return end
 
	if type(puzzle.uk) == 'number' then
		local ukpuzzle = data[puzzle.uk]
		ret[#ret+1] = string.format("* [[Puzzle:%s|%s]]\n** [[Puzzle:%s|UK]]",puzzle.name,puzzle.number,ukpuzzle.name)
	else
		ret[#ret+1] = string.format("* [[Puzzle:%s|%s]]",puzzle.name,puzzle.number)
	end
end
 
-- Build the actual thing
local function process( game )
	if not data then return 'List could not be generated (check your parameters)' end
 
	for _,puzzle in ipairs( data ) do
		if type(puzzle.uk) == 'boolean' then break end
		if puzzle.episode then break end
		processRow( puzzle, game )
	end
	return table.concat( ret, '\n' )
end
 
function p.normal( frame )
	local a = frame.args
	if not a.game then return end
 
	-- Load correct game
	data = mw.loadData('Module:PuzzleData/' .. a.game)
 
	return process()
end
 
function p.weekly( frame )
	local a = frame.args
	if not a.game then return end
 
	-- Load weekly puzzle data
	data = mw.loadData('Module:PuzzleData/weekly')
 
	return process( a.game )
end
 
function p.episodes( frame )
	local a = frame.args
	if not a.game then return end
 
	-- Load data
	data = mw.loadData('Module:PuzzleData/' .. a.game)
 
	if not data then return 'List could not be generated (check your parameters)' end
 
	for _,puzzle in ipairs( data ) do
		if type(puzzle.uk) == 'boolean' then break end
		if puzzle.episode then
			processRow( puzzle, game )
		end
	end
 
	return table.concat( ret, '\n' )
end
 
return p
-- [[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.