refactor: Verhaltenskern der Kürenverwaltung als Modell
`RoutineManagerModel` (src/whiteboard/view/routine_manager_model.gd) bündelt, was die Kürenverwaltung über Dateien wissen muss: - `list_routines(dir)` — eine Zeile pro Kür, JSON vor Legacy, nach Namen sortiert, Fremddateien ignoriert. - `variants(dir, name)` — alle vorhandenen Dateien einer Kür (JSON und/oder `.tres`), mit Rückfall auf den übergebenen Namen. Der Controller ruft nur noch die beiden Funktionen auf. Test mit temporärem Ordner: Dubletten, Sortierung, Fremddateien, fehlende Kür. Controller: 8.142 -> 8.116 Zeilen. Suite grün. Der Dialog selbst bleibt offen: Seine Zeilenknöpfe hängen an Controller-Handlern, und Öffnen/Umbenennen/Löschen brauchen Sync und den aktuellen Pfad.
This commit is contained in:
parent
5161869ec2
commit
a835831201
6 changed files with 92 additions and 31 deletions
|
|
@ -7225,18 +7225,7 @@ func _on_delete_routine_confirmed() -> void:
|
|||
## A routine can exist as JSON and as a legacy `.tres` twin. Deleting the
|
||||
## visible entry removes both so the old file does not reappear.
|
||||
func _routine_variants(file_name: String) -> PackedStringArray:
|
||||
var stem := file_name.get_basename()
|
||||
var result := PackedStringArray()
|
||||
for extension: String in [
|
||||
RoutineFile.JSON_EXTENSION,
|
||||
RoutineFile.LEGACY_EXTENSION,
|
||||
]:
|
||||
var candidate := stem + extension
|
||||
if FileAccess.file_exists(ROUTINES_DIR.path_join(candidate)):
|
||||
result.append(candidate)
|
||||
if result.is_empty():
|
||||
result.append(file_name)
|
||||
return result
|
||||
return RoutineManagerModel.variants(ROUTINES_DIR, file_name)
|
||||
|
||||
|
||||
func _open_rename_routine_dialog(file_name: String) -> void:
|
||||
|
|
@ -7483,22 +7472,7 @@ func _refresh_open_list() -> void:
|
|||
## Saved routine files, one per title (JSON wins over a legacy `.tres` twin).
|
||||
func _routine_entries() -> Array[String]:
|
||||
_ensure_routines_dir()
|
||||
var by_stem: Dictionary[String, String] = {}
|
||||
for file: String in DirAccess.get_files_at(ROUTINES_DIR):
|
||||
if not RoutineFile.is_routine_path(file):
|
||||
continue
|
||||
var stem := file.get_basename()
|
||||
var is_json := file.to_lower().ends_with(RoutineFile.JSON_EXTENSION)
|
||||
if not by_stem.has(stem) or is_json:
|
||||
by_stem[stem] = file
|
||||
var entries: Array[String] = []
|
||||
for file: String in by_stem.values():
|
||||
entries.append(file)
|
||||
entries.sort_custom(
|
||||
func(a: String, b: String) -> bool:
|
||||
return a.get_basename().naturalnocasecmp_to(b.get_basename()) < 0
|
||||
)
|
||||
return entries
|
||||
return RoutineManagerModel.list_routines(ROUTINES_DIR)
|
||||
|
||||
|
||||
func _on_open_file_pressed(path: String) -> void:
|
||||
|
|
|
|||
45
rinkplanner/src/whiteboard/view/routine_manager_model.gd
Normal file
45
rinkplanner/src/whiteboard/view/routine_manager_model.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
class_name RoutineManagerModel
|
||||
extends RefCounted
|
||||
|
||||
## What the routine manager lists and deletes.
|
||||
##
|
||||
## Pure over a directory: no scene, no sync. A routine may exist as JSON and as
|
||||
## the legacy `.tres`; the manager shows it once and works on all its variants.
|
||||
|
||||
|
||||
## Routine files of [param dir], one entry per routine, sorted by name.
|
||||
## JSON wins over the legacy format for the same stem.
|
||||
static func list_routines(dir: String) -> Array[String]:
|
||||
var by_stem: Dictionary[String, String] = {}
|
||||
for file: String in DirAccess.get_files_at(dir):
|
||||
if not RoutineFile.is_routine_path(file):
|
||||
continue
|
||||
var stem := file.get_basename()
|
||||
var is_json := file.to_lower().ends_with(RoutineFile.JSON_EXTENSION)
|
||||
if not by_stem.has(stem) or is_json:
|
||||
by_stem[stem] = file
|
||||
var entries: Array[String] = []
|
||||
for file: String in by_stem.values():
|
||||
entries.append(file)
|
||||
entries.sort_custom(
|
||||
func(a: String, b: String) -> bool:
|
||||
return a.get_basename().naturalnocasecmp_to(b.get_basename()) < 0
|
||||
)
|
||||
return entries
|
||||
|
||||
|
||||
## All existing file names of one routine: JSON and/or the legacy `.tres`.
|
||||
## Falls back to [param file_name] when no variant is on disk.
|
||||
static func variants(dir: String, file_name: String) -> PackedStringArray:
|
||||
var stem := file_name.get_basename()
|
||||
var result := PackedStringArray()
|
||||
for extension: String in [
|
||||
RoutineFile.JSON_EXTENSION,
|
||||
RoutineFile.LEGACY_EXTENSION,
|
||||
]:
|
||||
var candidate := stem + extension
|
||||
if FileAccess.file_exists(dir.path_join(candidate)):
|
||||
result.append(candidate)
|
||||
if result.is_empty():
|
||||
result.append(file_name)
|
||||
return result
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://5q62oxkubssd
|
||||
|
|
@ -837,6 +837,31 @@ func _test_controller_wiring() -> void:
|
|||
"Dropbox stays visible without credentials"
|
||||
)
|
||||
|
||||
# RoutineManagerModel: eine Zeile pro Kür, JSON vor Legacy, sortiert.
|
||||
var model_dir := "user://routine-manager-model"
|
||||
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(model_dir))
|
||||
for name: String in ["b.tres", "a.json", "c.json", "c.tres", "notes.txt"]:
|
||||
var file := FileAccess.open(model_dir.path_join(name), FileAccess.WRITE)
|
||||
if file != null:
|
||||
file.store_string("{}")
|
||||
file.close()
|
||||
var listed := RoutineManagerModel.list_routines(model_dir)
|
||||
_check(listed.size() == 3, "one row per routine, ignoring other files (%d)" % listed.size())
|
||||
_check(str(listed[0]) == "a.json", "routines are sorted by name")
|
||||
_check(listed.has("c.json") and not listed.has("c.tres"), "JSON wins over the legacy format")
|
||||
var variants := RoutineManagerModel.variants(model_dir, "c.json")
|
||||
_check(
|
||||
variants.size() == 2 and variants.has("c.json") and variants.has("c.tres"),
|
||||
"both variants of a routine are found"
|
||||
)
|
||||
_check(
|
||||
RoutineManagerModel.variants(model_dir, "missing.json") == PackedStringArray(["missing.json"]),
|
||||
"a missing routine falls back to its name"
|
||||
)
|
||||
for name: String in ["b.tres", "a.json", "c.json", "c.tres", "notes.txt"]:
|
||||
DirAccess.remove_absolute(model_dir.path_join(name))
|
||||
DirAccess.remove_absolute(model_dir)
|
||||
|
||||
# "Küren verwalten": rows expose open/delete, the music stay-check works.
|
||||
controller.sync_settings_dialog.hide()
|
||||
DirAccess.make_dir_recursive_absolute(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue