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/Facet/Seat/doc erstellt werden

require('strict')

--- @module Entity/Facet/Seat
--- Seat facet. Any item carrying a `seat` block (manned turrets, and — once
--- migrated — cockpit / pilot seats) gets its traverse limits and ejection
--- capability surfaced: the yaw / pitch range the seated operator can aim
--- through, shown as a degree range, plus whether the seat ejects. Data-driven:
--- appears whenever a `seat` block is present, regardless of the owning kind /
--- subtype (the seat key sits on TurretBase / manned turrets, not the remote
--- Turret subtype).

local format = require('Module:Entity/Format')
local sectionBuilder = require('Module:Entity/SectionBuilder')
local Boolean = require('Module:Boolean')
local msg = require('Module:Entity/Message').msg

local p = {}

--- Data-driven match: presence of the `seat` block.
---
--- @param apiData table|nil
--- @return boolean
function p.matches(apiData)
	return apiData ~= nil and type(apiData.seat) == 'table'
end

--- Formats a {min, max} axis as a signed degree range ("−20° — 20°"). Reads the
--- `min`/`max` pair (falling back to `minimum`/`maximum`). Returns nil when either
--- bound is non-numeric so the row collapses. The em dash separator stays clear
--- of the typographic minus on negative bounds.
---
--- @param axis table|nil
--- @return string|nil
local function formatRange(axis)
	if type(axis) ~= 'table' then
		return nil
	end
	local min = tonumber(axis.min)
	if min == nil then
		min = tonumber(axis.minimum)
	end
	local max = tonumber(axis.max)
	if max == nil then
		max = tonumber(axis.maximum)
	end
	if min == nil or max == nil then
		return nil
	end
	return format.formatNum(min) .. '° — ' .. format.formatNum(max) .. '°'
end

--- @param ctx EntityHookContext
--- @return table[] Ordered list of section entries with key field
function p.getSections(ctx)
	local apiData = ctx.apiData
	local seat = apiData.seat
	if type(seat) ~= 'table' then
		return {}
	end

	local items = {}

	sectionBuilder.push(items, msg('Yaw'), formatRange(seat.yaw))
	sectionBuilder.push(items, msg('Pitch'), formatRange(seat.pitch))
	if type(seat.has_ejection) == 'boolean' then
		sectionBuilder.push(items, msg('Ejection seat'), Boolean.render(seat.has_ejection))
	end

	return sectionBuilder.build(sectionBuilder.section({
		key = 'seat',
		label = msg('Seat'),
		collapsible = true,
		items = items,
	}))
end

--- Seat facets for structured data / query: the yaw / pitch traverse as both a
--- formatted display range (`Yaw` / `Pitch`, for the type index table) and the
--- raw numeric bounds (`Yaw min` … for numeric queries). has_ejection is rendered
--- in the section but kept out of the query layer for now — booleans aren't yet
--- used as Entity facets.
---
--- @param ctx EntityHookContext
--- @return table<string, any>
function p.getStructuredData(ctx)
	local apiData = ctx.apiData
	local seat = apiData.seat
	if type(seat) ~= 'table' then
		return {}
	end
	local yawAxis = type(seat.yaw) == 'table' and seat.yaw or {}
	local pitchAxis = type(seat.pitch) == 'table' and seat.pitch or {}
	return {
		yaw = formatRange(seat.yaw),
		pitch = formatRange(seat.pitch),
		yaw_min = tonumber(yawAxis.min) or tonumber(yawAxis.minimum),
		yaw_max = tonumber(yawAxis.max) or tonumber(yawAxis.maximum),
		pitch_min = tonumber(pitchAxis.min) or tonumber(pitchAxis.minimum),
		pitch_max = tonumber(pitchAxis.max) or tonumber(pitchAxis.maximum),
	}
end

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

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.