Module:LocLine

From Zeah RSPS - Wiki
Revision as of 08:57, 16 February 2022 by Soulgazer (talk | contribs) (Created page with "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').buildMap local tb = require('Module:Trailblazer Region')._main local membscol = { [true] = 'link=Members', [false] = 'link=Free-to-play', } function p.main(frame) local args = frame:getParent().a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:LocLine/doc

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').buildMap
local tb = require('Module:Trailblazer Region')._main

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

function p.main(frame)
	local args = frame:getParent().args
	local tempArgs = frame.args
	local locationRow
	-- Pin color from module invoke
	args.icon = tempArgs.icon
	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)	
	end
	
	return tostring(locationRow)
end

function itemLocation(args)
	local loc = args.location or '? ' .. editBtn
	local membs = membscol[yesno(args.members ~= nil and args.members or "no")]
	local mapID = args.mapID
	local plane = args.plane
	local icon = args.icon
	local ptype = args.ptype
	local r = args.r
	local mtype = args.mtype or 'pin'
	local name = args.name or mw.title.getCurrentTitle().text
	local spawns = args.spawns
	local region = args.trailblazerRegion
	local ret = mw.html.create('tr')
	
	if (isEmpty(loc)) then loc = '? ' .. editBtn end

	local buildArgs = {
		name = name,
		icon = icon,
		mtype = mtype,
		mapID = mapID,
		plane = plane,
		type = 'maplink',
		r = r,
		ptype = ptype
	}
	if args.nopreprocess then buildArgs.nopreprocess = args.nopreprocess end
	
	local i = 1
	while args[i] do
		local coordinate = string.format('%s', args[i])
		table.insert(buildArgs, coordinate)
		
		i = i + 1
	end
	-- Check if spawns is already populated
	if spawns == nil then spawns = i - 1 end
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local mapping = buildMap(buildArgs)
	
	-- build table row to return
	-- column order (from {{ItemSpawnTableHead}}): Location, Members, Spawns, Map, Region (if Trailblazer header is used)	
	-- if region and yesno(region,true) then
	-- 	ret:addClass('tbz-row'):attr('data-tbz-area', string.lower(region) )
	-- end
	ret:tag('td'):wikitext(loc):done()
	ret:tag('td'):wikitext(membs):done()
	ret:tag('td'):wikitext(spawns):done()
	ret:tag('td'):wikitext(mapping):done()

	-- Removed for now since Trailblazer League is over. Preserving for potential future leagues.
	-- if region then
	-- 	if yesno(region,true) then
	-- 		ret:tag('td'):wikitext(tb(region, string.format('This item is in the %s Trailblazer region.', region)))	
	-- 		mw.smw.set({
	-- 			['Trailblazer Region'] = region
	-- 		})
	-- 	else
	-- 		ret:tag('td'):attr('class','table-na'):wikitext('<small>N/A</small>')
	-- 	end
	-- end
	
	return ret	
end

function monsterLocation(args)
	local loc = args.location or '? ' .. editBtn
	local levels = args.levels
	local membs = membscol[yesno(args.members ~= nil and args.members or "no")]
	local mapID = args.mapID
	local plane = args.plane
	local mtype = args.mtype
	local icon = args.icon
	local ptype = args.ptype
	local r = args.r
	local name = args.name or mw.title.getCurrentTitle().text
	local spawns = args.spawns
	local region = args.trailblazerRegion
	local ret = mw.html.create('tr')
	local versions = args.version
	
	if versions ~= nil then
		versions = mw.text.split(versions, ",")
	end
	
	if (isEmpty(loc)) then loc = '? ' .. editBtn end
	if (isEmpty(levels)) then levels = '? ' .. editBtn end

	local buildArgs = {
		name = name,
		icon = icon,
		mtype = mtype,
		mapID = mapID,
		plane = plane,
		type = 'maplink',
		r = r,
		ptype = ptype,
		levels = args.levels
	}
	if args.nopreprocess then buildArgs.nopreprocess = args.nopreprocess end
	
	local i = 1
	while args[i] do
		local coordinate = string.format('%s', args[i])
		table.insert(buildArgs, coordinate)
		
		i = i + 1
	end
	-- Check if spawns is already populated
	if spawns == nil then spawns = i - 1 end
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local mapping = buildMap(buildArgs)
	
	-- build table row to return
	-- column order (from {{LocTableHead}}): Location, Levels, Members, Spawns, Map, Region (if Trailblazer header is used)	
	-- if region and yesno(region,true) then
	-- 	ret:addClass('tbz-row'):attr('data-tbz-area', string.lower(region) )
	-- end
	ret:tag('td'):wikitext(loc):done()
	ret:tag('td'):addClass(levels == 'N/A' and 'table-na' or ''):wikitext(levels):done()
	ret:tag('td'):wikitext(membs):done()
	ret:tag('td'):wikitext(spawns):done()
	ret:tag('td'):wikitext(mapping):done()

	-- Removed for now since Trailblazer League is over. Preserving for potential future leagues.
	-- if region then
	-- 	if yesno(region,true) then
	-- 		ret:tag('td'):wikitext(tb(region, string.format('This monster is in the %s Trailblazer region.', region)))
	-- 		if versions == nil then
	-- 			mw.smw.set({
	-- 				['Trailblazer Region'] = region
	-- 			})
	-- 		else
	-- 			for _, version in ipairs(versions) do
	-- 				mw.log(subobjName)
	-- 				mw.smw.subobject({
	-- 					['Trailblazer Region'] = region
	-- 				}, version)
	-- 			end
	-- 		end
	-- 	else
	-- 		ret:tag('td'):attr('class','table-na'):wikitext('<small>N/A</small>')
	-- 	end
	-- end
	
	return ret
end

function objectLocation(args)
	local loc = args.location or '? ' .. editBtn
	local membs = membscol[yesno(args.members ~= nil and args.members or "no")]
	local mapID = args.mapID
	local plane = args.plane
	local icon = args.icon
	local ptype = args.ptype
	local r = args.r
	local mtype = args.mtype
	local name = args.name or mw.title.getCurrentTitle().text
	local spawns = args.spawns
	local region = args.trailblazerRegion
	local ret = mw.html.create('tr')
	
	if (isEmpty(loc)) then loc = '? ' .. editBtn end

	local buildArgs = {
		name = name,
		icon = icon,
		mtype = mtype,
		mapID = mapID,
		plane = plane,
		type = 'maplink',
		r = r,
		ptype = ptype
	}
	if args.nopreprocess then buildArgs.nopreprocess = args.nopreprocess end
	
	local i = 1
	while args[i] do
		local coordinate = string.format('%s', args[i])
		table.insert(buildArgs, coordinate)
		
		i = i + 1
	end
	-- Check if spawns is already populated
	if spawns == nil then spawns = i - 1 end
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local mapping = buildMap(buildArgs)
	
	-- build table row to return
	-- column order (from {{ItemSpawnTableHead}}): Location, Members, Spawns, Map, Region (if Trailblazer header is used)	
	-- if region and yesno(region,true) then
	-- 	ret:addClass('tbz-row'):attr('data-tbz-area', string.lower(region) )
	-- end
	ret:tag('td'):wikitext(loc):done()
	ret:tag('td'):wikitext(membs):done()
	ret:tag('td'):wikitext(spawns):done()
	ret:tag('td'):wikitext(mapping):done()
	-- Removed for now since Trailblazer League is over. Preserving for potential future leagues.
	-- if region then
	-- 	if yesno(region,true) then
	-- 		ret:tag('td'):wikitext(tb(region, string.format('This object is in the %s Trailblazer region.', region)))	
	-- 		mw.smw.set({
	-- 			['Trailblazer Region'] = region
	-- 		})
	-- 	else
	-- 		ret:tag('td'):attr('class','table-na'):wikitext('<small>N/A</small>')
	-- 	end
	-- end
	
	return ret	
end

return p