(~) |
No edit summary |
||
(4 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
local function processRow( puzzle, game ) |
local function processRow( puzzle, game ) |
||
⚫ | |||
if game and puzzle.game ~= game then return end |
if game and puzzle.game ~= game then return end |
||
if type(puzzle.uk) == 'number' then |
if type(puzzle.uk) == 'number' then |
||
local ukpuzzle = data[puzzle.uk] |
local ukpuzzle = data[puzzle.uk] |
||
− | ret[#ret+1] = "* |
+ | ret[#ret+1] = string.format("* [[Puzzle:%s|%s]]\n** [[Puzzle:%s|UK]]",puzzle.name,puzzle.number,ukpuzzle.name) |
− | ret[#ret+1] = string.format("** [[Puzzle:%s|US]]",puzzle.name) |
||
− | ret[#ret+1] = string.format("** [[Puzzle:%s|UK]]",ukpuzzle.name) |
||
else |
else |
||
ret[#ret+1] = string.format("* [[Puzzle:%s|%s]]",puzzle.name,puzzle.number) |
ret[#ret+1] = string.format("* [[Puzzle:%s|%s]]",puzzle.name,puzzle.number) |
||
Line 25: | Line 22: | ||
for _,puzzle in ipairs( data ) do |
for _,puzzle in ipairs( data ) do |
||
⚫ | |||
+ | if puzzle.episode then break end |
||
processRow( puzzle, game ) |
processRow( puzzle, game ) |
||
end |
end |
||
Line 48: | Line 47: | ||
return process( a.game ) |
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 |
end |
||
return p |
return p |
||
+ | -- [[Category:Modules]] |
Revision as of 18:55, 17 January 2015
This Lua Module generates automatic lists of puzzles that is used in various Navbox templates. The data from which the list is generated can be edited in the PuzzleData modules. See also the Puzzle WikiProject.
-- 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]]