Modul:Entity/Vehicle
Aus Star Citizen Wiki
Weitere Optionen
Die Dokumentation für dieses Modul kann unter Modul:Entity/Vehicle/doc erstellt werden
require('strict')
--- @module Entity/Vehicle
--- Vehicle kind module: the orchestrator for the vehicle family. Exposes the
--- vehicles API endpoint, resolves the family subtype leaf (Ship / GroundVehicle
--- / Gravlev), and dispatches infobox sections to the per-section sub-builders
--- under Vehicle/ (Overview, Capacity, Cost, Stats, Dimensions, Lore, Development).
--- Editorial overlap fields are read through Module:Entity/Editorial's view.
local base = require('Module:Entity/Base')
local subtypeResolver = require('Module:Entity/SubtypeResolver')
local acq = require('Module:Entity/Acquisition')
local capacity = require('Module:Entity/Vehicle/Capacity')
local cost = require('Module:Entity/Vehicle/Cost')
local development = require('Module:Entity/Vehicle/Development')
local Editorial = require('Module:Entity/Editorial')
local vehicleDimensions = require('Module:Entity/Vehicle/Dimensions')
local format = require('Module:Entity/Format')
local lore = require('Module:Entity/Vehicle/Lore')
local overview = require('Module:Entity/Vehicle/Overview')
local productionStatus = require('Module:Entity/ProductionStatus')
local stats = require('Module:Entity/Vehicle/Stats')
local store = require('Module:Entity/Store')
local vehicleUtil = require('Module:Entity/Vehicle/Util')
local Vocab = require('Module:Entity/Vocab')
local msg = require('Module:Entity/Message').msg
local lang = mw.language.getContentLanguage()
local QUANTUM_SPEED_DIVISOR = 1000000
local QUANTUM_RANGE_DIVISOR = 1000000000
--- Medical facility tier as an integer: "T2" -> 2. Passes through a numeric
--- value; nil when absent or unparseable.
--- @param tier any
--- @return number|nil
local function medicalTierNum(tier)
if type(tier) == 'number' then
return tier
end
if type(tier) ~= 'string' then
return nil
end
local digits = tier:match('%d+')
return digits and tonumber(digits) or nil
end
local p = {}
--- Normalize a ship-matrix name to a URL slug (lowercase, spaces → hyphens). nil-safe.
--- @return string|nil
local function shipMatrixSlug(name)
if type(name) ~= 'string' or name == '' then
return nil
end
return (mw.ustring.lower(name):gsub(' ', '-'))
end
--- Canonical kind name, exposed as Data.get(args).kind (non-empty and
--- unique, enforced by the Registry conformance test).
p.name = 'Vehicle'
--- Opt into editorial mode (Module:Entity/Data): a page declared |kind=Vehicle
--- with no genuine API record (a planned / not-yet-in-game vehicle) renders from
--- editorial args alone. The family subtype then comes from |family=. Harmless on
--- a page that later gets a uuid — the genuine record takes over. See README.
p.editorialMode = true
--- A vehicle page with no manufacturer, from the record or |manufacturer=, is
--- tracked as missing one (Module:Entity/Categories).
p.hasManufacturer = true
--- @type string
p.parent = 'Entity/Base'
--- The vehicles endpoint includes uex_prices and msrp by default, so
--- no `include` param is required for Availability to render. The request is
--- de_DE: description and game_description arrive German, and the two
--- machine-compared fields the locale translates (production_status, size)
--- are normalized back to English tokens at ingest
--- (Module:Entity/Data.normalizeVehicleLocale).
---
--- @return EntityApiConfig[]
function p.getApiConfigs()
return {
{
name = 'StarCitizenWikiAPI',
endpoint = 'vehicles/%s',
params = { locale = 'de_DE' },
responseDataPath = 'data',
},
}
end
--- Positive identification: vehicles always carry the `is_vehicle`
--- key at the top level alongside `is_spaceship` and `is_gravlev`.
--- The value is the family flag (`is_vehicle=true` for ground vehicles,
--- `is_spaceship=true` for spaceships, `is_gravlev=true` for hover
--- bikes — a Cutlass Black has `is_vehicle=false, is_spaceship=true`),
--- so we check **presence** rather than value. Items don't have any
--- of these keys.
--- Safe on nil / empty / malformed apiData (returns false, never throws).
---
--- @param apiData table|nil
--- @return boolean
function p.matches(apiData)
return apiData ~= nil and apiData.is_vehicle ~= nil
end
--- Vehicle family → subtype leaf loader. The keys are the family tokens
--- (also each leaf's p.family tag and the curated |family= arg value).
local VEHICLE_FAMILY_MAP = {
gravlev = function()
return require('Module:Entity/Vehicle/Gravlev')
end,
ship = function()
return require('Module:Entity/Vehicle/Ship')
end,
ground = function()
return require('Module:Entity/Vehicle/GroundVehicle')
end,
}
--- Derive the family token: a genuine record's boolean flags (ordered
--- most-specific-first) win; in editorial mode (apiData = {}) the curated
--- |family= arg, normalised by SubtypeResolver.familyArg, selects it. nil when
--- neither resolves.
--- @param apiData table|nil
--- @param args table|nil
--- @return string|nil
local function deriveFamily(apiData, args)
if type(apiData) == 'table' then
if apiData.is_gravlev then
return 'gravlev'
end
if apiData.is_spaceship then
return 'ship'
end
if apiData.is_vehicle then
return 'ground'
end
end
return subtypeResolver.familyArg(args)
end
--- Refine a vehicle to its family subtype leaf. A genuine record carries all
--- three family flags (exactly one truthy), so order is defensive
--- most-specific-first. In editorial mode (apiData = {}, no flags) the curated
--- `|family=` arg selects the leaf instead. Returns nil when neither resolves
--- (the Vehicle kind itself stays the leaf).
--- @param apiData table|nil
--- @param args table|nil
--- @return table|nil
function p.resolveSubtype(apiData, args)
return subtypeResolver.resolve(deriveFamily(apiData, args), VEHICLE_FAMILY_MAP)
end
--- The German role word for the short description's adjective slot, or nil
--- when nothing grounded resolves. The API does not translate `role`, so the
--- English role is looked up in the role vocabulary, whose keys are
--- case-insensitive so the sentence-cased resolver output resolves too; a
--- curated role may instead already be the German value ("Einsteiger"), which
--- the vocabulary's reverse direction resolves to the same token. A miss
--- falls through to the record's German `foci` value, used only when it
--- round-trips through that same vocabulary (so an untranslated focus like
--- "Light Mining" is never mistaken for German). An ungrounded role is
--- omitted rather than shown in English inside a German sentence; a curated
--- `|role=` override suppresses the foci fallback entirely.
--- @param apiData table
--- @param args table
--- @return string|nil
local function roleAdjective(apiData, args)
local curated = type(args.role) == 'string' and args.role ~= ''
local roles = vehicleUtil.resolveRole(apiData, args)
local role = type(roles) == 'table' and roles[1] or nil
if role ~= nil then
-- toEnglish passes English tokens and unknown roles through unchanged,
-- so it is also the German-value normalization.
local token = Vocab.toEnglish('role', role)
local translated = Vocab.toGerman('role', token)
if translated ~= token then
return translated
end
end
if curated then
return nil
end
local foci = type(apiData.foci) == 'table' and apiData.foci[1] or nil
if type(foci) == 'string' and foci ~= '' and Vocab.toEnglish('role', foci) ~= foci then
return foci
end
return nil
end
--- Compose a manufacturer-led vehicle short description in the German wiki's
--- pattern: "[<Einzelsitz-|<Rollenwort->]<Noun> hergestellt von <Hersteller>"
--- (e.g. "Einzelsitz-Raumschiff hergestellt von Anvil Aerospace"). The noun
--- localizes from the family token; size words never appear (the German wiki
--- pattern drops the English adjective composition). Editorial-first for the
--- single-seat marker, like every editorial overlap field. The role word
--- composes only onto the localized noun: without the message dataset the
--- whole description degrades to English rather than mixing languages.
--- @param apiData table
--- @param args table
--- @param resolved table|nil
--- @param typeNoun string 'ship' | 'ground vehicle' | 'grav-lev vehicle'
--- @return string
function p.formatShortDescription(apiData, args, resolved, typeNoun)
local ed = Editorial.view(resolved)
local noun = msg(typeNoun)
local adjective
local crewMax = tonumber(ed:value('crew_max', apiData.crew and apiData.crew.max))
if crewMax == 1 then
adjective = msg('single-seat')
elseif noun ~= typeNoun then
-- The role vocabulary is a Lua table and answers even when the message
-- dataset does not, so the noun's fallback is the gate: its German word
-- beside the English fallback noun would mix languages.
adjective = roleAdjective(apiData, args)
end
local parts = {}
-- Einsteiger's ship compound is the hub's own singular noun Einsteigerschiff,
-- not a hyphen composition; only the ground noun composes.
if adjective == 'Einsteiger' and noun == 'Raumschiff' then
parts[#parts + 1] = 'Einsteigerschiff'
else
if adjective then
parts[#parts + 1] = adjective .. '-'
end
parts[#parts + 1] = noun
end
local mfr = base.resolveManufacturer(apiData, args)
if mfr and mfr.name then
parts[#parts + 1] = ' ' .. msg('manufactured by') .. ' ' .. mfr.name
end
return lang:ucfirst(table.concat(parts))
end
--- Manufacturer as a wikilink ([[Page]] or [[Page|Name]]), or nil when none
--- resolves. Shared by the header subtitle.
--- @param apiData table
--- @param args table
--- @return string|nil
local function manufacturerLink(apiData, args)
local mfr = base.resolveManufacturer(apiData, args)
if not mfr or not mfr.page then
return nil
end
if mfr.name and mfr.name ~= mfr.page then
return '[[' .. mfr.page .. '|' .. mfr.name .. ']]'
end
return '[[' .. mfr.page .. ']]'
end
--- @param ctx EntityHookContext
--- @return table[]
function p.getSections(ctx)
local apiData, args, resolved = ctx.apiData, ctx.args, ctx.resolved
local ed = Editorial.view(resolved)
local subtype = p.resolveSubtype(apiData, args)
local typeName = nil
if subtype and subtype.getTypeInfo then
local typeInfo = subtype.getTypeInfo(ctx)
typeName = typeInfo and typeInfo.name
end
local sections = {}
local function add(section)
if section ~= nil then
sections[#sections + 1] = section
end
end
add(overview.build(apiData, args, ed, typeName))
add(capacity.build(apiData, args, ed))
add(cost.build(apiData, args, ed))
add(stats.build(apiData, args, ed))
add(vehicleDimensions.build(apiData, args, ed))
add(lore.build(apiData, args, ed))
add(development.build(apiData, args, ed))
return sections
end
--- Vehicle header subtitle: the manufacturer (linked), shown in place of the
--- default type subtitle so vehicles are identified by maker (as the legacy
--- infobox did). nil when no manufacturer resolves → the infobox falls back to
--- the display type.
--- @param ctx EntityHookContext
--- @return string|nil
function p.getSubtitle(ctx)
local apiData, args = ctx.apiData, ctx.args
return manufacturerLink(apiData, args)
end
--- Vehicle production-state badge for the infobox header overlay. Uses the
--- editorial-resolved production_state (API production_status, override-able).
--- Vehicle-only: other entities are in-game by definition, so a status badge
--- would be noise. The per-ship milestone/note now lives in the Development
--- section (Added in version + production note), so the badge is a plain pill.
--- The flight-ready word is family-aware: ground vehicles read "Fahrbereit",
--- ships and gravlevs "Flugbereit"; every other tier uses its one word for
--- every family.
--- @param ctx EntityHookContext
--- @return string|nil
function p.getHeaderBadge(ctx)
local apiData, args, resolved = ctx.apiData, ctx.args, ctx.resolved
local ed = Editorial.view(resolved)
local state = ed:value('production_state', apiData.production_status)
local label
if productionStatus.key(state) == 'flightready' and deriveFamily(apiData, args) == 'ground' then
label = 'Flight ready (ground)'
end
return productionStatus.badge(state, label)
end
--- Return the Vehicle editorial manifest. Used by Module:Entity/Editorial to
--- resolve hybrid API/wikitext fields (crew, cargo, speed, mass, pledge price)
--- and to drive structured-data storage for those fields.
--- @return table
function p.getEditorialManifest()
return mw.loadJsonData('Module:Entity/Vehicle/editorial.json')
end
--- Return structured data for the pure-API vehicle fields not covered by the
--- editorial manifest (Career, Role, Size, agility rates). Fields owned
--- by the editorial layer (crew/cargo/speed/mass/pledge) are intentionally
--- absent here — the editorial resolver stores those.
--- @param ctx EntityHookContext
--- @return table
function p.getStructuredData(ctx)
local apiData, args, resolved = ctx.apiData, ctx.args, ctx.resolved
local agility = type(apiData.agility) == 'table' and apiData.agility or {}
local armor = type(apiData.armor) == 'table' and apiData.armor or {}
local cargoLimits = type(apiData.cargo_limits) == 'table' and apiData.cargo_limits or {}
local crossSection = type(apiData.cross_section) == 'table' and apiData.cross_section or {}
local emission = type(apiData.emission) == 'table' and apiData.emission or {}
local fuel = type(apiData.fuel) == 'table' and apiData.fuel or {}
local quantum = type(apiData.quantum) == 'table' and apiData.quantum or {}
local seating = type(apiData.seating) == 'table' and apiData.seating or {}
local speed = type(apiData.speed) == 'table' and apiData.speed or {}
local weaponStorage = type(apiData.weapon_storage) == 'table' and apiData.weapon_storage or {}
local weaponry = type(apiData.weaponry) == 'table' and apiData.weaponry or {}
local missiles = type(weaponry.missiles) == 'table' and weaponry.missiles or {}
local uex = type(apiData.uex_prices) == 'table' and apiData.uex_prices or {}
local ed = Editorial.view(resolved)
-- Loaner ship names (Page list), suppressed for flight-ready ships (implemented →
-- no loaner granted, even though the API may still return stale loaner data).
local loaner = nil
if productionStatus.key(ed:value('production_state', apiData.production_status)) ~= 'flightready' then
local raw = type(apiData.loaner) == 'table' and apiData.loaner or {}
local names = {}
for _, entry in ipairs(raw) do
if type(entry) == 'table' and type(entry.name) == 'string' and entry.name ~= '' then
names[#names + 1] = entry.name
end
end
loaner = names[1] and names or nil
end
-- Curated matrix size name (|size= wins over API), ucfirst'd. The numeric size
-- class is stored separately as Size; in-game ships have both, concept-only
-- (legacy {{Vehicle}}) ships carry just the matrix name.
local matrixSize = vehicleUtil.matrixSize(apiData, args)
local data = {
['Career'] = vehicleUtil.resolveCareer(apiData, args), -- wiki param wins (curated taxonomy)
['Role'] = vehicleUtil.resolveRole(apiData, args),
['Size'] = tonumber(apiData.size_class),
['Ship matrix size'] = (matrixSize and matrixSize ~= '') and lang:ucfirst(matrixSize) or nil,
['Storage capacity'] = tonumber(apiData.vehicle_inventory),
['Ore capacity'] = tonumber(apiData.ore_capacity),
['Maximum cargo container size'] = tonumber(cargoLimits.max_scu_box),
['Crew stations'] = tonumber(seating.crew_stations),
['Beds'] = tonumber(seating.beds),
['Medical bed tier'] = medicalTierNum(apiData.max_medical_tier),
['Weapon rack capacity'] = tonumber(weaponStorage.slots_total),
['Loaner vehicle'] = loaner,
['Roll rate'] = tonumber(agility.roll),
['Pitch rate'] = tonumber(agility.pitch),
['Yaw rate'] = tonumber(agility.yaw),
['Insurance claim time'] = apiData.insurance and tonumber(apiData.insurance.claim_time) or nil,
['Insurance expedite time'] = apiData.insurance and tonumber(apiData.insurance.expedite_time) or nil,
['Insurance expedite cost'] = apiData.insurance and tonumber(apiData.insurance.expedite_cost) or nil,
-- Estimated in-game prices: same median-of-latest-patch UEX value the Cost
-- infobox shows (Module:Entity/Acquisition.estimatePrice), stored unitless (aUEC).
['Average purchase price'] = acq.estimatePrice(uex.purchase, 'price_buy'),
['Average rental price'] = acq.estimatePrice(uex.rental, 'price_rent'),
['Health point'] = tonumber(apiData.health),
['Shield health point'] = tonumber(apiData.shield_hp),
['Pilot DPS'] = tonumber(weaponry.pilot_dps),
['Turret DPS'] = tonumber(weaponry.turret_dps),
['Pilot sustained DPS'] = tonumber(weaponry.pilot_sustained_dps),
['Turret sustained DPS'] = tonumber(weaponry.turret_sustained_dps),
['Missile damage'] = type(missiles.damage) == 'table' and tonumber(missiles.damage.total) or nil,
['Infrared emission'] = tonumber(emission.ir),
['Electromagnetic emission'] = tonumber(emission.em_max),
['Cross section'] = vehicleUtil.meanCrossSection(apiData.cross_section),
-- Per-axis cross-section (raw): the Stats tab ranks each axis against the size
-- class. The armor cross-section multiplier is stored separately and folded in at
-- cohort/render time (like the mean), so these stay raw.
['Cross section length'] = tonumber(crossSection.length),
['Cross section width'] = tonumber(crossSection.width),
['Cross section height'] = tonumber(crossSection.height),
['Armor resistance'] = vehicleUtil.meanArmorResistance(armor),
['Armor deflection'] = vehicleUtil.meanDeflection(armor),
['Physical deflection'] = type(armor.deflection) == 'table' and tonumber(armor.deflection.physical) or nil,
['Energy deflection'] = type(armor.deflection) == 'table' and tonumber(armor.deflection.energy) or nil,
['Zero to Maximum speed time'] = tonumber(speed.zero_to_max),
['Cross section signature modifier'] = armor.signal_cross_section and tonumber(armor.signal_cross_section)
or nil,
['Electromagnetic signature modifier'] = armor.signal_electromagnetic and tonumber(
armor.signal_electromagnetic
) or nil,
['Infrared signature modifier'] = armor.signal_infrared and tonumber(armor.signal_infrared) or nil,
['Hydrogen fuel capacity'] = tonumber(fuel.capacity),
['Hydrogen fuel intake rate'] = tonumber(fuel.intake_rate),
['Quantum fuel capacity'] = tonumber(quantum.quantum_fuel_capacity),
['Quantum speed'] = (function()
local qsRaw = tonumber(quantum.quantum_speed)
return qsRaw and (qsRaw / QUANTUM_SPEED_DIVISOR) or nil -- Mm/s, matches QuantumDrive
end)(),
['Quantum range'] = (function()
local qrRaw = tonumber(quantum.quantum_range)
return qrRaw and (qrRaw / QUANTUM_RANGE_DIVISOR) or nil -- Gm
end)(),
['Quantum spool time'] = tonumber(quantum.quantum_spool_time),
}
for _, dt in ipairs(vehicleUtil.DAMAGE_TYPES) do
data[dt.label .. ' damage modifier'] = tonumber(armor[dt.key])
end
return data
end
--- The sides of a grid's `min_size` or `max_size` box, shortest first. The
--- box's x/y/z do not follow the grid's own axes (the Zeus Mk II CL allows
--- 10 m on z in a 3.75 m tall hold), so only the sorted sides mean anything.
--- @param box any
--- @return number[]|nil
local function limitSides(box)
if type(box) ~= 'table' then
return nil
end
local sides = { tonumber(box.x), tonumber(box.y), tonumber(box.z) }
if not (sides[1] and sides[2] and sides[3]) then
return nil
end
table.sort(sides)
return sides
end
--- One `cargo_grid` row per cargo grid, in the API's order. `sub` is the
--- grid's 1-based position: identical grids on one ship (the Caterpillar's
--- modules) share everything else, the API's grid uuid included.
--- @param ctx EntityHookContext
--- @return EntityStructuredRow[]
function p.getStructuredRows(ctx)
local grids = type(ctx.apiData.cargo_grids) == 'table' and ctx.apiData.cargo_grids or {}
local rows = {}
for i, grid in ipairs(grids) do
if type(grid) == 'table' then
local external = nil
if type(grid.external) == 'boolean' then
external = grid.external
end
local min = limitSides(grid.min_size) or {}
local max = limitSides(grid.max_size) or {}
rows[#rows + 1] = {
sub = tostring(i),
data = {
cargo_grid_length = tonumber(grid.length),
cargo_grid_width = tonumber(grid.width),
cargo_grid_height = tonumber(grid.height),
cargo_grid_capacity = tonumber(grid.scu),
cargo_grid_external = external,
cargo_grid_maximum_container_size = tonumber(grid.max_scu_box),
cargo_grid_minimum_item_shortest_side = min[1],
cargo_grid_minimum_item_middle_side = min[2],
cargo_grid_minimum_item_longest_side = min[3],
cargo_grid_maximum_item_shortest_side = max[1],
cargo_grid_maximum_item_middle_side = max[2],
cargo_grid_maximum_item_longest_side = max[3],
},
}
end
end
return rows
end
--- External-site links: Official (pledgeurl from API + editorial galactapediaurl /
--- brochureurl / trailerurl / presentationurl / qaurl / whitleysguideurl) and Community
--- (ship tools from API identifiers). The brochure/trailer/presentation/Q&A args each accept a
--- semicolon-separated list for multiple URLs (e.g. presentationurl = url1; url2 — the
--- wiki multi-value convention). The footer merges the "Official sites" row with Base's
--- same-label row.
--- @param ctx EntityHookContext
--- @return table[]
function p.getExternalSiteItems(ctx)
local apiData, args = ctx.apiData, ctx.args
local items = {}
local official = format.buildSiteLinks(mw.loadJsonData('Module:Entity/Vehicle/officialSites.json'), {
pledge_url = args.pledgeurl or apiData.pledge_url,
galactapedia = args.galactapediaurl,
brochure = format.splitSemi(args.brochureurl),
trailer = format.splitSemi(args.trailerurl),
presentation = format.splitSemi(args.presentationurl),
qa = format.splitSemi(args.qaurl),
whitleys_guide = format.splitSemi(args.whitleysguideurl),
})
if official then
items[#items + 1] = { label = msg('Official sites'), content = official }
end
local className = type(apiData.class_name) == 'string' and mw.ustring.lower(apiData.class_name) or nil
local uuid = args.uuid or apiData.uuid
local community = format.buildSiteLinks(mw.loadJsonData('Module:Entity/Vehicle/communitySites.json'), {
uuid = type(uuid) == 'string' and mw.ustring.lower(uuid) or nil,
class_name = className,
ship_matrix = shipMatrixSlug(apiData.shipmatrix_name),
})
if community then
items[#items + 1] = { label = msg('Community sites'), content = community }
end
return items
end
--- Production states whose browse category is not the plain state word. Keyed
--- by the normalized ProductionStatus key (see
--- Module:Entity/ProductionStatus.key). Their category pages are deliberately
--- never created: a wanted-category with its member listing is this wiki's
--- established pattern for browse categories that need no page of their own.
--- @type table<string, string>
local STATE_BROWSE_CATEGORY = {
loreonly = 'Nur Lore',
unconfirmed = 'Unbestätigt',
}
--- Does a pledge price resolve for this vehicle? Editorial pledge_price wins,
--- else the API msrp. Shared by the family leaves, whose pledge browse
--- category differs by noun (Pledge Raumschiff / Pledge Bodenfahrzeug).
--- @param apiData table
--- @param resolved table|nil
--- @return boolean
function p.hasPledgePrice(apiData, resolved)
local pledge = tonumber(Editorial.view(resolved):value('pledge_price', apiData.msrp))
return pledge ~= nil and pledge > 0
end
--- Browse categories that do not depend on the family: production state and
--- the series grouping. The family leaves (Ship / GroundVehicle / Gravlev)
--- contribute the structural and pledge categories. These are ALSO stored
--- properties; the categories are additive for navigation. Pure.
--- @param ctx EntityHookContext
--- @return string[]
function p.getCategories(ctx)
local apiData, args, resolved = ctx.apiData, ctx.args, ctx.resolved
local ed = Editorial.view(resolved)
local cats = {}
-- Production state category: the German state word via Vocab, never msg()
-- (categories are structural and deterministic, not display strings). Only
-- the flight-ready word splits by family: ground vehicles carry their own
-- Fahrbereit category, matching the badge; every other state shares one
-- word across families.
local state = ed:value('production_state', apiData.production_status)
local stateCat = STATE_BROWSE_CATEGORY[productionStatus.key(state)]
if stateCat == nil then
local stateLabel = productionStatus.label(state)
stateCat = stateLabel and Vocab.toGerman('production_state', stateLabel) or nil
end
if stateCat == 'Flugbereit' and deriveFamily(apiData, args) == 'ground' then
stateCat = 'Fahrbereit'
end
if stateCat then
cats[#cats + 1] = stateCat
end
-- Series grouping "<series> (Baureihe)" (e.g. "Carrack (Baureihe)") - the
-- series-led spelling the live wiki's Baureihe categories already use, so
-- existing browse pages keep their members at cutover. Generation
-- groupings are gone: one category per generation diluted the browse.
-- Career compounds are emitted by the family modules (the noun differs
-- per family), so nothing here. Upstream additionally emits a per-variant
-- category (suppressed by novariant); this wiki's Baureihe grouping
-- replaces it, and novariant only stores (Keine Varianten).
local series = ed:value('series')
if series ~= nil and series ~= '' then
cats[#cats + 1] = series .. ' (Baureihe)'
end
return cats
end
--- Acquisition data for {{Entity/Availability}}: Buy/Rent/Pledge summary flags
--- (Loot/Craft omitted — neither applies to vehicles) and Shops + Rentals
--- terminal cards from uex_prices.{purchase,rental}. Pledge derives from msrp.
--- @param ctx EntityHookContext
--- @return { summary: table[], cards: table[] }
function p.getAcquisition(ctx)
local apiData, args = ctx.apiData, ctx.args
local prices = type(apiData.uex_prices) == 'table' and apiData.uex_prices or {}
local purchase = type(prices.purchase) == 'table' and prices.purchase or {}
local rental = type(prices.rental) == 'table' and prices.rental or {}
local summary = {
{
label = msg('Buy'),
icon = '🛒',
value = acq.resolveFlag(args.canBuy, acq.inferCanAcquire(purchase, 'price_buy')),
},
{
label = msg('Rent'),
icon = '⏳',
value = acq.resolveFlag(args.canRent, acq.inferCanAcquire(rental, 'price_rent')),
},
{ label = 'Pledge', icon = '💵', value = acq.resolveFlag(args.canPledge, apiData.msrp ~= nil) },
}
local hasPurchase = #purchase > 0
local hasSell = hasPurchase and acq.priceRange(purchase, 'price_sell') ~= nil
local shopColumns = { { id = 'buy', key = 'price_buy', label = msg('Buy') } }
if hasSell then
shopColumns[#shopColumns + 1] = { id = 'sell', key = 'price_sell', label = msg('Sell') }
end
local shopDescription
if hasPurchase then
shopDescription = hasSell and acq.buildShopTerminalsDescription(purchase)
or acq.buildSinglePriceDescription(purchase, 'price_buy')
else
shopDescription = msg('No shop data in UEX')
end
local hasRental = #rental > 0
return {
summary = summary,
cards = {
{
type = 'terminals',
title = '<span aria-hidden="true">🛒</span> Shops',
caption = msg('Shop terminals'),
description = shopDescription,
prices = hasPurchase and purchase or nil,
priceColumns = shopColumns,
},
{
type = 'terminals',
title = '<span aria-hidden="true">⏳</span> ' .. msg('Rentals'),
caption = msg('Vehicle rental terminals'),
description = hasRental and acq.buildSinglePriceDescription(rental, 'price_rent')
or msg('No rental data in UEX'),
prices = hasRental and rental or nil,
priceColumns = { { id = 'rent', key = 'price_rent', label = msg('Rent') } },
},
},
}
end
--- Ports payload for {{Entity/Ports}}. Vehicle port trees carry cockpit
--- panels, displays and similar sub-ports that are not `collapsed` but do
--- not belong in a component's L-tree, so the Ports pipeline narrows
--- children by each category's expandIntoTypes allowlist.
--- @param ctx EntityHookContext
--- @return EntityPortsPayload
function p.getPorts(ctx)
local apiData = ctx.apiData
return { ports = apiData.ports, narrowChildren = true }
end
--- Vehicle series variants for {{Entity/Related}} (Entity/Related.renderVehicleVariants
--- queries Bucket for the rest of the series). A sibling {{Entity/Related}} invocation
--- carries no {{Entity}} arguments, so with no editorial series this reads it back from
--- Bucket instead (Store.selfValue, written on the page's last link update). nil when
--- neither resolves: Entity/Related resolves getRelated with acceptNonEmpty, so a nil
--- answer here falls through to Base's own related_items payload rather than showing
--- nothing.
--- @param ctx EntityHookContext
--- @return EntityRelatedPayload|nil
function p.getRelated(ctx)
local series = Editorial.view(ctx.resolved):value('series')
if series == nil or series == '' then
series = store.selfValue('Series', 'Vehicle')
end
if series == nil or series == '' then
return nil
end
return { vehicleSeries = series }
end
return p