frame-of-mind/src/base-environments/transition/code/dolly.gd

89 lines
2.6 KiB
GDScript3
Raw Normal View History

2026-01-20 20:07:41 +00:00
## A dolly tweens all contents to and from two destination points, and to its origin.
class_name Dolly
extends Node3D
2026-01-20 21:47:44 +00:00
@export var index : int = -1
@export var signage_group : String
2026-01-20 17:35:37 +00:00
@export var pre_arrival_time : float = 17.0
2026-01-20 16:23:11 +00:00
@export var arrival_time : float = 15.0
2026-01-20 17:18:10 +00:00
@export var pre_leave_time : float = 20.0
2026-01-20 17:35:37 +00:00
@export var door_close_time : float = 1.0
2026-01-20 16:23:11 +00:00
@export var leave_time : float = 16.0
@export var post_leave_time : float = 5.0
2026-01-20 11:37:17 +00:00
@onready var origination : Node3D = $Origination
2026-01-20 20:07:41 +00:00
@onready var destination : Node3D = $Destination
2026-01-20 11:37:17 +00:00
2026-01-20 20:07:41 +00:00
@onready var subway : SubwayTrain = $Train
2026-01-20 16:23:11 +00:00
2026-01-20 11:37:17 +00:00
var tween : Tween = null
2026-01-20 21:47:44 +00:00
signal departure(index : int)
2026-01-20 20:07:41 +00:00
2026-01-20 21:47:44 +00:00
func _ready() -> void:
reset()
2026-01-20 20:07:41 +00:00
## One arrival and departure
2026-01-20 17:18:10 +00:00
func cycle() -> void:
await arrive()
await leave()
2026-01-20 21:47:44 +00:00
func reset() -> void:
if tween: tween.kill()
for child in get_children(true):
if not child.visible: continue
child.global_position = origination.global_position
func _seat_player_if_inside() -> bool:
2026-01-20 20:07:41 +00:00
if %EntryDetect.overlaps_body(State.player):
2026-01-20 20:35:12 +00:00
prints("Player asleep inside Train", self.name)
2026-01-20 20:07:41 +00:00
State.player.sleeping = true
var s1 := %Seat1
var s2 := %Seat2
var seat : Node3D = s1 if (s1.global_position-State.player.global_position).length() < (s2.global_position-State.player.global_position).length() else s2
State.player.reparent(seat)
2026-01-20 21:47:44 +00:00
return true
return false
2026-01-20 20:07:41 +00:00
2026-01-20 17:18:10 +00:00
2026-01-20 20:35:12 +00:00
func _unseat_player_if_inside() -> void:
if %EntryDetect.overlaps_body(State.player):
prints("Player no longer asleep on Train", self.name)
State.player.sleeping = false
State.player.reparent(get_parent())
2026-01-20 11:37:17 +00:00
func arrive() -> void:
2026-01-20 16:23:11 +00:00
%SubwayTrainAudio.play(0)
2026-01-20 19:01:59 +00:00
%SubwayTrainAudioIntense.play(0)
2026-01-20 17:35:37 +00:00
await get_tree().create_timer(pre_arrival_time).timeout
2026-01-20 11:37:17 +00:00
if tween: tween.kill()
tween = create_tween().set_trans(Tween.TRANS_CIRC).set_ease(Tween.EASE_OUT)
for child in get_children(true):
if not child.visible: continue
tween.parallel().tween_property(child, "global_position", self.global_position, arrival_time)
2026-01-20 16:23:11 +00:00
await tween.finished
2026-01-20 20:07:41 +00:00
subway.door_open = true
2026-01-20 20:35:12 +00:00
_unseat_player_if_inside()
2026-01-20 11:37:17 +00:00
func leave() -> void:
2026-01-20 16:23:11 +00:00
await get_tree().create_timer(pre_leave_time).timeout
2026-01-20 17:18:10 +00:00
subway.door_open = false
2026-01-20 17:35:37 +00:00
await get_tree().create_timer(door_close_time).timeout
2026-01-20 21:47:44 +00:00
var seated := _seat_player_if_inside()
2026-01-20 17:18:10 +00:00
if tween: tween.kill()
2026-01-20 11:37:17 +00:00
tween = create_tween().set_trans(Tween.TRANS_QUART).set_ease(Tween.EASE_IN)
for child in get_children(true):
if not child.visible: continue
tween.parallel().tween_property(child, "global_position", destination.global_position, leave_time)
2026-01-20 16:23:11 +00:00
await tween.finished
await %SubwayTrainAudio.finished
2026-01-20 21:47:44 +00:00
# Player was on board and has left the station
if seated: departure.emit(index)
# Reset is called by Fahrplan