class_name CockpitAlertBox extends Node3D ## Drives the three lamps of the imported alert box model. Exactly one lamp is ## lit for the alert level carried by the dive snapshot; the lamps are also ## distinguished by position and by their engraved ALERTE / ATTENTION / DANGER ## plates, so the reading does not depend on colour alone. const DiveAlertLevel = preload("res://game/domain/dive/dive_alert_level.gd") const CockpitMeshFactory = preload("res://game/presentation/cockpit/cockpit_mesh_factory.gd") const LAMP_NAMES: Array[String] = ["Lamp_Alerte", "Lamp_Attention", "Lamp_Danger"] const LIT_ENERGY := 4.0 const UNLIT_ENERGY := 0.0 var _lamp_materials: Array[BaseMaterial3D] = [] func _ready() -> void: for lamp_name: String in LAMP_NAMES: var lamp := find_child(lamp_name, true, false) as MeshInstance3D var material := CockpitMeshFactory.own_surface_material(lamp) if material == null: push_error("Alert box model has no usable %s lamp" % lamp_name) continue material.emission_energy_multiplier = UNLIT_ENERGY _lamp_materials.append(material) func present(alert_level: DiveAlertLevel.Value) -> void: var active_index := _lamp_index_for(alert_level) for lamp_index in _lamp_materials.size(): _lamp_materials[lamp_index].emission_energy_multiplier = ( LIT_ENERGY if lamp_index == active_index else UNLIT_ENERGY ) func indicator_count() -> int: return _lamp_materials.size() func active_indicator_count() -> int: var count := 0 for material: BaseMaterial3D in _lamp_materials: if material.emission_energy_multiplier > UNLIT_ENERGY: count += 1 return count func active_indicator_name() -> String: for lamp_index in _lamp_materials.size(): if _lamp_materials[lamp_index].emission_energy_multiplier > UNLIT_ENERGY: return LAMP_NAMES[lamp_index] return "" func _lamp_index_for(alert_level: DiveAlertLevel.Value) -> int: if alert_level >= DiveAlertLevel.Value.CRITICAL: return 2 if alert_level >= DiveAlertLevel.Value.ATTENTION: return 1 return 0