refactor: Inhalt der Statusleisten-Auswahl aus dem Controller lösen

Etappe 6 der Controller-Zerlegung. `SeasonPanelModel`
(src/whiteboard/view/season_panel_model.gd) baut den Inhalt der drei
Dropdowns: Beschriftungen, Werte und die passende Auswahl, zurückgegeben als
`{"items": [...], "selected": int}`.

- Der Controller füllt seine OptionButtons nur noch über `_fill_option()`;
  Signalverdrahtung und Zustand bleiben bei ihm.
- `_season_tooltip()` entfällt, die Tooltip-Texte kommen ebenfalls aus dem
  Modell.
- Test für die Fälle, die vorher nur über die Szene prüfbar waren: "nicht
  festgelegt", unbekannte Saison, unbekannte Kategorie (bleibt als "nicht
  verfügbar" sichtbar), Programmtyp.

Controller: 8.513 -> 8.459 Zeilen. Kein Verhalten geändert, Suite grün.

Offen bleibt der Node-Schnitt der Widgets; er ändert nur die Verdrahtung und
lohnt erst mit der UI-Gliederung.
This commit is contained in:
torsten 2026-11-13 13:32:30 +01:00
parent ef25c380c9
commit dbc7e1e484
6 changed files with 195 additions and 93 deletions

View file

@ -2458,16 +2458,8 @@ func _setup_element_controls() -> void:
func _setup_adult_category_controls() -> void:
adult_category_option.clear()
adult_category_option.add_item("Ohne Kategorie", 0)
adult_category_option.set_item_metadata(0, "")
if _ruleset.adult != null:
for category: AdultCategoryRules.Category in _ruleset.adult.get_categories(
_program_type()
):
var index := adult_category_option.item_count
adult_category_option.add_item(category.name, index)
adult_category_option.set_item_metadata(index, category.code)
if adult_category_option == null:
return
if not adult_category_option.item_selected.is_connected(
_on_adult_category_selected
):
@ -2475,7 +2467,6 @@ func _setup_adult_category_controls() -> void:
_sync_adult_category_option()
## Programme type of the current routine: "free" (Kür) or "artistic".
func _program_type() -> String:
if _routine == null:
return AdultCategoryRules.PROGRAM_FREE
@ -2485,11 +2476,6 @@ func _program_type() -> String:
func _setup_program_controls() -> void:
if program_option == null:
return
program_option.clear()
program_option.add_item(I18n.t("Kür"), 0)
program_option.set_item_metadata(0, AdultCategoryRules.PROGRAM_FREE)
program_option.add_item(I18n.t("Artistic"), 1)
program_option.set_item_metadata(1, AdultCategoryRules.PROGRAM_ARTISTIC)
if not program_option.item_selected.is_connected(_on_program_selected):
program_option.item_selected.connect(_on_program_selected)
_sync_program_option()
@ -2498,12 +2484,7 @@ func _setup_program_controls() -> void:
func _sync_program_option() -> void:
if program_option == null:
return
var program := _program_type()
for index: int in range(program_option.item_count):
if str(program_option.get_item_metadata(index)) == program:
program_option.select(index)
return
program_option.select(0)
_fill_option(program_option, SeasonPanelModel.program_items(_program_type()))
func _on_program_selected(index: int) -> void:
@ -2572,28 +2553,31 @@ func get_adult_rules() -> AdultCategoryRules:
func _sync_adult_category_option() -> void:
if adult_category_option == null:
return
var code := _routine.adult_category if _routine != null else ""
for index: int in range(adult_category_option.item_count):
if str(adult_category_option.get_item_metadata(index)) == code:
adult_category_option.select(index)
return
# The stored category is not part of this season. Show it instead of
# pretending the routine has no category.
if not code.is_empty():
var index := adult_category_option.item_count
adult_category_option.add_item(
I18n.t("Kategorie „%s“ nicht verfügbar") % code.capitalize(),
index
var categories: Array = []
if _ruleset.adult != null:
categories.assign(_ruleset.adult.get_categories(_program_type()))
_fill_option(
adult_category_option,
SeasonPanelModel.category_items(
_routine.adult_category if _routine != null else "",
categories
)
adult_category_option.set_item_metadata(index, code)
adult_category_option.select(index)
return
if adult_category_option.item_count > 0:
adult_category_option.select(0)
)
## Fills an OptionButton from a SeasonPanelModel result.
func _fill_option(option: OptionButton, content: Dictionary) -> void:
option.clear()
var items: Array = content.get("items", [])
for index: int in range(items.size()):
var item: Dictionary = items[index]
option.add_item(str(item.get("label", "")), index)
option.set_item_metadata(index, str(item.get("value", "")))
var selected := int(content.get("selected", -1))
if selected >= 0:
option.select(selected)
## Fills the season dropdown. The list comes from the rules library, so a new
## season folder appears without touching this code.
func _setup_upgrade_controls() -> void:
if upgrade_run_button != null:
upgrade_run_button.pressed.connect(_run_upgrade_check)
@ -2621,54 +2605,16 @@ func _sync_season_option() -> void:
if season_option == null:
return
var current := _routine.season.strip_edges() if _routine != null else ""
season_option.clear()
var selected := -1
if current.is_empty():
season_option.add_item(I18n.t("Saison nicht festgelegt"), 0)
season_option.set_item_metadata(0, "")
selected = 0
if _ruleset.library != null:
for season: String in _ruleset.library.get_seasons():
var index := season_option.item_count
var label := I18n.t("Saison %s") % season
var status := str(
_ruleset.library.get_manifest(season).get("status", "complete")
).strip_edges()
if status != "complete":
label += " " + I18n.t("(unvollständig)")
season_option.add_item(label, index)
season_option.set_item_metadata(index, season)
if season == current:
selected = index
if not current.is_empty() and selected < 0:
var index := season_option.item_count
season_option.add_item(I18n.t("Saison %s (unbekannt)") % current, index)
season_option.set_item_metadata(index, current)
selected = index
if selected >= 0:
season_option.select(selected)
season_option.tooltip_text = _season_tooltip(current)
func _season_tooltip(current: String) -> String:
if not current.is_empty():
return I18n.t("Regelwerk, gegen das diese Kür geprüft wird")
var inferred := _infer_season_from_current_path()
if inferred.is_empty():
return I18n.t("Ohne Saison kann die Kür nicht geprüft werden")
return (
I18n.t("Ohne Saison kann die Kür nicht geprüft werden")
+ " "
+ I18n.t("Vermutlich Saison %s (Dateidatum).") % inferred
_fill_option(
season_option,
SeasonPanelModel.season_items(current, _ruleset.library)
)
season_option.tooltip_text = SeasonPanelModel.season_tooltip(
current,
_infer_season_from_current_path()
)
## Best guess for a routine that predates the season field: the season that was
## valid when its file was last written. Only used as a hint, never applied.
func _infer_season_from_current_path() -> String:
if _current_path.is_empty() or _ruleset.library == null:
return ""

View file

@ -0,0 +1,93 @@
class_name SeasonPanelModel
extends RefCounted
## Content of the three status bar dropdowns: season, programme type and adult
## category.
##
## Pure functions: they build labels and metadata, but never touch a node. The
## controller fills its OptionButtons from the result and keeps the signal
## wiring. Returns `{"items": [{"label": String, "value": String}], "selected": int}`.
const NO_CATEGORY := "Ohne Kategorie"
static func season_items(current: String, library: RulesLibrary) -> Dictionary:
var items: Array[Dictionary] = []
var selected := -1
var cleaned := current.strip_edges()
if cleaned.is_empty():
items.append({"label": I18n.t("Saison nicht festgelegt"), "value": ""})
selected = 0
if library != null:
for season: String in library.get_seasons():
var label := I18n.t("Saison %s") % season
var status := str(
library.get_manifest(season).get("status", "complete")
).strip_edges()
if status != "complete":
label += " " + I18n.t("(unvollständig)")
items.append({"label": label, "value": season})
if season == cleaned:
selected = items.size() - 1
if not cleaned.is_empty() and selected < 0:
items.append(
{
"label": I18n.t("Saison %s (unbekannt)") % cleaned,
"value": cleaned,
}
)
selected = items.size() - 1
return {"items": items, "selected": selected}
static func program_items(current: String) -> Dictionary:
var items: Array[Dictionary] = [
{"label": I18n.t("Kür"), "value": AdultCategoryRules.PROGRAM_FREE},
{"label": I18n.t("Artistic"), "value": AdultCategoryRules.PROGRAM_ARTISTIC},
]
var selected := 0
for index: int in range(items.size()):
if str(items[index]["value"]) == current:
selected = index
return {"items": items, "selected": selected}
## Categories of one programme type plus "no category". A stored code that the
## season does not know stays visible as "nicht verfügbar" instead of silently
## selecting "no category".
static func category_items(
current: String,
categories: Array
) -> Dictionary:
var items: Array[Dictionary] = [{"label": NO_CATEGORY, "value": ""}]
var cleaned := current.strip_edges()
for category: AdultCategoryRules.Category in categories:
items.append({"label": category.name, "value": category.code})
for index: int in range(items.size()):
if str(items[index]["value"]) == cleaned:
return {"items": items, "selected": index}
if not cleaned.is_empty():
items.append(
{
"label": I18n.t("Kategorie „%s“ nicht verfügbar") % cleaned.capitalize(),
"value": cleaned,
}
)
return {"items": items, "selected": items.size() - 1}
return {"items": items, "selected": 0}
static func season_tooltip(current: String, inferred: String) -> String:
if not current.strip_edges().is_empty():
return I18n.t("Regelwerk, gegen das diese Kür geprüft wird")
var base := I18n.t("Ohne Saison kann die Kür nicht geprüft werden")
if inferred.is_empty():
return base
return base + " " + I18n.t("Vermutlich Saison %s (Dateidatum).") % inferred

View file

@ -0,0 +1 @@
uid://cpd3460lrabou

View file

@ -21,6 +21,7 @@ func _init() -> void:
_test_upgrade_check()
_test_season_comparison_text()
_test_rules_context()
_test_season_panel_model()
_cleanup()
_finish()
@ -316,6 +317,53 @@ func _test_rules_context() -> void:
_check(context.package == null, "an unknown season clears the documents")
## Inhalt der Statusleisten-Auswahl: Beschriftung, Zuordnung, Auswahl.
func _test_season_panel_model() -> void:
var library := RulesLibrary.scan()
var empty := SeasonPanelModel.season_items("", library)
_check(int(empty["selected"]) == 0, "without a season the first entry is selected")
_check(str(empty["items"][0]["value"]) == "", "the first entry has no value")
var current := SeasonPanelModel.season_items("2026/27", library)
_check(
str(current["items"][int(current["selected"])]["value"]) == "2026/27",
"the current season is selected"
)
var unknown := SeasonPanelModel.season_items("2030/31", library)
_check(
str(unknown["items"][int(unknown["selected"])]["value"]) == "2030/31",
"an unknown season stays visible"
)
var categories: Array = []
var package := library.get_package("2026/27")
if package != null and package.adult != null:
categories.assign(package.adult.get_categories("free"))
_check(categories.size() == 5, "the free-skating categories are offered")
var known := SeasonPanelModel.category_items("gold", categories)
_check(
str(known["items"][int(known["selected"])]["value"]) == "gold",
"a known category is selected"
)
var missing := SeasonPanelModel.category_items("legacy", categories)
_check(
str(missing["items"][int(missing["selected"])]["value"]) == "legacy",
"an unknown category stays visible"
)
_check(
str(missing["items"][int(missing["selected"])]["label"]).contains(
"nicht verfügbar"
),
"an unknown category is labelled"
)
_check(
SeasonPanelModel.program_items("artistic")["selected"] == 1,
"the artistic programme is selected"
)
func _make_pair_routine() -> Routine:
var routine := Routine.new()
routine.routine_id = "season-pair"