297 lines
7.9 KiB
GDScript
297 lines
7.9 KiB
GDScript
class_name CockpitDetailing
|
|
extends Node3D
|
|
|
|
const DiveUpdate = preload("res://game/domain/dive/dive_update.gd")
|
|
const DiveAlertLevel = preload("res://game/domain/dive/dive_alert_level.gd")
|
|
const VehicleTelemetry = preload("res://game/application/dive/vehicle_telemetry.gd")
|
|
const CockpitAnalogGauges = preload("res://game/presentation/cockpit/cockpit_analog_gauges.gd")
|
|
const CockpitDashboardDetailing = preload(
|
|
"res://game/presentation/cockpit/cockpit_dashboard_detailing.gd"
|
|
)
|
|
const CockpitMaterialPalette = preload("res://game/presentation/cockpit/cockpit_material_palette.gd")
|
|
const CockpitMeshFactory = preload("res://game/presentation/cockpit/cockpit_mesh_factory.gd")
|
|
const CockpitSideEquipment = preload(
|
|
"res://game/presentation/cockpit/cockpit_side_equipment.gd"
|
|
)
|
|
const CockpitSonarConsole = preload(
|
|
"res://game/presentation/cockpit/cockpit_sonar_console.gd"
|
|
)
|
|
const CockpitPracticalLighting = preload(
|
|
"res://game/presentation/cockpit/cockpit_practical_lighting.gd"
|
|
)
|
|
|
|
var _materials: CockpitMaterialPalette
|
|
var _painted_steel: Material
|
|
var _dark_steel: Material
|
|
var _brass: Material
|
|
var _copper: Material
|
|
var _analog_gauges: CockpitAnalogGauges
|
|
var _dashboard_detailing: CockpitDashboardDetailing
|
|
var _side_equipment: CockpitSideEquipment
|
|
var _sonar_console: CockpitSonarConsole
|
|
var _practical_lighting: CockpitPracticalLighting
|
|
|
|
|
|
func _ready() -> void:
|
|
_create_materials()
|
|
_apply_materials_to_existing_cockpit()
|
|
_build_pressure_hull_ribs()
|
|
_build_life_support_pipes()
|
|
_build_panel_hardware()
|
|
_build_dashboard_instrumentation()
|
|
_build_equipment_assemblies()
|
|
|
|
|
|
func present(update: DiveUpdate, telemetry: VehicleTelemetry) -> void:
|
|
if update == null or update.snapshot == null or telemetry == null:
|
|
return
|
|
var snapshot = update.snapshot
|
|
_analog_gauges.present(
|
|
snapshot.oxygen.ratio,
|
|
snapshot.battery.ratio,
|
|
snapshot.hull.ratio,
|
|
clampf(
|
|
snapshot.depth.current_m
|
|
/ maxf(snapshot.depth.certified_m, 0.001),
|
|
0.0,
|
|
1.0
|
|
),
|
|
snapshot.alerts.maximum
|
|
)
|
|
var alert_level: DiveAlertLevel.Value = snapshot.alerts.maximum
|
|
_practical_lighting.present(alert_level)
|
|
|
|
|
|
func pressure_hull_rib_count() -> int:
|
|
var ribs := get_node_or_null("PressureHullRibs")
|
|
return 0 if ribs == null else ribs.get_child_count()
|
|
|
|
|
|
func pipe_segment_count() -> int:
|
|
var pipes := get_node_or_null("LifeSupportPipes")
|
|
return 0 if pipes == null else pipes.get_child_count()
|
|
|
|
|
|
func battery_needle_degrees() -> float:
|
|
return 0.0 if _analog_gauges == null else _analog_gauges.battery_needle_degrees()
|
|
|
|
|
|
func textures_are_loaded() -> bool:
|
|
return (
|
|
_materials != null
|
|
and _materials.overhead_steel.albedo_texture != null
|
|
and _materials.oxygen_gauge_face.albedo_texture != null
|
|
and _materials.battery_gauge_face.albedo_texture != null
|
|
and _materials.hull_gauge_face.albedo_texture != null
|
|
and _materials.depth_gauge_face.albedo_texture != null
|
|
)
|
|
|
|
|
|
func dashboard_control_count() -> int:
|
|
return 0 if _dashboard_detailing == null else _dashboard_detailing.control_count()
|
|
|
|
|
|
func side_equipment_count() -> int:
|
|
if _side_equipment == null:
|
|
return 0
|
|
return _side_equipment.tank_count() + _side_equipment.junction_box_count()
|
|
|
|
|
|
func side_control_count() -> int:
|
|
return 0 if _side_equipment == null else _side_equipment.control_count()
|
|
|
|
|
|
func sonar_control_count() -> int:
|
|
return 0 if _sonar_console == null else _sonar_console.control_count()
|
|
|
|
|
|
func practical_light_count() -> int:
|
|
return 0 if _practical_lighting == null else _practical_lighting.practical_light_count()
|
|
|
|
|
|
func gauges_are_dashboard_mounted() -> bool:
|
|
return _analog_gauges != null and _analog_gauges.get_parent() == get_parent().get_node("Dashboard")
|
|
|
|
|
|
func _create_materials() -> void:
|
|
_materials = CockpitMaterialPalette.new()
|
|
_painted_steel = _materials.painted_steel
|
|
_dark_steel = _materials.dark_steel
|
|
_brass = _materials.brass
|
|
_copper = _materials.copper
|
|
|
|
|
|
func _apply_materials_to_existing_cockpit() -> void:
|
|
_apply_material_to_paths(
|
|
_painted_steel,
|
|
[
|
|
"CabinShell/LeftWall",
|
|
"CabinShell/RightWall",
|
|
"LeftConsole",
|
|
"RightConsole",
|
|
]
|
|
)
|
|
_apply_material_to_paths(
|
|
_dark_steel,
|
|
[
|
|
"CabinShell/RearBulkhead",
|
|
"PortholeAssembly/LeftBulkhead",
|
|
"PortholeAssembly/RightBulkhead",
|
|
"PortholeAssembly/BottomBulkhead",
|
|
"ThrottleLever",
|
|
"VerticalLever",
|
|
]
|
|
)
|
|
_apply_material_to_paths(
|
|
_materials.overhead_steel,
|
|
[
|
|
"CabinShell/Ceiling",
|
|
"PortholeAssembly/TopBulkhead",
|
|
"Dashboard/MainPanel",
|
|
]
|
|
)
|
|
_apply_material_to_paths(
|
|
_brass,
|
|
[
|
|
"PortholeAssembly/WindowFrame",
|
|
"Dashboard/ResourcesFrame",
|
|
"Dashboard/NavigationFrame",
|
|
"Dashboard/IntegrityFrame",
|
|
"ThrottleKnob",
|
|
"VerticalKnob",
|
|
]
|
|
)
|
|
func _apply_material_to_paths(material: Material, paths: Array[String]) -> void:
|
|
var cockpit := get_parent()
|
|
for path: String in paths:
|
|
var mesh := cockpit.get_node_or_null(path) as MeshInstance3D
|
|
if mesh != null:
|
|
mesh.material_override = material
|
|
|
|
|
|
func _build_pressure_hull_ribs() -> void:
|
|
var root := Node3D.new()
|
|
root.name = "PressureHullRibs"
|
|
add_child(root)
|
|
for rib_index in 2:
|
|
var rib := MeshInstance3D.new()
|
|
rib.name = "CircularRib%d" % (rib_index + 1)
|
|
var torus := TorusMesh.new()
|
|
torus.inner_radius = 1.00
|
|
torus.outer_radius = 1.075
|
|
torus.rings = 48
|
|
torus.ring_segments = 10
|
|
rib.mesh = torus
|
|
rib.material_override = _dark_steel
|
|
rib.position = Vector3(0.0, 0.22, -0.90 + rib_index * 1.35)
|
|
rib.rotation_degrees.x = 90.0
|
|
root.add_child(rib)
|
|
|
|
for side: float in [-1.0, 1.0]:
|
|
CockpitMeshFactory.add_box(
|
|
"AngledShoulder",
|
|
root,
|
|
Vector3(side * 0.88, 0.84, -0.36),
|
|
Vector3(0.11, 0.62, 1.52),
|
|
_painted_steel,
|
|
Vector3(0.0, 0.0, side * -18.0)
|
|
)
|
|
CockpitMeshFactory.add_box(
|
|
"LowerStringer",
|
|
root,
|
|
Vector3(side * 0.91, -0.38, -0.18),
|
|
Vector3(0.10, 0.12, 1.70),
|
|
_dark_steel
|
|
)
|
|
|
|
|
|
func _build_life_support_pipes() -> void:
|
|
var root := Node3D.new()
|
|
root.name = "LifeSupportPipes"
|
|
add_child(root)
|
|
for side: float in [-1.0, 1.0]:
|
|
var x: float = side * 0.83
|
|
CockpitMeshFactory.add_cylinder(
|
|
"VerticalPipe",
|
|
root,
|
|
Vector3(x, 0.33, -1.12),
|
|
0.027,
|
|
1.18,
|
|
_copper
|
|
)
|
|
CockpitMeshFactory.add_cylinder(
|
|
"ReturnPipe",
|
|
root,
|
|
Vector3(side * 0.73, 0.47, -1.09),
|
|
0.019,
|
|
0.92,
|
|
_brass
|
|
)
|
|
for clamp_y: float in [-0.04, 0.35, 0.72]:
|
|
var clamp := MeshInstance3D.new()
|
|
clamp.name = "PipeClamp"
|
|
var torus := TorusMesh.new()
|
|
torus.inner_radius = 0.027
|
|
torus.outer_radius = 0.041
|
|
torus.rings = 16
|
|
torus.ring_segments = 6
|
|
clamp.mesh = torus
|
|
clamp.material_override = _dark_steel
|
|
clamp.position = Vector3(x, clamp_y, -1.12)
|
|
root.add_child(clamp)
|
|
CockpitMeshFactory.add_sphere(
|
|
"PipeJunction",
|
|
root,
|
|
Vector3(x, 0.91, -1.12),
|
|
0.052,
|
|
_copper
|
|
)
|
|
CockpitMeshFactory.add_cylinder_between(
|
|
"UpperBranchPipe",
|
|
root,
|
|
Vector3(x, 0.84, -1.12),
|
|
Vector3(side * 0.72, 0.77, -1.10),
|
|
0.019,
|
|
_brass
|
|
)
|
|
|
|
|
|
func _build_panel_hardware() -> void:
|
|
var root := Node3D.new()
|
|
root.name = "PanelHardware"
|
|
add_child(root)
|
|
for x: float in [-0.73, -0.49, -0.24, 0.24, 0.49, 0.73]:
|
|
for y: float in [-0.18, 0.22]:
|
|
CockpitMeshFactory.add_cylinder(
|
|
"PanelFastener",
|
|
root,
|
|
Vector3(x, y, -1.105),
|
|
0.014,
|
|
0.018,
|
|
_dark_steel,
|
|
Vector3(90.0, 0.0, 0.0)
|
|
)
|
|
|
|
|
|
|
|
func _build_dashboard_instrumentation() -> void:
|
|
var dashboard := get_parent().get_node_or_null("Dashboard") as Node3D
|
|
if dashboard == null:
|
|
return
|
|
_dashboard_detailing = CockpitDashboardDetailing.new(_materials)
|
|
dashboard.add_child(_dashboard_detailing)
|
|
_dashboard_detailing.hide_obsolete_elements(get_parent())
|
|
_analog_gauges = CockpitAnalogGauges.new(_materials)
|
|
dashboard.add_child(_analog_gauges)
|
|
|
|
|
|
func _build_equipment_assemblies() -> void:
|
|
_side_equipment = CockpitSideEquipment.new(_materials)
|
|
add_child(_side_equipment)
|
|
var sonar_monitor := get_parent().get_node_or_null("SonarMonitor") as Node3D
|
|
if sonar_monitor != null:
|
|
_sonar_console = CockpitSonarConsole.new(_materials)
|
|
sonar_monitor.add_child(_sonar_console)
|
|
_practical_lighting = CockpitPracticalLighting.new(_materials)
|
|
add_child(_practical_lighting)
|