Files
millimeters-of-aluminum/scenes/ship/computer/shards/helm_ship_status.gd
2025-10-21 17:26:31 +02:00

38 lines
1.2 KiB
GDScript

extends Databank
class_name ShipStatusShard
## This shard emits a signal with the formatted ship status text.
signal status_updated(text: String)
# Called by the Station when it's created.
func initialize(ship_root: Module):
self.root_module = ship_root
## Describes the functions this shard needs as input.
func get_input_sockets() -> Array[String]:
return []
## Describes the signals this shard can output.
func get_output_sockets() -> Array[String]:
return ["status_updated"]
func _physics_process(delta):
if not is_instance_valid(root_module):
return
# 1. Gather all the data from the root module.
var rotation_deg = rad_to_deg(root_module.rotation)
var angular_vel_dps = rad_to_deg(root_module.angular_velocity)
var linear_vel_mps = root_module.linear_velocity.length()
# 2. Build the string that will be displayed.
var status_text = """
[font_size=24]Ship Status[/font_size]
[font_size=18]Rotation: %.1f deg[/font_size]
[font_size=18]Ang. Vel.: %.2f deg/s[/font_size]
[font_size=18]Velocity: %.2f m/s[/font_size]
""" % [rotation_deg, angular_vel_dps, linear_vel_mps]
# 3. Emit the signal with the formatted text.
status_updated.emit(status_text)