feat: Level automatisch aus Features

- Katalog-Pirouetten und -Sequenzen setzen element_level aus dem
  Feature-Ergebnis
- Spruenge fest Base, ChSq fest Level 1
- Level-Regler bei Katalog-Elementen read-only
- Unbekannte Freitext-Codes behalten den manuellen Level
- Undo umfasst Feature- und Levelaenderung gemeinsam
- Whiteboard-Tests auf 253 Assertions erweitert (912 gesamt)
- Doku und Findings aktualisiert
This commit is contained in:
torsten 2026-10-31 10:42:55 +01:00
parent 9cb880fca0
commit 1f5834752e
7 changed files with 256 additions and 55 deletions

View file

@ -617,29 +617,39 @@ func get_selected_element_features() -> PackedStringArray:
return segment.element_features.duplicate()
## Replaces the feature selection of the selected element. Returns true when
## the model changed. Features are stored as codes; duplicates are kept for
## features that count more than once (e.g. difficult variations).
## Replaces the feature selection of the selected element and, for catalog
## elements, the derived level. Returns true when the model changed.
func set_selected_element_features(features: PackedStringArray) -> bool:
var segment := get_selected_segment()
if segment == null or not segment.is_element():
return false
var cleaned := _clean_feature_codes(features)
if segment.element_features == cleaned:
var derived := _is_derived_level(segment.element_type, segment.element_code)
var new_level := segment.element_level
if derived:
new_level = _derived_level(
segment.element_type,
segment.element_code,
cleaned
)
if segment.element_features == cleaned and segment.element_level == new_level:
return false
_record_undo()
segment.set_element_features(cleaned)
if derived:
segment.element_level = new_level
_mark_dirty()
rink_canvas.refresh()
_update_status()
_update_level_control_state()
update_element_feature_hint()
update_element_value_hint()
return true
## Shows the feature count and the derived level in the element inspector.
## The authored level stays untouched; a mismatch is shown explicitly.
func update_element_feature_hint() -> void:
if element_feature_hint == null or element_features_button == null:
return
@ -831,6 +841,66 @@ func _dialog_element_code() -> String:
return str(metadata).strip_edges() if metadata != null else ""
## True when the level is determined by the rule set instead of the manual
## dropdown: jumps (always Base), fixed elements (ChSq) and catalog spins or
## sequences. Unknown free-text codes keep a manual level.
func _is_derived_level(
type: PathSegment.ElementType,
code: String
) -> bool:
if type == PathSegment.ElementType.JUMP:
return true
if (
type == PathSegment.ElementType.NONE
or _element_catalog == null
or _level_rules == null
):
return false
var definition := _element_catalog.find(code)
if definition == null or definition.element_type != type:
return false
if _level_rules.get_fixed_level(type, code) >= 0:
return true
return not _level_rules.get_features(type).is_empty()
func _derived_level(
type: PathSegment.ElementType,
code: String,
features: PackedStringArray
) -> int:
if type == PathSegment.ElementType.JUMP:
return 0
if _level_rules == null:
return 0
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
var type_index := element_dialog_type_option.selected
var type: PathSegment.ElementType = PathSegment.ElementType.NONE
if type_index >= 0:
type = element_dialog_type_option.get_item_id(type_index)
var code := _dialog_element_code()
var derived := _is_derived_level(type, code)
element_level_option.disabled = derived
if derived:
_select_level_option(
_derived_level(type, code, _features_for_pending_type(type))
)
## Fills the catalog dropdown for one element type. The free-text entry stays
## available for combinations and variants that the catalog does not model.
func _populate_code_options(type: PathSegment.ElementType) -> void:
@ -940,6 +1010,7 @@ func _on_element_code_option_selected(index: int) -> void:
var fixed := _level_rules.get_fixed_level(type, family)
if fixed >= 0:
_select_level_option(fixed)
_update_level_control_state()
update_element_value_hint()
@ -951,6 +1022,7 @@ func _on_element_dialog_type_selected(index: int) -> void:
type,
"" if type == PathSegment.ElementType.NONE else current
)
_update_level_control_state()
update_element_value_hint()
@ -1008,6 +1080,11 @@ func set_selected_element(
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)
var clamped_duration := -1.0
if type == PathSegment.ElementType.NONE:
cleaned = ""
@ -1078,6 +1155,12 @@ func add_element_marker(
str(normalized["code"]),
int(normalized["level"])
)
if _is_derived_level(type, segment.element_code):
segment.element_level = _derived_level(
type,
segment.element_code,
segment.element_features
)
segment.set_element_duration(
float(ELEMENT_DEFAULT_DURATIONS.get(type, 0.0))
if duration < 0.0
@ -1131,6 +1214,7 @@ func _setup_element_controls() -> void:
func _on_element_code_text_changed(_text: String) -> void:
_update_level_control_state()
update_element_value_hint()
@ -1167,6 +1251,7 @@ func _open_element_dialog() -> void:
level_index = 0
element_level_option.select(level_index)
_select_code_in_option(segment.element_type, segment.element_code)
_update_level_control_state()
var is_marker := segment.is_element_marker()
element_duration_spin.set_value_no_signal(segment.element_duration_seconds)

View file

@ -720,12 +720,12 @@ func _run() -> void:
"element code and level can be edited"
)
_check(
spin.element_code == "CCoSp" and spin.element_level == 4,
"a canonical level suffix is moved into the level field"
spin.element_code == "CCoSp" and spin.element_level == 0,
"a canonical suffix is normalized; without features the level is Base"
)
_check(
spin.get_element_caption() == "CCoSp L4",
"marker caption includes code and level"
spin.get_element_caption() == "CCoSp",
"marker caption omits the derived Base level"
)
_check_approx(
spin.element_duration_seconds,
@ -745,9 +745,28 @@ func _run() -> void:
_check(controller.redo(), "element edit can be redone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(
spin != null and spin.get_element_caption() == "CCoSp L4",
spin != null and spin.element_code == "CCoSp",
"redo restores the element data"
)
controller.select_segment(spin.segment_id)
_check(
controller.set_selected_element_features(
PackedStringArray(
[
"difficult_variation",
"difficult_variation",
"difficult_exit",
"change_of_edge",
]
)
),
"features derive the level"
)
_check(spin.element_level == 4, "four features derive Level 4")
_check(
spin.get_element_caption() == "CCoSp L4",
"marker caption includes the derived level"
)
# Element inspector dialog.
controller.select_segment(spin.segment_id)
@ -775,6 +794,10 @@ func _run() -> void:
) == 4,
"element dialog is prefilled with the normalized level"
)
_check(
controller.element_level_option.disabled,
"the level is read-only for a catalog spin"
)
var catalog := controller.get_element_catalog()
_check(catalog != null and catalog.season == "2025/26", "controller loads the ISU catalog")
_check(
@ -783,13 +806,22 @@ func _run() -> void:
)
_select_dialog_code(controller, "CCoSp")
controller.element_level_option.select(
controller.element_level_option.get_item_index(2)
_check(
controller.set_selected_element_features(
PackedStringArray(["difficult_variation", "difficult_exit"])
),
"features update the derived level"
)
_check(
controller.element_level_option.get_item_id(
controller.element_level_option.selected
) == 2,
"the level dropdown follows two features"
)
controller.update_element_value_hint()
_check(
controller.element_value_label.text.contains("2,50"),
"base value follows a family code and level 2"
"base value follows the derived level 2"
)
_set_dialog_free_text(controller, "CCoSp4")
@ -799,7 +831,7 @@ func _run() -> void:
)
_check(
controller.element_value_label.text.contains("3,50"),
"a canonical suffix wins over the level control"
"a canonical suffix wins over the derived level"
)
_set_dialog_free_text(controller, "3X")
@ -809,21 +841,14 @@ func _run() -> void:
)
# Level features and the derived level.
_check(
controller.set_selected_element_features(
PackedStringArray(["difficult_variation", "difficult_exit"])
),
"features can be assigned to an element"
)
_check(
controller.get_selected_element_features().size() == 2,
"features are stored on the selected segment"
)
_check(
controller.element_feature_hint.text.contains("Features: 2")
and controller.element_feature_hint.text.contains("Level 2")
and controller.element_feature_hint.text.contains("gewählt: Level 4"),
"feature hint shows the derived level and the mismatch"
and controller.element_feature_hint.text.contains("Level 2"),
"feature hint shows the derived level"
)
_check(
not controller.element_features_button.disabled,
@ -860,9 +885,11 @@ func _run() -> void:
controller.get_selected_element_features().size() == 3,
"a second difficult variation can be added"
)
_check(spin.element_level == 3, "three features derive Level 3")
_check(
controller.element_feature_hint.text.contains("Features: 3"),
"feature hint follows the selection"
controller.element_feature_hint.text.contains("Features: 3")
and controller.element_feature_hint.text.contains("Level 3"),
"feature hint follows the selection and level"
)
_check(controller.undo(), "feature selection can be undone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
@ -872,6 +899,7 @@ func _run() -> void:
controller.get_selected_element_features().size() == 2,
"undo restores the previous feature selection"
)
_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")
@ -880,6 +908,7 @@ func _run() -> void:
controller.get_selected_element_features().size() == 3,
"redo restores the feature selection"
)
_check(spin.element_level == 3, "redo restores the derived level")
_check(
controller.set_selected_element_features(PackedStringArray()),
"features can be cleared"
@ -888,16 +917,21 @@ func _run() -> void:
controller.get_selected_element_features().is_empty(),
"clearing removes all features"
)
_check(spin.element_level == 0, "clearing features resets the level to Base")
_select_dialog_code(controller, "CCoSp")
controller.element_level_option.select(
controller.element_level_option.get_item_index(2)
_check(
controller.set_selected_element_features(
PackedStringArray(["difficult_variation", "difficult_exit"])
),
"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 code and level"
"element dialog applies the derived level"
)
_check_approx(
controller.get_selected_segment().element_duration_seconds,
@ -977,9 +1011,15 @@ func _run() -> void:
),
"a drawn segment can carry a sequence element"
)
_check(
controller.set_selected_element_features(
PackedStringArray(["variety_of_turns", "both_rotations"])
),
"a sequence range can carry level features"
)
_check(
controller.get_selected_element_caption() == "StSq L2",
"sequence range caption combines code and level"
"sequence range caption combines code and derived level"
)
_check(
controller.set_selected_element(PathSegment.ElementType.NONE, "", 0),