Files
Trinittu/scripts/traincontrol.gd
Overside srl 65bb24ff6a fix sky
2026-02-16 07:19:27 +01:00

51 lines
1.2 KiB
GDScript

extends Node3D
@export var main_scene: PackedScene
@onready var speed_label : Label = $HUD/speed_label
@onready var camera_label : Label = $HUD/camera_label
@onready var train: MeshInstance3D = $Ground/Train
@onready var camera: TrainControlCamera = $TrainCamera
@onready var rail_switch: Area3D = $Ground/RailSwtich
@onready var switch_label : Label = $HUD/switch_label
func _ready() -> void:
_update_switch_status()
func _process(_delta: float) -> void:
_update_ui()
if Input.is_action_just_pressed("ui_cancel"):
SceneSwitcher.switch_scene(main_scene.resource_path)
if Input.is_action_just_pressed("change_train"):
_toggle_rail()
func _update_ui() -> void:
if speed_label and train:
var kmh = train.get_speed() * 3.6
speed_label.text = "Velocità: %.0f km/h" % kmh
if camera_label and camera:
camera_label.text = "Camera: %s" % camera.get_mode_name()
func _toggle_rail() -> void:
if train and rail_switch:
rail_switch.toggle_switch()
#train.switch_to_rail(rail_switch.switch_to_rail)
#_update_switch_status()
func _update_switch_status():
if not switch_label:
return
if rail_switch:
var state_name = rail_switch.get_state_name()
switch_label.text = "Scambio: %s" % state_name
else:
switch_label.text = "Scambio: N/A"