No edit summary |
No edit summary |
||
Line 151: | Line 151: | ||
description = data.mission_briefing, |
description = data.mission_briefing, |
||
difficulties = table.concat(difficulties, ', '), |
difficulties = table.concat(difficulties, ', '), |
||
− | numberofplayers = p.get |
+ | numberofplayers = p.get{name, 'max_players'}, |
numberofchests = data.number_chests, |
numberofchests = data.number_chests, |
||
prerequisites = table.concat(pres, ', '), |
prerequisites = table.concat(pres, ', '), |
Revision as of 19:19, 7 May 2021
Description
Handles together with template Map page template the creation of the playable maps' appearences in the wiki.
See also
- Module Map/data
- Template Map page template
- Category Modules
local p = {}
local lib = require('Module:Shared')
local concat = lib.concat
local format = lib.format
local getArgs = lib.getArgs
local function positions(pos, pos_type)
local res = mw.html.create('')
for k,v in ipairs(pos or {}) do
local wktxt = ''
if pos_type == 'player' then
wktxt = format("[[File:Starting_Position_Player_%02d_Icon.png|23px|link=]]", k)
elseif pos_type == 'quest' then
wktxt = format("[[File:Goal_Letter_Icon_%s.png|17px|link=]]", (v.letter or 'C'):upper())
elseif pos_type == 'chest' then
wktxt = "[[File:Gold_Chest_Icon_Glow.png|23px|link=]]"
end
res:tag('div'):css({
["position"] = "absolute",
["z-index"] = 100,
["left"] = (v[1] or '') .. '%',
["bottom"] = (v[2] or '') .. '%',
}):wikitext(wktxt):done()
end
return tostring(res:allDone())
end
function p.gallery(frame)
local args = getArgs(frame)
local name = args.name or args[1]
if not name then return 'Error: Missing Map Name' end
local mini = 'File:'..name..'_Minimap.jpg'
local orig = 'File:'..name..'_Minimap_Original.jpg'
local over = 'File:'..name..'_Overview.jpg'
local bann = 'File:'..name..'_Banner.png'
local orig_old = 'File:'..name..'_Original_Old.png'
local mini_old = 'File:'..name..'_Old.png'
local images = {}
if mw.title.new(orig).fileExists then images[#images+1] = zoom..'|Original Minimap' end
if mw.title.new(mini).fileExists then images[#images+1] = mini..'|Blank Minimap' end
if mw.title.new(over).fileExists then images[#images+1] = over..'|'..name..' Overview' end
if mw.title.new(bann).fileExists then images[#images+1] = bann..'|Loading Screen Banner' end
if mw.title.new(orig_old).fileExists then images[#images+1] = orig_old..'|Old Original Minimap' end
if mw.title.new(mini_old).fileExists then images[#images+1] = mini_old..'|Old Minimap' end
local gal = frame:extensionTag(
'gallery',
table.concat(images, '\n'),
{ type="slideshow", widths="700px", position="center", hideaddbutton="true" }
)
return gal
end
function p.get(frame)
local args = getArgs(frame)
local name = args['name'] or args[1]
if not name then return 'Error: Missing Map Name' end
local getter = args['get'] or args[2]
if not getter then return 'Error: No value to get specified' end
getter = getter:lower()
local data = mw.loadData('Module:Map/data')[name]
if not data then return format('Error: Map "%s" not found', name) end
local val = {}
if getter == 'difficulties' then
if (data.difficulties or {})['standard'] then
table.insert(val, 'Standard')
end
if (data.difficulties or {})['advanced'] then
table.insert(val, 'Advanced')
end
if (data.difficulties or {})['expert'] then
table.insert(val, 'Expert')
end
elseif getter == 'max_players' then
val = 0
for k,_ in pairs(data.starting_positions or {}) do val = k end
else
val = data[getter]
end
if type(args[3]) == 'string' and args[3]:lower() == 'listtotext' then
return mw.text.listToText(val, ', ', ' and ')
end
if type(args[3]) == 'string' and args[3]:lower() == 'concat' then
return table.concat(val, ', ')
end
if type(val) == 'string' and type(args[3]) == 'string' and args[3]:lower() == 'preprocess' then
return frame:preprocess(val)
end
if type(val) == 'table' then
if type(args[3]) == 'number' then return val[args[3]] end
return table.concat(val, ', ')
end
return val
end
function p.infobox(frame)
local args = getArgs(frame)
local name = args['name'] or args[1]
if not name then return 'Error: Missing Map Name' end
local data = mw.loadData('Module:Map/data')[name]
if not data then return format('Error: Map "%s" not found', name) end
local difficulties = {}
if (data.difficulties or {})['standard'] then
table.insert(difficulties, 'Standard')
end
if (data.difficulties or {})['advanced'] then
table.insert(difficulties, 'advanced')
end
if (data.difficulties or {})['expert'] then
table.insert(difficulties, 'Expert')
end
local pres, unlocks = {}, {}
for k,v in pairs(data.prerequisites or {}) do
table.insert(pres, '[['..v..']]')
end
for k,v in pairs(data.unlocks or {}) do
table.insert(unlocks, '[['..v..']]')
end
return frame:expandTemplate{
title = 'Infobox map test',
args = {
name = name,
maptype = data.type,
minimap_image = data.minimap_image,
startings = positions(data.starting_positions, 'player'),
quests = positions(data.quest_positions, 'quest'),
chests = positions(data.chest_positions, 'chest'),
description = data.mission_briefing,
difficulties = table.concat(difficulties, ', '),
numberofplayers = p.get{name, 'max_players'},
numberofchests = data.number_chests,
prerequisites = table.concat(pres, ', '),
unlocks = table.concat(unlocks, ', '),
ranking_4p_time = ((data.rankings or {})[1] or {})['time'],
ranking_4p_names = table.concat(((data.rankings or {})[1] or {})['players'] or {}, ' + '),
ranking_4p_date = ((data.rankings or {})[1] or {})['date'],
ranking_3p_time = ((data.rankings or {})[2] or {})['time'],
ranking_3p_names = table.concat(((data.rankings or {})[2] or {})['players'] or {}, ' + '),
ranking_3p_date = ((data.rankings or {})[2] or {})['date'],
ranking_2p_time = ((data.rankings or {})[3] or {})['time'],
ranking_2p_names = table.concat(((data.rankings or {})[3] or {})['players'] or {}, ' + '),
ranking_2p_date = ((data.rankings or {})[3] or {})['date'],
ranking_1p_time = ((data.rankings or {})[4] or {})['time'],
ranking_1p_names = table.concat(((data.rankings or {})[4] or {})['players'] or {}, ' + '),
ranking_1p_date = ((data.rankings or {})[4] or {})['date'],
}
}
end
return p