2026-10-30 08:27:58 +01:00
|
|
|
extends SceneTree
|
|
|
|
|
|
|
|
|
|
## Headless tests for the playback dot and timeline.
|
|
|
|
|
##
|
|
|
|
|
## Run with:
|
|
|
|
|
## godot --headless --path rinkplanner --script res://tests/run_playback_tests.gd
|
|
|
|
|
|
|
|
|
|
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
|
|
|
|
|
|
|
|
|
var _assertions: int = 0
|
|
|
|
|
var _failures: PackedStringArray = PackedStringArray()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
|
_run.call_deferred()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _run() -> void:
|
|
|
|
|
var scene := WhiteboardScene.instantiate()
|
|
|
|
|
var controller := scene as WhiteboardController
|
|
|
|
|
if controller != null:
|
|
|
|
|
controller.restore_autosave = false
|
|
|
|
|
controller.autosave_enabled = false
|
|
|
|
|
root.add_child(scene)
|
|
|
|
|
await process_frame
|
|
|
|
|
|
|
|
|
|
_check(controller != null, "playback scene has a controller")
|
|
|
|
|
if controller == null:
|
|
|
|
|
_finish()
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
_check_approx(controller.get_playback_duration(), 0.0, "empty routine has no duration")
|
|
|
|
|
_check(controller.play_button.disabled, "play is disabled without segments")
|
|
|
|
|
_check(controller.playback_timeline.editable == false, "timeline is disabled without segments")
|
|
|
|
|
|
|
|
|
|
var section_one := controller.get_active_section()
|
|
|
|
|
var forward := controller.add_segment(
|
|
|
|
|
Vector2(-20.0, 0.0),
|
|
|
|
|
Vector2(-8.0, 0.0),
|
|
|
|
|
PathSegment.Direction.FORWARD,
|
|
|
|
|
PathSegment.Edge.OUTSIDE
|
|
|
|
|
)
|
|
|
|
|
var backward := controller.add_segment(
|
|
|
|
|
Vector2(-8.0, 0.0),
|
|
|
|
|
Vector2(4.0, 0.0),
|
|
|
|
|
PathSegment.Direction.BACKWARD,
|
|
|
|
|
PathSegment.Edge.INSIDE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var section_two := controller.add_section()
|
|
|
|
|
var last := controller.add_segment(
|
|
|
|
|
Vector2(4.0, 0.0),
|
|
|
|
|
Vector2(16.0, 0.0),
|
|
|
|
|
PathSegment.Direction.FORWARD,
|
|
|
|
|
PathSegment.Edge.OUTSIDE
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-30 08:48:12 +01:00
|
|
|
for segment: PathSegment in [forward, backward, last]:
|
|
|
|
|
segment.set_speed_mps(6.0)
|
|
|
|
|
controller._update_status()
|
|
|
|
|
|
2026-10-30 08:27:58 +01:00
|
|
|
_check_approx(controller.get_playback_duration(), 6.0, "duration sums all sections")
|
|
|
|
|
_check(not controller.play_button.disabled, "play is enabled with segments")
|
|
|
|
|
_check(controller.playback_timeline.editable, "timeline is enabled with segments")
|
|
|
|
|
_check_approx(
|
|
|
|
|
controller.playback_timeline.max_value,
|
|
|
|
|
6.0,
|
|
|
|
|
"timeline covers the whole routine"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.seek_playback(1.0)
|
|
|
|
|
_check(not controller.is_playing(), "seeking does not start playback")
|
|
|
|
|
_check_vec(
|
|
|
|
|
controller.get_playback_position(),
|
|
|
|
|
Vector2(-14.0, 0.0),
|
|
|
|
|
"dot follows the first segment"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_heading().x > 0.9,
|
|
|
|
|
"forward segment faces the travel direction"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_section_id() == section_one.section_id,
|
|
|
|
|
"playback reports the first section"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_segment_id() == forward.segment_id,
|
|
|
|
|
"playback reports the first segment"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.rink_canvas.get_playback_section_id() == section_one.section_id,
|
|
|
|
|
"canvas highlights the playing section"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.seek_playback(3.0)
|
|
|
|
|
_check_vec(
|
|
|
|
|
controller.get_playback_position(),
|
|
|
|
|
Vector2(-2.0, 0.0),
|
|
|
|
|
"dot follows the backward segment"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_heading().x < -0.9,
|
|
|
|
|
"backward segment faces against the travel direction"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_segment_id() == backward.segment_id,
|
|
|
|
|
"playback reports the backward segment"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.seek_playback(5.0)
|
|
|
|
|
_check_vec(
|
|
|
|
|
controller.get_playback_position(),
|
|
|
|
|
Vector2(10.0, 0.0),
|
|
|
|
|
"dot follows the second section"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_section_id() == section_two.section_id,
|
|
|
|
|
"playback reports the second section"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_segment_id() == last.segment_id,
|
|
|
|
|
"playback reports the last segment"
|
|
|
|
|
)
|
|
|
|
|
_check(
|
|
|
|
|
controller.rink_canvas.get_playback_section_id() == section_two.section_id,
|
|
|
|
|
"canvas highlights the second section"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.play_button.pressed.emit()
|
|
|
|
|
_check(controller.is_playing(), "play button starts playback")
|
|
|
|
|
controller.play_button.pressed.emit()
|
|
|
|
|
_check(not controller.is_playing(), "play button pauses playback")
|
|
|
|
|
|
|
|
|
|
controller.play()
|
|
|
|
|
_check(controller.is_playing(), "play starts playback")
|
|
|
|
|
_check(controller.play_button.text == "Pause", "play button switches to pause")
|
|
|
|
|
controller.advance_playback(0.5)
|
|
|
|
|
_check_approx(controller.get_playback_time(), 5.5, "playback advances by delta")
|
|
|
|
|
controller.advance_playback(1.0)
|
|
|
|
|
_check(not controller.is_playing(), "playback stops at the end")
|
|
|
|
|
_check_approx(controller.get_playback_time(), 6.0, "playback ends at the total duration")
|
|
|
|
|
_check(controller.play_button.text == "Start", "play button switches back after the end")
|
|
|
|
|
|
|
|
|
|
controller.play()
|
|
|
|
|
_check_approx(
|
|
|
|
|
controller.get_playback_time(),
|
|
|
|
|
0.0,
|
|
|
|
|
"playing after the end restarts at the start"
|
|
|
|
|
)
|
|
|
|
|
_check(controller.is_playing(), "restarted playback is running")
|
|
|
|
|
controller.pause()
|
|
|
|
|
_check(not controller.is_playing(), "pause stops playback")
|
|
|
|
|
controller.reset_playback_button.pressed.emit()
|
|
|
|
|
_check_approx(controller.get_playback_time(), 0.0, "reset returns to the start")
|
|
|
|
|
_check(
|
|
|
|
|
controller.rink_canvas.get_playback_section_id().is_empty(),
|
|
|
|
|
"reset clears the playback highlight"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.playback_timeline.value = 2.5
|
|
|
|
|
_check_approx(
|
|
|
|
|
controller.get_playback_time(),
|
|
|
|
|
2.5,
|
|
|
|
|
"timeline scrubbing seeks the playback"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
controller.speed_option.item_selected.emit(4)
|
|
|
|
|
_check_approx(controller.get_playback_speed(), 2.0, "speed option selects 2x")
|
|
|
|
|
controller.reset_playback()
|
|
|
|
|
controller.play()
|
|
|
|
|
controller.advance_playback(1.0)
|
|
|
|
|
_check_approx(
|
|
|
|
|
controller.get_playback_time(),
|
|
|
|
|
2.0,
|
|
|
|
|
"2x speed doubles the elapsed routine time"
|
|
|
|
|
)
|
|
|
|
|
controller.pause()
|
|
|
|
|
controller.speed_option.item_selected.emit(2)
|
|
|
|
|
_check_approx(controller.get_playback_speed(), 1.0, "speed option returns to 1x")
|
|
|
|
|
|
2026-10-30 23:48:47 +01:00
|
|
|
# Element markers take their stand time from the element, not the geometry,
|
|
|
|
|
# and a spin rotates the playback dot in place.
|
|
|
|
|
var jump_marker := controller.add_element_marker(
|
|
|
|
|
Vector2(20.0, 3.0),
|
|
|
|
|
PathSegment.ElementType.JUMP,
|
|
|
|
|
"3Lz",
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
_check_approx(
|
|
|
|
|
jump_marker.element_duration_seconds,
|
|
|
|
|
0.7,
|
|
|
|
|
"jump marker gets a default air time"
|
|
|
|
|
)
|
|
|
|
|
var spin_marker := controller.add_element_marker(
|
|
|
|
|
Vector2(22.0, 6.0),
|
|
|
|
|
PathSegment.ElementType.SPIN,
|
|
|
|
|
"CCoSp4",
|
|
|
|
|
3
|
|
|
|
|
)
|
|
|
|
|
_check_approx(
|
|
|
|
|
spin_marker.element_duration_seconds,
|
|
|
|
|
8.0,
|
|
|
|
|
"spin marker gets a default stand time"
|
|
|
|
|
)
|
|
|
|
|
controller._update_status()
|
|
|
|
|
_check_approx(
|
|
|
|
|
controller.get_playback_duration(),
|
|
|
|
|
14.7,
|
|
|
|
|
"timeline duration includes the element stand times"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var jump_start := 6.0
|
|
|
|
|
controller.seek_playback(jump_start)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_segment_id() == jump_marker.segment_id,
|
|
|
|
|
"timeline stops at the jump marker"
|
|
|
|
|
)
|
|
|
|
|
var jump_heading := controller.get_playback_heading()
|
|
|
|
|
controller.seek_playback(jump_start + 0.35)
|
|
|
|
|
_check(
|
|
|
|
|
jump_heading.dot(controller.get_playback_heading()) > 0.99,
|
|
|
|
|
"jump marker keeps the arrival heading"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var spin_start := jump_start + 0.7
|
|
|
|
|
controller.seek_playback(spin_start)
|
|
|
|
|
_check(
|
|
|
|
|
controller.get_playback_segment_id() == spin_marker.segment_id,
|
|
|
|
|
"timeline stops at the spin marker"
|
|
|
|
|
)
|
|
|
|
|
var spin_arrival := controller.get_playback_heading()
|
|
|
|
|
controller.seek_playback(spin_start + 1.0 / 3.0)
|
|
|
|
|
_check(
|
|
|
|
|
spin_arrival.dot(controller.get_playback_heading()) < -0.9,
|
|
|
|
|
"spin marker rotates the playback dot in place"
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-30 08:27:58 +01:00
|
|
|
scene.queue_free()
|
|
|
|
|
await process_frame
|
|
|
|
|
_finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
|
|
|
_assertions += 1
|
|
|
|
|
if not condition:
|
|
|
|
|
_failures.append(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _check_approx(actual: float, expected: float, message: String) -> void:
|
|
|
|
|
_check(
|
|
|
|
|
absf(actual - expected) <= 0.001,
|
|
|
|
|
"%s (expected %.3f, got %.3f)" % [message, expected, actual]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _check_vec(actual: Vector2, expected: Vector2, message: String) -> void:
|
|
|
|
|
_check(
|
|
|
|
|
actual.distance_to(expected) <= 0.01,
|
|
|
|
|
"%s (expected %s, got %s)" % [message, expected, actual]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _finish() -> void:
|
|
|
|
|
if _failures.is_empty():
|
|
|
|
|
print("PASS: %d assertions" % _assertions)
|
|
|
|
|
quit(0)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for failure: String in _failures:
|
|
|
|
|
printerr("FAIL: %s" % failure)
|
|
|
|
|
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
|
|
|
|
|
quit(1)
|