İçeriğe atla

Modül:Maps

Deltarune Wiki sitesinden

Generates a list of all map marker groups available on Map:Common Data.

Documentation

Package items

maps.groups() (function)
Returns a table showing marker group names, labels, descriptions and colors.
Returns: Wikitext table with marker group data (string)
maps.interwiki() (function)
Generates a list of interwiki links for the current map.
Returns: Interwiki links for the current map (string)
--- Generates a list of all map marker groups available on [[Map:Common Data]].
--  @module             maps
--  @alias              p
--  @author             [[User:KockaAdmiralac|KockaAdmiralac]]
--  <nowiki>
require('strict')
local p = {}

local function getMapData(title)
	return mw.text.jsonDecode(title:getContent())
end

--- Returns a table showing marker group names, labels, descriptions and colors.
--  @function           p.groups
--  @return             {string} Wikitext table with marker group data
function p.groups()
	local mapTitle = mw.title.new('Map:Common Data')
	local mapContent = mapTitle:getContent()
	local mapData = mw.text.jsonDecode(mapContent)
	local html = mw.html.create('table'):addClass('wikitable')
	html:tag('tr')
			:tag('th')
				:wikitext('Code')
			:done()
			:tag('th')
				:wikitext('Name')
			:done()
			:tag('th')
				:wikitext('Description')
			:done()
		:done()
	for groupName, groupData in pairs(mapData['groups']) do
		html:tag('tr')
				:tag('td')
					:tag('code')
						:wikitext(groupName)
					:done()
				:done()
				:tag('td')
					:tag('span')
						:css('color', groupData['pinColor'])
						:wikitext(groupData['name'])
					:done()
				:done()
				:tag('td')
					:wikitext(groupData['description'])
				:done()
			:done()
	end
	return tostring(html:done())
end

--- Generates a list of interwiki links for the current map.
--  @function           p.interwiki
--  @return             {string} Interwiki links for the current map
function p.interwiki()
	local currentLang = mw.language.getContentLanguage():getCode()
	local mapTitle = mw.title.getCurrentTitle().rootPageTitle
	if mapTitle.namespace ~= 2900 then
		return
	end
	local mapData = getMapData(mw.title.getCurrentTitle().rootPageTitle)
	if mapData.custom == nil or mapData.custom.interwiki == nil then
		return
	end
	local interwiki = {}
	for lang, langData in pairs(mapData.custom.interwiki) do
		if lang ~= currentLang and langData.mapName ~= nil then
			table.insert(interwiki, string.format(
				'[[%s:Map:%s]]',
				lang,
				langData.mapName
			))
		end
	end
	return table.concat(interwiki)
end

return p
--  </nowiki>
Konu ekle