feat: Speichern, Laden und Autosave für Kürläufe hinzufügen

- Datei-Menü mit Neu, Öffnen, Speichern und Speichern unter
- .tres-Persistenz unter user://routines mit Schema-Version
- Autosave nach 1,5 s und Wiederherstellung beim Start
- Dirty-State im Fenstertitel und Rückfrage vor Verwerfen
- Öffnen-Dialog mit 48-px-Buttons für Touch-Bedienung
- Tests auf 265 Assertions erweitert
This commit is contained in:
torsten 2026-10-30 08:11:00 +01:00
parent 98eb5b7e2f
commit 1623fb2590
8 changed files with 590 additions and 34 deletions

View file

@ -1,6 +1,8 @@
# Tests
Headless tests for the Phase 1 model. They require no editor and no display.
Headless tests for the Phase 1 model, canvas and whiteboard controller. They
require no editor and no display. `tools/test.sh` isolates `user://` in a
temporary `XDG_DATA_HOME`, so tests never touch real autosaves or routines.
From the repository root:

View file

@ -154,6 +154,10 @@ func _test_section_aggregation() -> void:
func _test_routine_validation() -> void:
var routine: Routine = _make_routine()
_check(
routine.schema_version == Routine.CURRENT_SCHEMA_VERSION,
"new routines use the current schema version"
)
_check(routine.is_valid(), "complete routine is valid")
_check(routine.validate().is_empty(), "valid routine reports no errors")
_check_approx(routine.get_duration_seconds(), 9.5, "routine duration sums all sections")

View file

@ -18,10 +18,13 @@ func _init() -> void:
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
var controller := scene as WhiteboardController
_check(controller != null, "whiteboard scene has a controller")
if controller == null:
_finish()
@ -535,6 +538,91 @@ func _run() -> void:
"rename dialog applies the edited title"
)
# Save/load round-trip.
var roundtrip_path := "user://test_roundtrip.tres"
var saved_section_title := controller.get_active_section().title
var saved_segment_count := controller.get_active_section().segments.size()
var saved_arc_id := arc_left.segment_id
var saved_arc_depth := arc_left.arc_depth_ratio
var saved_arc_left := arc_left.arc_bulge_left
_check(controller.save_to_path(roundtrip_path), "routine can be saved")
_check(not controller.is_dirty(), "saving clears the dirty flag")
_check(
FileAccess.file_exists(roundtrip_path),
"save creates a routine file"
)
controller.add_section()
_check(controller.is_dirty(), "changes mark the routine dirty")
_check(controller.load_from_path(roundtrip_path), "routine can be loaded")
_check(
controller.get_routine().sections.size() == 1,
"load restores the section count"
)
_check(
controller.get_active_section().title == saved_section_title,
"load restores the section title"
)
_check(
controller.get_active_section().segments.size() == saved_segment_count,
"load restores all segments"
)
_check(not controller.is_dirty(), "loading clears the dirty flag")
var loaded_arc := controller.get_active_section().get_segment_by_id(
saved_arc_id
)
_check(loaded_arc != null, "loaded segments keep their ids")
if loaded_arc != null:
_check(
loaded_arc.template == PathSegment.Template.ARC,
"load restores the arc template"
)
_check_approx(
loaded_arc.arc_depth_ratio,
saved_arc_depth,
"load restores the arc depth"
)
_check(
loaded_arc.arc_bulge_left == saved_arc_left,
"load restores the arc side"
)
_check(
loaded_arc.curve.point_count > 2,
"load restores the sampled arc curve"
)
DirAccess.remove_absolute(roundtrip_path)
var too_new_path := "user://test_too_new.tres"
var too_new: Routine = controller.get_routine().duplicate(true)
too_new.schema_version = Routine.CURRENT_SCHEMA_VERSION + 1
ResourceSaver.save(too_new, too_new_path)
_check(
not controller.load_from_path(too_new_path),
"newer schema versions are rejected"
)
DirAccess.remove_absolute(too_new_path)
controller.save_name_edit.text = "Test Kür"
controller.save_as_dialog.confirmed.emit()
var save_as_path := "user://routines/test_kür.tres"
_check(
FileAccess.file_exists(save_as_path),
"save-as dialog writes a normalized filename"
)
_check(
controller.get_routine().title == "Test Kür",
"save-as dialog updates the routine title"
)
_check(
controller.get_current_path() == save_as_path,
"save-as dialog becomes the current file"
)
DirAccess.remove_absolute(save_as_path)
scene.queue_free()
await process_frame
_finish()