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:Entity/Location/Place/Classes/doc erstellt werden

require('strict')

--- @module Entity/Location/Place/Classes
--- The closed class vocabulary of the Place leaf. A class names what a place
--- IS (its function when the name states it, the game's archetype
--- otherwise); where it sits comes from the record, not from here. `zone` is
--- only the default for a page with no record.

local DATA_PAGE = 'Module:Entity/Location/Place/classes.json'

local p = {}

--- The zones a place can occupy. `star` is a place around the star with no
--- body (a gateway), shown on the star's page rather than a planet's.
--- @type table<string, boolean>
p.ZONES = { surface = true, orbit = true, lagrange = true, inside = true, star = true }

--- German zone spellings onto the English tokens the framework stores and
--- the SMW `Zone` property already holds, so a curated German |zone= validates
--- and canonicalises in one step.
local ZONE_ALIASES = {
	['oberfläche'] = 'surface',
	['oberflaeche'] = 'surface',
	['innerhalb'] = 'inside',
	['stern'] = 'star',
}

--- A curated zone text as the canonical English token, or nil when the
--- wording is neither an English token nor one of its German spellings.
--- @param text any
--- @return string|nil
function p.zoneToken(text)
	if type(text) ~= 'string' then
		return nil
	end
	local key = mw.ustring.lower(mw.text.trim(text))
	if key == '' then
		return nil
	end
	return ZONE_ALIASES[key] or (p.ZONES[key] and key or nil)
end

--- Retired |classification= spellings onto the class names they resolved
--- to. The German category is the index's only German key, so renaming one
--- strands every page still carrying the old spelling in the unknown-class
--- tracking category.
local CLASS_ALIASES = {
	wohnungen = 'Residences',
}

--- @type table<string, { name: string, category: string, parent: string, zone: string }>|nil
local index

--- Lower-cased lookup built once per parse. Built with pairs because a
--- mw.loadJsonData table answers neither # nor next().
--- @return table<string, { name: string, category: string, parent: string, zone: string }>
local function build()
	if index then
		return index
	end
	index = {}
	for name, def in pairs(mw.loadJsonData(DATA_PAGE).classes) do
		local entry = {
			name = name,
			category = def.category,
			parent = def.parent,
			zone = def.zone,
		}
		index[mw.ustring.lower(name)] = entry
		-- The German browse category doubles as a lookup key (the German
		-- template args carry 'Stadt', 'Raumstation', ...), without shadowing an
		-- English class name should one ever collide.
		local de = mw.ustring.lower(def.category)
		if index[de] == nil then
			index[de] = entry
		end
	end
	-- Retired spellings register last, so a live key always outranks them.
	for alias, name in pairs(CLASS_ALIASES) do
		if index[alias] == nil then
			local entry = index[mw.ustring.lower(name)]
			if entry then
				index[alias] = entry
			end
		end
	end
	return index
end

--- The class entry for an editor's |classification=, trimmed and matched
--- case-insensitively; nil for anything outside the vocabulary.
--- @param text any
--- @return { name: string, category: string, parent: string, zone: string }|nil
function p.get(text)
	if type(text) ~= 'string' then
		return nil
	end
	local key = mw.ustring.lower(mw.text.trim(text))
	if key == '' then
		return nil
	end
	return build()[key]
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.