Module:LocLine/sandbox

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:LocLine/sandbox/doc. [edit] [history] [purge]
Module:LocLine/sandbox's function main is invoked by Template:LocLine/sandbox.
Module:LocLine/sandbox requires Module:Edit button.
Module:LocLine/sandbox requires Module:Map.
Module:LocLine/sandbox requires Module:Paramtest.
Module:LocLine/sandbox requires Module:Yesno.
Function list
L 15 — p.main
L 44 — monsterLocation
L 89 — itemLocation
L 119 — objectLocation

Module:LocLine testing location. Please test changes here rather than in the base module.


local p = {}

local editBtn = '<small>' .. require('Module:Edit button')() .. '</small>'
local yesno = require('Module:Yesno')
local isEmpty = require('Module:Paramtest').is_empty
-- local buildMap = require('Module:Map/sandbox').buildMap
local buildMap = require('Module:Map').createMap
local maps = require('Module:Map')

local membscol = {
	[true] = '[[File:P2P icon.png|30px|link=Members]]',
	[false] = '[[File:F2P icon.png|30px|link=Free-to-play]]',
}

function p.main(frame)
	local args = frame:getParent().args
	local args = {}
	for i,v in pairs(frame:getParent().args) do
		args[i] = v
	end
	local tempArgs = frame.args
	local locationRow
	-- Pin color from module invoke
	if tempArgs.icon then
		args.icon = tempArgs.icon
	end
	args.ptype = tempArgs.ptype or 'generic'
	
	if tempArgs.ptype == 'monster' then
		locationRow = monsterLocation(args)
	elseif tempArgs.ptype == 'object' then
		locationRow = objectLocation(args)
	elseif tempArgs.ptype == 'item' then
		locationRow = itemLocation(args)
	else
		-- default is monster location row
		locationRow = monsterLocation(args)
	end
	
	return tostring(locationRow)
end

--function p.main(frame)
function monsterLocation(args)
	local loc = args.loc or '? ' .. editBtn
	local levels = args.lvls or '? ' .. editBtn
	local membs = membscol[yesno(args.mem ~= nil and args.mem or "no")]
	local name = args.name or mw.title.getCurrentTitle().text
	
	if(isEmpty(loc)) then loc = '? ' .. editBtn end
	if(isEmpty(levels)) then levels = '? ' .. editBtn end
	
	args.desc = name
	local i = 1
	while args[i] do
		-- add "NPC ID: ####" pin descriptions only if description not already provided
		if not string.find(args[i], 'desc:') then
			local desc = ''
			local npcid = string.match(args[i], 'npcid:(%d+)')
			if npcid then
				desc = 'NPC ID&#58; ' .. npcid
			end
			args[i] = args[i] .. ',desc:' .. desc
		end
		i = i + 1
	end
	local spawns = i - 1
	
	args.etype = 'maplink'
	args.icon = 'redPin'
	args.features = 'pins'
	args = maps.parseArgs(args, 'other')
	
	local map = maps.createMap(args)
	
	-- build table row to return
	-- column order (from {{LocTableHead}}): Location, Levels, Members, Spawns, Map
	local ret = mw.html.create('tr')
	ret
		:tag('td'):wikitext(loc):done()
		:tag('td'):wikitext(levels):done()
		:tag('td'):wikitext(membs):done()
		:tag('td'):wikitext(tostring(spawns)):done()
		:tag('td'):wikitext(map):done()
	
	return ret
end

function itemLocation(args)
	local loc = args.loc or '? ' .. editBtn
	if (isEmpty(loc)) then loc = '? ' .. editBtn end
	local membs = membscol[yesno(args.mem ~= nil and args.mem or "no")]
	
	args.etype = 'maplink'
	args.features = 'pins'
	args.icon = 'bluePin'
	args.name = args.name or mw.title.getCurrentTitle().text
	local ptype = args.ptype or 'item'
	
	args = maps.parseArgs(args, ptype)
	
	local spawns = args.pin_count
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local map = maps.createMap(args)
	
	-- build table row to return
	-- column order (from {{ItemSpawnTableHead}}): Location, Members, Spawns, Map
	local ret = mw.html.create('tr')
	ret
		:tag('td'):wikitext(loc):done()
		:tag('td'):wikitext(membs):done()
		:tag('td'):wikitext(spawns):done()
		:tag('td'):wikitext(map):done()
	
	return ret	
end

function objectLocation(args)
	local loc = args.loc or '? ' .. editBtn
	if (isEmpty(loc)) then loc = '? ' .. editBtn end
	local membs = membscol[yesno(args.mem ~= nil and args.mem or "no")]
	
	args.etype = 'maplink'
	args.features = 'pins'
	args.icon = args.icon or 'bluePin'
	args.name = args.name or mw.title.getCurrentTitle().text
	local ptype = args.ptype or 'object'
	
	args = maps.parseArgs(args, ptype)
	
	local spawns = args.pin_count
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local map = maps.createMap(args)
	
	-- build table row to return
	-- column order (from {{ItemSpawnTableHead}}): Location, Members, Spawns, Map
	local ret = mw.html.create('tr')
	ret
		:tag('td'):wikitext(loc):done()
		:tag('td'):wikitext(membs):done()
		:tag('td'):wikitext(spawns):done()
		:tag('td'):wikitext(map):done()
	
	return ret	
end

return p