feat: Playback-Dot mit Blickrichtung und Timeline hinzufügen

- Dot durchläuft alle Sections und Segmente per Bogenlängen-Sampling
- Blickrichtung folgt der Tangente, rückwärts um 180° gedreht
- Play/Pause, Reset, Timeline-Scrubbing und Geschwindigkeit 0,25×–2,0×
- aktuelle Playback-Section wird hervorgehoben
- Timing aus Segmentdauern; Bearbeitung setzt das Playback zurück
- Tests auf 350 Assertions erweitert
This commit is contained in:
torsten 2026-10-30 08:27:58 +01:00
parent 976b0e98bf
commit 07f09143eb
8 changed files with 698 additions and 10 deletions

View file

@ -29,6 +29,9 @@ $GODOT --headless --path rinkplanner --script res://tests/run_whiteboard_tests.g
# Run undo/redo history tests
$GODOT --headless --path rinkplanner --script res://tests/run_history_tests.gd
# Run playback dot/timeline tests
$GODOT --headless --path rinkplanner --script res://tests/run_playback_tests.gd
```
Exit code `0` means all assertions passed. Failures are printed to stderr.

View file

@ -0,0 +1,211 @@
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
)
_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")
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)

View file

@ -0,0 +1 @@
uid://2ho2htoy3p6i