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

require('strict')

--- @module Entity/Facet/Gadget
--- Gadget facet (WeaponPersonal sub_type "Gadget"): multi-tools, handheld
--- salvage tools, tractor beams, fire extinguishers, rangefinders. Their stats
--- live in the shared `personal_weapon` block, but the gun "Weapon" section is
--- meaningless for a utility tool — so WeaponPersonal suppresses it for gadgets
--- and this facet renders the utility overview (type / range / capacity) instead.
---
--- Per-mode behaviour is owned by data-driven facets that match on the mode
--- itself, not on the Gadget sub_type: a Salvage mode renders via the Salvage
--- facet, a healing-beam mode via the Heal facet, and optical zoom via the
--- WeaponModifier facet. Stat-less modes (tractor toggle, rangefinder single) add
--- nothing.

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

local p = {}

--- @param apiData table|nil
--- @return boolean
function p.matches(apiData)
	return apiData ~= nil and apiData.sub_type == 'Gadget'
end

--- @param ctx EntityHookContext
--- @return EntitySectionEntry[]
function p.getSections(ctx)
	local apiData = ctx.apiData
	local pw = apiData.personal_weapon
	if type(pw) ~= 'table' then
		return {}
	end
	local ammunition = type(pw.ammunition) == 'table' and pw.ammunition or {}

	local overview = {}
	sectionBuilder.push(overview, msg('Type'), type(pw.type) == 'string' and pw.type ~= '' and pw.type or nil)
	-- `range` (the API's non-deprecated field; `effective_range` is deprecated).
	-- Skip it when a tractor_beam block is present: the Beam facet renders the
	-- authoritative beam range, so the gadget overview would just duplicate it.
	if type(apiData.tractor_beam) ~= 'table' then
		sectionBuilder.push(overview, msg('Range'), Util.withUnit(pw.range, ' m'))
	end
	local capacity = tonumber(ammunition.capacity)
	if capacity and capacity > 0 then
		sectionBuilder.push(overview, msg('Capacity'), format.formatNum(capacity))
	end

	return sectionBuilder.build(sectionBuilder.section({
		key = 'gadget',
		label = 'Gadget',
		collapsible = true,
		items = overview,
	}))
end

--- @param ctx EntityHookContext
--- @return table<string, any>
function p.getStructuredData(ctx)
	local apiData = ctx.apiData
	local pw = apiData.personal_weapon
	if type(pw) ~= 'table' then
		return {}
	end
	local data = {}
	local range = tonumber(pw.range)
	if range then
		data.max_range = range
	end
	return data
end

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.