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:StatTiles/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Function list
L 29 — presentItems
L 43 — p.render

Ein Streifen kleiner Statistik-Kacheln: ein markanter Wert über einem Overline-artigen Label pro Kachel. Das Aufs-Gefühl-zählen-Geschwister von Modul:MeterBar (ein begrenzter Wert auf einer Füllspur) und Modul:ProgressTiles (Ringmesser): greif hierzu, wenn der Payload eine Reihe diskreter Anzahlen ist statt einer Skala.

Wird von Modul:Entity/Location/StarSystem benötigt; nicht aus Vorlagen gerufen.

Für Modul-Editoren

API

p.render(data) liefert <templatestyles> plus ein t-stat-tiles-Grid (feste 3 Spalten), oder , wenn kein Item die Filterung überlebt, sodass eine SectionBuilder-Zeile kollabiert.

Feld Typ Beschreibung
items StatTilesItem[] { value, label, title? }. Ein Item ohne value oder label wird verworfen. title ist ein Hover-Tooltip für abgekürzte Labels.
local statTiles = require( 'Module:StatTiles' )
statTiles.render( {
	items = {
		{ value = 4, label = 'Planeten' },
		{ value = 12, label = 'Monde' },
		{ value = 2, label = 'Gürtel', title = 'Asteroidengürtel' },
	},
} )

Styles

Modul:StatTiles/styles.css bindet Citizen-Design-Tokens, von Haus aus theme-erfahren. Wert und Label nutzen bewusst eine feste 1.25-Zeilenhöhe statt eines Token-Paars: Labels kommen aus einem festen Katalog und brechen nie um, die Token-Zeilenhöhen ließen die Kachel sichtbar schlaff.


require('strict')

--- @module StatTiles
--- A strip of small stat tiles: a prominent value over an overline-style label
--- per tile. The count-at-a-glance sibling of Module:MeterBar (one bounded
--- value on a track) and Module:ProgressTiles (ring gauges): reach for
--- StatTiles when the payload is a row of discrete counts rather than a scale.
---
--- Domain-agnostic: the caller passes { value, label, title? } items; items
--- without a value are dropped, so callers can pass a fixed catalog and let
--- absent stats collapse. All visuals live in the stylesheet and bind to
--- Citizen tokens, so the output is theme-aware.

local p = {}

local STYLES = 'Module:StatTiles/styles.css'

--- @class StatTilesItem
--- @field value number|string The stat value, shown prominently.
--- @field label string Short tile label (overline style; keep to a word or two).
--- @field title string|nil Full name surfaced as a hover tooltip on the tile.

--- @class StatTilesData
--- @field items StatTilesItem[]

--- Keep the items that actually carry a value and a label.
--- @param items StatTilesItem[]|nil
--- @return StatTilesItem[]
local function presentItems(items)
	local out = {}
	for _, item in ipairs(items or {}) do
		if item.value ~= nil and item.value ~= '' and item.label ~= nil then
			out[#out + 1] = item
		end
	end
	return out
end

--- Render the tile strip, or '' when no item carries a value — so callers can
--- hand the result to SectionBuilder and let the empty row collapse.
--- @param data StatTilesData
--- @return string
function p.render(data)
	data = data or {}
	local items = presentItems(data.items)
	if #items == 0 then
		return ''
	end

	local root = mw.html.create('div'):addClass('t-stat-tiles')
	for _, item in ipairs(items) do
		local tile = root:tag('div'):addClass('t-stat-tiles__cell')
		if item.title then
			tile:attr('title', item.title)
		end
		tile:tag('div'):addClass('t-stat-tiles__value'):wikitext(tostring(item.value))
		tile:tag('div'):addClass('t-stat-tiles__label'):wikitext(item.label)
	end

	local styles = mw.getCurrentFrame():extensionTag({ name = 'templatestyles', args = { src = STYLES } })
	return styles .. tostring(root)
end

-- Test-only exports. Not part of the public API.
p._internal = {
	presentItems = presentItems,
}

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.