Jump to content
Menü aufrufen
Toggle preferences menu
Persönliches Menü aufrufen
Nicht angemeldet
Ihre IP-Adresse wird öffentlich sichtbar sein, wenn Sie Änderungen vornehmen.

Die Dokumentation für dieses Modul kann unter Modul:Jump points/doc erstellt werden

require('strict')

local DataGrid = require('Module:DataGrid')

local SIZES = {
	Small = 'Klein',
	Medium = 'Mittel',
	Large = 'Groß',
}

local p = {}

local function fail(msg)
	return '<strong class="error">Modul:Jump points: ' .. mw.text.nowiki(msg) .. '</strong>'
end

--- Unknown size values pass through unchanged.
local function sizeLabel(raw)
	if raw == nil then
		return ''
	end
	return SIZES[raw] or tostring(raw)
end

--- @param row table
--- @return string
local function destLink(row)
	local links = {}
	for _, key in ipairs({ 'Destination gate', 'Destination system' }) do
		local target = row[key]
		if type(target) == 'string' and target ~= '' then
			links[#links + 1] = '[[' .. target .. ']]'
		end
	end
	return table.concat(links, ', ')
end

function p.main(frame)
	local parent = frame:getParent()
	local args = parent and parent.args or frame.args

	local systemName = mw.text.trim(args[1] or '')
	if systemName == '' then
		systemName = mw.title.getCurrentTitle().text
	end
	if systemName == '' then
		return fail('Ungültige oder fehlende Parameter.')
	end

	-- The lead column already uses the page title as Name; an entity Name column would replace it.
	local columns = {
		{ property = 'Destination system' },
		{ property = 'Destination gate' },
		{ property = 'Jump point size' },
		{ property = 'Jump point direction' },
	}
	local spec, specErr =
		DataGrid.buildSpec('Location', 'Category:Sprungpunkt', { { 'System', '=', systemName } }, columns, nil)
	if not spec then
		return fail('Abfrage konnte nicht gebaut werden: ' .. tostring(specErr))
	end

	local results, qErr = DataGrid.runQuery(spec)
	if not results then
		return fail('Abfrage konnte nicht ausgeführt werden: ' .. tostring(qErr))
	end
	DataGrid.sortRows(results)

	if #results == 0 then
		return string.format('Von oder nach %s sind keine [[Sprungpunkte]] bekannt.', systemName)
	end

	local out = {}
	out[#out + 1] = '{| class="wikitable"'
	out[#out + 1] = '! Sprungtor'
	out[#out + 1] = '! Richtung'
	out[#out + 1] = '! Größe'
	out[#out + 1] = '! Ziel'
	for _, row in ipairs(results) do
		out[#out + 1] = '|-'
		out[#out + 1] = '| [[' .. tostring(row['Name'] or '') .. ']]'
		out[#out + 1] = '| ' .. tostring(row['Jump point direction'] or '')
		out[#out + 1] = '| ' .. sizeLabel(row['Jump point size'])
		out[#out + 1] = '| ' .. destLink(row)
	end
	out[#out + 1] = '|}'
	return table.concat(out, '\n')
end

--- @param systemName string
--- @return string
function p.test(systemName)
	return p.main({
		getParent = function()
			return { args = { systemName } }
		end,
	})
end

return p
Zuletzt geändert
Urheberrecht
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.