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.
Modul Dokumentation[view][edit][history][purge]
Diese Dokumentation wird von Modul:SystemMap/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Function list
L 36 — eachBody
L 76 — p.annotateExistence
L 102 — eyebrowFor
L 125 — p.render
L 161 — p.main

Trägt {{System map}}, das ein Sternensystem als horizontale Orbit-Schiene zeichnet: den Stern oder die Sterne, die Planeten und Gürtel, die sie umkreisen, und die Monde und Ringe darüber. Aufgeteilt in Unterseiten: Modul:SystemMap/Data löst das System auf und baut das Modell, Modul:SystemMap/Renderer macht die Schiene daraus, und Modul:SystemMap/systems.json hält die Körper jedes Systems in Orbitreihenfolge.

Editoren nutzen dies über {{System map}}; Parameter und Tracking-Kategorien stehen auf der Vorlagendoku.

Für Modul-Editoren

API

  • Data.resolveKey(input) / Data.buildModel(input, currentTitle): Systemname auflösen und das SystemMapModel bauen (Körper, Stufen, Aktuell-Seite-Flag).
  • Data.discSize(tier, km): ein Durchmesser auf eine Scheibengröße abgebildet, logarithmisch innerhalb seiner Stufe.
  • Data.findBody(page): wo eine Seite in den Systemdaten sitzt, oder nil für Gürtel, Ring, Ort, unbekannten Titel.
  • Renderer.renderRail(model): das Modell als Schienen-Markup.
  • p.render(input, currentTitle, exists, collapsed, track): der testbare Kern; alles Parser-abhängige kommt als Argument.
  • p.main(frame): Wikitext-Einstieg; verdrahtet den echten Titel, eine mw.title-Existenzsonde und Modul:CollapsibleCard.

Stolperfallen

  • Der Eyebrow des Kartenkopfes ist die Zugehörigkeit des Systems (systems.json-affiliation, ein Code) in der Kompaktform der Standort-Breadcrumb, etwa „UEE-Raum“, und verlinkt die <Label>-Systeme-Kategorie. Das Rendern requires Modul:Entity/Location/Vocabulary; eine Änderung daran re-rendert jede Seite mit Systemkarte.
  • Die Scheibengröße ist logarithmisch und nur rang-erhaltend, nicht proportional: Pyro V misst das 6,6-fache Hurstons, rendert aber etwa 1,3× dessen Breite. Ein über dem Stufenmaximum liegender Durchmesser klemmt auf die Stufendeckel.
  • p.annotateExistence ruft mw.title.new(page).exists einmal pro Körper — eine teure Parserfunktion, auf diesem Wiki auf 100 Aufrufe gedeckelt; Sol (36 Sonden) ist der schlimmste Fall der 75 Systeme. Eine größere Ausrollung auf Ortsseiten deckelt das Budget nicht.
  • Ein Überschreiten des Budgets wirft einen LuaError; p.main hüllt die Sonde in pcall und degradiert zur fehlenden Tracking-Kategorie statt zum Skriptfehler.
  • systems.json ist generiert, nicht handgepflegt: das Go-Werkzeug scripts/cmd/systemmap im wiki-tools-Repository baut es aus der ARK-Starmap plus overlay.json neu. Ein Edit auf der Wiki-Seite wird beim nächsten Neuaufbau überschrieben; ein falscher Körper, Link oder Platz gehört ins Overlay und zurück ins Wiki deployt. Titel werden gespeichert, nicht nachgeschlagen — eine Seitenverschiebung heilt erst mit Overlay-Korrektur und Neuaufbau.

require('strict')

--- @module SystemMap
--- Entry point for {{System map}}. Renders the star -> planet -> moon hierarchy
--- of one star system as a horizontal orbit rail.
---
--- Splits three ways so the logic stays testable: Module:SystemMap/Data builds
--- the model (pure), Module:SystemMap/Renderer builds the markup (pure), and
--- this file supplies everything that needs the parser — the current title,
--- page existence and tracking categories — and hands the rail to
--- Module:CollapsibleCard for the card shell and collapse mechanics.

local Data = require('Module:SystemMap/Data')
local Renderer = require('Module:SystemMap/Renderer')
local CollapsibleCard = require('Module:CollapsibleCard')
local yesno = require('Module:Yesno')
local locationVocabulary = require('Module:Entity/Location/Vocabulary')

local p = {}

local STYLES = 'Module:SystemMap/styles.css'
local CATEGORY_UNKNOWN_SYSTEM = '[[Category:Systemkarte mit unbekanntem System]]'
local CATEGORY_BROKEN_LINK = '[[Category:Seiten mit defektem Systemkarten-Link]]'

--- Walk every body in a model: the star or stars first, then planets with their
--- moons.
---
--- Both stars are optional and are visited on their own rather than through the
--- rail, because neither is reliably reachable from `bodies`: a system upstream
--- files no star for has none, and a nested companion sits in the primary's
--- `moons` list while a paired one sits nowhere but here. Missing either would
--- leave a red-linked star unflagged by the tracking category, which is the one
--- job this walk has.
--- @param model SystemMapModel
--- @param fn fun(body: SystemMapBody)
local function eachBody(model, fn)
	if model.star then
		fn(model.star)
	end
	if model.companion then
		fn(model.companion)
	end
	for _, body in ipairs(model.bodies) do
		fn(body)
		for _, moon in ipairs(body.moons) do
			fn(moon)
		end
	end
end

--- Flag bodies whose target page does not exist.
---
--- systems.json is hand-owned, so a page move does not self-heal — this is the
--- tracking category that surfaces the breakage. `exists` is injected so the
--- suite can drive it without a parser; production passes an mw.title probe.
---
--- Cost note: the production probe is an expensive parser function, one call
--- per body plus one for the system article. The limit on this wiki is 100
--- (measured, not the 500 quoted for a stock MediaWiki), and existing usage on
--- the target pages runs 5-14 calls, so the worst case — Sol, 35 bodies + 1 =
--- 36, counting the four rings that share the moons array — lands around a
--- third of the budget with room for the page's own usage on top. Stanton is
--- 19, Pyro 15, Nyx 8, and a binary costs one probe more than its bodies for its
--- second star (Tyrol is 12). Worth watching as the rollout continues: the
--- ceiling is a body count, and Sol is the largest system upstream has.
--- That is fine for the ~90 system articles this ships on; the deferred
--- rollout to ~1,400 location pages is NOT covered by this arithmetic and needs
--- a different approach (a precomputed existence set, or dropping the probe).
--- Overflow is not graceful — the title library raises a LuaError rather than
--- returning nil — so the caller's probe swallows it (see p.main). If the
--- ceiling ever becomes a real problem, deleting this call is safe: MediaWiki
--- still red-links the target on its own, only the tracking category is lost.
--- @param model SystemMapModel
--- @param exists fun(page: string): boolean
--- @return string category Empty string when nothing is missing
function p.annotateExistence(model, exists)
	local anyMissing = false

	-- The system article itself is linked from the header, so a move of that
	-- page has to trip the category too. There is no body to flag for it.
	if not exists(model.page) then
		anyMissing = true
	end

	eachBody(model, function(body)
		if not exists(body.page) then
			body.missing = true
			anyMissing = true
		end
	end)

	if anyMissing then
		return CATEGORY_BROKEN_LINK
	end
	return ''
end

--- "UEE-Raum" over the system: the compact form the Location breadcrumb's
--- first tier shows, linking the category StarSystem files systems under.
--- @param model table
--- @return string|nil
local function eyebrowFor(model)
	local entry = locationVocabulary.affiliationEntry({ affiliation = { { code = model.affiliation } } })
	if not entry then
		return nil
	end
	return '[[:Category:'
		.. locationVocabulary.systemsCategory(entry)
		.. '|'
		.. locationVocabulary.spaceText(entry)
		.. ']]'
end

--- Testable core. Everything parser-dependent arrives as an argument.
--- @param input string|nil        System name as written in the template call
--- @param currentTitle string     Page title being rendered
--- @param exists (fun(page: string): boolean)|nil Existence probe; skipped when nil
--- @param collapsed boolean|nil   Render the box closed
--- @param track boolean|nil       Emit tracking categories. Main namespace only:
---                                these flag ARTICLE problems, and a category
---                                documented as "should normally be empty" stops
---                                being useful the moment it permanently holds
---                                sandboxes and module subpages.
--- @return string
function p.render(input, currentTitle, exists, collapsed, track)
	local model = Data.buildModel(input, currentTitle)
	if not model then
		return track and CATEGORY_UNKNOWN_SYSTEM or ''
	end

	local category = ''
	if exists then
		category = p.annotateExistence(model, exists)
		if not track then
			category = ''
		end
	end

	-- The shell — card frame, header row, collapse affordance and chevron — comes
	-- from Module:CollapsibleCard, so the map matches every other card on the
	-- wiki instead of hand-rolling a lookalike. This module only supplies the
	-- title and the rail.
	--
	-- The geometry custom properties do NOT live on this card's root: styles.css
	-- declares them on .t-system-map__scroll, which Module:SystemMap/Renderer
	-- emits itself. See the note on renderRail for why.
	local card = CollapsibleCard.render({
		title = string.format('[[%s|%s]]', model.page, model.page),
		eyebrow = eyebrowFor(model),
		content = tostring(Renderer.renderRail(model)),
		open = not collapsed,
		class = 't-system-map',
	})

	return card .. category
end

--- Wikitext entry point (backs {{System map}}).
--- @param frame mw.frame
--- @return string
function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)

	local styles = frame:extensionTag({ name = 'templatestyles', args = { src = STYLES } })

	-- Exceeding the expensive-parser-function budget raises a LuaError (it is the
	-- `.exists` access that is metered, not mw.title.new, so both sit inside the
	-- pcall). Degrade to "no tracking category" rather than a red script error:
	-- on failure we genuinely do not know whether the page is there, and a false
	-- "missing" flag is worse than a missing category.
	local exists = function(page)
		local ok, result = pcall(function()
			local title = mw.title.new(page)
			return title ~= nil and title.exists
		end)
		if not ok then
			return true
		end
		return result
	end

	local title = mw.title.getCurrentTitle()
	local body = p.render(args[1], title.text, exists, yesno(args.collapsed, false), title.namespace == 0)

	return styles .. body
end

return p
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.