(omg)
 
(36 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
local function positions(pos, pos_type)
 
local function positions(pos, pos_type)
 
local res = mw.html.create('')
 
local res = mw.html.create('')
for k,v in ipairs(pos or {}) do
+
if type(pos) ~= 'table' then return end
  +
if type(pos[1]) ~= 'table' then pos = {pos} end
 
for k,v in ipairs(pos) do
 
local wktxt = ''
 
local wktxt = ''
 
if pos_type == 'player' then
 
if pos_type == 'player' then
Line 27: Line 29:
 
end
 
end
   
  +
local function rankings(rankings)
  +
local res = { ['#p1'] = {}, ['#p2'] = {}, ['#p3'] = {}, ['#p4'] = {} }
  +
if type(rankings) ~= 'table' then return res end
  +
  +
for k,v in ipairs(rankings) do
  +
local key = '#p'..v.ranking_numberplayers
  +
local t = {}
  +
for k_,v_ in ipairs(type(v.ranking_players) == 'table' and v.ranking_players or {v.ranking_players}) do t[k_] = v_ end
  +
res[key].t = v.ranking_time
  +
res[key].d = v.ranking_date
  +
res[key].p = table.concat(t, ' + ')
 
end
  +
  +
return res
 
end
   
   
Line 37: Line 54:
 
local mini = 'File:'..name..'_Minimap.jpg'
 
local mini = 'File:'..name..'_Minimap.jpg'
 
local orig = 'File:'..name..'_Minimap_Original.jpg'
 
local orig = 'File:'..name..'_Minimap_Original.jpg'
local over = 'File:'..name..'_Overview.jpg'
 
 
local bann = 'File:'..name..'_Banner.png'
 
local bann = 'File:'..name..'_Banner.png'
local orig_old = 'File:'..name..'_Original_Old.png'
+
local orig_old = 'File:'..name..'_Minimap_Original_Old.jpg'
local mini_old = 'File:'..name..'_Old.png'
+
local mini_old = 'File:'..name..'_Minimap_Old.jpg'
  +
local orig_old2 = 'File:'..name..'_Minimap_Original_Old_2.jpg'
 
local mini_old2 = 'File:'..name..'_Minimap_Old_2.jpg'
  +
local orig_old3 = 'File:'..name..'_Minimap_Original_Old_3.jpg'
  +
local mini_old3 = 'File:'..name..'_Minimap_Old_3.jpg'
   
 
local images = {}
 
local images = {}
if mw.title.new(orig).fileExists then images[#images+1] = zoom..'|Original Minimap' end
+
if mw.title.new(orig).fileExists then images[#images+1] = orig..'|Original Minimap' end
if mw.title.new(mini).fileExists then images[#images+1] = mini..'|Blank Minimap' end
+
if mw.title.new(mini).fileExists then images[#images+1] = mini..'|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(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(orig_old).fileExists then images[#images+1] = orig_old..'|Old Original Minimap - Version 1' end
if mw.title.new(mini_old).fileExists then images[#images+1] = mini_old..'|Old Minimap' end
+
if mw.title.new(mini_old).fileExists then images[#images+1] = mini_old..'|Old Minimap - Version 1' end
  +
if mw.title.new(orig_old2).fileExists then images[#images+1] = orig_old2..'|Old Original Minimap - Version 2' end
 
if mw.title.new(mini_old2).fileExists then images[#images+1] = mini_old2..'|Old Minimap - Version 2' end
  +
if mw.title.new(orig_old3).fileExists then images[#images+1] = orig_old3..'|Old Original Minimap - Version 3' end
  +
if mw.title.new(mini_old3).fileExists then images[#images+1] = mini_old3..'|Old Minimap - Version 3' end
   
 
local gal = frame:extensionTag(
 
local gal = frame:extensionTag(
 
'gallery',
 
'gallery',
 
table.concat(images, '\n'),
 
table.concat(images, '\n'),
{ type="slideshow", widths="700px", position="center", hideaddbutton="true" }
+
{ mode="slideshow", type="slideshow", widths="700px", position="center", hideaddbutton="true" }
 
)
 
)
   
Line 84: Line 107:
 
table.insert(val, 'Expert')
 
table.insert(val, 'Expert')
 
end
 
end
  +
elseif getter == 'prerequisites' then
 
for k,v in pairs(type(data.prerequisites) == 'table' and data.prerequisites or {data.prerequisites}) do
 
table.insert(val, v)
 
end
  +
elseif getter == 'unlocks' then
  +
for k,v in pairs(type(data.unlocks) == 'table' and data.unlocks or {data.unlocks}) do
 
table.insert(val, v)
 
end
  +
elseif getter == 'number_of_players' then
  +
val = 0
 
for k,_ in pairs(data.starting_positions or {}) do val = k end
  +
if data.min_players ~= val then val = (data.min_players or 0) .. ' - ' .. val end
 
elseif getter == 'max_players' then
 
elseif getter == 'max_players' then
  +
val = 0
for k,_ in pairs(data[getter] or {}) do val = k end
 
  +
for k,_ in pairs(data.starting_positions or {}) do val = k end
  +
elseif getter == 'number_of_chests' then
  +
val = 0
  +
for k,_ in pairs(data.chest_positions or {}) do val = k end
 
else
 
else
 
val = data[getter]
 
val = data[getter]
Line 109: Line 148:
 
return val
 
return val
   
 
end
  +
  +
function p.icon(frame)
  +
local args = getArgs(frame)
  +
  +
local el = mw.html.create('span')
  +
:addClass('custom-tooltip')
  +
:attr('data-tt-type', 'map')
  +
:attr('data-1', args[1])
  +
  +
if args['icononly'] then
  +
el:wikitext(format('[[File:%s_Minimap.jpg|%s|link=%s]]', args[1], args['size'] or '20px', args[1]))
  +
else
  +
el:wikitext(format('[[File:%s_Minimap.jpg|%s|link=%s]] [[%s|%s]]', args[1], args['size'] or '20px', args[1], args[1], args[2] or args[1]))
  +
end
  +
  +
return el:done()
 
end
 
end
   
Line 119: Line 175:
 
local data = mw.loadData('Module:Map/data')[name]
 
local data = mw.loadData('Module:Map/data')[name]
 
if not data then return format('Error: Map "%s" not found', name) end
 
if not data then return format('Error: Map "%s" not found', name) end
  +
  +
local prereq = p.get{name, 'prerequisites'}
 
local unlocks = p.get{name, 'unlocks'}
  +
prereq = type(prereq) == 'table' and prereq or {prereq}
  +
unlocks = type(unlocks) == 'table' and unlocks or {unlocks}
  +
  +
for k,v in ipairs(prereq) do if v ~= 'None' then prereq[k] = tostring(p.icon{v}) end end
  +
for k,v in ipairs(unlocks) do if v ~= 'None' then unlocks[k] = tostring(p.icon{v}) end end
   
local difficulties = {}
+
local rankings = rankings(data.rankings)
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{
 
return frame:expandTemplate{
Line 149: Line 196:
 
chests = positions(data.chest_positions, 'chest'),
 
chests = positions(data.chest_positions, 'chest'),
 
description = data.mission_briefing,
 
description = data.mission_briefing,
difficulties = table.concat(difficulties, ', '),
+
campaign_name = data.campaign_name,
numberofplayers = data.max_players,
+
difficulties = p.get{name, 'difficulties'},
numberofchests = data.number_chests,
+
numberofplayers = p.get{name, 'number_of_players'},
prerequisites = table.concat(pres, ', '),
+
numberofchests = p.get{name, 'number_of_chests'},
unlocks = table.concat(unlocks, ', '),
+
prerequisites = table.concat(prereq),
ranking_4p_time = ((data.rankings or {})[1] or {})['time'],
+
unlocks = table.concat(unlocks),
  +
mission_briefing_description = data.mission_briefing_description,
ranking_4p_names = table.concat(((data.rankings or {})[1] or {})['players'] or {}, ' + '),
 
  +
spectator_map_available = data.spectator_map_available ~= nil and (data.spectator_map_available and 'Available' or 'Unavailable') or nil,
ranking_4p_date = ((data.rankings or {})[1] or {})['date'],
 
ranking_3p_time = ((data.rankings or {})[2] or {})['time'],
+
ranking_4p_time = rankings['#p4'].t,
ranking_3p_names = table.concat(((data.rankings or {})[2] or {})['players'] or {}, ' + '),
+
ranking_4p_names = rankings['#p4'].p,
ranking_3p_date = ((data.rankings or {})[2] or {})['date'],
+
ranking_4p_date = rankings['#p4'].d,
ranking_2p_time = ((data.rankings or {})[3] or {})['time'],
+
ranking_3p_time = rankings['#p3'].t,
ranking_2p_names = table.concat(((data.rankings or {})[3] or {})['players'] or {}, ' + '),
+
ranking_3p_names = rankings['#p3'].p,
ranking_2p_date = ((data.rankings or {})[3] or {})['date'],
+
ranking_3p_date = rankings['#p3'].d,
ranking_1p_time = ((data.rankings or {})[4] or {})['time'],
+
ranking_2p_time = rankings['#p2'].t,
ranking_1p_names = table.concat(((data.rankings or {})[4] or {})['players'] or {}, ' + '),
+
ranking_2p_names = rankings['#p2'].p,
ranking_1p_date = ((data.rankings or {})[4] or {})['date'],
+
ranking_2p_date = rankings['#p2'].d,
  +
ranking_1p_time = rankings['#p1'].t,
  +
ranking_1p_names = rankings['#p1'].p,
  +
ranking_1p_date = rankings['#p1'].d,
 
}
 
}
 
}
 
}

Latest revision as of 23:02, 11 June 2021

Edit documentation

Description

Handles together with template Map page template the creation of the playable maps' appearences in the wiki.

See also


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('')
    if type(pos) ~= 'table' then return end
    if type(pos[1]) ~= 'table' then pos = {pos} end
    for k,v in ipairs(pos) 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

local function rankings(rankings)
	local res = { ['#p1'] = {}, ['#p2'] = {}, ['#p3'] = {}, ['#p4'] = {} }
	if type(rankings) ~= 'table' then return res end
	
	for k,v in ipairs(rankings) do
		local key = '#p'..v.ranking_numberplayers
		local t = {}
		for k_,v_ in ipairs(type(v.ranking_players) == 'table' and v.ranking_players or {v.ranking_players}) do t[k_] = v_ end
		res[key].t = v.ranking_time
		res[key].d = v.ranking_date
		res[key].p = table.concat(t, ' + ')
	end
	
	return res
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 bann = 'File:'..name..'_Banner.png'
	local orig_old = 'File:'..name..'_Minimap_Original_Old.jpg'
	local mini_old = 'File:'..name..'_Minimap_Old.jpg'
	local orig_old2 = 'File:'..name..'_Minimap_Original_Old_2.jpg'
	local mini_old2 = 'File:'..name..'_Minimap_Old_2.jpg'
	local orig_old3 = 'File:'..name..'_Minimap_Original_Old_3.jpg'
	local mini_old3 = 'File:'..name..'_Minimap_Old_3.jpg'

	local images = {}
	if mw.title.new(orig).fileExists then images[#images+1] = orig..'|Original Minimap' end
	if mw.title.new(mini).fileExists then images[#images+1] = mini..'|Minimap' 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 - Version 1' end
	if mw.title.new(mini_old).fileExists then images[#images+1] = mini_old..'|Old Minimap - Version 1' end
	if mw.title.new(orig_old2).fileExists then images[#images+1] = orig_old2..'|Old Original Minimap - Version 2' end
	if mw.title.new(mini_old2).fileExists then images[#images+1] = mini_old2..'|Old Minimap - Version 2' end
	if mw.title.new(orig_old3).fileExists then images[#images+1] = orig_old3..'|Old Original Minimap - Version 3' end
	if mw.title.new(mini_old3).fileExists then images[#images+1] = mini_old3..'|Old Minimap - Version 3' end

    local gal = frame:extensionTag(
    	'gallery',
    	table.concat(images, '\n'),
    	{ mode="slideshow", 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 == 'prerequisites' then
    	for k,v in pairs(type(data.prerequisites) == 'table' and data.prerequisites or {data.prerequisites}) do
	        table.insert(val, v)
	    end
	elseif getter == 'unlocks' then
		for k,v in pairs(type(data.unlocks) == 'table' and data.unlocks or {data.unlocks}) do
	        table.insert(val, v)
	    end
	elseif getter == 'number_of_players' then
    	val = 0
    	for k,_ in pairs(data.starting_positions or {}) do val = k end
    	if data.min_players ~= val then val = (data.min_players or 0) .. ' - ' .. val end
    elseif getter == 'max_players' then
    	val = 0
    	for k,_ in pairs(data.starting_positions or {}) do val = k end
    elseif getter == 'number_of_chests' then
    	val = 0
    	for k,_ in pairs(data.chest_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.icon(frame)
	local args = getArgs(frame)
	
	local el = mw.html.create('span')
		:addClass('custom-tooltip')
		:attr('data-tt-type', 'map')
		:attr('data-1', args[1])
		
	if args['icononly'] then
		el:wikitext(format('[[File:%s_Minimap.jpg|%s|link=%s]]', args[1], args['size'] or '20px', args[1]))
	else
		el:wikitext(format('[[File:%s_Minimap.jpg|%s|link=%s]] [[%s|%s]]', args[1], args['size'] or '20px', args[1], args[1], args[2] or args[1]))
	end
	
	return el:done()
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 prereq = p.get{name, 'prerequisites'}
	local unlocks = p.get{name, 'unlocks'}
	prereq = type(prereq) == 'table' and prereq or {prereq}
	unlocks = type(unlocks) == 'table' and unlocks or {unlocks}
	
	for k,v in ipairs(prereq) do if v ~= 'None' then prereq[k] = tostring(p.icon{v}) end end
	for k,v in ipairs(unlocks) do if v ~= 'None' then unlocks[k] = tostring(p.icon{v}) end end

    local rankings = rankings(data.rankings)

    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,
            campaign_name = data.campaign_name,
            difficulties = p.get{name, 'difficulties'},
            numberofplayers = p.get{name, 'number_of_players'},
            numberofchests = p.get{name, 'number_of_chests'},
            prerequisites = table.concat(prereq),
            unlocks = table.concat(unlocks),
            mission_briefing_description = data.mission_briefing_description,
            spectator_map_available = data.spectator_map_available ~= nil and (data.spectator_map_available and 'Available' or 'Unavailable') or nil,
            ranking_4p_time = rankings['#p4'].t,
            ranking_4p_names = rankings['#p4'].p,
            ranking_4p_date = rankings['#p4'].d,
            ranking_3p_time = rankings['#p3'].t,
            ranking_3p_names = rankings['#p3'].p,
            ranking_3p_date = rankings['#p3'].d,
            ranking_2p_time = rankings['#p2'].t,
            ranking_2p_names = rankings['#p2'].p,
            ranking_2p_date = rankings['#p2'].d,
            ranking_1p_time = rankings['#p1'].t,
            ranking_1p_names = rankings['#p1'].p,
            ranking_1p_date = rankings['#p1'].d,
        }
    }
end

return p
Community content is available under CC-BY-SA unless otherwise noted.