Module:LocLine

This is the current revision of this page, as edited by Alex (talk | contribs) at 22:08, 11 October 2024 (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 hc = require('Module:Paramtest').has_content local buildMap = require('Module:Map').buildMap local membscol = { [true] = 'link=Members|alt=Members', [false] = 'link=Free-to-play|alt=Free-to-play', } function p.main(frame) local..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:LocLine/doc. [edit]
Module:LocLine's function main is invoked by Template:ItemSpawnLine.
Module:LocLine's function main is invoked by Template:LocLine.
Module:LocLine's function main is invoked by Template:ObjectLocLine.
Module:LocLine requires Module:Edit button.
Module:LocLine requires Module:Map.
Module:LocLine requires Module:Paramtest.
Module:LocLine requires Module:Yesno.

local p = {}

local editBtn = '<small>' .. require('Module:Edit button')() .. '</small>'
local yesno = require('Module:Yesno')
local isEmpty = require('Module:Paramtest').is_empty
local hc = require('Module:Paramtest').has_content
local buildMap = require('Module:Map').buildMap

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

function p.main(frame)
	local args = frame:getParent().args
	local templateArgs = frame.args

	-- Copy args into new table to avoid custom scribunto iteration behavior on args
	local mapArgs = {}
	for k,v in pairs(args) do
    	mapArgs[k] = v
	end
	
	if not hc(mapArgs.mtype) then mapArgs.mtype = 'pin' end
	if not hc(mapArgs.icon) then mapArgs.icon = templateArgs.icon end
	mapArgs.ptype = templateArgs.ptype
	mapArgs.type = 'maplink'

	local loc = args.location or '? ' .. editBtn
	if (isEmpty(loc)) then loc = '? ' .. editBtn end

	local membs = membscol[yesno(args.members ~= nil and args.members or "no")]
	
	local spawns = args.spawns
	if spawns == nil then
		local i = 1
		while args[i] do i = i + 1 end -- Counts up the amount of spawns
		spawns = i - 1
	end
	if spawns == 0 then spawns = '? ' .. editBtn end
	
	local mapping = buildMap(mapArgs)
	
	-- build table row to return
	local locationRow = mw.html.create('tr')
	locationRow:tag('td'):wikitext(loc):done()
	if templateArgs.ptype == 'monster' then
		local levels = args.levels
		if (isEmpty(levels)) then levels = '? ' .. editBtn end
		locationRow:tag('td'):addClass(levels == 'N/A' and 'table-na' or ''):wikitext(levels):done()
	end
	locationRow:tag('td'):wikitext(membs):done()
	locationRow:tag('td'):wikitext(spawns):done()
	locationRow:tag('td'):wikitext(mapping):done()

	return tostring(locationRow)
end

return p