Module:Map/templates

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Map/templates/doc. [edit] [history] [purge]
Module:Map/templates is invoked by .
Module:Map/templates requires Module:Map.
Module:Map/templates requires Module:Paramtest.

Provides the template endpoints for various map templates. These were previously included in the map module itself.


-- <nowiki>
local maps = require('Module:Map')
local hc = require('Module:Paramtest').has_content

local p = {}

-- NPC maps --
function p.npcmap(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	--[[ Each unnamed arg is 1 pin in format:
		x,y
		or
		x:#,y:#,version:#,npcid:#,notes:#
	]]
	args = maps.parseArgs(args, 'npc')

	-- Min square size
	if args.squareX < 20 then
		args.squareX = 20
	end
	if args.squareY < 20 then
		args.squareY = 20
	end

	-- Default green pins
	if not hc(args.icon) then
		args.icon = 'greenPin'
	end
	-- Pin group
	if not hc(args.group) then
		args.group = 'npcspawns'
	end
	-- Map type
	local mtype = 'normal'
	if hc(args.type) then
		mtype = string.lower(args.type)
	end

	if mtype == 'maplink' then
		-- Link to map with pins
		args.etype = 'maplink'
		args.features = 'pins'
		if not hc(args.text) then
			args.text = 'Spawn location'
		end
		return maps.createMap(args)
	elseif mtype == 'pin' or mtype == 'pins' then
		-- Map with pins
		args.etype = 'mapframe'
		args.features = 'pins'
		return maps.createMap(args)
	else
		-- Standard map (square with link to all)
		if args.pin_count > 1 then
			if not hc(args.text) then
				args.text = 'show exact spawns'
			end
			local capt = args.pin_count .. ' spawns '
			if hc(args.caption) then
				capt = args.caption
			end

			args.etype = 'maplink'
			args.features = 'pins'
			local link = tostring(maps.createMap(args))
			capt = capt .. link

			args.etype = 'mapframe'
			args.caption = ''
			args.features = 'square'
			args.group = args.group..'area'
			local map = tostring(maps.createMap(args))

			local classes = 'mw-kartographer-container thumb'
			if hc(args.align) then
				local align = string.lower(args.align)
				if align == 'left' then
					classes = classes..' tleft'
				elseif align == 'right' then
					classes = classes..' tright'
				else
					classes = classes..' center'
				end
			else
				classes = classes..' center'
			end

			local width = args.width or 300
			local ret = mw.html.create('div')
			ret:addClass(classes)
				:tag('div')
					:addClass('thumbinner')
					:css('width', width..'px')
					:node(map)
					:tag('div')
						:addClass('thumbcaption')
						:node(capt)

			return ret
		end

		args.etype = 'mapframe'
		args.group = args.group..'area'
		args.features = 'square'
		return maps.createMap(args)
	end
end
function p.monstermap(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	--[[ Each unnamed arg is 1 pin in format:
		x,y
		or
		x:#,y:#,version:#,npcid:#,notes:#
	]]
	args = maps.parseArgs(args, 'npc')

	-- Default red pins
	if not hc(args.icon) then
		args.icon = 'redPin'
	end
	-- Pin group
	if not hc(args.group) then
		args.group = 'monsterspawns'
	end
	if not hc(args.align) then
		args.align = 'center'
	end
	
	args.etype = 'mapframe'
	args.features = 'pins'
	if hc(args.type) and string.lower(args.type) == 'maplink' then
		args.etype = 'maplink'
	end

	return maps.createMap(args)
end
function p.objectmap(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	--[[ Each unnamed arg is 1 pin in format:
		x,y
		or
		x:#,y:#,version:#,objectid:#,notes:#
	]]
	args = maps.parseArgs(args, 'object')

	-- Default blue pins
	if not hc(args.icon) then
		args.icon = 'bluePin'
	end
	-- Pin group
	if not hc(args.group) then
		args.group = 'objectspawns'
	end
	if not hc(args.align) then
		args.align = 'center'
	end
	
	args.etype = 'mapframe'
	args.features = 'pins'
	if hc(args.type) and string.lower(args.type) == 'maplink' then
		args.etype = 'maplink'
	end

	return maps.createMap(args)
end
function p.locationmap(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	if hc(args[1]) then
		local arr = mw.text.split(args[1], '%s*,%s*')
		args.x = arr[1]
		args.y = arr[2]
	end
	args.etype = 'mapframe'
	args.features = 'none'
	return maps.blankMap(args)
end
function p.spawnmaplink(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	--[[ Each unnamed arg is 1 pin in format:
		x,y
		or
		x:#,y:#,qty:#,respawn:#,notes:#
	]]
	args = maps.parseArgs(args, 'item')

	-- Default green pins
	if not hc(args.icon) then
		args.icon = 'greenPin'
	end
	-- Pin group
	if not hc(args.group) then
		args.group = 'spawns'
	end
	
	args.etype = 'maplink'
	args.features = 'pins'
	return '<span class="rsw-maplink-spawns">'..tostring(maps.createMap(args))..'</span>'
end
function p.maptemp(frame)
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	-- Allow map/element type per template easily
	local inv_args = {}
	for i,v in pairs(frame.args) do
		inv_args[i] = v
	end

	--[[ Each unnamed arg is 1 pin in format:
		x,y
		or
		x:#,y:#,desc:#
	]]
	args = maps.parseArgs(args, 'generic')

	if hc(args.iconSize) then
		if string.find(args.iconSize, ',') then
			local isize = mw.text.split(args.iconSize, '%s*,%s*')
			args.iconSize = { tonumber(isize[1]) or 25, tonumber(isize[2]) or 25}
		else
			args.iconSize = { tonumber(args.iconSize) or 25, tonumber(args.iconSize) or 25}
		end
	end
	if hc(args.iconAnchor) then
		if string.find(args.iconAnchor, ',') then
			local ianch = mw.text.split(args.iconAnchor, '%s*,%s*')
			args.iconAnchor = { tonumber(ianch[1]) or 0, tonumber(ianch[2]) or 0}
		else
			args.iconAnchor = { tonumber(args.iconAnchor) or 0, tonumber(args.iconAnchor) or 0}
		end
	end
	if hc(args.popupAnchor) then
		if string.find(args.popupAnchor, ',') then
			local panch = mw.text.split(args.popupAnchor, '%s*,%s*')
			args.popupAnchor = { tonumber(panch[1]) or 0, tonumber(panch[2]) or 0}
		else
			args.popupAnchor = { tonumber(args.popupAnchor) or 0, tonumber(args.popupAnchor) or 0}
		end
	end

	if hc(inv_args.mtype) then
		args.features = string.lower(inv_args.mtype)
	end
	if hc(args.mtype) then
		args.features = string.lower(args.mtype)
	end
	if not args.features then
		args.features = 'none'
	end

	args.etype = 'mapframe'
	if hc(inv_args.type) then
		args.etype = string.lower(inv_args.type)
	end
	if hc(args.type) then
		args.etype = string.lower(args.type)
	end

	return maps.createMap(args)
end

return p