feat: working on train labels

This commit is contained in:
tiger tiger tiger 2026-01-24 13:59:14 +01:00
parent 2e473e4b4e
commit 2ceb9216e0
10 changed files with 65 additions and 45 deletions

View File

@ -52,6 +52,8 @@ signal train_left(track : Dolly)
func _ready() -> void:
reset()
func set_line(line: StringName):
subway.set_line(line)
## One arrival and departure
func cycle() -> void:

View File

@ -26,29 +26,28 @@ func _set_signage_texts(group: StringName, message: String) -> void:
await get_tree().create_timer(0.05).timeout
func _ready() -> void:
var x : Station = $hirschfeld
print(x.name)
await get_tree().process_frame
tracks[0].train_left.connect(_player_train_left)
tracks[1].train_left.connect(_player_train_left)
_unparent_all_stations_except($hirschfeld)
enter_station(current_station)
enter_station(current)
var current_station : Station = null
## The current station
var current : Station
var stop := false
var destinations : Array[Station] = [null, null]
## Begins the scheduled traffic (looping through the list of destinations) on a given track
func _begin_traffic_loop(track: Dolly, cancel: Array) -> void:
if not track.player_on_board and fahrplan[current_station][track.index] == null: # empty trains dont arrive at endstation
if not track.player_on_board and fahrplan[current][track.index] == null: # empty trains dont arrive at endstation
track.arrive(true)
_set_signage_texts(track.signage_group, "Endstation")
return
var routes : Array = fahrplan[current_station][track.index]
var routes : Array = fahrplan[current][track.index]
if routes.is_empty():
_set_signage_texts(track.signage_group, "Verkehr z. Zt.\nunregelmäßig")
return
@ -56,11 +55,15 @@ func _begin_traffic_loop(track: Dolly, cancel: Array) -> void:
while true:
if cancel.is_empty(): return # abort the loop
var next : Node = routes.pop_front()
var line : StringName = routes.pop_front()
var next : Station = routes.pop_front()
routes.append(line) # It's a ring buffer
routes.append(next) # It's a ring buffer
destinations[track.index] = next
_set_signage_texts(track.signage_group, next.name) # TODO: load nice string
track.set_line(line)
_set_signage_texts(track.signage_group, current.get_label(line, next)) # TODO: load nice string
# Vary our schedule a little by making empty trains wait a random amount of time
if not track.player_on_board:
@ -72,11 +75,11 @@ func _begin_traffic_loop(track: Dolly, cancel: Array) -> void:
var cancellation_token : Array
func enter_station(station: Node):
func enter_station(station: Station):
prints("------------", "ENTER STATION", station, station.name, "------------")
remove_child(current_station)
current_station = station
add_child(current_station)
remove_child(current)
current = station
add_child(station)
cancellation_token = ["go"] # Allocate a new stopping token
_begin_traffic_loop(tracks[0], cancellation_token)
@ -89,9 +92,9 @@ func _player_train_left(track: Dolly) -> void:
func _unparent_all_stations_except(except : Node3D):
for station in stations:
if station == except:
current_station = station
continue
assert(station.get_parent() == self, "A station that isn't a child of Fahrplan is in the Fahrplan: %s" % station.name)
remove_child(station)
station.visible = true # Make visible by default, parenting handles visibility and collision
if station == except:
current = station
continue
remove_child(station)

View File

@ -3,3 +3,6 @@ class_name Station
@export var i18n_key : StringName
@export var train_labels : Dictionary[StringName,String] = {}
func get_label(line: StringName, next_stop: Station) -> String:
return train_labels.get(line+next_stop.name, line+next_stop.name)

View File

@ -1,9 +1,6 @@
extends Room
class_name SubwaySequence
@export var all_stations: Dictionary[Station.id, Station]
@export var all_lines: Dictionary[TrainLine.id, TrainLine]
func _ready() -> void:
id = State.rooms.TRANSITION
super._ready()

View File

@ -1,6 +1,8 @@
extends Node3D
class_name SubwayTrain
@export var materials : Dictionary[StringName, Material] = {}
@export var door_open: bool:
set(open):
if door_open == open: return
@ -11,3 +13,9 @@ class_name SubwayTrain
%TrainModel/AnimationPlayer.play("door_close")
%FrontWallClosed.disabled = door_open
func set_line(line : StringName):
$TrainModel/traun_hull.material_overlay = materials[line]
get_tree().call_group("labels", "set_text", line.to_upper())

View File

@ -1,14 +0,0 @@
class_name TrainLine extends Resource
enum id {
NONE,
RING,
U2,
U3,
U8
}
@export var train_id: id = id.NONE
@export var destination: StringName = ""
@export var via: StringName = ""
@export var stops: Dictionary[Station, float]

View File

@ -1 +0,0 @@
uid://dfkq0djtygmma

View File

@ -233,14 +233,14 @@ signage_group = "signage1"
script = ExtResource("4_yfan7")
metadata/_custom_type_script = "uid://bi4cwmajhpa5f"
[node name="hirschfeld" parent="Logic/Fahrplan" instance=ExtResource("5_rum2v")]
[node name="hirschfeld" parent="Logic/Fahrplan" groups=["signage1"] instance=ExtResource("5_rum2v")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.015596004, 0.007891655, -0.018885009)
script = ExtResource("10_iq74k")
i18n_key = &"Hirschfeld-Str."
train_labels = Dictionary[StringName, String]({
&"u1lise_meitner": "U1 Ring ↺",
&"u1parity_square": "U1 Ring ↻",
&"u2station_university_mens": "U2 Ambitz"
&"u2uni_mensa": "U2 Ambitz"
})
[node name="VoxelGI" type="VoxelGI" parent="Logic/Fahrplan/hirschfeld"]

View File

@ -1,9 +1,15 @@
[gd_scene load_steps=25 format=3 uid="uid://df3ur5wll8vx7"]
[gd_scene load_steps=31 format=3 uid="uid://df3ur5wll8vx7"]
[ext_resource type="PackedScene" uid="uid://4j1tlhfm3p40" path="res://base-environments/transition/subway_train.tscn" id="1_2h2xx"]
[ext_resource type="Script" uid="uid://dgfje4druu3sw" path="res://base-environments/transition/code/dolly.gd" id="1_5jpg8"]
[ext_resource type="Script" uid="uid://cyohujvfoiof7" path="res://base-environments/transition/code/subway_train.gd" id="2_aacjs"]
[ext_resource type="AudioStream" uid="uid://cwfr6sgcwg7sl" path="res://base-environments/transition/audio/450918__kyles__metro-subway-montreal-verdun-station-arrive-and-leave-semidistant-from-bridge-over-tracks-overpass.ogg" id="3_4h0n7"]
[ext_resource type="Material" uid="uid://cl7e6lpjalm0c" path="res://base-environments/transition/shaders/u1.material" id="3_j8pin"]
[ext_resource type="Material" uid="uid://c0baqy42xdxtg" path="res://base-environments/transition/shaders/u2.material" id="4_3w708"]
[ext_resource type="Material" uid="uid://bw4y5b5lnw3cn" path="res://base-environments/transition/shaders/u4.material" id="5_3x5rc"]
[ext_resource type="Material" uid="uid://cor0uho8hnfqc" path="res://base-environments/transition/shaders/u7.material" id="6_ckebf"]
[ext_resource type="Material" uid="uid://d0kk76pja0orj" path="res://base-environments/transition/shaders/u8.material" id="7_dyyau"]
[ext_resource type="FontFile" uid="uid://b231f0liphck" path="res://import/fonts/AtkinsonHyperlegible-Regular.ttf" id="10_3w708"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_aacjs"]
shading_mode = 0
@ -122,6 +128,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -150)
[node name="Subway" type="Node3D" parent="."]
script = ExtResource("2_aacjs")
materials = Dictionary[StringName, Material]({
&"u1": ExtResource("3_j8pin"),
&"u2": ExtResource("4_3w708"),
&"u4": ExtResource("5_3x5rc"),
&"u7": ExtResource("6_ckebf"),
&"u8": ExtResource("7_dyyau")
})
metadata/_custom_type_script = "uid://cyohujvfoiof7"
[node name="WarpEffecScreen" type="MeshInstance3D" parent="Subway"]
@ -174,7 +187,18 @@ playback_type = 1
[node name="TrainModel" parent="Subway" instance=ExtResource("1_2h2xx")]
unique_name_in_owner = true
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -3.4114173e-08, 0, -0.7804413)
script = null
[node name="Label3D" type="Label3D" parent="Subway/TrainModel" groups=["labels"]]
transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, -15.413577, 2.7434583, -6.737489e-07)
text = "U0"
font = ExtResource("10_3w708")
font_size = 64
[node name="Label3D2" type="Label3D" parent="Subway/TrainModel" groups=["labels"]]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 15.410003, 2.7434583, 6.9981036e-07)
text = "U0"
font = ExtResource("10_3w708")
font_size = 64
[node name="Collider" type="AnimatableBody3D" parent="Subway"]
unique_name_in_owner = true

View File

@ -1,8 +1,7 @@
[gd_scene load_steps=15 format=4 uid="uid://4j1tlhfm3p40"]
[gd_scene load_steps=14 format=4 uid="uid://4j1tlhfm3p40"]
[ext_resource type="PackedScene" uid="uid://dmh8tmuvftqus" path="res://base-environments/transition/import/subway_train.glb" id="1_8e51f"]
[ext_resource type="Material" uid="uid://dchm78gv31r6a" path="res://base-environments/transition/shaders/timetravel.tres" id="2_g5p57"]
[ext_resource type="Script" uid="uid://cyohujvfoiof7" path="res://base-environments/transition/code/subway_train.gd" id="2_skiem"]
[ext_resource type="Material" uid="uid://ddw7mob1qmlbj" path="res://base-environments/transition/shaders/u0.material" id="3_81crm"]
[ext_resource type="Material" uid="uid://rh1lc61j6qd8" path="res://base-environments/transition/import/textures/roof_greeble.tres" id="3_q0ort"]
[ext_resource type="Texture2D" uid="uid://bewykr0twbplg" path="res://base-environments/transition/import/textures/LateralTren_baseColor_upscayl_2x_realesrgan-x4plus-anime.png" id="5_6pwip"]
@ -137,7 +136,6 @@ _data = {
}
[node name="subway_train" instance=ExtResource("1_8e51f")]
script = ExtResource("2_skiem")
[node name="traun_hull" parent="." index="0"]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 0, 0)