feat: Segment-Timing mit Profilen und Kalibrierung hinzufügen
- Timing-Leiste mit gekoppelter Dauer-/Tempo-Bearbeitung - Level-Presets Adult Bronze bis Elite, Default Adult Gold 4,3 m/s - Kalibrierdialog Strecke/Zeit und Standard-Reset - PathSegment speichert Geschwindigkeit oder Dauer als maßgebliche Größe - Schema-Version 2 mit Migration alter Dateien - Tests auf 400 Assertions erweitert
This commit is contained in:
parent
d163b01fa5
commit
43da04b3cc
13 changed files with 819 additions and 44 deletions
|
|
@ -95,8 +95,9 @@ eine Abkürzung. So kann die UI Fehler konkret anzeigen.
|
|||
- **Zeichenwerkzeuge:** `WhiteboardController` hält eine Draft-Routine mit
|
||||
einer Section. Die Toolbar bietet Auswählen, Linie, Bogen links und Bogen
|
||||
rechts; Richtung (vorwärts/rückwärts) und Kante (innen/außen) gelten für das
|
||||
nächste Segment. Die Dauer wird mit 6 m/s aus der Länge abgeleitet, Züge
|
||||
über die Bande werden per `clamp_point()` auf die Eisfläche begrenzt.
|
||||
nächste Segment. Neue Segmente starten mit dem gewählten Timing-Profil
|
||||
(Default Adult Gold, 4,3 m/s); Züge über die Bande werden per
|
||||
`clamp_point()` auf die Eisfläche begrenzt.
|
||||
- **Bogen-Vorlage:** `ArcGeometry` erzeugt einen Kreisbogen mit 40 % der
|
||||
Sehnenlänge als Pfeilhöhe und liefert eine gesampelte `Curve2D`-Polyline.
|
||||
Liegt der Bogen außerhalb des Rinks, wird die Pfeilhöhe schrittweise
|
||||
|
|
@ -134,11 +135,16 @@ eine Abkürzung. So kann die UI Fehler konkret anzeigen.
|
|||
sodass die Bewegung entlang des Pfades und die Körperrichtung getrennt
|
||||
sichtbar sind. Während des Playbacks wird die aktuelle Section hervorgehoben,
|
||||
ohne die Bearbeitungs-Section zu wechseln. Steuerung: Play/Pause, Reset,
|
||||
Timeline-Scrubbing und Geschwindigkeit 0,25×–2,0×. Die Dauer kommt aus den
|
||||
Segmentdauern (aktuell 6 m/s Platzhalter). Nicht verbundene Segmente führen
|
||||
zu einem Sprung des Markers an den Start des nächsten Segments.
|
||||
Timeline-Scrubbing und Geschwindigkeit 0,25×–2,0×. Die Dauer kommt aus dem
|
||||
Segment-Timing (Default Adult Gold, 4,3 m/s). Nicht verbundene Segmente
|
||||
führen zu einem Sprung des Markers an den Start des nächsten Segments.
|
||||
- **Geschwindigkeitsannahmen:** Die belastbaren Referenzwerte, Level-Profile
|
||||
und Kalibrierung stehen in `docs/speed-assumptions.md`.
|
||||
- **Segment-Timing:** Die Timing-Leiste zeigt Dauer und Tempo des ausgewählten
|
||||
Segments. Beide Werte sind gekoppelt; `PathSegment.timing_mode` legt fest,
|
||||
welche Größe bei Geometrieänderungen erhalten bleibt. Level-Presets
|
||||
(Adult Bronze bis Elite), `±`-Schritte, „Standard“ (Adult Gold, 4,3 m/s) und
|
||||
ein Kalibrierdialog (Strecke/Zeit → m/s) sind umgesetzt.
|
||||
- **Darstellung:** vorwärts durchgezogen, rückwärts gestrichelt, außen rot,
|
||||
innen blau. Inaktive Sections werden mit 20 % Deckkraft geghostet.
|
||||
- **Ghosting** ist reine View-Logik: pro Section ein eigener Layer,
|
||||
|
|
@ -173,8 +179,9 @@ standardmäßig bleibt es aus.
|
|||
- **PDF** ist nicht nativ in Godot. Erste Stufe: Browser-Druck aus SVG;
|
||||
eine echte PDF-Ausgabe ist ein separates Arbeitspaket.
|
||||
- **Persistenz** erfolgt lokal als `.tres`-Ressourcen unter
|
||||
`user://routines/`. `Routine.schema_version` schützt vor inkompatiblen
|
||||
neueren Dateien. Benannte Kürläufe werden über das Datei-Menü gespeichert
|
||||
`user://routines/`. `Routine.schema_version` (aktuell 2) schützt vor
|
||||
inkompatiblen neueren Dateien; Schema-1-Dateien werden beim Laden migriert
|
||||
und behalten ihre bisherige Dauer. Benannte Kürläufe werden über das Datei-Menü gespeichert
|
||||
und geladen; der Öffnen-Dialog nutzt 48-px-Buttons statt einer kleinen
|
||||
Dateiliste.
|
||||
- **Autosave** schreibt nach 1,5 s Inaktivität nach `user://autosave.tres`
|
||||
|
|
@ -194,8 +201,8 @@ Headless, ohne Editor und ohne Display:
|
|||
|
||||
Aktueller Stand:
|
||||
|
||||
- **Model:** 46 Assertions für Rink-Geometrie, Clamping, Segment-Timing,
|
||||
Template-Metadaten, Schema-Version, Section-Aggregation und
|
||||
- **Model:** 55 Assertions für Rink-Geometrie, Clamping, Segment-Timing,
|
||||
Timing-Modi, Template-Metadaten, Schema-Version, Section-Aggregation und
|
||||
Routine-Validierung.
|
||||
- **Canvas:** 90 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan,
|
||||
Rink-Kontur und die reine Bogen-Geometrie.
|
||||
|
|
@ -210,6 +217,8 @@ Aktueller Stand:
|
|||
- **Playback:** 38 Assertions für Dauer/Timeline, Vorwärts-/Rückwärts-
|
||||
Blickrichtung, Section-Hervorhebung, Play/Pause/Reset inklusive
|
||||
Button-Verdrahtung, Scrubbing und Geschwindigkeitswechsel.
|
||||
- **Timing:** 41 Assertions für Dauer-/Tempo-Kopplung, Level-Presets,
|
||||
Kalibrierung, Undo, Persistenz und Schema-1-Migration.
|
||||
|
||||
Autosave/Restore wird zusätzlich in einem isolierten `XDG_DATA_HOME`
|
||||
end-to-end geprüft.
|
||||
|
|
@ -249,9 +258,8 @@ Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
|||
10. **Snapshot-Clone:** `_clone_routine()` kopiert die Modellfelder manuell.
|
||||
Neue Felder am Modell müssen dort ergänzt werden, sonst fehlen sie in
|
||||
Undo/Redo-Snapshots.
|
||||
11. **Segment-Timing:** Die Dauer wird weiterhin mit 6 m/s aus der Länge
|
||||
abgeleitet. Eine direkte Dauer-/Geschwindigkeitsbearbeitung pro Segment
|
||||
ist der nächste Timing-Schritt; die Profile stehen in
|
||||
`docs/speed-assumptions.md`.
|
||||
11. **Segment-Timing:** Dauer/Tempo, Presets, Kalibrierung und Migration sind
|
||||
umgesetzt. Offen sind Beschleunigung/Verzögerung innerhalb eines Segments
|
||||
und eine noch genauere Profilpflege aus eigenen Messungen.
|
||||
12. **Playback-Komfort:** Loop, Scrubbing während des Abspielens und
|
||||
Audio-Synchronisation sind bewusst noch nicht enthalten.
|
||||
|
|
|
|||
|
|
@ -30,18 +30,18 @@ Voraussetzung für Phase 1.
|
|||
- [x] Geschwindigkeits-Arbeitsannahmen in `docs/speed-assumptions.md`
|
||||
- [x] Headless-Tests und visuelle Smoke-Tests
|
||||
|
||||
### Nächster Schritt: Segment-Timing
|
||||
### Erledigt: Segment-Timing
|
||||
|
||||
- [ ] Dauer oder Geschwindigkeit pro Segment editieren
|
||||
- [ ] Gekoppelte Anzeige: Dauer ↔ Geschwindigkeit
|
||||
- [ ] Level-Presets aus `docs/speed-assumptions.md`
|
||||
- [x] Dauer oder Geschwindigkeit pro Segment editieren
|
||||
- [x] Gekoppelte Anzeige: Dauer ↔ Geschwindigkeit
|
||||
- [x] Level-Presets aus `docs/speed-assumptions.md`
|
||||
(Adult Bronze/Silver/Gold, Masters, Elite)
|
||||
- [ ] Preset „Auf Standard zurücksetzen“ pro Segment
|
||||
- [ ] Kalibrierung: bekannte Strecke, Zeit messen, Geschwindigkeit berechnen
|
||||
- [ ] Timing in Playback, Timeline, Undo/Redo und Speichern/Laden integrieren
|
||||
- [ ] Aktuellen 6-m/s-Platzhalter durch bewusste Profile ersetzen
|
||||
- [x] Preset „Standard“ pro Segment (Adult Gold, 4,3 m/s)
|
||||
- [x] Kalibrierung: bekannte Strecke, Zeit messen, Geschwindigkeit berechnen
|
||||
- [x] Timing in Playback, Timeline, Undo/Redo und Speichern/Laden integriert
|
||||
- [x] 6-m/s-Platzhalter durch bewusste Profile ersetzt
|
||||
|
||||
### Danach: Export
|
||||
### Nächster Schritt: Export
|
||||
|
||||
- [ ] PNG in hoher Auflösung für Tablet-Weitergabe
|
||||
- [ ] SVG direkt aus dem Modell (Kurven, Sections, Legende, Rink)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ werden.
|
|||
| Masters / fortgeschritten | 4,5–5,5 m/s | 16,2–19,8 km/h |
|
||||
| Elite / Wettkampf | 5,0–7,0 m/s | 18,0–25,2 km/h |
|
||||
|
||||
Vorgeschlagene Preset-Defaults:
|
||||
Umgesetzte Preset-Defaults:
|
||||
|
||||
| Profil | Default |
|
||||
| :--- | ---: |
|
||||
|
|
@ -101,25 +101,27 @@ Orientierung für Rinkplanung und Playback:
|
|||
|
||||
## 6. Verwendung in Rinkplanner
|
||||
|
||||
- Der aktuelle Code-Default von **6 m/s** ist ein Platzhalter und entspricht
|
||||
eher einem schnellen Elite-/Wettkampf-Profil. Er ist zu hoch für Adult-
|
||||
Bronze/Silver und für technische Abschnitte.
|
||||
- Geplant sind Level-Presets gemäß Abschnitt 3.
|
||||
- Jedes Segment soll Dauer oder Geschwindigkeit individuell speichern können.
|
||||
- Der Playback berechnet die Dauer aus `Strecke / Geschwindigkeit` bzw. nutzt
|
||||
die gespeicherte Segmentdauer.
|
||||
- Der Code-Default ist **Adult Gold mit 4,3 m/s**. Die Level-Presets aus
|
||||
Abschnitt 3 sind in der Timing-Leiste umgesetzt.
|
||||
- Die Presets gelten für das ausgewählte Segment; ohne Auswahl legen sie das
|
||||
Tempo für neue Segmente fest.
|
||||
- Jedes Segment speichert entweder die **Geschwindigkeit** oder die **Dauer**
|
||||
als maßgebliche Größe. Die jeweils andere wird daraus berechnet.
|
||||
- Bei einer Geometrieänderung bleibt die maßgebliche Größe erhalten:
|
||||
- Geschwindigkeitsmodus: Dauer wird neu berechnet.
|
||||
- Dauer-Modus: Geschwindigkeit wird neu berechnet.
|
||||
- Der Playback nutzt die gespeicherte Segmentdauer.
|
||||
- Innerhalb eines Segments wird weiterhin eine konstante Geschwindigkeit
|
||||
angenommen. Beschleunigung und Verzögerung sind ein späterer Ausbauschritt.
|
||||
|
||||
## 7. Einfache Kalibrierung
|
||||
## 7. Kalibrierung im Tool
|
||||
|
||||
1. Eine bekannte Strecke auf dem Eis abstecken oder im Plan zeichnen,
|
||||
z. B. 20 m geradeaus.
|
||||
2. Skater diese Strecke mit dem gewünschten Tempo fahren lassen.
|
||||
3. Zeit mit Stoppuhr oder Video messen.
|
||||
4. `Geschwindigkeit = Strecke / Zeit` berechnen.
|
||||
5. Drei Durchläufe messen und den Median verwenden.
|
||||
6. Den Wert als Segment- oder Profilgeschwindigkeit eintragen.
|
||||
1. Segment auswählen.
|
||||
2. „Kalibrieren“ öffnen.
|
||||
3. Gemessene Strecke und Zeit eingeben.
|
||||
4. Das Tool berechnet `Geschwindigkeit = Strecke / Zeit` und setzt sie am
|
||||
Segment.
|
||||
5. Für belastbare Werte drei Durchläufe messen und den Median verwenden.
|
||||
|
||||
Beispiel: 20 m in 4,4 s → 4,55 m/s (16,4 km/h).
|
||||
|
||||
|
|
|
|||
|
|
@ -273,6 +273,135 @@ size_flags_horizontal = 3
|
|||
theme_override_font_sizes/font_size = 14
|
||||
text = "Abschnitt löschen"
|
||||
|
||||
[node name="TimingBar" type="PanelContainer" parent="Layout"]
|
||||
custom_minimum_size = Vector2(0, 64)
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_playback")
|
||||
|
||||
[node name="TimingContent" type="HBoxContainer" parent="Layout/TimingBar"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="TimingTitle" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Timing"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TimingSelectionLabel" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(170, 48)
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.85098, 0.890196, 0.941176, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Kein Segment ausgewählt"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TimingSeparator1" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="DurationLabel" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Dauer"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="DurationMinusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 18
|
||||
disabled = true
|
||||
text = "−"
|
||||
tooltip_text = "Dauer verringern"
|
||||
|
||||
[node name="DurationValueLabel" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(64, 48)
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.85098, 0.890196, 0.941176, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "–"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="DurationPlusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 18
|
||||
disabled = true
|
||||
text = "+"
|
||||
tooltip_text = "Dauer erhöhen"
|
||||
|
||||
[node name="TimingSeparator2" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SpeedLabel" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Tempo"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="SpeedMinusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 18
|
||||
disabled = true
|
||||
text = "−"
|
||||
tooltip_text = "Tempo verringern"
|
||||
|
||||
[node name="SpeedValueLabel" type="Label" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(78, 48)
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.85098, 0.890196, 0.941176, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "–"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="SpeedPlusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 18
|
||||
disabled = true
|
||||
text = "+"
|
||||
tooltip_text = "Tempo erhöhen"
|
||||
|
||||
[node name="TimingSeparator3" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ProfileOption" type="OptionButton" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(140, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
tooltip_text = "Geschwindigkeitsprofil für Auswahl bzw. neue Segmente"
|
||||
|
||||
[node name="CalibrateButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
disabled = true
|
||||
text = "Kalibrieren"
|
||||
tooltip_text = "Geschwindigkeit aus Strecke und gemessener Zeit berechnen"
|
||||
|
||||
[node name="ResetTimingButton" type="Button" parent="Layout/TimingBar/TimingContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(90, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
disabled = true
|
||||
text = "Standard"
|
||||
tooltip_text = "Auf Adult Gold (4,3 m/s) zurücksetzen"
|
||||
|
||||
[node name="PlaybackBar" type="PanelContainer" parent="Layout"]
|
||||
custom_minimum_size = Vector2(0, 64)
|
||||
layout_mode = 2
|
||||
|
|
@ -451,3 +580,41 @@ unique_name_in_owner = true
|
|||
title = "Rinkplanner"
|
||||
size = Vector2i(520, 180)
|
||||
ok_button_text = "OK"
|
||||
|
||||
[node name="CalibrationDialog" type="ConfirmationDialog" parent="."]
|
||||
unique_name_in_owner = true
|
||||
title = "Timing kalibrieren"
|
||||
size = Vector2i(460, 300)
|
||||
ok_button_text = "Übernehmen"
|
||||
cancel_button_text = "Abbrechen"
|
||||
|
||||
[node name="CalibrationBox" type="VBoxContainer" parent="CalibrationDialog"]
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 452.0
|
||||
offset_bottom = 230.0
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="CalibrationDistanceLabel" type="Label" parent="CalibrationDialog/CalibrationBox"]
|
||||
layout_mode = 2
|
||||
text = "Strecke (m)"
|
||||
|
||||
[node name="CalibrationDistanceEdit" type="LineEdit" parent="CalibrationDialog/CalibrationBox"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CalibrationTimeLabel" type="Label" parent="CalibrationDialog/CalibrationBox"]
|
||||
layout_mode = 2
|
||||
text = "Gemessene Zeit (s)"
|
||||
|
||||
[node name="CalibrationTimeEdit" type="LineEdit" parent="CalibrationDialog/CalibrationBox"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CalibrationHint" type="Label" parent="CalibrationDialog/CalibrationBox"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Geschwindigkeit = Strecke / Zeit"
|
||||
|
|
|
|||
|
|
@ -21,11 +21,18 @@ enum Template {
|
|||
ARC,
|
||||
}
|
||||
|
||||
enum TimingMode {
|
||||
SPEED,
|
||||
DURATION,
|
||||
}
|
||||
|
||||
@export var segment_id: String = ""
|
||||
@export var curve: Curve2D
|
||||
@export var direction: Direction = Direction.FORWARD
|
||||
@export var edge: Edge = Edge.OUTSIDE
|
||||
@export var duration_seconds: float = 0.0
|
||||
@export var speed_mps: float = 4.3
|
||||
@export var timing_mode: TimingMode = TimingMode.SPEED
|
||||
@export var element_id: String = ""
|
||||
@export var label: String = ""
|
||||
|
||||
|
|
@ -51,6 +58,35 @@ func get_speed_mps() -> float:
|
|||
return get_length_m() / duration_seconds
|
||||
|
||||
|
||||
## Authors a speed and derives the duration from the current geometry.
|
||||
func set_speed_mps(value: float) -> void:
|
||||
speed_mps = maxf(value, 0.1)
|
||||
timing_mode = TimingMode.SPEED
|
||||
var length := get_length_m()
|
||||
if length > 0.0:
|
||||
duration_seconds = maxf(length / speed_mps, 0.001)
|
||||
|
||||
|
||||
## Authors a duration and derives the implied speed.
|
||||
func set_duration_seconds(value: float) -> void:
|
||||
duration_seconds = maxf(value, 0.001)
|
||||
timing_mode = TimingMode.DURATION
|
||||
var length := get_length_m()
|
||||
if length > 0.0:
|
||||
speed_mps = length / duration_seconds
|
||||
|
||||
|
||||
## Called after a geometry edit. The authored value (speed or duration) is
|
||||
## preserved and the other value is updated.
|
||||
func apply_geometry_length(length: float) -> void:
|
||||
if length <= 0.0:
|
||||
return
|
||||
if timing_mode == TimingMode.SPEED:
|
||||
duration_seconds = maxf(length / maxf(speed_mps, 0.1), 0.001)
|
||||
else:
|
||||
speed_mps = length / maxf(duration_seconds, 0.001)
|
||||
|
||||
|
||||
func is_marker() -> bool:
|
||||
return get_length_m() <= 0.0
|
||||
|
||||
|
|
@ -72,6 +108,8 @@ func validate() -> PackedStringArray:
|
|||
errors.append("duration_seconds must not be negative")
|
||||
if duration_seconds <= 0.0 and not is_marker():
|
||||
errors.append("a segment with length needs a positive duration_seconds")
|
||||
if speed_mps <= 0.0:
|
||||
errors.append("speed_mps must be positive")
|
||||
if template == Template.ARC:
|
||||
if arc_depth_ratio <= 0.0 or arc_depth_ratio >= 0.5:
|
||||
errors.append("arc_depth_ratio must be between 0 and 0.5")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ extends Resource
|
|||
## Root aggregate of a choreography. Pure data: no rendering, no input, no
|
||||
## timing state. The whiteboard view and the future 3D layer both consume it.
|
||||
|
||||
const CURRENT_SCHEMA_VERSION := 1
|
||||
const CURRENT_SCHEMA_VERSION := 2
|
||||
|
||||
@export var schema_version: int = CURRENT_SCHEMA_VERSION
|
||||
@export var routine_id: String = ""
|
||||
|
|
|
|||
|
|
@ -18,9 +18,24 @@ enum FileAction {
|
|||
SAVE_AS,
|
||||
}
|
||||
|
||||
const DEFAULT_SPEED_MPS := 6.0
|
||||
const DEFAULT_SPEED_MPS := 4.3
|
||||
const MIN_SEGMENT_LENGTH_M := 0.3
|
||||
const EPSILON := 0.0001
|
||||
const MIN_SPEED_MPS := 0.5
|
||||
const MAX_SPEED_MPS := 12.0
|
||||
const SPEED_STEP_MPS := 0.1
|
||||
const DURATION_STEP_SECONDS := 0.1
|
||||
const MIN_DURATION_SECONDS := 0.1
|
||||
const MAX_DURATION_SECONDS := 120.0
|
||||
const DEFAULT_PROFILE_INDEX := 2
|
||||
const PROFILE_NAMES := [
|
||||
"Adult Bronze",
|
||||
"Adult Silver",
|
||||
"Adult Gold",
|
||||
"Masters",
|
||||
"Elite",
|
||||
]
|
||||
const PROFILE_SPEEDS := [3.0, 3.8, 4.3, 5.0, 6.0]
|
||||
const ROUTINES_DIR := "user://routines"
|
||||
const AUTOSAVE_PATH := "user://autosave.tres"
|
||||
const AUTOSAVE_DELAY_SECONDS := 1.5
|
||||
|
|
@ -63,6 +78,19 @@ const MAX_HISTORY := 50
|
|||
@onready var playback_time_label: Label = %PlaybackTimeLabel
|
||||
@onready var playback_timeline: HSlider = %PlaybackTimeline
|
||||
@onready var speed_option: OptionButton = %SpeedOption
|
||||
@onready var timing_selection_label: Label = %TimingSelectionLabel
|
||||
@onready var duration_minus_button: Button = %DurationMinusButton
|
||||
@onready var duration_plus_button: Button = %DurationPlusButton
|
||||
@onready var duration_value_label: Label = %DurationValueLabel
|
||||
@onready var speed_minus_button: Button = %SpeedMinusButton
|
||||
@onready var speed_plus_button: Button = %SpeedPlusButton
|
||||
@onready var speed_value_label: Label = %SpeedValueLabel
|
||||
@onready var profile_option: OptionButton = %ProfileOption
|
||||
@onready var calibrate_button: Button = %CalibrateButton
|
||||
@onready var reset_timing_button: Button = %ResetTimingButton
|
||||
@onready var calibration_dialog: ConfirmationDialog = %CalibrationDialog
|
||||
@onready var calibration_distance_edit: LineEdit = %CalibrationDistanceEdit
|
||||
@onready var calibration_time_edit: LineEdit = %CalibrationTimeEdit
|
||||
|
||||
var _routine: Routine
|
||||
var _active_section: RoutineSection
|
||||
|
|
@ -74,6 +102,7 @@ var _section_buttons: Dictionary[String, Button] = {}
|
|||
var _tool: Tool = Tool.LINE
|
||||
var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
||||
var _edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
|
||||
var _preset_speed: float = DEFAULT_SPEED_MPS
|
||||
var _current_path: String = ""
|
||||
var _dirty: bool = false
|
||||
var _pending_action: Callable
|
||||
|
|
@ -98,6 +127,7 @@ func _ready() -> void:
|
|||
_setup_tool_options()
|
||||
_setup_file_menu()
|
||||
_setup_playback_controls()
|
||||
_setup_timing_controls()
|
||||
|
||||
tool_option.item_selected.connect(_on_tool_selected)
|
||||
forward_button.pressed.connect(
|
||||
|
|
@ -138,6 +168,14 @@ func _ready() -> void:
|
|||
reset_playback_button.pressed.connect(reset_playback)
|
||||
playback_timeline.value_changed.connect(_on_timeline_changed)
|
||||
speed_option.item_selected.connect(_on_speed_selected)
|
||||
duration_minus_button.pressed.connect(_change_selected_duration.bind(-1))
|
||||
duration_plus_button.pressed.connect(_change_selected_duration.bind(1))
|
||||
speed_minus_button.pressed.connect(_change_selected_speed.bind(-1))
|
||||
speed_plus_button.pressed.connect(_change_selected_speed.bind(1))
|
||||
profile_option.item_selected.connect(_on_profile_selected)
|
||||
calibrate_button.pressed.connect(_open_calibration_dialog)
|
||||
reset_timing_button.pressed.connect(_reset_selected_timing)
|
||||
calibration_dialog.confirmed.connect(_on_calibration_confirmed)
|
||||
|
||||
_ensure_routines_dir()
|
||||
if not (restore_autosave and _try_load_autosave()):
|
||||
|
|
@ -208,6 +246,10 @@ func get_tool() -> Tool:
|
|||
return _tool
|
||||
|
||||
|
||||
func get_preset_speed() -> float:
|
||||
return _preset_speed
|
||||
|
||||
|
||||
func get_selected_segment() -> PathSegment:
|
||||
return _find_segment(_selected_segment_id)
|
||||
|
||||
|
|
@ -466,6 +508,8 @@ func _clone_segment(source: PathSegment) -> PathSegment:
|
|||
clone.direction = source.direction
|
||||
clone.edge = source.edge
|
||||
clone.duration_seconds = source.duration_seconds
|
||||
clone.speed_mps = source.speed_mps
|
||||
clone.timing_mode = source.timing_mode
|
||||
clone.element_id = source.element_id
|
||||
clone.label = source.label
|
||||
clone.template = source.template
|
||||
|
|
@ -761,6 +805,8 @@ func _create_segment(
|
|||
curve.add_point(clamped_start)
|
||||
curve.add_point(clamped_start)
|
||||
segment.curve = curve
|
||||
segment.speed_mps = _preset_speed
|
||||
segment.timing_mode = PathSegment.TimingMode.SPEED
|
||||
segment.duration_seconds = 0.001
|
||||
return segment
|
||||
|
||||
|
|
@ -832,10 +878,7 @@ func _set_arc_geometry(
|
|||
|
||||
|
||||
func _update_duration(segment: PathSegment) -> void:
|
||||
segment.duration_seconds = maxf(
|
||||
segment.get_length_m() / DEFAULT_SPEED_MPS,
|
||||
0.001
|
||||
)
|
||||
segment.apply_geometry_length(segment.get_length_m())
|
||||
|
||||
|
||||
func is_playing() -> bool:
|
||||
|
|
@ -1112,6 +1155,171 @@ func _format_seconds(seconds: float) -> String:
|
|||
return ("%.1f" % seconds).replace(".", ",")
|
||||
|
||||
|
||||
func _format_decimal(value: float) -> String:
|
||||
return ("%.1f" % value).replace(".", ",")
|
||||
|
||||
|
||||
func _setup_timing_controls() -> void:
|
||||
profile_option.clear()
|
||||
for index: int in range(PROFILE_NAMES.size()):
|
||||
profile_option.add_item(PROFILE_NAMES[index], index)
|
||||
profile_option.add_item("Individuell", -1)
|
||||
|
||||
_preset_speed = DEFAULT_SPEED_MPS
|
||||
profile_option.select(profile_option.get_item_index(DEFAULT_PROFILE_INDEX))
|
||||
_update_timing_ui()
|
||||
|
||||
|
||||
func _set_timing_controls_enabled(enabled: bool) -> void:
|
||||
duration_minus_button.disabled = not enabled
|
||||
duration_plus_button.disabled = not enabled
|
||||
speed_minus_button.disabled = not enabled
|
||||
speed_plus_button.disabled = not enabled
|
||||
calibrate_button.disabled = not enabled
|
||||
reset_timing_button.disabled = not enabled
|
||||
|
||||
|
||||
func _update_timing_ui() -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
timing_selection_label.text = "Kein Segment ausgewählt"
|
||||
duration_value_label.text = "–"
|
||||
speed_value_label.text = "–"
|
||||
_set_timing_controls_enabled(false)
|
||||
_select_profile_for_speed(_preset_speed)
|
||||
return
|
||||
|
||||
_set_timing_controls_enabled(true)
|
||||
var kind := "Bogen" if selected.is_arc() else "Linie"
|
||||
timing_selection_label.text = "%s · %s m" % [
|
||||
kind,
|
||||
_format_decimal(selected.get_length_m()),
|
||||
]
|
||||
duration_value_label.text = "%s s" % _format_seconds(selected.duration_seconds)
|
||||
speed_value_label.text = "%s m/s" % _format_decimal(selected.get_speed_mps())
|
||||
_select_profile_for_speed(selected.get_speed_mps())
|
||||
_preset_speed = selected.get_speed_mps()
|
||||
|
||||
|
||||
func _select_profile_for_speed(speed: float) -> void:
|
||||
var item_index := PROFILE_NAMES.size()
|
||||
for index: int in range(PROFILE_SPEEDS.size()):
|
||||
if absf(speed - PROFILE_SPEEDS[index]) <= 0.05:
|
||||
item_index = index
|
||||
break
|
||||
|
||||
profile_option.set_block_signals(true)
|
||||
profile_option.select(item_index)
|
||||
profile_option.set_block_signals(false)
|
||||
|
||||
|
||||
func _change_selected_duration(direction: int) -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
return
|
||||
|
||||
_record_undo()
|
||||
var value := clampf(
|
||||
selected.duration_seconds + direction * DURATION_STEP_SECONDS,
|
||||
MIN_DURATION_SECONDS,
|
||||
MAX_DURATION_SECONDS
|
||||
)
|
||||
selected.set_duration_seconds(value)
|
||||
_preset_speed = selected.get_speed_mps()
|
||||
_mark_dirty()
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _change_selected_speed(direction: int) -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
return
|
||||
|
||||
_record_undo()
|
||||
var value := clampf(
|
||||
selected.get_speed_mps() + direction * SPEED_STEP_MPS,
|
||||
MIN_SPEED_MPS,
|
||||
MAX_SPEED_MPS
|
||||
)
|
||||
selected.set_speed_mps(value)
|
||||
_preset_speed = selected.get_speed_mps()
|
||||
_mark_dirty()
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _on_profile_selected(index: int) -> void:
|
||||
var preset_index := profile_option.get_item_id(index)
|
||||
if preset_index < 0:
|
||||
_update_timing_ui()
|
||||
return
|
||||
|
||||
var speed: float = PROFILE_SPEEDS[preset_index]
|
||||
_preset_speed = speed
|
||||
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
_update_timing_ui()
|
||||
return
|
||||
|
||||
_record_undo()
|
||||
selected.set_speed_mps(speed)
|
||||
_mark_dirty()
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _reset_selected_timing() -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
return
|
||||
|
||||
_record_undo()
|
||||
_preset_speed = DEFAULT_SPEED_MPS
|
||||
selected.set_speed_mps(DEFAULT_SPEED_MPS)
|
||||
_mark_dirty()
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _open_calibration_dialog() -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
return
|
||||
|
||||
calibration_distance_edit.text = _format_decimal(selected.get_length_m())
|
||||
calibration_time_edit.text = _format_seconds(selected.duration_seconds)
|
||||
calibration_dialog.popup_centered(Vector2i(460, 260))
|
||||
calibration_distance_edit.grab_focus()
|
||||
calibration_distance_edit.select_all()
|
||||
|
||||
|
||||
func _on_calibration_confirmed() -> void:
|
||||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
return
|
||||
|
||||
var distance := _parse_float(calibration_distance_edit.text)
|
||||
var duration := _parse_float(calibration_time_edit.text)
|
||||
if distance <= 0.0 or duration <= 0.0:
|
||||
_show_message("Strecke und Zeit müssen größer als 0 sein.")
|
||||
return
|
||||
|
||||
_record_undo()
|
||||
selected.set_speed_mps(
|
||||
clampf(distance / duration, MIN_SPEED_MPS, MAX_SPEED_MPS)
|
||||
)
|
||||
_preset_speed = selected.get_speed_mps()
|
||||
_mark_dirty()
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _parse_float(text: String) -> float:
|
||||
return text.strip_edges().replace(",", ".").to_float()
|
||||
|
||||
|
||||
func _setup_file_menu() -> void:
|
||||
var popup := file_menu_button.get_popup()
|
||||
popup.add_item("Neu", FileAction.NEW)
|
||||
|
|
@ -1170,6 +1378,7 @@ func _install_routine(
|
|||
if section != null:
|
||||
valid_sections.append(section)
|
||||
_routine.sections = valid_sections
|
||||
_migrate_routine(_routine)
|
||||
|
||||
if _routine.sections.is_empty():
|
||||
var fallback := RoutineSection.new()
|
||||
|
|
@ -1196,6 +1405,28 @@ func _install_routine(
|
|||
_update_status()
|
||||
|
||||
|
||||
func _migrate_routine(routine: Routine) -> void:
|
||||
if routine.schema_version >= Routine.CURRENT_SCHEMA_VERSION:
|
||||
return
|
||||
|
||||
for section: RoutineSection in routine.sections:
|
||||
if section == null:
|
||||
continue
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment == null:
|
||||
continue
|
||||
var length := segment.get_length_m()
|
||||
if length > 0.0 and segment.duration_seconds > 0.0:
|
||||
segment.speed_mps = length / segment.duration_seconds
|
||||
segment.timing_mode = PathSegment.TimingMode.DURATION
|
||||
else:
|
||||
segment.speed_mps = DEFAULT_SPEED_MPS
|
||||
segment.timing_mode = PathSegment.TimingMode.SPEED
|
||||
segment.apply_geometry_length(length)
|
||||
|
||||
routine.schema_version = Routine.CURRENT_SCHEMA_VERSION
|
||||
|
||||
|
||||
func _rebuild_counters_from_ids() -> void:
|
||||
var section_ids: Array[String] = []
|
||||
var segment_ids: Array[String] = []
|
||||
|
|
@ -1510,6 +1741,7 @@ func _update_status() -> void:
|
|||
return
|
||||
|
||||
_refresh_playback_timeline()
|
||||
_update_timing_ui()
|
||||
|
||||
var segment_count := _active_section.segments.size()
|
||||
var segment_word := "Segment" if segment_count == 1 else "Segmente"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ $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
|
||||
|
||||
# Run segment timing/presets/calibration tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_timing_tests.gd
|
||||
```
|
||||
|
||||
Exit code `0` means all assertions passed. Failures are printed to stderr.
|
||||
|
|
|
|||
|
|
@ -110,6 +110,48 @@ func _test_segment_timing() -> void:
|
|||
"segment with length but no duration is invalid"
|
||||
)
|
||||
|
||||
var timed: PathSegment = PathSegmentModel.new()
|
||||
timed.segment_id = "seg-timed"
|
||||
timed.curve = _make_curve(Vector2(0.0, 0.0), Vector2(10.0, 0.0))
|
||||
_check_approx(timed.speed_mps, 4.3, "default segment speed is adult gold")
|
||||
_check(
|
||||
timed.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"default timing mode is speed"
|
||||
)
|
||||
timed.set_speed_mps(5.0)
|
||||
_check_approx(timed.duration_seconds, 2.0, "speed sets the duration")
|
||||
timed.set_duration_seconds(4.0)
|
||||
_check_approx(timed.get_speed_mps(), 2.5, "duration sets the speed")
|
||||
_check(
|
||||
timed.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"duration mode is stored"
|
||||
)
|
||||
timed.curve.set_point_position(1, Vector2(20.0, 0.0))
|
||||
timed.apply_geometry_length(20.0)
|
||||
_check_approx(
|
||||
timed.duration_seconds,
|
||||
4.0,
|
||||
"duration mode preserves the authored duration"
|
||||
)
|
||||
_check_approx(
|
||||
timed.get_speed_mps(),
|
||||
5.0,
|
||||
"duration mode updates the implied speed"
|
||||
)
|
||||
timed.set_speed_mps(4.0)
|
||||
timed.curve.set_point_position(1, Vector2(8.0, 0.0))
|
||||
timed.apply_geometry_length(8.0)
|
||||
_check_approx(
|
||||
timed.duration_seconds,
|
||||
2.0,
|
||||
"speed mode preserves the authored speed"
|
||||
)
|
||||
_check_approx(
|
||||
timed.get_speed_mps(),
|
||||
4.0,
|
||||
"speed mode keeps the speed after a geometry edit"
|
||||
)
|
||||
|
||||
var arc_segment: PathSegment = PathSegmentModel.new()
|
||||
arc_segment.segment_id = "seg-arc"
|
||||
arc_segment.curve = _make_curve(Vector2(-5.0, 0.0), Vector2(5.0, 0.0))
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ func _run() -> void:
|
|||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
|
||||
for segment: PathSegment in [forward, backward, last]:
|
||||
segment.set_speed_mps(6.0)
|
||||
controller._update_status()
|
||||
|
||||
_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")
|
||||
|
|
|
|||
275
rinkplanner/tests/run_timing_tests.gd
Normal file
275
rinkplanner/tests/run_timing_tests.gd
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
extends SceneTree
|
||||
|
||||
## Headless tests for segment timing, presets and calibration.
|
||||
##
|
||||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_timing_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, "timing scene has a controller")
|
||||
if controller == null:
|
||||
_finish()
|
||||
return
|
||||
|
||||
_check(
|
||||
controller.timing_selection_label.text.contains("Kein Segment"),
|
||||
"timing starts without a selected segment"
|
||||
)
|
||||
_check(
|
||||
controller.duration_plus_button.disabled,
|
||||
"duration controls start disabled"
|
||||
)
|
||||
_check(
|
||||
controller.profile_option.selected == WhiteboardController.DEFAULT_PROFILE_INDEX,
|
||||
"adult gold is the default profile"
|
||||
)
|
||||
|
||||
var segment := controller.add_segment(
|
||||
Vector2(-5.0, 0.0),
|
||||
Vector2(5.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
_check_approx(segment.get_length_m(), 10.0, "test segment is 10 m long")
|
||||
_check_approx(
|
||||
segment.duration_seconds,
|
||||
10.0 / WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"new segments use the default speed"
|
||||
)
|
||||
_check_approx(
|
||||
segment.speed_mps,
|
||||
WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"new segment stores the authored speed"
|
||||
)
|
||||
|
||||
controller.select_segment(segment.segment_id)
|
||||
_check(
|
||||
not controller.duration_plus_button.disabled,
|
||||
"timing controls enable with a selection"
|
||||
)
|
||||
_check(
|
||||
controller.timing_selection_label.text.contains("10,0 m"),
|
||||
"timing bar shows the segment length"
|
||||
)
|
||||
_check(
|
||||
controller.duration_value_label.text.contains("2,3"),
|
||||
"timing bar shows the duration"
|
||||
)
|
||||
_check(
|
||||
controller.speed_value_label.text.contains("4,3"),
|
||||
"timing bar shows the speed"
|
||||
)
|
||||
|
||||
var duration_before := segment.duration_seconds
|
||||
controller.duration_plus_button.pressed.emit()
|
||||
_check_approx(
|
||||
segment.duration_seconds,
|
||||
duration_before + 0.1,
|
||||
"duration plus increases the duration"
|
||||
)
|
||||
_check(
|
||||
segment.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"duration editing switches to duration mode"
|
||||
)
|
||||
_check(
|
||||
segment.get_speed_mps() < WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"a longer duration lowers the implied speed"
|
||||
)
|
||||
|
||||
_check(controller.undo(), "duration change can be undone")
|
||||
var restored := controller.get_active_section().get_segment_by_id(
|
||||
segment.segment_id
|
||||
)
|
||||
_check(restored != null, "segment survives undo")
|
||||
if restored != null:
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
duration_before,
|
||||
"undo restores the duration"
|
||||
)
|
||||
_check(
|
||||
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"undo restores the timing mode"
|
||||
)
|
||||
controller.select_segment(restored.segment_id)
|
||||
controller.speed_plus_button.pressed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
4.4,
|
||||
"speed plus increases the speed"
|
||||
)
|
||||
_check(
|
||||
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"speed editing switches to speed mode"
|
||||
)
|
||||
|
||||
var speed_before_profile := restored.get_speed_mps()
|
||||
controller.profile_option.item_selected.emit(3)
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
5.0,
|
||||
"masters profile applies 5 m/s"
|
||||
)
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
2.0,
|
||||
"profile updates the duration"
|
||||
)
|
||||
_check(controller.undo(), "profile change can be undone")
|
||||
restored = controller.get_active_section().get_segment_by_id(segment.segment_id)
|
||||
if restored != null:
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
speed_before_profile,
|
||||
"undo restores the previous speed"
|
||||
)
|
||||
controller.select_segment(restored.segment_id)
|
||||
|
||||
controller.reset_timing_button.pressed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"reset applies the default profile speed"
|
||||
)
|
||||
|
||||
controller.calibrate_button.pressed.emit()
|
||||
controller.calibration_distance_edit.text = "20"
|
||||
controller.calibration_time_edit.text = "4"
|
||||
controller.calibration_dialog.confirmed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
5.0,
|
||||
"calibration derives speed from distance and time"
|
||||
)
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
2.0,
|
||||
"calibration updates the duration"
|
||||
)
|
||||
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
controller.profile_option.item_selected.emit(0)
|
||||
_check_approx(
|
||||
controller.get_preset_speed(),
|
||||
3.0,
|
||||
"profile without selection sets the next-segment speed"
|
||||
)
|
||||
var bronze := controller.add_segment(
|
||||
Vector2(0.0, 8.0),
|
||||
Vector2(6.0, 8.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
)
|
||||
_check_approx(bronze.get_speed_mps(), 3.0, "new segment uses the bronze preset")
|
||||
_check_approx(bronze.duration_seconds, 2.0, "bronze duration follows the length")
|
||||
|
||||
var save_path := "user://test_timing.tres"
|
||||
_check(controller.save_to_path(save_path), "timing routine can be saved")
|
||||
_check(controller.load_from_path(save_path), "timing routine can be loaded")
|
||||
var loaded_first := controller.get_routine().get_section_by_id(
|
||||
"section-001"
|
||||
)
|
||||
_check(loaded_first != null, "loaded timing routine has its section")
|
||||
if loaded_first != null:
|
||||
var loaded_arc := loaded_first.get_segment_by_id(segment.segment_id)
|
||||
_check(loaded_arc != null, "loaded timing routine has the first segment")
|
||||
if loaded_arc != null:
|
||||
_check_approx(
|
||||
loaded_arc.get_speed_mps(),
|
||||
5.0,
|
||||
"load preserves the authored speed"
|
||||
)
|
||||
_check(
|
||||
loaded_arc.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"load preserves the timing mode"
|
||||
)
|
||||
DirAccess.remove_absolute(save_path)
|
||||
|
||||
# Migration: old routines had no speed field; their duration must survive.
|
||||
var old_routine := Routine.new()
|
||||
old_routine.schema_version = 1
|
||||
old_routine.routine_id = "old-routine"
|
||||
old_routine.title = "Alt"
|
||||
old_routine.rink = RinkDimensions.new()
|
||||
var old_section := RoutineSection.new()
|
||||
old_section.section_id = "section-001"
|
||||
old_section.title = "Abschnitt 1"
|
||||
old_section.sequence_order = 0
|
||||
var old_segment := PathSegment.new()
|
||||
old_segment.segment_id = "seg-old"
|
||||
old_segment.curve = Curve2D.new()
|
||||
old_segment.curve.add_point(Vector2(-5.0, 0.0))
|
||||
old_segment.curve.add_point(Vector2(5.0, 0.0))
|
||||
old_segment.duration_seconds = 5.0
|
||||
old_segment.speed_mps = 4.3
|
||||
old_segment.timing_mode = PathSegment.TimingMode.SPEED
|
||||
old_section.segments = [old_segment]
|
||||
old_routine.sections = [old_section]
|
||||
|
||||
var old_path := "user://test_timing_v1.tres"
|
||||
ResourceSaver.save(old_routine, old_path)
|
||||
_check(controller.load_from_path(old_path), "schema-1 routine can be loaded")
|
||||
var migrated := controller.get_active_section().get_segment_by_id("seg-old")
|
||||
_check(migrated != null, "migrated segment exists")
|
||||
if migrated != null:
|
||||
_check(
|
||||
migrated.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"migration preserves the old duration"
|
||||
)
|
||||
_check_approx(
|
||||
migrated.speed_mps,
|
||||
2.0,
|
||||
"migration derives the old speed"
|
||||
)
|
||||
_check(
|
||||
controller.get_routine().schema_version == Routine.CURRENT_SCHEMA_VERSION,
|
||||
"migration updates the schema version"
|
||||
)
|
||||
DirAccess.remove_absolute(old_path)
|
||||
|
||||
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 _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)
|
||||
1
rinkplanner/tests/run_timing_tests.gd.uid
Normal file
1
rinkplanner/tests/run_timing_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cu00yy7ajnuqb
|
||||
|
|
@ -33,3 +33,6 @@ fi
|
|||
|
||||
"$GODOT" --headless --path "$PROJECT_DIR" \
|
||||
--script res://tests/run_playback_tests.gd
|
||||
|
||||
"$GODOT" --headless --path "$PROJECT_DIR" \
|
||||
--script res://tests/run_timing_tests.gd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue