diff --git a/docs/architecture.md b/docs/architecture.md index 957ed73..22f1cc2 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -195,7 +195,9 @@ Begrenzung auf zwei Features pro Fuß. (Pirouetten, Schrittsequenzen) und übernimmt die Auswahl undo-fähig. Der Level wird daraus automatisch gesetzt und der Level-Regler ist bei Katalog-Elementen read-only; Sprünge sind fest Base, `ChSq` fest Level 1. - Ein Hinweis zeigt Feature-Anzahl und abgeleitetes Level. + Die Feature-Auswahl bleibt bis zum Übernehmen pending; erst dann werden + Typ, Kürzel, Features, Level und Standzeit in einem Undo-Schritt + gespeichert. Ein Hinweis zeigt Feature-Anzahl und abgeleitetes Level. Die Timing-Details (Dauer/Tempo/Profil) werden beim Setzen und für Punktmarker ausgeblendet, damit die Leiste auch im Landscape kompakt bleibt. - **Prüfung:** Der Button „Prüfen“ in der Statusleiste validiert alle @@ -366,7 +368,7 @@ Aktueller Stand: Prüfstatistik je Kategorie. - **Canvas:** 90 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan, Rink-Kontur und die reine Bogen-Geometrie. -- **Whiteboard:** 253 Assertions für Controller-Verdrahtung, Segmenterzeugung, +- **Whiteboard:** 259 Assertions für Controller-Verdrahtung, Segmenterzeugung, Linien-/Bogenpfade, Klemmen an der Bande, Auswahl, Griff- und Richtungs-/Kanten-Bearbeitung, Segmentlöschung, Element-Marker (Setzen, Typwechsel, Inspector inkl. Kürzelauswahl, Standzeit, Base-Value- und diff --git a/docs/findings-2026-10-31-level-aus-features.md b/docs/findings-2026-10-31-level-aus-features.md index a63751d..d497141 100644 --- a/docs/findings-2026-10-31-level-aus-features.md +++ b/docs/findings-2026-10-31-level-aus-features.md @@ -15,7 +15,7 @@ der Feature-Auswahl. | Unbekannte Freitext-Codes | Level bleibt manuell | | Oberfläche | Level-Regler bei Katalog-Elementen read-only | | Undo | Feature- und Leveländerung in einem Schritt | -| Tests | 912 Assertions gesamt, `./tools/test.sh` grün | +| Tests | 918 Assertions gesamt, `./tools/test.sh` grün | ## Verhalten @@ -34,6 +34,21 @@ der Feature-Auswahl. - Der Feature-Hinweis zeigt nur noch `Features: n · Level m`; die frühere Mismatch-Anzeige entfällt bei automatisch abgeleiteten Elementen. +## Feature-Auswahl im Dialog + +Die Feature-Auswahl ist eine **Pending-Auswahl**: + +1. Typ und Kürzel im Dialog wählen. +2. Der Button **Features (n)** wird aktiv, sobald das Kürzel im Katalog steht. +3. Features anhaken; Level, Base Value und Hinweis aktualisieren sich sofort. +4. Erst **Übernehmen** schreibt Typ, Kürzel, Features, Level und Standzeit in + einem Undo-Schritt ins Segment. **Abbrechen** verwirft die Auswahl. + +Damit ist die Feature-Prüfung nicht mehr an das bereits gespeicherte Segment +gebunden. Vorher blieb der Button nach einem Typ-/Kürzelwechsel stumm, weil er +noch die alten Segmentdaten las; das war der gemeldete „Level bleibt Base“- +Effekt. + ## Auswirkungen auf Altdaten - Ein gespeicherter manueller Level ohne Features wird beim nächsten Öffnen @@ -55,7 +70,7 @@ der Feature-Auswahl. ## Tests -Erweitert: `tests/run_whiteboard_tests.gd` (241 → 253 Assertions) +Erweitert: `tests/run_whiteboard_tests.gd` (241 → 259 Assertions) - Katalog-Spin ohne Features ist Base - vier Features ergeben Level 4, drei Level 3, zwei Level 2 @@ -64,6 +79,8 @@ Erweitert: `tests/run_whiteboard_tests.gd` (241 → 253 Assertions) - Level-Regler ist bei Katalog-Spin deaktiviert - Suffix-Code und unbekannter Freitext-Code funktionieren weiterhin - Sequenzbereich erhält Level 2 aus zwei Features +- kompletter Dialogfluss von leeren Marker über Typ-/Kürzelwahl und + Feature-Auswahl bis zum bestätigten Level 2 Visuell geprüft über `tests/manual/capture_elements.gd ... features` bei 1400 × 876: `Level 2` ausgegraut, `Base Value: 2,50`, Status `CCoSp L2`. diff --git a/docs/isu-rules.md b/docs/isu-rules.md index 107685f..0eeed63 100644 --- a/docs/isu-rules.md +++ b/docs/isu-rules.md @@ -160,11 +160,12 @@ Unbekannte Kürzel erscheinen als „Kürzel nicht im Katalog 2025/26“. Der Hinweis aktualisiert sich bei Änderungen an Typ, Kürzel und Features; der Tooltip nennt Saison und Quelle. -Darunter liegt der Button **Features (n)**. Er öffnet eine Checkbox-Liste mit -den Features des Elementtyps; die Auswahl wird beim Schließen übernommen und -ist undo-fähig. Der Level-Regler ist bei Katalog-Elementen read-only und folgt -der Feature-Auswahl: 0 Features → Base, 1 → Level 1 … 4 → Level 4. Der Hinweis -zeigt z. B. `Features: 2 · Level 2`. +Darunter liegt der Button **Features (n)**. Er wird aktiv, sobald Typ und +Kürzel im Katalog stehen. Er öffnet eine Checkbox-Liste mit den Features des +Elementtyps; die Auswahl bleibt bis zum Übernehmen pending und ist dann Teil +desselben Undo-Schritts. Der Level-Regler ist bei Katalog-Elementen read-only +und folgt der Feature-Auswahl: 0 Features → Base, 1 → Level 1 … 4 → Level 4. +Der Hinweis zeigt z. B. `Features: 2 · Level 2`. ## Prüfung diff --git a/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd b/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd index 54afe5b..306469c 100644 --- a/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd +++ b/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd @@ -165,6 +165,7 @@ var _element_type: PathSegment.ElementType = PathSegment.ElementType.JUMP var _element_level: int = 0 var _element_catalog: ElementCatalog var _level_rules: ElementLevelRules +var _dialog_features: PackedStringArray = PackedStringArray() var _preset_speed: float = DEFAULT_SPEED_MPS var _current_path: String = "" var _dirty: bool = false @@ -640,6 +641,8 @@ func set_selected_element_features(features: PackedStringArray) -> bool: segment.set_element_features(cleaned) if derived: segment.element_level = new_level + if element_dialog.visible: + _dialog_features = cleaned.duplicate() _mark_dirty() rink_canvas.refresh() _update_status() @@ -650,6 +653,8 @@ func set_selected_element_features(features: PackedStringArray) -> bool: ## Shows the feature count and the derived level in the element inspector. +## While the dialog is open the pending type, code and feature selection are +## used, so the level updates before the dialog is confirmed. func update_element_feature_hint() -> void: if element_feature_hint == null or element_features_button == null: return @@ -660,14 +665,24 @@ func update_element_feature_hint() -> void: if segment == null or not segment.is_element(): element_feature_hint.text = "Kein Element ausgewählt." return - if segment.element_type == PathSegment.ElementType.JUMP: + + var type := segment.element_type + var code := segment.element_code.strip_edges() + var features := segment.element_features + if element_dialog.visible: + type = _dialog_element_type() + code = _dialog_element_code() + features = _dialog_features + + if type == PathSegment.ElementType.NONE: + element_feature_hint.text = "Kein Element ausgewählt." + return + if type == PathSegment.ElementType.JUMP: element_feature_hint.text = "Sprünge haben keine Level-Features." return if _level_rules == null: element_feature_hint.text = "" return - - var code := segment.element_code.strip_edges() if code.is_empty(): element_feature_hint.text = "Kürzel wählen, um Level-Features zu erfassen." return @@ -675,11 +690,7 @@ func update_element_feature_hint() -> void: element_feature_hint.text = "Kürzel nicht im Katalog." return - var result := _level_rules.calculate_level( - segment.element_type, - code, - segment.element_features - ) + var result := _level_rules.calculate_level(type, code, features) element_features_button.disabled = false element_features_button.text = "Features (%d)" % result.counted_features @@ -689,8 +700,13 @@ func update_element_feature_hint() -> void: ) return + var chosen_level := segment.element_level + if element_dialog.visible and element_level_option.selected >= 0: + chosen_level = element_level_option.get_item_id( + element_level_option.selected + ) var computed := ElementDefinition.level_label(result.level) - var chosen := ElementDefinition.level_label(segment.element_level) + var chosen := ElementDefinition.level_label(chosen_level) var suffix := "" if computed == chosen else " · gewählt: %s" % chosen if not result.ignored_features.is_empty(): suffix += " · %d ignoriert" % result.ignored_features.size() @@ -720,18 +736,18 @@ func _open_feature_menu() -> void: ) -## Fills the feature menu from the selected element. Split from the popup call -## so tests can inspect the items without opening a window. +## Fills the feature menu from the pending dialog state. Split from the popup +## call so tests can inspect the items without opening a window. func _populate_feature_menu() -> bool: - var segment := get_selected_segment() - if segment == null or _level_rules == null: + if _level_rules == null or not element_dialog.visible: return false - var features := _level_rules.get_features(segment.element_type) + var type := _dialog_element_type() + var features := _level_rules.get_features(type) if features.is_empty(): return false var counts: Dictionary[String, int] = {} - for code: String in segment.element_features: + for code: String in _dialog_features: var key := code.strip_edges() if not key.is_empty(): counts[key] = counts.get(key, 0) + 1 @@ -780,7 +796,10 @@ func _on_feature_menu_hidden() -> void: and element_feature_menu.is_item_checked(index) ): features.append(str(element_feature_menu.get_item_metadata(index))) - set_selected_element_features(features) + _dialog_features = _clean_feature_codes(features) + _update_level_control_state() + update_element_feature_hint() + update_element_value_hint() ## Updates the Base-Value hint in the element inspector. Public so tests and @@ -823,6 +842,13 @@ func get_selected_element_caption() -> String: return segment.get_element_caption() if segment != null else "" +func _dialog_element_type() -> PathSegment.ElementType: + var index := element_dialog_type_option.selected + if index < 0: + return PathSegment.ElementType.NONE + return element_dialog_type_option.get_item_id(index) + + ## Returns the code currently entered in the dialog, either from the catalog ## selection or from the free-text fallback. func _dialog_element_code() -> String: @@ -876,15 +902,6 @@ func _derived_level( return _level_rules.calculate_level(type, code, features).level -## Features that survive a pending type change: they are cleared when the -## dialog type differs from the stored element type. -func _features_for_pending_type(type: PathSegment.ElementType) -> PackedStringArray: - var segment := get_selected_segment() - if segment == null or segment.element_type != type: - return PackedStringArray() - return segment.element_features - - func _update_level_control_state() -> void: if element_level_option == null: return @@ -895,9 +912,14 @@ func _update_level_control_state() -> void: var code := _dialog_element_code() var derived := _is_derived_level(type, code) element_level_option.disabled = derived + element_level_option.tooltip_text = ( + "Wird aus den Features berechnet" + if derived + else "Manueller Level für Freitext-Codes" + ) if derived: _select_level_option( - _derived_level(type, code, _features_for_pending_type(type)) + _derived_level(type, code, _dialog_features) ) @@ -1011,11 +1033,15 @@ func _on_element_code_option_selected(index: int) -> void: if fixed >= 0: _select_level_option(fixed) _update_level_control_state() + update_element_feature_hint() update_element_value_hint() func _on_element_dialog_type_selected(index: int) -> void: var type: PathSegment.ElementType = element_dialog_type_option.get_item_id(index) + var segment := get_selected_segment() + if segment != null and type != segment.element_type: + _dialog_features = PackedStringArray() var current := _dialog_element_code() _populate_code_options(type) _select_code_in_option( @@ -1023,6 +1049,7 @@ func _on_element_dialog_type_selected(index: int) -> void: "" if type == PathSegment.ElementType.NONE else current ) _update_level_control_state() + update_element_feature_hint() update_element_value_hint() @@ -1065,6 +1092,31 @@ func set_selected_element( code: String, level: int, duration: float = -1.0 +) -> bool: + var segment := get_selected_segment() + var features := ( + segment.element_features if segment != null else PackedStringArray() + ) + if segment != null and type != segment.element_type: + features = PackedStringArray() + return set_selected_element_with_features( + type, + code, + level, + features, + duration + ) + + +## Applies type, code, pending features, derived level and duration in one +## undo step. Used by the element dialog so feature and level changes stay +## together. +func set_selected_element_with_features( + type: PathSegment.ElementType, + code: String, + level: int, + features: PackedStringArray, + duration: float = -1.0 ) -> bool: var segment := get_selected_segment() if segment == null: @@ -1076,19 +1128,18 @@ func set_selected_element( var cleaned := code.strip_edges().left(PathSegment.ELEMENT_CODE_MAX_LENGTH) var clamped := clampi(level, 0, PathSegment.ELEMENT_MAX_LEVEL) + var cleaned_features := _clean_feature_codes(features) if type != PathSegment.ElementType.NONE: var normalized := _normalize_element_input(type, cleaned, clamped) cleaned = str(normalized["code"]) clamped = int(normalized["level"]) if _is_derived_level(type, cleaned): - var features := segment.element_features - if type != segment.element_type: - features = PackedStringArray() - clamped = _derived_level(type, cleaned, features) + clamped = _derived_level(type, cleaned, cleaned_features) var clamped_duration := -1.0 if type == PathSegment.ElementType.NONE: cleaned = "" clamped = 0 + cleaned_features = PackedStringArray() clamped_duration = 0.0 elif duration >= 0.0: clamped_duration = clampf( @@ -1105,12 +1156,14 @@ func set_selected_element( segment.element_type == type and segment.element_code == cleaned and segment.element_level == clamped + and segment.element_features == cleaned_features and segment.element_duration_seconds == clamped_duration ): return false _record_undo() segment.set_element(type, cleaned, clamped) + segment.set_element_features(cleaned_features) segment.set_element_duration(maxf(clamped_duration, 0.0)) if type != PathSegment.ElementType.NONE: # Keep the placement defaults on the last real element type. @@ -1121,6 +1174,7 @@ func set_selected_element( _sync_toolbar_to_selection() _update_status() update_element_feature_hint() + update_element_value_hint() return true @@ -1215,6 +1269,7 @@ func _setup_element_controls() -> void: func _on_element_code_text_changed(_text: String) -> void: _update_level_control_state() + update_element_feature_hint() update_element_value_hint() @@ -1245,6 +1300,7 @@ func _open_element_dialog() -> void: if type_index < 0: type_index = 0 element_dialog_type_option.select(type_index) + _dialog_features = segment.element_features.duplicate() _populate_code_options(segment.element_type) var level_index := element_level_option.get_item_index(segment.element_level) if level_index < 0: @@ -1277,10 +1333,11 @@ func _on_element_confirmed() -> void: element_dialog_type_option.selected ) var level: int = element_level_option.get_item_id(element_level_option.selected) - set_selected_element( + set_selected_element_with_features( type, _dialog_element_code(), level, + _dialog_features, element_duration_spin.value ) diff --git a/rinkplanner/tests/manual/capture_elements.gd b/rinkplanner/tests/manual/capture_elements.gd index c6c9bbf..8b0b3eb 100644 --- a/rinkplanner/tests/manual/capture_elements.gd +++ b/rinkplanner/tests/manual/capture_elements.gd @@ -91,6 +91,21 @@ func _capture() -> void: controller.element_button.pressed.emit() elif args.size() > 3 and args[3] == "validate": controller.open_validation_dialog() + elif args.size() > 3 and args[3] == "pending": + controller.select_segment(jump.segment_id) + controller.element_button.pressed.emit() + var spin_type_index := controller.element_dialog_type_option.get_item_index( + PathSegment.ElementType.SPIN + ) + controller.element_dialog_type_option.select(spin_type_index) + controller.element_dialog_type_option.item_selected.emit(spin_type_index) + var code_index := controller._find_code_option_index("CCoSp") + controller.element_code_option.select(code_index) + controller.element_code_option.item_selected.emit(code_index) + controller._populate_feature_menu() + controller.element_feature_menu.set_item_checked(0, true) + controller.element_feature_menu.set_item_checked(6, true) + controller._on_feature_menu_hidden() elif args.size() > 3 and args[3] == "free": controller.select_segment(free_marker.segment_id) controller.element_button.pressed.emit() diff --git a/rinkplanner/tests/run_whiteboard_tests.gd b/rinkplanner/tests/run_whiteboard_tests.gd index 0d679da..9ed26d8 100644 --- a/rinkplanner/tests/run_whiteboard_tests.gd +++ b/rinkplanner/tests/run_whiteboard_tests.gd @@ -839,8 +839,17 @@ func _run() -> void: controller.element_value_label.text.contains("nicht im Katalog"), "unknown codes are marked as not in the catalog" ) + _check( + controller.element_features_button.disabled, + "feature button is disabled for an unknown code" + ) # Level features and the derived level. + _select_dialog_code(controller, "CCoSp") + _check( + not controller.element_features_button.disabled, + "feature button is enabled for a catalog spin" + ) _check( controller.get_selected_element_features().size() == 2, "features are stored on the selected segment" @@ -850,10 +859,6 @@ func _run() -> void: and controller.element_feature_hint.text.contains("Level 2"), "feature hint shows the derived level" ) - _check( - not controller.element_features_button.disabled, - "feature button is enabled for a spin" - ) _check( controller._populate_feature_menu(), "feature menu populates for a spin" @@ -882,33 +887,52 @@ func _run() -> void: ) controller._on_feature_menu_hidden() _check( - controller.get_selected_element_features().size() == 3, - "a second difficult variation can be added" + controller._dialog_features.size() == 3, + "a second difficult variation updates the pending selection" + ) + _check( + controller.element_level_option.get_item_id( + controller.element_level_option.selected + ) == 3, + "the pending level follows the pending features" ) - _check(spin.element_level == 3, "three features derive Level 3") _check( controller.element_feature_hint.text.contains("Features: 3") and controller.element_feature_hint.text.contains("Level 3"), - "feature hint follows the selection and level" + "feature hint follows the pending selection and level" ) - _check(controller.undo(), "feature selection can be undone") - spin = controller.get_active_section().get_segment_by_id(spin.segment_id) - _check(spin != null, "the spin survives undo") - controller.select_segment(spin.segment_id) + + controller.element_duration_spin.value = 6.5 + controller.element_dialog.confirmed.emit() _check( - controller.get_selected_element_features().size() == 2, - "undo restores the previous feature selection" + controller.get_selected_element_caption() == "CCoSp L3", + "element dialog applies features and the derived level" ) - _check(spin.element_level == 2, "undo restores the derived level") - _check(controller.redo(), "feature selection can be redone") - spin = controller.get_active_section().get_segment_by_id(spin.segment_id) - _check(spin != null, "the spin survives redo") - controller.select_segment(spin.segment_id) _check( - controller.get_selected_element_features().size() == 3, - "redo restores the feature selection" + spin.element_features.size() == 3 and spin.element_level == 3, + "features and level are stored together" ) - _check(spin.element_level == 3, "redo restores the derived level") + _check_approx( + controller.get_selected_segment().element_duration_seconds, + 6.5, + "element dialog applies the stand time" + ) + + _check(controller.undo(), "element dialog change can be undone") + spin = controller.get_active_section().get_segment_by_id(spin.segment_id) + _check( + spin != null and spin.element_features.size() == 2 and spin.element_level == 2, + "undo restores features and the derived level" + ) + controller.select_segment(spin.segment_id) + _check(controller.redo(), "element dialog change can be redone") + spin = controller.get_active_section().get_segment_by_id(spin.segment_id) + _check( + spin != null and spin.element_features.size() == 3 and spin.element_level == 3, + "redo restores features and the derived level" + ) + controller.select_segment(spin.segment_id) + _check( controller.set_selected_element_features(PackedStringArray()), "features can be cleared" @@ -918,7 +942,6 @@ func _run() -> void: "clearing removes all features" ) _check(spin.element_level == 0, "clearing features resets the level to Base") - _check( controller.set_selected_element_features( PackedStringArray(["difficult_variation", "difficult_exit"]) @@ -926,18 +949,11 @@ func _run() -> void: "features restore Level 2" ) _check(spin.element_level == 2, "the restored level is Level 2") - _select_dialog_code(controller, "CCoSp") - controller.element_duration_spin.value = 6.5 - controller.element_dialog.confirmed.emit() _check( controller.get_selected_element_caption() == "CCoSp L2", - "element dialog applies the derived level" - ) - _check_approx( - controller.get_selected_segment().element_duration_seconds, - 6.5, - "element dialog applies the stand time" + "the restored caption shows Level 2" ) + controller.element_button.pressed.emit() _check_approx( controller.element_duration_spin.value, @@ -1157,6 +1173,58 @@ func _run() -> void: ) DirAccess.remove_absolute(save_as_path) + # Flow from an empty marker to a derived spin level. + controller.message_dialog.hide() + controller.element_dialog.hide() + var derived_marker := controller.add_element_marker( + Vector2(0.0, 0.0), + PathSegment.ElementType.JUMP, + "", + 0 + ) + _check(derived_marker != null, "an empty marker can be created") + controller.select_segment(derived_marker.segment_id) + controller.element_button.pressed.emit() + var spin_type_index := controller.element_dialog_type_option.get_item_index( + PathSegment.ElementType.SPIN + ) + controller.element_dialog_type_option.select(spin_type_index) + controller.element_dialog_type_option.item_selected.emit(spin_type_index) + _check( + controller.element_features_button.disabled, + "feature button waits for a catalog code" + ) + _select_dialog_code(controller, "CCoSp") + _check( + not controller.element_features_button.disabled, + "selecting a catalog code enables the feature button" + ) + _check( + controller.element_feature_hint.text.contains("Features: 0") + and controller.element_feature_hint.text.contains("Base"), + "a catalog spin without features starts at Base" + ) + _check( + controller._populate_feature_menu(), + "the feature menu opens for the pending spin" + ) + controller.element_feature_menu.set_item_checked(0, true) + controller.element_feature_menu.set_item_checked(6, true) + controller._on_feature_menu_hidden() + _check( + controller.element_level_option.get_item_id( + controller.element_level_option.selected + ) == 2, + "two pending features raise the pending level to Level 2" + ) + controller.element_dialog.confirmed.emit() + controller.element_dialog.hide() + _check( + derived_marker.element_level == 2 + and derived_marker.element_features.size() == 2, + "the confirmed marker stores features and the derived level" + ) + # Validation dialog. controller.new_routine() controller.add_element_marker( @@ -1258,6 +1326,8 @@ func _set_dialog_free_text( controller.element_code_option.select(free_index) controller.element_code_option.item_selected.emit(free_index) controller.element_code_edit.text = code + controller._update_level_control_state() + controller.update_element_feature_hint() controller.update_element_value_hint()