Modul:Entity/SubtypeResolver
Aus Star Citizen Wiki
Weitere Optionen
Die Dokumentation für dieses Modul kann unter Modul:Entity/SubtypeResolver/doc erstellt werden
require('strict')
--- @module Entity/SubtypeResolver
--- The mechanical half of subtype dispatch shared by kinds whose resolveSubtype
--- selects a leaf by a string token: a `token → loader` lookup that returns the
--- leaf module. The *derivation* of the token (a record field, a flag ladder) stays per-kind; the lookup and the curated-arg normalisation (familyArg) are shared.
--- Sibling of Module:Entity/TypeResolver (which resolves display metadata, not
--- behavior modules).
local p = {}
--- @param token string|nil the dispatch token (e.g. apiData.type, or a vehicle family)
--- @param map table<string, fun(): table> token → loader. Each loader wraps a literal
--- `require('Module:…')`: the leaf loads only when selected, and Module:Dependencies
--- reads the dependency from the kind's source.
--- @return table|nil the leaf module, or nil for nil/empty/unmapped token
function p.resolve(token, map)
if type(token) ~= 'string' or token == '' then
return nil
end
local loader = map[token]
if loader == nil then
return nil
end
return loader()
end
--- The curated `|family=` arg as a dispatch token: trimmed and lowercased so
--- editors may write `Ship` or ` JumpPoint `, nil when absent, blank, or not a
--- string. German tokens map onto the English leaf keys (Sternensystem,
--- Stern, Himmelskörper, Gürtel, Ort, Interessenpunkt, Sprungpunkt), with the
--- unaccented spellings accepted alongside, so every kind's resolveSubtype
--- reads the arg through here and the normalisation cannot drift between
--- kinds or languages.
local FAMILY_ALIASES = {
['sternensystem'] = 'starsystem',
['stern'] = 'star',
['himmelskörper'] = 'body',
['himmelskoerper'] = 'body',
['gürtel'] = 'belt',
['guertel'] = 'belt',
['ort'] = 'place',
['interessenpunkt'] = 'poi',
['sprungpunkt'] = 'jumppoint',
}
--- @param args table|nil
--- @return string|nil
function p.familyArg(args)
if type(args) ~= 'table' or type(args.family) ~= 'string' then
return nil
end
local token = mw.text.trim(args.family):lower()
if token == '' then
return nil
end
return FAMILY_ALIASES[token] or token
end
return p