feat: Regelwerk als Saisonordner mit Invariantenprüfung
Das ISU-Regelwerk liegt jetzt je Saison in einem eigenen Ordner mit Manifest. Der Code fragt nach Dokumentarten (sov, levels, adult) statt nach Dateinamen; eine neue Saison braucht kein GDScript. - Manifest je Saison mit Quellen, valid_from und deklarativen Policies. Fehlt eine Policy, gilt sie in dieser Saison nicht – alte Saisons erben keine später erfundenen Regeln. - RulesLibrary findet die Saisons per Verzeichnis-Scan, löst Vererbung für zeitversetzt erscheinende Papiere auf und wählt als Voreinstellung die neueste vollständige Saison ab valid_from. - RulesAudit prüft den Invariantenkatalog A–F (Sprungreihenfolge, Level- Schwellen, Adult-Grenzen, Policies) und läuft über tools/check_rules.sh sowie in ./tools/test.sh. - Saison an der Kür (Schema 7): alte Küren werden gegen das Regelwerk ihrer eigenen Saison geprüft. Die Statusleiste zeigt und wechselt die Saison; ohne Zuordnung prüft die App nichts, statt still gegen die falsche Saison zu rechnen. - Validator läuft pro Regelpaket; ein Saison-Paar-Test sichert die dokumentierte Differenz zwischen 2025/26 und 2026/27 ab. - PDF-Kopf nennt die Saison, docs/manual.md erklärt die Zuordnung, docs/isu-rules-structure.md beschreibt Struktur und Migrationsplan. 2025/26 hat noch keine Adult-Regeln; das Manifest markiert das Dokument als missing, die Prüfung meldet die Kategorie als nicht anwendbar.
This commit is contained in:
parent
e31e78d464
commit
386105aa71
40 changed files with 2716 additions and 77 deletions
|
|
@ -750,3 +750,14 @@
|
|||
"ⓘ Annahmen ändern","ⓘ Annahmen ändern","ⓘ Change assumptions"
|
||||
"ⓘ Details ausblenden","ⓘ Details ausblenden","ⓘ Hide details"
|
||||
"ⓘ Was ist enthalten?","ⓘ Was ist enthalten?","ⓘ What is included?"
|
||||
"Saison %s","Saison %s","Season %s"
|
||||
"Saison nicht festgelegt","Saison nicht festgelegt","Season not assigned"
|
||||
"(unvollständig)","(unvollständig)","(incomplete)"
|
||||
"Saison %s (unbekannt)","Saison %s (unbekannt)","Season %s (unknown)"
|
||||
"Regelwerk, gegen das diese Kür geprüft wird","Regelwerk, gegen das diese Kür geprüft wird","Rulebook this programme is checked against"
|
||||
"Ohne Saison kann die Kür nicht geprüft werden","Ohne Saison kann die Kür nicht geprüft werden","Without a season the programme cannot be checked"
|
||||
"Vermutlich Saison %s (Dateidatum).","Vermutlich Saison %s (Dateidatum).","Probably season %s (file date)."
|
||||
"Kategorie „%s“ nicht verfügbar","Kategorie „%s“ nicht verfügbar","Category “%s” not available"
|
||||
"Saison nicht festgelegt: In der Statusleiste wählen, sonst prüft die App nichts.","Saison nicht festgelegt: In der Statusleiste wählen, sonst prüft die App nichts.","Season not assigned: pick one in the status bar, otherwise nothing is checked."
|
||||
"Saison „%s“ kennt diese App-Version nicht. Bitte die App aktualisieren.","Saison „%s“ kennt diese App-Version nicht. Bitte die App aktualisieren.","This app version does not know season “%s”. Please update the app."
|
||||
"nicht festgelegt","nicht festgelegt","not assigned"
|
||||
|
|
|
|||
|
|
|
@ -778,6 +778,12 @@ theme_override_font_sizes/font_size = 18
|
|||
text = "?"
|
||||
tooltip_text = "Hilfe und Annahmen"
|
||||
|
||||
[node name="SeasonOption" type="OptionButton" parent="Layout/StatusBar/StatusBarContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(190, 48)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="AdultCategoryOption" type="OptionButton" parent="Layout/StatusBar/StatusBarContent"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(170, 48)
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ static func decode_json(text: String) -> Dictionary:
|
|||
routine.adult_category = (
|
||||
_text(data, "adult_category", "").left(MAX_TEXT_LENGTH)
|
||||
)
|
||||
routine.season = _text(data, "season", "").left(MAX_TEXT_LENGTH)
|
||||
routine.assumed_pcs_average = clampf(
|
||||
_number(data, "assumed_pcs_average", 5.0),
|
||||
0.0,
|
||||
|
|
@ -282,6 +283,7 @@ static func encode(routine: Routine) -> String:
|
|||
"saved_at": routine.saved_at,
|
||||
"music_file": safe_music_file_name(routine.music_file),
|
||||
"adult_category": routine.adult_category,
|
||||
"season": routine.season,
|
||||
"assumed_pcs_average": routine.assumed_pcs_average,
|
||||
"assumed_falls": routine.assumed_falls,
|
||||
"timeline_labels": _encode_timeline_labels(routine.timeline_labels),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ extends Resource
|
|||
## Root aggregate of a choreography. Pure data: no rendering, no input, no
|
||||
## timing state. The whiteboard view and the future 3D layer both consume it.
|
||||
|
||||
const CURRENT_SCHEMA_VERSION := 6
|
||||
const CURRENT_SCHEMA_VERSION := 7
|
||||
|
||||
@export var schema_version: int = CURRENT_SCHEMA_VERSION
|
||||
@export var routine_id: String = ""
|
||||
|
|
@ -22,6 +22,11 @@ const CURRENT_SCHEMA_VERSION := 6
|
|||
## Adult competition category code (e.g. "gold", "silver", "bronze"). Empty
|
||||
## means no category-specific validation.
|
||||
@export var adult_category: String = ""
|
||||
## Season whose rule package this routine is checked against ("2026/27").
|
||||
## Empty means the season was never assigned; the app then cannot validate the
|
||||
## elements and says so instead of guessing. The season is part of the file
|
||||
## because an old routine must keep the rules it was skated under.
|
||||
@export var season: String = ""
|
||||
## Rough scoring assumptions for the estimate: average PCS per component
|
||||
## (0-10) and number of falls.
|
||||
@export var assumed_pcs_average: float = 5.0
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ extends RefCounted
|
|||
## level caps, required elements and scoring factors. Combination and
|
||||
## repetition details are stored but validated only in later stages.
|
||||
|
||||
const DEFAULT_PATH := "res://src/core/rules/data/isu_adult_2026_27.json"
|
||||
const SUPPORTED_SCHEMA_VERSION := 1
|
||||
const ROTATION_NAMES := ["", "single", "double", "triple", "quad"]
|
||||
|
||||
|
|
@ -98,9 +97,6 @@ var _by_code: Dictionary[String, Category] = {}
|
|||
var _errors: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
static func load_default() -> AdultCategoryRules:
|
||||
return load_from(DEFAULT_PATH)
|
||||
|
||||
|
||||
static func load_from(path: String) -> AdultCategoryRules:
|
||||
var rules := AdultCategoryRules.new()
|
||||
|
|
|
|||
27
rinkplanner/src/core/rules/data/2025-26/manifest.json
Normal file
27
rinkplanner/src/core/rules/data/2025-26/manifest.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"schema_version": 1,
|
||||
"season": "2025/26",
|
||||
"label": "Saison 2025/26",
|
||||
"valid_from": "2025-07-01",
|
||||
"status": "complete",
|
||||
"replaces": null,
|
||||
"documents": {
|
||||
"sov": {
|
||||
"file": "sov.json",
|
||||
"source": "ISU Communication No. 2707, Scale of Values valid as of July 1, 2025",
|
||||
"valid_from": "2025-07-01"
|
||||
},
|
||||
"levels": {
|
||||
"file": "levels.json",
|
||||
"source": "ISU Communication No. 2701, Levels of Difficulty and Guidelines for marking Grade of Execution and Program Components, Season 2025/26",
|
||||
"valid_from": "2025-07-01"
|
||||
},
|
||||
"adult": {
|
||||
"status": "missing",
|
||||
"reason": "Adult-Announcement 2025/26 nicht erfasst"
|
||||
}
|
||||
},
|
||||
"policies": {
|
||||
"axel_required_in_sequence": true
|
||||
}
|
||||
}
|
||||
38
rinkplanner/src/core/rules/data/2025-26/notes.md
Normal file
38
rinkplanner/src/core/rules/data/2025-26/notes.md
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Saison 2025/26 – Notizen zur Pflege
|
||||
|
||||
Stand: 2026-11-13
|
||||
|
||||
## Quellen
|
||||
|
||||
| Dokument | Communication | gültig ab |
|
||||
| :--- | :--- | :--- |
|
||||
| `sov.json` | ISU 2707 (Scale of Values) | 2025-07-01 |
|
||||
| `levels.json` | ISU 2701 (Levels of Difficulty) | 2025-07-01 |
|
||||
| `adult.json` | — **fehlt** — | — |
|
||||
|
||||
## Bekannte Lücken
|
||||
|
||||
- **Adult-Regeln fehlen.** Das IAFSC Technical Announcement 2025/26 ist nicht
|
||||
erfasst. Der Eintrag im Manifest steht auf `status: missing`; die App meldet
|
||||
die Kategorieprüfung deshalb als nicht anwendbar. Sobald das Announcement
|
||||
vorliegt, wird `adult.json` ergänzt und der Manifest-Eintrag auf `file`
|
||||
umgestellt.
|
||||
- Die Saison steht trotzdem auf `status: complete`: vollständig heißt, dass
|
||||
Katalog und Level-Regeln ohne Vererbung vorliegen. Fehlende Einzeldokumente
|
||||
werden am Dokument gemeldet, nicht durch einen halben Saisonstatus.
|
||||
- GOE-Tabellen und `V`-Varianten sind wie in allen Saisons bewusst offen.
|
||||
|
||||
## Nachgetragene Policies
|
||||
|
||||
Die Policies wurden beim Umzug auf die Saisonordner-Struktur aus dem damals
|
||||
gültigen Code übernommen, nicht neu aus der Quelle gelesen:
|
||||
|
||||
- `axel_required_in_sequence: true` – der Validator erzwang die Axel-Pflicht in
|
||||
Sprungfolgen bereits vor der Saisonordner-Struktur. Gegen Communication 2701
|
||||
ist das noch nicht gegengeprüft; bis dahin bleibt das bisherige Verhalten
|
||||
erhalten, damit sich Prüfergebnisse nicht rückwirkend ändern.
|
||||
|
||||
## Codes
|
||||
|
||||
`element_code` und die Feature-Codes werden in Kürdateien gespeichert. Sie
|
||||
werden **nie** umbenannt; geändert werden nur `name` und `description`.
|
||||
28
rinkplanner/src/core/rules/data/2026-27/manifest.json
Normal file
28
rinkplanner/src/core/rules/data/2026-27/manifest.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"schema_version": 1,
|
||||
"season": "2026/27",
|
||||
"label": "Saison 2026/27",
|
||||
"valid_from": "2026-07-01",
|
||||
"status": "complete",
|
||||
"replaces": "2025/26",
|
||||
"documents": {
|
||||
"sov": {
|
||||
"file": "sov.json",
|
||||
"source": "ISU Communication No. 2786, Scale of Values and Program Components Factors valid as of July 1, 2026",
|
||||
"valid_from": "2026-07-01"
|
||||
},
|
||||
"levels": {
|
||||
"file": "levels.json",
|
||||
"source": "ISU Communication No. 2788, Levels of Difficulty and Guidelines for marking Grade of Execution and Program Components, Season 2026/27",
|
||||
"valid_from": "2026-06-01"
|
||||
},
|
||||
"adult": {
|
||||
"file": "adult.json",
|
||||
"source": "ISU International Adult Figure Skating Competitions 2026/27 – Technical Announcement",
|
||||
"valid_from": "2026-07-01"
|
||||
}
|
||||
},
|
||||
"policies": {
|
||||
"axel_required_in_sequence": true
|
||||
}
|
||||
}
|
||||
42
rinkplanner/src/core/rules/data/2026-27/notes.md
Normal file
42
rinkplanner/src/core/rules/data/2026-27/notes.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Saison 2026/27 – Notizen zur Pflege
|
||||
|
||||
Stand: 2026-11-13
|
||||
|
||||
## Quellen
|
||||
|
||||
| Dokument | Communication | gültig ab |
|
||||
| :--- | :--- | :--- |
|
||||
| `sov.json` | ISU 2786 (Scale of Values) | 2026-07-01 |
|
||||
| `levels.json` | ISU 2788 (Levels of Difficulty) | 2026-06-01 |
|
||||
| `adult.json` | IAFSC Technical Announcement 2026/27 | 2026-07-01 |
|
||||
|
||||
Die drei Papiere erscheinen zu verschiedenen Terminen. Das ist zulässig; die
|
||||
Prüfung A8 verlangt nur, dass alle im selben Saisonfenster liegen.
|
||||
|
||||
## Änderungen gegenüber 2025/26
|
||||
|
||||
- Katalog auf ISU 2786 umgestellt (vorher 2707).
|
||||
- Level-Regeln auf ISU 2788 (vorher 2701).
|
||||
- `ChSp1` als festes Level 1 ergänzt.
|
||||
- Adult-Kategorien neu erfasst: Bronze, Silver, Gold, Masters, Masters Elite.
|
||||
|
||||
## Policies
|
||||
|
||||
- `axel_required_in_sequence: true` – Axel als zweiter oder dritter Sprung
|
||||
einer Sprungfolge. Wurde aus dem bisher fest verdrahteten Validator
|
||||
übernommen; das Verhalten der App ändert sich dadurch nicht.
|
||||
- `max_features_per_foot` und `feature_position_rules` sind noch nicht
|
||||
deklariert; die Regeln gelten in dieser Saison also nicht (F1).
|
||||
|
||||
## Bekannte Lücken
|
||||
|
||||
- GOE-Tabellen, `V`-Varianten, Unterrotations-/Fehlkanten-Suffixe und
|
||||
Paarlauf-/Eistanz-Elemente sind bewusst nicht erfasst.
|
||||
- `forbidden_jumps` in den Adult-Kategorien meint Element-Codes, nicht
|
||||
Rotationen: In Gold steht `2A` in der Liste, obwohl `allow_axel: true` gilt.
|
||||
Verboten ist der gesprungene 2A, nicht der Axel an sich.
|
||||
|
||||
## Codes
|
||||
|
||||
`element_code` und die Feature-Codes werden in Kürdateien gespeichert. Sie
|
||||
werden **nie** umbenannt; geändert werden nur `name` und `description`.
|
||||
|
|
@ -9,7 +9,6 @@ extends RefCounted
|
|||
## a level suffix ("CCoSp4", "StSqB"). Jump levels are ignored because jumps
|
||||
## have a single base value.
|
||||
|
||||
const DEFAULT_PATH := "res://src/core/rules/data/isu_sov_2026_27.json"
|
||||
const SUPPORTED_SCHEMA_VERSION := 1
|
||||
|
||||
const TYPE_BY_NAME := {
|
||||
|
|
@ -29,9 +28,6 @@ var _by_key: Dictionary[String, ElementDefinition] = {}
|
|||
var _errors: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
static func load_default() -> ElementCatalog:
|
||||
return load_from(DEFAULT_PATH)
|
||||
|
||||
|
||||
static func load_from(path: String) -> ElementCatalog:
|
||||
var catalog := ElementCatalog.new()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ extends RefCounted
|
|||
## only once per program, maximum features per foot) are stored in the data but
|
||||
## not enforced here yet.
|
||||
|
||||
const DEFAULT_PATH := "res://src/core/rules/data/isu_levels_2026_27.json"
|
||||
const SUPPORTED_SCHEMA_VERSION := 1
|
||||
const MAX_LEVEL := PathSegment.ELEMENT_MAX_LEVEL
|
||||
|
||||
|
|
@ -50,9 +49,6 @@ var _fixed_levels: Dictionary[String, int] = {}
|
|||
var _errors: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
static func load_default() -> ElementLevelRules:
|
||||
return load_from(DEFAULT_PATH)
|
||||
|
||||
|
||||
static func load_from(path: String) -> ElementLevelRules:
|
||||
var rules := ElementLevelRules.new()
|
||||
|
|
@ -101,6 +97,14 @@ func get_fixed_level(type: PathSegment.ElementType, code: String) -> int:
|
|||
return _fixed_levels[key]
|
||||
|
||||
|
||||
## All codes that carry a fixed level, in data order.
|
||||
func get_fixed_level_codes() -> PackedStringArray:
|
||||
var codes := PackedStringArray()
|
||||
for code: String in _fixed_levels:
|
||||
codes.append(code)
|
||||
return codes
|
||||
|
||||
|
||||
func get_thresholds() -> Array[Dictionary]:
|
||||
var copy: Array[Dictionary] = []
|
||||
copy.assign(_thresholds)
|
||||
|
|
|
|||
861
rinkplanner/src/core/rules/rules_audit.gd
Normal file
861
rinkplanner/src/core/rules/rules_audit.gd
Normal file
|
|
@ -0,0 +1,861 @@
|
|||
class_name RulesAudit
|
||||
extends RefCounted
|
||||
|
||||
## Checks the rule packages against the invariant catalog in
|
||||
## `docs/isu-rules-structure.md` (groups A-F).
|
||||
##
|
||||
## The audit is pure data checking: it never changes a file and never loads the
|
||||
## whiteboard. `tools/check_rules.sh` runs it headless, and
|
||||
## `tests/run_rules_audit_tests.gd` exercises the checks themselves.
|
||||
|
||||
const SEVERITY_ERROR := 0
|
||||
const SEVERITY_WARNING := 1
|
||||
|
||||
const JUMP_ORDER := ["T", "S", "Lo", "F", "Lz", "A"]
|
||||
const MAX_BASE_VALUE := 15.0
|
||||
const MIN_BASE_VALUE := 0.3
|
||||
## Documents of one season may cite different valid_from dates (the ISU papers
|
||||
## are published at different times), but they must share one season window.
|
||||
const MAX_DOCUMENT_SPREAD_DAYS := 120
|
||||
|
||||
const ROTATION_NAMES := ["single", "double", "triple", "quad"]
|
||||
|
||||
|
||||
class Finding extends RefCounted:
|
||||
var severity: int = SEVERITY_ERROR
|
||||
var code: String = ""
|
||||
var season: String = ""
|
||||
var message: String = ""
|
||||
|
||||
func is_error() -> bool:
|
||||
return severity == SEVERITY_ERROR
|
||||
|
||||
func format() -> String:
|
||||
var level := "FEHLER" if is_error() else "WARNUNG"
|
||||
return "%s %s %s: %s" % [level, code, season, message]
|
||||
|
||||
|
||||
class Report extends RefCounted:
|
||||
var findings: Array[Finding] = []
|
||||
var seasons_checked: int = 0
|
||||
|
||||
func error_count() -> int:
|
||||
var count := 0
|
||||
for finding: Finding in findings:
|
||||
if finding.is_error():
|
||||
count += 1
|
||||
return count
|
||||
|
||||
func warning_count() -> int:
|
||||
return findings.size() - error_count()
|
||||
|
||||
func is_ok() -> bool:
|
||||
return error_count() == 0
|
||||
|
||||
func to_lines() -> PackedStringArray:
|
||||
var lines := PackedStringArray()
|
||||
for finding: Finding in findings:
|
||||
lines.append(finding.format())
|
||||
return lines
|
||||
|
||||
|
||||
static func audit(library: RulesLibrary) -> Report:
|
||||
var report := Report.new()
|
||||
for error: String in library.get_errors():
|
||||
_error(report, "", "LOAD", error)
|
||||
|
||||
var seasons := library.get_seasons()
|
||||
report.seasons_checked = seasons.size()
|
||||
if seasons.is_empty():
|
||||
_error(report, "", "LOAD", "keine Saisonordner gefunden")
|
||||
return report
|
||||
|
||||
for season: String in seasons:
|
||||
_audit_manifest(report, library, season)
|
||||
|
||||
for season: String in seasons:
|
||||
var package := library.get_package(season)
|
||||
if package == null:
|
||||
_error(report, season, "LOAD", "Saison lässt sich nicht laden")
|
||||
continue
|
||||
for error: String in package.get_errors():
|
||||
_error(report, season, "LOAD", error)
|
||||
for warning: String in package.get_warnings():
|
||||
_warn(report, season, "LOAD", warning)
|
||||
_audit_catalog(report, season, package)
|
||||
_audit_levels(report, season, package)
|
||||
_audit_adults(report, season, package)
|
||||
_audit_policies(report, season, library, package)
|
||||
_audit_season_diff(report, season, library, package)
|
||||
return report
|
||||
|
||||
|
||||
## Convenience for tooling: scans the default data root and audits it.
|
||||
static func audit_root(root: String = RulesLibrary.DATA_ROOT) -> Report:
|
||||
return audit(RulesLibrary.scan(root))
|
||||
|
||||
|
||||
# --- A. Manifest und Ordner -------------------------------------------------
|
||||
|
||||
static func _audit_manifest(
|
||||
report: Report,
|
||||
library: RulesLibrary,
|
||||
season: String
|
||||
) -> void:
|
||||
var data := library.get_manifest(season)
|
||||
var folder := library.get_folder(season)
|
||||
|
||||
if folder.get_file() != RulesLibrary.season_to_folder(season):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A1",
|
||||
"Ordner '%s' passt nicht zur Saison '%s'"
|
||||
% [folder.get_file(), RulesLibrary.season_to_folder(season)]
|
||||
)
|
||||
|
||||
var schema := int(data.get("schema_version", 0))
|
||||
if schema != RulesPackage.SUPPORTED_MANIFEST_SCHEMA:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A2",
|
||||
"unbekanntes Manifest-Schema %d" % schema
|
||||
)
|
||||
|
||||
var valid_from := str(data.get("valid_from", "")).strip_edges()
|
||||
if not _is_iso_date(valid_from):
|
||||
_error(report, season, "A8", "'valid_from' ist kein Datum")
|
||||
|
||||
for kind: String in RulesPackage.DOCUMENT_KINDS:
|
||||
var entry := _document_entry(data, kind)
|
||||
if entry.is_empty():
|
||||
_error(report, season, "A3", "Dokument '%s' fehlt im Manifest" % kind)
|
||||
continue
|
||||
|
||||
var has_file := entry.has("file")
|
||||
var has_inherit := entry.has("inherit_from")
|
||||
var is_missing := (
|
||||
str(entry.get("status", "")) == RulesPackage.DOCUMENT_STATUS_MISSING
|
||||
)
|
||||
var set_count := int(has_file) + int(has_inherit) + int(is_missing)
|
||||
if set_count != 1:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A4",
|
||||
"Dokument '%s' braucht genau eines von 'file', 'inherit_from' "
|
||||
% kind
|
||||
+ "oder 'status: missing'"
|
||||
)
|
||||
continue
|
||||
|
||||
if has_file:
|
||||
var path := folder.path_join(str(entry["file"]))
|
||||
if not FileAccess.file_exists(path):
|
||||
_error(report, season, "A5", "Datei '%s' fehlt" % path)
|
||||
|
||||
if has_inherit:
|
||||
var base := str(entry["inherit_from"]).strip_edges()
|
||||
if not library.has_season(base):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A9",
|
||||
"Dokument '%s' erbt von unbekannter Saison '%s'"
|
||||
% [kind, base]
|
||||
)
|
||||
elif str(library.get_manifest(base).get("valid_from", "")) >= valid_from:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A9",
|
||||
"Dokument '%s' erbt von '%s', das nicht älter ist"
|
||||
% [kind, base]
|
||||
)
|
||||
|
||||
var document_valid_from := str(entry.get("valid_from", "")).strip_edges()
|
||||
if not document_valid_from.is_empty():
|
||||
if not _is_iso_date(document_valid_from):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A8",
|
||||
"'valid_from' von '%s' ist kein Datum" % kind
|
||||
)
|
||||
elif _is_iso_date(valid_from) and absi(
|
||||
_days_between(valid_from, document_valid_from)
|
||||
) > MAX_DOCUMENT_SPREAD_DAYS:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A8",
|
||||
"'%s' liegt mit %s außerhalb des Saisonfensters"
|
||||
% [kind, document_valid_from]
|
||||
)
|
||||
|
||||
var is_complete := str(data.get("status", "complete")).strip_edges() == "complete"
|
||||
if is_complete:
|
||||
for kind: String in RulesPackage.DOCUMENT_KINDS:
|
||||
var entry := _document_entry(data, kind)
|
||||
if entry.has("inherit_from"):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A6",
|
||||
"vollständige Saison erbt Dokument '%s'" % kind
|
||||
)
|
||||
for kind: String in ["sov", "levels"]:
|
||||
if _document_entry(data, kind).has("status"):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A6",
|
||||
"vollständige Saison ohne Dokument '%s'" % kind
|
||||
)
|
||||
|
||||
var replaces := ""
|
||||
var raw_replaces: Variant = data.get("replaces", "")
|
||||
if raw_replaces != null:
|
||||
replaces = str(raw_replaces).strip_edges()
|
||||
if replaces.is_empty():
|
||||
if not _is_oldest_season(library, season):
|
||||
_error(report, season, "A11", "'replaces' fehlt")
|
||||
elif not library.has_season(replaces):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A11",
|
||||
"'replaces' verweist auf unbekannte Saison '%s'" % replaces
|
||||
)
|
||||
elif str(library.get_manifest(replaces).get("valid_from", "")) >= valid_from:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"A10",
|
||||
"'replaces' ('%s') ist nicht älter als die Saison" % replaces
|
||||
)
|
||||
|
||||
|
||||
# --- B. Katalog -------------------------------------------------------------
|
||||
|
||||
static func _audit_catalog(
|
||||
report: Report,
|
||||
season: String,
|
||||
package: RulesPackage
|
||||
) -> void:
|
||||
var catalog := package.catalog
|
||||
if catalog == null:
|
||||
return
|
||||
|
||||
var thresholds: Array[Dictionary] = []
|
||||
if package.levels != null:
|
||||
thresholds = package.levels.get_thresholds()
|
||||
|
||||
var seen: Dictionary[String, bool] = {}
|
||||
for definition: ElementDefinition in catalog.get_definitions():
|
||||
var code := definition.code
|
||||
if code.strip_edges().is_empty() or code != code.strip_edges():
|
||||
_error(report, season, "B1", "Kürzel '%s' ist leer oder hat Leerraum" % code)
|
||||
if seen.has(code):
|
||||
_error(report, season, "B1", "Kürzel '%s' ist doppelt" % code)
|
||||
seen[code] = true
|
||||
|
||||
var levels: Array[int] = definition.get_levels()
|
||||
var fixed := _fixed_level(package, definition)
|
||||
if definition.element_type == PathSegment.ElementType.JUMP:
|
||||
if not _is_jump_code(code):
|
||||
_error(report, season, "B2", "Sprungkürzel '%s' hat ein unbekanntes Muster" % code)
|
||||
if levels.size() != 1 or not levels.has(0):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B3",
|
||||
"Sprung '%s' muss genau einen Base Value (Level 0) haben" % code
|
||||
)
|
||||
elif fixed >= 0:
|
||||
if levels.size() != 1 or not levels.has(fixed):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B3",
|
||||
"'%s' ist fest auf Level %d, hat aber %s"
|
||||
% [code, fixed, str(levels)]
|
||||
)
|
||||
else:
|
||||
if not levels.has(0) or levels.size() < 2:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B3",
|
||||
"'%s' braucht 'B' und mindestens ein Level" % code
|
||||
)
|
||||
for threshold: Dictionary in thresholds:
|
||||
var level := int(threshold["level"])
|
||||
if not levels.has(level):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B4",
|
||||
"'%s' fehlt der Base Value für Level %d" % [code, level]
|
||||
)
|
||||
_audit_level_ascending(report, season, code, definition)
|
||||
|
||||
for level: int in levels:
|
||||
var value := definition.get_base_value(level)
|
||||
if value < MIN_BASE_VALUE or value > MAX_BASE_VALUE:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B5",
|
||||
"'%s' Level %d liegt mit %.2f außerhalb des Bereichs"
|
||||
% [code, level, value]
|
||||
)
|
||||
elif not is_equal_approx(value * 100.0, roundf(value * 100.0)):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B5",
|
||||
"'%s' Level %d hat mehr als zwei Nachkommastellen" % [code, level]
|
||||
)
|
||||
|
||||
_audit_jump_families(report, season, catalog)
|
||||
_audit_jump_order(report, season, catalog)
|
||||
|
||||
|
||||
static func _audit_level_ascending(
|
||||
report: Report,
|
||||
season: String,
|
||||
code: String,
|
||||
definition: ElementDefinition
|
||||
) -> void:
|
||||
var levels: Array[int] = definition.get_levels()
|
||||
for index: int in range(levels.size() - 1):
|
||||
var lower := definition.get_base_value(levels[index])
|
||||
var higher := definition.get_base_value(levels[index + 1])
|
||||
if higher <= lower:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B9",
|
||||
"'%s': Level %d (%.2f) ist nicht höher als Level %d (%.2f)"
|
||||
% [code, levels[index + 1], higher, levels[index], lower]
|
||||
)
|
||||
|
||||
|
||||
static func _audit_jump_families(
|
||||
report: Report,
|
||||
season: String,
|
||||
catalog: ElementCatalog
|
||||
) -> void:
|
||||
for rotation: int in range(1, 5):
|
||||
for jump_type: String in JUMP_ORDER:
|
||||
var code := "%d%s" % [rotation, jump_type]
|
||||
var definition := catalog.find(code)
|
||||
if definition == null or (
|
||||
definition.element_type != PathSegment.ElementType.JUMP
|
||||
):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"B6",
|
||||
"Sprungfamilie '%s' fehlt (in notes.md begründen)" % code
|
||||
)
|
||||
|
||||
|
||||
static func _audit_jump_order(
|
||||
report: Report,
|
||||
season: String,
|
||||
catalog: ElementCatalog
|
||||
) -> void:
|
||||
for rotation: int in range(1, 5):
|
||||
var previous := -1.0
|
||||
var previous_type := ""
|
||||
for jump_type: String in JUMP_ORDER:
|
||||
var definition := catalog.find("%d%s" % [rotation, jump_type])
|
||||
if definition == null:
|
||||
continue
|
||||
var value := definition.get_base_value(0)
|
||||
if previous >= 0.0 and value < previous:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B7",
|
||||
"%d%s (%.2f) ist weniger wert als %d%s (%.2f)"
|
||||
% [rotation, jump_type, value, rotation, previous_type, previous]
|
||||
)
|
||||
previous = value
|
||||
previous_type = jump_type
|
||||
|
||||
for jump_type: String in JUMP_ORDER:
|
||||
var previous := -1.0
|
||||
var previous_rotation := 0
|
||||
for rotation: int in range(1, 5):
|
||||
var definition := catalog.find("%d%s" % [rotation, jump_type])
|
||||
if definition == null:
|
||||
continue
|
||||
var value := definition.get_base_value(0)
|
||||
if previous >= 0.0 and value <= previous:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"B8",
|
||||
"%d%s (%.2f) ist nicht höher als %d%s (%.2f)"
|
||||
% [rotation, jump_type, value, previous_rotation, jump_type, previous]
|
||||
)
|
||||
previous = value
|
||||
previous_rotation = rotation
|
||||
|
||||
|
||||
# --- C. Level-Regeln --------------------------------------------------------
|
||||
|
||||
static func _audit_levels(
|
||||
report: Report,
|
||||
season: String,
|
||||
package: RulesPackage
|
||||
) -> void:
|
||||
var rules := package.levels
|
||||
var catalog := package.catalog
|
||||
if rules == null or catalog == null:
|
||||
return
|
||||
|
||||
var thresholds := rules.get_thresholds()
|
||||
var last_level := 0
|
||||
var last_min := 0
|
||||
for threshold: Dictionary in thresholds:
|
||||
var level := int(threshold["level"])
|
||||
var min_features := int(threshold["min_features"])
|
||||
if level != last_level + 1:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C6",
|
||||
"Level-Schwellen sind nicht lückenlos (%d nach %d)" % [level, last_level]
|
||||
)
|
||||
if level == 1 and min_features != 1:
|
||||
_error(report, season, "C6", "Level 1 muss bei einem Feature beginnen")
|
||||
if min_features <= last_min:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C6",
|
||||
"Level %d verlangt nicht mehr Features als das Level davor" % level
|
||||
)
|
||||
last_level = level
|
||||
last_min = min_features
|
||||
|
||||
var max_level := last_level
|
||||
var threshold_levels: Array[int] = []
|
||||
for threshold: Dictionary in thresholds:
|
||||
threshold_levels.append(int(threshold["level"]))
|
||||
|
||||
for definition: ElementDefinition in catalog.get_definitions():
|
||||
if definition.element_type == PathSegment.ElementType.JUMP:
|
||||
continue
|
||||
var fixed := _fixed_level(package, definition)
|
||||
var features := rules.get_features(definition.element_type)
|
||||
if fixed >= 0:
|
||||
continue
|
||||
if features.is_empty():
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C2",
|
||||
"'%s' ist levelbar, aber der Elementtyp hat keine Level-Regeln"
|
||||
% definition.code
|
||||
)
|
||||
continue
|
||||
var highest_min := int(thresholds[thresholds.size() - 1]["min_features"]) if (
|
||||
not thresholds.is_empty()
|
||||
) else 0
|
||||
if highest_min > features.size():
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C7",
|
||||
"Level %d verlangt %d Features, '%s' hat nur %d"
|
||||
% [max_level, highest_min, definition.code, features.size()]
|
||||
)
|
||||
|
||||
var element_levels: Array[int] = definition.get_levels()
|
||||
for level: int in element_levels:
|
||||
if level > 0 and not threshold_levels.has(level):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C8",
|
||||
"'%s' hat einen Base Value für Level %d, das es nicht gibt"
|
||||
% [definition.code, level]
|
||||
)
|
||||
|
||||
for code: String in rules.get_fixed_level_codes():
|
||||
if not catalog.has_code(code):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C1",
|
||||
"festes Level für unbekanntes Element '%s'" % code
|
||||
)
|
||||
|
||||
for type: int in [
|
||||
PathSegment.ElementType.SPIN,
|
||||
PathSegment.ElementType.SEQUENCE
|
||||
]:
|
||||
var seen: Dictionary[String, bool] = {}
|
||||
for feature: ElementFeature in rules.get_features(type):
|
||||
var key := feature.code.to_lower()
|
||||
if seen.has(key):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C3",
|
||||
"Feature '%s' ist doppelt" % feature.code
|
||||
)
|
||||
seen[key] = true
|
||||
if feature.description.strip_edges().is_empty():
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"C3",
|
||||
"Feature '%s' hat keine Beschreibung" % feature.code
|
||||
)
|
||||
for required: String in rules.get_required_features(type):
|
||||
if not seen.has(required.to_lower()):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C4",
|
||||
"Pflichtfeature '%s' ist nicht definiert" % required
|
||||
)
|
||||
for level4: String in rules.get_level4_features(type):
|
||||
if not seen.has(level4.to_lower()):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"C5",
|
||||
"Level-4-Feature '%s' ist nicht definiert" % level4
|
||||
)
|
||||
|
||||
|
||||
# --- D. Adult-Kategorien ----------------------------------------------------
|
||||
|
||||
static func _audit_adults(
|
||||
report: Report,
|
||||
season: String,
|
||||
package: RulesPackage
|
||||
) -> void:
|
||||
var rules := package.adult
|
||||
var catalog := package.catalog
|
||||
if rules == null or catalog == null:
|
||||
return
|
||||
|
||||
var max_level := 0
|
||||
for threshold: Dictionary in package.levels.get_thresholds():
|
||||
max_level = maxi(max_level, int(threshold["level"]))
|
||||
|
||||
var seen: Dictionary[String, bool] = {}
|
||||
for category: AdultCategoryRules.Category in rules.get_categories():
|
||||
var key := category.code.to_lower()
|
||||
if seen.has(key):
|
||||
_error(report, season, "D1", "Kategorie '%s' ist doppelt" % category.code)
|
||||
seen[key] = true
|
||||
if category.duration_seconds < 60 or category.duration_seconds > 300:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D1",
|
||||
"Kategorie '%s' hat eine unplausible Dauer" % category.code
|
||||
)
|
||||
|
||||
for jump: String in category.forbidden_jumps:
|
||||
var definition := catalog.find(jump)
|
||||
if definition == null or (
|
||||
definition.element_type != PathSegment.ElementType.JUMP
|
||||
):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D2",
|
||||
"Kategorie '%s' verbietet unbekannten Sprung '%s'"
|
||||
% [category.code, jump]
|
||||
)
|
||||
elif category.allow_axel and jump.to_upper().ends_with("A"):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"D5",
|
||||
"Kategorie '%s' erlaubt den Axel, verbietet aber '%s' – "
|
||||
% [category.code, jump]
|
||||
+ "falls bewusst, in notes.md begründen"
|
||||
)
|
||||
|
||||
for rotation: String in category.allowed_rotations:
|
||||
if not ROTATION_NAMES.has(rotation) and not rotation.is_empty():
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D3",
|
||||
"Kategorie '%s' nennt unbekannte Rotation '%s'"
|
||||
% [category.code, rotation]
|
||||
)
|
||||
|
||||
if category.required_axel and not category.allow_axel:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D4",
|
||||
"Kategorie '%s' verlangt den Axel, erlaubt ihn aber nicht"
|
||||
% category.code
|
||||
)
|
||||
if category.max_spin_level > max_level:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D6",
|
||||
"Kategorie '%s' erlaubt Spin-Level %d, es gibt nur %d"
|
||||
% [category.code, category.max_spin_level, max_level]
|
||||
)
|
||||
if category.max_sequence_level > max_level:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D6",
|
||||
"Kategorie '%s' erlaubt Sequenz-Level %d, es gibt nur %d"
|
||||
% [category.code, category.max_sequence_level, max_level]
|
||||
)
|
||||
if category.required_step_sequences > category.max_step_sequences:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D7",
|
||||
"Kategorie '%s' verlangt mehr Schrittsequenzen als erlaubt"
|
||||
% category.code
|
||||
)
|
||||
if (
|
||||
category.required_choreographic_sequences
|
||||
> category.max_choreographic_sequences
|
||||
):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D7",
|
||||
"Kategorie '%s' verlangt mehr Choreo-Sequenzen als erlaubt"
|
||||
% category.code
|
||||
)
|
||||
if category.max_jump_combinations > 0 and (
|
||||
category.max_jumps_per_combination < 2
|
||||
):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D8",
|
||||
"Kategorie '%s' erlaubt Kombinationen mit weniger als zwei Sprüngen"
|
||||
% category.code
|
||||
)
|
||||
if (
|
||||
category.max_jumps_per_combination > category.max_jump_elements
|
||||
and category.max_jump_elements > 0
|
||||
):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D11",
|
||||
"Kategorie '%s' erlaubt mehr Sprünge pro Kombination als Elemente"
|
||||
% category.code
|
||||
)
|
||||
if category.requires_choreographic_spin and not catalog.has_code("ChSp"):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D9",
|
||||
"Kategorie '%s' verlangt ChSp, das der Katalog nicht kennt"
|
||||
% category.code
|
||||
)
|
||||
if category.pcs_factor <= 0.0 or category.fall_deduction < 0.0:
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"D10",
|
||||
"Kategorie '%s' hat unplausible Faktoren" % category.code
|
||||
)
|
||||
|
||||
|
||||
# --- F. Policies ------------------------------------------------------------
|
||||
|
||||
static func _audit_policies(
|
||||
report: Report,
|
||||
season: String,
|
||||
library: RulesLibrary,
|
||||
package: RulesPackage
|
||||
) -> void:
|
||||
for key: String in package.policies:
|
||||
if not RulesPackage.KNOWN_POLICIES.has(key):
|
||||
_error(
|
||||
report,
|
||||
season,
|
||||
"F2",
|
||||
"unbekannte Policy '%s'" % key
|
||||
)
|
||||
continue
|
||||
var expected := str(RulesPackage.KNOWN_POLICIES[key])
|
||||
var value: Variant = package.policies[key]
|
||||
var actual_type := typeof(value)
|
||||
if expected == "bool" and actual_type != TYPE_BOOL:
|
||||
_error(report, season, "F3", "Policy '%s' muss true/false sein" % key)
|
||||
elif expected == "int" and actual_type != TYPE_INT and not (
|
||||
actual_type == TYPE_FLOAT and is_equal_approx(value, roundf(value))
|
||||
):
|
||||
_error(report, season, "F3", "Policy '%s' muss eine Zahl sein" % key)
|
||||
|
||||
if package.replaces.is_empty() or not library.has_season(package.replaces):
|
||||
return
|
||||
var base := library.get_package(package.replaces)
|
||||
if base == null:
|
||||
return
|
||||
var notes := _read_notes(package)
|
||||
for key: String in _policy_keys(package.policies):
|
||||
if not _policy_keys(base.policies).has(key) and not notes.contains(key):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"F4",
|
||||
"neue Policy '%s' ist nicht in notes.md erwähnt" % key
|
||||
)
|
||||
for key: String in _policy_keys(base.policies):
|
||||
if not _policy_keys(package.policies).has(key) and not notes.contains(key):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"F4",
|
||||
"Policy '%s' gilt nicht mehr, ist aber nicht in notes.md erwähnt"
|
||||
% key
|
||||
)
|
||||
|
||||
|
||||
# --- E. Über Saisons hinweg -------------------------------------------------
|
||||
|
||||
static func _audit_season_diff(
|
||||
report: Report,
|
||||
season: String,
|
||||
library: RulesLibrary,
|
||||
package: RulesPackage
|
||||
) -> void:
|
||||
if package.replaces.is_empty() or not library.has_season(package.replaces):
|
||||
return
|
||||
var base := library.get_package(package.replaces)
|
||||
if base == null or base.catalog == null or package.catalog == null:
|
||||
return
|
||||
var notes := _read_notes(package)
|
||||
|
||||
var current := _catalog_codes(package.catalog)
|
||||
var previous := _catalog_codes(base.catalog)
|
||||
for code: String in previous:
|
||||
if not current.has(code) and not notes.contains(code):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"E1",
|
||||
"'%s' fehlt gegenüber %s, ist aber nicht in notes.md erwähnt"
|
||||
% [code, package.replaces]
|
||||
)
|
||||
for code: String in current:
|
||||
if not previous.has(code) and not notes.contains(code):
|
||||
_warn(
|
||||
report,
|
||||
season,
|
||||
"E2",
|
||||
"'%s' ist neu gegenüber %s, steht aber nicht in notes.md"
|
||||
% [code, package.replaces]
|
||||
)
|
||||
|
||||
|
||||
# --- Helpers ----------------------------------------------------------------
|
||||
|
||||
static func _policy_keys(policies: Dictionary) -> PackedStringArray:
|
||||
var keys := PackedStringArray()
|
||||
for key: String in policies:
|
||||
keys.append(key)
|
||||
return keys
|
||||
|
||||
|
||||
static func _catalog_codes(catalog: ElementCatalog) -> Dictionary[String, bool]:
|
||||
var codes: Dictionary[String, bool] = {}
|
||||
for definition: ElementDefinition in catalog.get_definitions():
|
||||
codes[definition.code] = true
|
||||
return codes
|
||||
|
||||
|
||||
static func _read_notes(package: RulesPackage) -> String:
|
||||
var path := package.get_notes_path()
|
||||
if path.is_empty() or not FileAccess.file_exists(path):
|
||||
return ""
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
return "" if file == null else file.get_as_text()
|
||||
|
||||
|
||||
static func _fixed_level(package: RulesPackage, definition: ElementDefinition) -> int:
|
||||
if package.levels == null:
|
||||
return -1
|
||||
return package.levels.get_fixed_level(definition.element_type, definition.code)
|
||||
|
||||
|
||||
static func _document_entry(data: Dictionary, kind: String) -> Dictionary:
|
||||
var documents: Variant = data.get("documents", {})
|
||||
if typeof(documents) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
var entry: Variant = (documents as Dictionary).get(kind, {})
|
||||
if typeof(entry) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
return entry as Dictionary
|
||||
|
||||
|
||||
static func _is_oldest_season(library: RulesLibrary, season: String) -> bool:
|
||||
var seasons := library.get_seasons()
|
||||
return seasons.is_empty() or seasons[0] == season
|
||||
|
||||
|
||||
static func _is_jump_code(code: String) -> bool:
|
||||
if code.length() < 2:
|
||||
return false
|
||||
var rotation := code.substr(0, 1)
|
||||
if not rotation.is_valid_int() or int(rotation) < 1 or int(rotation) > 4:
|
||||
return false
|
||||
return JUMP_ORDER.has(code.substr(1))
|
||||
|
||||
|
||||
static func _is_iso_date(value: String) -> bool:
|
||||
if value.length() != 10 or value[4] != "-" or value[7] != "-":
|
||||
return false
|
||||
var parts := value.split("-")
|
||||
if parts.size() != 3:
|
||||
return false
|
||||
for part: String in parts:
|
||||
if not part.is_valid_int():
|
||||
return false
|
||||
var month := int(parts[1])
|
||||
var day := int(parts[2])
|
||||
return month >= 1 and month <= 12 and day >= 1 and day <= 31
|
||||
|
||||
|
||||
static func _days_between(from: String, to: String) -> int:
|
||||
var a := Time.get_unix_time_from_datetime_string(from + "T00:00:00")
|
||||
var b := Time.get_unix_time_from_datetime_string(to + "T00:00:00")
|
||||
return int((b - a) / 86400.0)
|
||||
|
||||
|
||||
static func _error(report: Report, season: String, code: String, message: String) -> void:
|
||||
var finding := Finding.new()
|
||||
finding.severity = SEVERITY_ERROR
|
||||
finding.code = code
|
||||
finding.season = season
|
||||
finding.message = message
|
||||
report.findings.append(finding)
|
||||
|
||||
|
||||
static func _warn(report: Report, season: String, code: String, message: String) -> void:
|
||||
var finding := Finding.new()
|
||||
finding.severity = SEVERITY_WARNING
|
||||
finding.code = code
|
||||
finding.season = season
|
||||
finding.message = message
|
||||
report.findings.append(finding)
|
||||
1
rinkplanner/src/core/rules/rules_audit.gd.uid
Normal file
1
rinkplanner/src/core/rules/rules_audit.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cn0hfm2m5ri1j
|
||||
252
rinkplanner/src/core/rules/rules_library.gd
Normal file
252
rinkplanner/src/core/rules/rules_library.gd
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
class_name RulesLibrary
|
||||
extends RefCounted
|
||||
|
||||
## Discovers the season rule packages under res://src/core/rules/data and
|
||||
## loads them on demand.
|
||||
##
|
||||
## A season is identified by its manifest and rendered into a folder name by
|
||||
## replacing "/" with "-" ("2026/27" -> "2026-27"). The library is the only
|
||||
## place that knows file names; everything else asks for a season and receives
|
||||
## a [RulesPackage].
|
||||
|
||||
const DATA_ROOT := "res://src/core/rules/data"
|
||||
const MANIFEST_FILE := "manifest.json"
|
||||
|
||||
var _folders: Dictionary[String, String] = {}
|
||||
var _manifests: Dictionary[String, Dictionary] = {}
|
||||
var _packages: Dictionary[String, RulesPackage] = {}
|
||||
var _errors: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
static func scan(root: String = DATA_ROOT) -> RulesLibrary:
|
||||
var library := RulesLibrary.new()
|
||||
library._scan_root(root)
|
||||
return library
|
||||
|
||||
|
||||
func get_seasons() -> PackedStringArray:
|
||||
var list: Array[String] = []
|
||||
for season: String in _manifests:
|
||||
list.append(season)
|
||||
list.sort_custom(_compare_seasons)
|
||||
var seasons := PackedStringArray()
|
||||
for season: String in list:
|
||||
seasons.append(season)
|
||||
return seasons
|
||||
|
||||
|
||||
func has_season(season: String) -> bool:
|
||||
return _manifests.has(season.strip_edges())
|
||||
|
||||
|
||||
func get_folder(season: String) -> String:
|
||||
return _folders.get(season.strip_edges(), "")
|
||||
|
||||
|
||||
func get_manifest(season: String) -> Dictionary:
|
||||
return _manifests.get(season.strip_edges(), {})
|
||||
|
||||
|
||||
## Returns the cached package, or null for an unknown season.
|
||||
func get_package(season: String) -> RulesPackage:
|
||||
var key := season.strip_edges()
|
||||
if key.is_empty() or not _manifests.has(key):
|
||||
return null
|
||||
return _load_package(key, {})
|
||||
|
||||
|
||||
## The season new routines should use: the newest complete season that has
|
||||
## already started. Partial seasons never activate on their own, so a season
|
||||
## whose papers are still missing cannot silently become the default.
|
||||
func get_default_season(today: String = "") -> String:
|
||||
var reference := today if not today.is_empty() else RulesLibrary.today()
|
||||
var best := ""
|
||||
var best_from := ""
|
||||
for season: String in get_seasons():
|
||||
var data := _manifests[season]
|
||||
if str(data.get("status", "complete")).strip_edges() != "complete":
|
||||
continue
|
||||
var valid_from := str(data.get("valid_from", "")).strip_edges()
|
||||
if valid_from <= reference and valid_from > best_from:
|
||||
best = season
|
||||
best_from = valid_from
|
||||
if not best.is_empty():
|
||||
return best
|
||||
return get_latest_complete_season()
|
||||
|
||||
|
||||
## Newest complete season, regardless of its validity date.
|
||||
func get_latest_complete_season() -> String:
|
||||
var best := ""
|
||||
var best_from := ""
|
||||
for season: String in get_seasons():
|
||||
if str(_manifests[season].get("status", "complete")).strip_edges() != "complete":
|
||||
continue
|
||||
var valid_from := str(_manifests[season].get("valid_from", "")).strip_edges()
|
||||
if valid_from > best_from:
|
||||
best = season
|
||||
best_from = valid_from
|
||||
return best
|
||||
|
||||
|
||||
## Newest season of any status. Used for messages when nothing is complete.
|
||||
func get_latest_season() -> String:
|
||||
var seasons := get_seasons()
|
||||
return "" if seasons.is_empty() else seasons[seasons.size() - 1]
|
||||
|
||||
|
||||
func get_errors() -> PackedStringArray:
|
||||
return _errors.duplicate()
|
||||
|
||||
|
||||
static func today() -> String:
|
||||
return Time.get_date_string_from_system()
|
||||
|
||||
|
||||
## "2026/27" -> "2026-27"
|
||||
static func season_to_folder(season: String) -> String:
|
||||
return season.strip_edges().replace("/", "-")
|
||||
|
||||
|
||||
func _scan_root(root: String) -> void:
|
||||
var dir := DirAccess.open(root)
|
||||
if dir == null:
|
||||
_errors.append("Regelordner '%s' nicht lesbar" % root)
|
||||
return
|
||||
dir.list_dir_begin()
|
||||
var name := dir.get_next()
|
||||
while not name.is_empty():
|
||||
if dir.current_is_dir() and not name.begins_with("."):
|
||||
_read_manifest(root.path_join(name))
|
||||
name = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
|
||||
|
||||
func _read_manifest(folder: String) -> void:
|
||||
var path := folder.path_join(MANIFEST_FILE)
|
||||
if not FileAccess.file_exists(path):
|
||||
_errors.append("'%s' hat kein %s" % [folder, MANIFEST_FILE])
|
||||
return
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
_errors.append("'%s' nicht lesbar" % path)
|
||||
return
|
||||
var json := JSON.new()
|
||||
if json.parse(file.get_as_text()) != OK:
|
||||
_errors.append(
|
||||
"'%s' ist kein gültiges JSON (Zeile %d)"
|
||||
% [path, json.get_error_line()]
|
||||
)
|
||||
return
|
||||
if typeof(json.data) != TYPE_DICTIONARY:
|
||||
_errors.append("'%s' muss ein Objekt sein" % path)
|
||||
return
|
||||
var data := json.data as Dictionary
|
||||
var season := str(data.get("season", "")).strip_edges()
|
||||
if season.is_empty():
|
||||
_errors.append("'%s' hat keine Saison" % path)
|
||||
return
|
||||
if _manifests.has(season):
|
||||
_errors.append("Saison '%s' ist doppelt vorhanden" % season)
|
||||
return
|
||||
_manifests[season] = data
|
||||
_folders[season] = folder
|
||||
|
||||
|
||||
func _load_package(season: String, visiting: Dictionary) -> RulesPackage:
|
||||
if _packages.has(season):
|
||||
return _packages[season]
|
||||
if visiting.has(season):
|
||||
_errors.append("'%s' verweist im Kreis auf sich selbst" % season)
|
||||
return null
|
||||
visiting[season] = true
|
||||
|
||||
var package := RulesPackage.create(_folders[season], _manifests[season])
|
||||
if package.season != season:
|
||||
package.add_error(
|
||||
"Saison im Manifest ('%s') passt nicht zum Verzeichnis ('%s')"
|
||||
% [package.season, season]
|
||||
)
|
||||
|
||||
for kind: String in RulesPackage.DOCUMENT_KINDS:
|
||||
var entry := package.document_entry(kind)
|
||||
if entry.is_empty():
|
||||
package.add_error("Dokument '%s' fehlt im Manifest" % kind)
|
||||
continue
|
||||
if str(entry.get("status", "")) == RulesPackage.DOCUMENT_STATUS_MISSING:
|
||||
package.add_warning(
|
||||
"Dokument '%s' ist für diese Saison nicht erfasst" % kind
|
||||
)
|
||||
continue
|
||||
if entry.has("inherit_from"):
|
||||
var base_season := str(entry["inherit_from"]).strip_edges()
|
||||
var base: RulesPackage = null
|
||||
if _manifests.has(base_season):
|
||||
base = _load_package(base_season, visiting)
|
||||
if base == null:
|
||||
package.add_error(
|
||||
"Dokument '%s' verweist auf unbekannte Saison '%s'"
|
||||
% [kind, base_season]
|
||||
)
|
||||
continue
|
||||
package.inherited_from[kind] = base_season
|
||||
_assign_document(package, kind, base, base_season)
|
||||
continue
|
||||
if not entry.has("file"):
|
||||
package.add_error(
|
||||
"Dokument '%s' hat weder 'file' noch 'inherit_from'" % kind
|
||||
)
|
||||
continue
|
||||
var path := package.folder.path_join(str(entry["file"]))
|
||||
_load_document(package, kind, path)
|
||||
|
||||
visiting.erase(season)
|
||||
_packages[season] = package
|
||||
return package
|
||||
|
||||
|
||||
func _load_document(package: RulesPackage, kind: String, path: String) -> void:
|
||||
if not FileAccess.file_exists(path):
|
||||
package.add_error("Datei '%s' fehlt" % path)
|
||||
return
|
||||
match kind:
|
||||
"sov":
|
||||
var catalog := ElementCatalog.load_from(path)
|
||||
package.catalog = catalog
|
||||
for message: String in catalog.get_errors():
|
||||
package.add_error("sov: %s" % message)
|
||||
"levels":
|
||||
var levels := ElementLevelRules.load_from(path)
|
||||
package.levels = levels
|
||||
for message: String in levels.get_errors():
|
||||
package.add_error("levels: %s" % message)
|
||||
"adult":
|
||||
var adult := AdultCategoryRules.load_from(path)
|
||||
package.adult = adult
|
||||
for message: String in adult.get_errors():
|
||||
package.add_error("adult: %s" % message)
|
||||
|
||||
|
||||
func _assign_document(
|
||||
package: RulesPackage,
|
||||
kind: String,
|
||||
base: RulesPackage,
|
||||
base_season: String
|
||||
) -> void:
|
||||
match kind:
|
||||
"sov":
|
||||
package.catalog = base.catalog
|
||||
"levels":
|
||||
package.levels = base.levels
|
||||
"adult":
|
||||
package.adult = base.adult
|
||||
if not package.has_document(kind):
|
||||
package.add_error(
|
||||
"Dokument '%s' aus '%s' ist dort nicht verfügbar" % [kind, base_season]
|
||||
)
|
||||
|
||||
|
||||
func _compare_seasons(a: String, b: String) -> bool:
|
||||
return str(_manifests[a].get("valid_from", "")) < str(
|
||||
_manifests[b].get("valid_from", "")
|
||||
)
|
||||
1
rinkplanner/src/core/rules/rules_library.gd.uid
Normal file
1
rinkplanner/src/core/rules/rules_library.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ce4wrhktaxu33
|
||||
146
rinkplanner/src/core/rules/rules_package.gd
Normal file
146
rinkplanner/src/core/rules/rules_package.gd
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
class_name RulesPackage
|
||||
extends RefCounted
|
||||
|
||||
## One season's complete rule package.
|
||||
##
|
||||
## A package bundles the three season documents (SoV catalog, level rules,
|
||||
## adult categories) together with the season's policies. There is exactly one
|
||||
## package per season; the folder name is the season with "-" instead of "/".
|
||||
##
|
||||
## Policies are season-scoped checks (e.g. "an Axel is required in a jump
|
||||
## sequence"). A policy that a season does not declare is **inactive** for that
|
||||
## season – there is deliberately no default, so old seasons never inherit
|
||||
## rules that were invented later.
|
||||
|
||||
const SUPPORTED_MANIFEST_SCHEMA := 1
|
||||
const DOCUMENT_KINDS: PackedStringArray = ["sov", "levels", "adult"]
|
||||
const DOCUMENT_STATUS_MISSING := "missing"
|
||||
|
||||
## Policy keys the code knows, with their expected JSON type. Unknown keys in
|
||||
## the data are an error (typo protection).
|
||||
const KNOWN_POLICIES := {
|
||||
"axel_required_in_sequence": "bool",
|
||||
"max_features_per_foot": "int",
|
||||
"feature_position_rules": "bool",
|
||||
}
|
||||
|
||||
var folder: String = ""
|
||||
var manifest: Dictionary = {}
|
||||
var season: String = ""
|
||||
var label: String = ""
|
||||
var valid_from: String = ""
|
||||
var status: String = ""
|
||||
var replaces: String = ""
|
||||
var policies: Dictionary = {}
|
||||
|
||||
var catalog: ElementCatalog
|
||||
var levels: ElementLevelRules
|
||||
var adult: AdultCategoryRules
|
||||
|
||||
## Document kind -> season the document was inherited from.
|
||||
var inherited_from: Dictionary[String, String] = {}
|
||||
|
||||
var _errors: PackedStringArray = PackedStringArray()
|
||||
var _warnings: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
static func create(folder_path: String, data: Dictionary) -> RulesPackage:
|
||||
var package := RulesPackage.new()
|
||||
package.folder = folder_path
|
||||
package.set_manifest(data)
|
||||
return package
|
||||
|
||||
|
||||
## Reads the header fields of a parsed manifest. Document entries are inspected
|
||||
## through [method document_entry]; loading happens in [RulesLibrary].
|
||||
func set_manifest(data: Dictionary) -> void:
|
||||
manifest = data
|
||||
season = str(data.get("season", "")).strip_edges()
|
||||
label = str(data.get("label", "")).strip_edges()
|
||||
valid_from = str(data.get("valid_from", "")).strip_edges()
|
||||
status = str(data.get("status", "complete")).strip_edges()
|
||||
var raw_replaces: Variant = data.get("replaces", "")
|
||||
replaces = "" if raw_replaces == null else str(raw_replaces).strip_edges()
|
||||
var raw_policies: Variant = data.get("policies", {})
|
||||
if typeof(raw_policies) == TYPE_DICTIONARY:
|
||||
policies = (raw_policies as Dictionary).duplicate()
|
||||
else:
|
||||
_errors.append("'policies' muss ein Objekt sein")
|
||||
|
||||
|
||||
func is_complete() -> bool:
|
||||
return status == "complete"
|
||||
|
||||
|
||||
func document_entry(kind: String) -> Dictionary:
|
||||
var documents: Variant = manifest.get("documents", {})
|
||||
if typeof(documents) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
var entry: Variant = (documents as Dictionary).get(kind, {})
|
||||
if typeof(entry) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
return entry as Dictionary
|
||||
|
||||
|
||||
## True when the season actually provides usable data for [param kind].
|
||||
func has_document(kind: String) -> bool:
|
||||
match kind:
|
||||
"sov":
|
||||
return catalog != null
|
||||
"levels":
|
||||
return levels != null
|
||||
"adult":
|
||||
return adult != null
|
||||
return false
|
||||
|
||||
|
||||
func is_document_missing(kind: String) -> bool:
|
||||
var entry := document_entry(kind)
|
||||
return str(entry.get("status", "")) == DOCUMENT_STATUS_MISSING
|
||||
|
||||
|
||||
## Source citation of one document, including the inheritance hint.
|
||||
func get_document_source(kind: String) -> String:
|
||||
var entry := document_entry(kind)
|
||||
var source := str(entry.get("source", "")).strip_edges()
|
||||
if inherited_from.has(kind):
|
||||
var base := inherited_from[kind]
|
||||
if source.is_empty():
|
||||
return I18n.t("übernommen aus Saison %s") % base
|
||||
return "%s (%s)" % [source, I18n.t("übernommen aus Saison %s") % base]
|
||||
return source
|
||||
|
||||
|
||||
func has_policy(key: String) -> bool:
|
||||
return policies.has(key)
|
||||
|
||||
|
||||
## Value of a season policy, or [param fallback] when the season does not
|
||||
## declare it. Callers must pass the "off" value (false / 0) so that a missing
|
||||
## key really disables the rule.
|
||||
func get_policy(key: String, fallback: Variant = false) -> Variant:
|
||||
if not policies.has(key):
|
||||
return fallback
|
||||
return policies[key]
|
||||
|
||||
|
||||
func get_notes_path() -> String:
|
||||
if folder.is_empty():
|
||||
return ""
|
||||
return folder.path_join("notes.md")
|
||||
|
||||
|
||||
func add_error(message: String) -> void:
|
||||
_errors.append(message)
|
||||
|
||||
|
||||
func add_warning(message: String) -> void:
|
||||
_warnings.append(message)
|
||||
|
||||
|
||||
func get_errors() -> PackedStringArray:
|
||||
return _errors.duplicate()
|
||||
|
||||
|
||||
func get_warnings() -> PackedStringArray:
|
||||
return _warnings.duplicate()
|
||||
1
rinkplanner/src/core/rules/rules_package.gd.uid
Normal file
1
rinkplanner/src/core/rules/rules_package.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dyrle72rbtfeb
|
||||
|
|
@ -100,10 +100,7 @@ const EXPORT_SHEET_SCENE := preload("res://scenes/export/export_sheet.tscn")
|
|||
const PRESENTATION_3D_SCENE_PATH := "res://scenes/presentation3d/presentation_3d.tscn"
|
||||
const PLAYBACK_PLAY_ICON := preload("res://assets/icons/playback/play.svg")
|
||||
const PLAYBACK_PAUSE_ICON := preload("res://assets/icons/playback/pause.svg")
|
||||
const ELEMENT_CATALOG_SCRIPT := preload("res://src/core/rules/element_catalog.gd")
|
||||
const ELEMENT_LEVEL_RULES_SCRIPT := preload("res://src/core/rules/element_level_rules.gd")
|
||||
const ROUTINE_VALIDATOR_SCRIPT := preload("res://src/core/rules/routine_validator.gd")
|
||||
const ADULT_CATEGORY_RULES_SCRIPT := preload("res://src/core/rules/adult_category_rules.gd")
|
||||
const FEATURE_MENU_RESET_ID := 1000000
|
||||
const CODE_OPTION_PLACEHOLDER_ID := 0
|
||||
const CODE_OPTION_FREE_ID := 1000000
|
||||
|
|
@ -226,6 +223,7 @@ const UPDATE_FILE_NAMES := {
|
|||
@onready var element_feature_hint: Label = %ElementFeatureHint
|
||||
@onready var element_feature_menu: PopupMenu = %ElementFeatureMenu
|
||||
@onready var validation_button: Button = %ValidationButton
|
||||
@onready var season_option: OptionButton = %SeasonOption
|
||||
@onready var adult_category_option: OptionButton = %AdultCategoryOption
|
||||
@onready var validation_dialog: AcceptDialog = %ValidationDialog
|
||||
@onready var validation_text: RichTextLabel = %ValidationText
|
||||
|
|
@ -333,6 +331,9 @@ var _element_level: int = 0
|
|||
var _element_catalog: ElementCatalog
|
||||
var _level_rules: ElementLevelRules
|
||||
var _adult_rules: AdultCategoryRules
|
||||
var _rules_library: RulesLibrary
|
||||
var _rules_package: RulesPackage
|
||||
var _default_season: String = ""
|
||||
var _dialog_features: PackedStringArray = PackedStringArray()
|
||||
var _dialog_jump_kind: PathSegment.JumpKind = PathSegment.JumpKind.SOLO
|
||||
var _dialog_combination_jumps: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -436,31 +437,15 @@ func _ready() -> void:
|
|||
_apply_sport_theme()
|
||||
_maximize_window_on_desktop.call_deferred()
|
||||
autosave_timer.wait_time = AUTOSAVE_DELAY_SECONDS
|
||||
_element_catalog = ELEMENT_CATALOG_SCRIPT.load_default()
|
||||
if not _element_catalog.get_errors().is_empty():
|
||||
push_warning(
|
||||
"Element catalog: %s" % ", ".join(_element_catalog.get_errors())
|
||||
)
|
||||
_level_rules = ELEMENT_LEVEL_RULES_SCRIPT.load_default()
|
||||
if not _level_rules.get_errors().is_empty():
|
||||
push_warning(
|
||||
"Level rules: %s" % ", ".join(_level_rules.get_errors())
|
||||
)
|
||||
_adult_rules = ADULT_CATEGORY_RULES_SCRIPT.load_default()
|
||||
if not _adult_rules.get_errors().is_empty():
|
||||
push_warning(
|
||||
"Adult categories: %s" % ", ".join(_adult_rules.get_errors())
|
||||
)
|
||||
validation_button.tooltip_text = (
|
||||
"Prüft Kürzel, Elementtyp, Level, Features und Einmal-Regeln (Saison %s)"
|
||||
% _element_catalog.season
|
||||
)
|
||||
_load_default_rules()
|
||||
_refresh_validation_tooltip()
|
||||
_setup_tool_buttons()
|
||||
_setup_file_menu()
|
||||
_setup_hub_controls()
|
||||
_setup_playback_controls()
|
||||
_setup_timing_controls()
|
||||
_setup_element_controls()
|
||||
_setup_season_controls()
|
||||
_setup_adult_category_controls()
|
||||
_setup_export_controls()
|
||||
labels_toggle.set_pressed_no_signal(rink_canvas.labels_visible)
|
||||
|
|
@ -605,6 +590,7 @@ func new_routine() -> void:
|
|||
var routine := Routine.new()
|
||||
routine.routine_id = "draft-routine"
|
||||
routine.title = "Neue Kür"
|
||||
routine.season = _default_season
|
||||
routine.rink = RinkDimensions.new()
|
||||
|
||||
var section := RoutineSection.new()
|
||||
|
|
@ -812,6 +798,58 @@ func get_level_rules() -> ElementLevelRules:
|
|||
return _level_rules
|
||||
|
||||
|
||||
func get_rules_package() -> RulesPackage:
|
||||
return _rules_package
|
||||
|
||||
|
||||
func get_rules_library() -> RulesLibrary:
|
||||
return _rules_library
|
||||
|
||||
|
||||
## Loads the season package new routines start with. Seasons are discovered on
|
||||
## disk; there is no hardcoded file name here.
|
||||
func _load_default_rules() -> void:
|
||||
_rules_library = RulesLibrary.scan()
|
||||
if not _rules_library.get_errors().is_empty():
|
||||
push_warning("Rules: %s" % ", ".join(_rules_library.get_errors()))
|
||||
_default_season = _rules_library.get_default_season()
|
||||
if _default_season.is_empty():
|
||||
push_warning("Rules: keine nutzbare Saison gefunden")
|
||||
_apply_rules_for_season(_default_season)
|
||||
|
||||
|
||||
## Resolves the rule package of one season and points the inspector, the
|
||||
## category list and the validator at it. An empty or unknown season leaves the
|
||||
## rules unset on purpose: the app then says that it cannot check instead of
|
||||
## silently validating against the wrong rulebook.
|
||||
func _apply_rules_for_season(season: String) -> void:
|
||||
_rules_package = null
|
||||
_element_catalog = null
|
||||
_level_rules = null
|
||||
_adult_rules = null
|
||||
if _rules_library == null:
|
||||
return
|
||||
var cleaned := season.strip_edges()
|
||||
if cleaned.is_empty():
|
||||
return
|
||||
_rules_package = _rules_library.get_package(cleaned)
|
||||
if _rules_package == null:
|
||||
return
|
||||
for error: String in _rules_package.get_errors():
|
||||
push_warning("Rules (%s): %s" % [_rules_package.season, error])
|
||||
_element_catalog = _rules_package.catalog
|
||||
_level_rules = _rules_package.levels
|
||||
_adult_rules = _rules_package.adult
|
||||
|
||||
|
||||
func _catalog_season_label() -> String:
|
||||
if _rules_package != null and not _rules_package.season.is_empty():
|
||||
return _rules_package.season
|
||||
if _routine != null and not _routine.season.is_empty():
|
||||
return _routine.season
|
||||
return I18n.t("nicht festgelegt")
|
||||
|
||||
|
||||
## Cross-checks all element segments against the catalog and level rules.
|
||||
## Paths and section bookkeeping are validated by the model itself.
|
||||
func validate_routine() -> Array[ValidationIssue]:
|
||||
|
|
@ -848,9 +886,7 @@ func _render_validation_dialog() -> void:
|
|||
report.issues,
|
||||
ValidationIssue.Severity.WARNING
|
||||
)
|
||||
var season := (
|
||||
_element_catalog.season if _element_catalog != null else "unbekannt"
|
||||
)
|
||||
var season := _catalog_season_label()
|
||||
|
||||
var lines := PackedStringArray()
|
||||
lines.append(
|
||||
|
|
@ -861,6 +897,9 @@ func _render_validation_dialog() -> void:
|
|||
season,
|
||||
]
|
||||
)
|
||||
var season_note := _season_note()
|
||||
if not season_note.is_empty():
|
||||
lines.append("[color=#e0b050]%s[/color]" % season_note)
|
||||
var category: AdultCategoryRules.Category = null
|
||||
if (
|
||||
_routine != null
|
||||
|
|
@ -2589,7 +2628,10 @@ func _setup_adult_category_controls() -> void:
|
|||
var index := adult_category_option.item_count
|
||||
adult_category_option.add_item(category.name, index)
|
||||
adult_category_option.set_item_metadata(index, category.code)
|
||||
adult_category_option.item_selected.connect(_on_adult_category_selected)
|
||||
if not adult_category_option.item_selected.is_connected(
|
||||
_on_adult_category_selected
|
||||
):
|
||||
adult_category_option.item_selected.connect(_on_adult_category_selected)
|
||||
_sync_adult_category_option()
|
||||
|
||||
|
||||
|
|
@ -2632,10 +2674,156 @@ func _sync_adult_category_option() -> void:
|
|||
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
|
||||
)
|
||||
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 the season dropdown. The list comes from the rules library, so a new
|
||||
## season folder appears without touching this code.
|
||||
func _setup_season_controls() -> void:
|
||||
if season_option == null:
|
||||
return
|
||||
if not season_option.item_selected.is_connected(_on_season_selected):
|
||||
season_option.item_selected.connect(_on_season_selected)
|
||||
_sync_season_option()
|
||||
|
||||
|
||||
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 _rules_library != null:
|
||||
for season: String in _rules_library.get_seasons():
|
||||
var index := season_option.item_count
|
||||
var label := I18n.t("Saison %s") % season
|
||||
var status := str(
|
||||
_rules_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
|
||||
)
|
||||
|
||||
|
||||
## 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 _rules_library == null:
|
||||
return ""
|
||||
if not FileAccess.file_exists(_current_path):
|
||||
return ""
|
||||
var unix := FileAccess.get_modified_time(_current_path)
|
||||
if unix <= 0:
|
||||
return ""
|
||||
var date := Time.get_date_string_from_unix_time(unix)
|
||||
return _rules_library.get_default_season(date)
|
||||
|
||||
|
||||
func _on_season_selected(index: int) -> void:
|
||||
set_season(str(season_option.get_item_metadata(index)))
|
||||
|
||||
|
||||
## Assigns the season whose rules the routine is checked against. Empty clears
|
||||
## the assignment; unknown seasons are rejected so a typo cannot mute the
|
||||
## validation.
|
||||
func set_season(season: String) -> bool:
|
||||
if _routine == null:
|
||||
return false
|
||||
var cleaned := season.strip_edges()
|
||||
if _routine.season == cleaned:
|
||||
return false
|
||||
if (
|
||||
not cleaned.is_empty()
|
||||
and (_rules_library == null or not _rules_library.has_season(cleaned))
|
||||
):
|
||||
return false
|
||||
_record_undo()
|
||||
_routine.season = cleaned
|
||||
_apply_rules_for_season(cleaned)
|
||||
_sync_season_option()
|
||||
_setup_adult_category_controls()
|
||||
_mark_dirty()
|
||||
_update_status()
|
||||
_refresh_validation_tooltip()
|
||||
if validation_dialog != null and validation_dialog.visible:
|
||||
_render_validation_dialog()
|
||||
return true
|
||||
|
||||
|
||||
func get_season() -> String:
|
||||
return _routine.season if _routine != null else ""
|
||||
|
||||
|
||||
## One line that explains why the check cannot use a rule package, if that is
|
||||
## the case. Empty when the season resolved normally.
|
||||
func _season_note() -> String:
|
||||
if _rules_package != null:
|
||||
return ""
|
||||
var raw := _routine.season.strip_edges() if _routine != null else ""
|
||||
if raw.is_empty():
|
||||
var inferred := _infer_season_from_current_path()
|
||||
var note := I18n.t(
|
||||
"Saison nicht festgelegt: In der Statusleiste wählen, sonst prüft die App nichts."
|
||||
)
|
||||
if not inferred.is_empty():
|
||||
note += " " + I18n.t("Vermutlich Saison %s (Dateidatum).") % inferred
|
||||
return note
|
||||
return I18n.t(
|
||||
"Saison „%s“ kennt diese App-Version nicht. Bitte die App aktualisieren."
|
||||
) % raw
|
||||
|
||||
|
||||
func _refresh_validation_tooltip() -> void:
|
||||
if validation_button != null:
|
||||
validation_button.tooltip_text = I18n.t(
|
||||
"Prüft Kürzel, Elementtyp, Level, Features und Einmal-Regeln (Saison %s)"
|
||||
) % _catalog_season_label()
|
||||
|
||||
|
||||
func _on_element_code_text_changed(_text: String) -> void:
|
||||
_update_level_control_state()
|
||||
update_element_feature_hint()
|
||||
|
|
@ -3004,6 +3192,7 @@ func _clone_routine(source: Routine) -> Routine:
|
|||
clone.music_file = source.music_file
|
||||
clone.timeline_labels.assign(source.timeline_labels.duplicate(true))
|
||||
clone.adult_category = source.adult_category
|
||||
clone.season = source.season
|
||||
clone.assumed_pcs_average = source.assumed_pcs_average
|
||||
clone.assumed_falls = source.assumed_falls
|
||||
if source.rink != null:
|
||||
|
|
@ -5374,6 +5563,7 @@ func _set_routine(routine: Routine, path: String) -> void:
|
|||
if not path.is_empty():
|
||||
_save_session_path(path)
|
||||
_delete_autosave()
|
||||
_sync_season_option()
|
||||
|
||||
_undo_stack.clear()
|
||||
_redo_stack.clear()
|
||||
|
|
@ -5408,7 +5598,9 @@ func _install_routine(
|
|||
for segment: PathSegment in section.segments:
|
||||
if segment != null:
|
||||
segment.normalize_jump_combination()
|
||||
_sync_adult_category_option()
|
||||
_apply_rules_for_season(_routine.season)
|
||||
_sync_season_option()
|
||||
_setup_adult_category_controls()
|
||||
|
||||
var valid_sections: Array[RoutineSection] = []
|
||||
for section: RoutineSection in _routine.sections:
|
||||
|
|
|
|||
|
|
@ -339,6 +339,9 @@ static func _routine_subtitle(routine: Routine, section_count: int) -> String:
|
|||
var category := routine.adult_category.strip_edges()
|
||||
if not category.is_empty():
|
||||
parts.append("Kategorie: %s" % category.capitalize())
|
||||
var season := routine.season.strip_edges()
|
||||
if not season.is_empty():
|
||||
parts.append(I18n.t("Saison %s") % season)
|
||||
parts.append("%d Abschnitte" % section_count)
|
||||
parts.append(I18n.t("Gesamt %s") % _fmt_clock(routine.get_duration_seconds()))
|
||||
if routine.has_music():
|
||||
|
|
|
|||
25
rinkplanner/tests/check_rules.gd
Normal file
25
rinkplanner/tests/check_rules.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
extends SceneTree
|
||||
|
||||
## Prints the invariant report for all season rule packages.
|
||||
##
|
||||
## Run with:
|
||||
## ./tools/check_rules.sh
|
||||
##
|
||||
## Exit code 0 means "no errors"; warnings are printed but do not fail, because
|
||||
## they are deliberately non-blocking notes (e.g. a missing jump family that
|
||||
## notes.md explains).
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var report := RulesAudit.audit_root()
|
||||
var lines := report.to_lines()
|
||||
for line: String in lines:
|
||||
print(line)
|
||||
|
||||
var errors := report.error_count()
|
||||
var warnings := report.warning_count()
|
||||
print(
|
||||
"%d Saison(s) geprüft: %d Fehler, %d Warnung(en)"
|
||||
% [report.seasons_checked, errors, warnings]
|
||||
)
|
||||
quit(1 if errors > 0 else 0)
|
||||
1
rinkplanner/tests/check_rules.gd.uid
Normal file
1
rinkplanner/tests/check_rules.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://db7n7aoih1v6s
|
||||
|
|
@ -5,13 +5,11 @@ extends SceneTree
|
|||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_adult_tests.gd
|
||||
|
||||
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
|
||||
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
|
||||
const AdultCategoryRulesScript := preload("res://src/core/rules/adult_category_rules.gd")
|
||||
const RoutineValidatorScript := preload("res://src/core/rules/routine_validator.gd")
|
||||
const RoutineModel := preload("res://src/core/model/routine.gd")
|
||||
const RoutineSectionModel := preload("res://src/core/model/routine_section.gd")
|
||||
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
|
||||
const SEASON := "2026/27"
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -22,9 +20,15 @@ var _validator: RoutineValidator
|
|||
|
||||
|
||||
func _init() -> void:
|
||||
_catalog = ElementCatalogScript.load_default()
|
||||
_rules = ElementLevelRulesScript.load_default()
|
||||
_adult = AdultCategoryRulesScript.load_default()
|
||||
var library := RulesLibrary.scan()
|
||||
var package := library.get_package(SEASON)
|
||||
_check(package != null, "Saison %s ist ladbar" % SEASON)
|
||||
if package == null:
|
||||
_finish()
|
||||
return
|
||||
_catalog = package.catalog
|
||||
_rules = package.levels
|
||||
_adult = package.adult
|
||||
_validator = RoutineValidatorScript.new(_catalog, _rules, _adult)
|
||||
|
||||
_test_metadata()
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ func _test_json_roundtrip() -> void:
|
|||
"second timeline label survives"
|
||||
)
|
||||
_check(loaded.adult_category == routine.adult_category, "category survives")
|
||||
_check(loaded.season == routine.season, "season survives")
|
||||
_check_approx(
|
||||
loaded.assumed_pcs_average,
|
||||
routine.assumed_pcs_average,
|
||||
|
|
@ -212,6 +213,21 @@ func _test_json_rejects() -> void:
|
|||
RoutineFile.json_path("user://kuer.tres") == "user://kuer.json",
|
||||
"legacy paths migrate to the JSON extension"
|
||||
)
|
||||
|
||||
# Files written before the season field existed stay loadable and are not
|
||||
# silently assigned to a season.
|
||||
var legacy_data: Dictionary = JSON.parse_string(encoded)
|
||||
legacy_data.erase("season")
|
||||
var without_season := RoutineFile.decode_json(JSON.stringify(legacy_data))
|
||||
_check(
|
||||
str(without_season["error"]).is_empty(),
|
||||
"a file without a season still loads"
|
||||
)
|
||||
var old_routine: Routine = without_season["routine"]
|
||||
_check(
|
||||
old_routine != null and old_routine.season.is_empty(),
|
||||
"a missing season stays unassigned"
|
||||
)
|
||||
_check(
|
||||
RoutineFile.json_path("user://kuer") == "user://kuer.json",
|
||||
"paths without extension get .json"
|
||||
|
|
@ -363,6 +379,7 @@ func _make_routine() -> Routine:
|
|||
{"time_seconds": 1.25, "text": "Dreh"},
|
||||
]
|
||||
routine.adult_category = "gold"
|
||||
routine.season = "2026/27"
|
||||
routine.assumed_pcs_average = 4.75
|
||||
routine.assumed_falls = 1
|
||||
routine.rink = RinkDimensions.new()
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ extends SceneTree
|
|||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_level_tests.gd
|
||||
|
||||
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
|
||||
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
|
||||
const SEASON := "2026/27"
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -14,7 +14,13 @@ var _rules: ElementLevelRules
|
|||
|
||||
|
||||
func _init() -> void:
|
||||
_rules = ElementLevelRulesScript.load_default()
|
||||
var library := RulesLibrary.scan()
|
||||
var package := library.get_package(SEASON)
|
||||
_check(package != null, "Saison %s ist ladbar" % SEASON)
|
||||
if package == null:
|
||||
_finish()
|
||||
return
|
||||
_rules = package.levels
|
||||
|
||||
_test_rules_metadata()
|
||||
_test_spin_levels()
|
||||
|
|
|
|||
296
rinkplanner/tests/run_rules_audit_tests.gd
Normal file
296
rinkplanner/tests/run_rules_audit_tests.gd
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
extends SceneTree
|
||||
|
||||
## Headless tests for the season rule packages and the invariant audit.
|
||||
##
|
||||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_rules_audit_tests.gd
|
||||
|
||||
const FIXTURE_ROOT := "user://rules-audit-fixture"
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_test_library_discovery()
|
||||
_test_season_resolution()
|
||||
_test_package_contents()
|
||||
_test_real_data_passes_audit()
|
||||
_test_broken_fixture_is_reported()
|
||||
_test_season_pair_difference()
|
||||
_cleanup()
|
||||
_finish()
|
||||
|
||||
|
||||
func _test_library_discovery() -> void:
|
||||
var library := RulesLibrary.scan()
|
||||
_check(library.get_errors().is_empty(), "rule library scans without errors")
|
||||
var seasons := library.get_seasons()
|
||||
_check(seasons.has("2025/26"), "library knows 2025/26")
|
||||
_check(seasons.has("2026/27"), "library knows 2026/27")
|
||||
_check(seasons.size() == 2, "library finds exactly two seasons")
|
||||
_check(
|
||||
seasons[0] == "2025/26" and seasons[1] == "2026/27",
|
||||
"seasons are sorted oldest first"
|
||||
)
|
||||
_check(library.has_season("2026/27"), "has_season finds 2026/27")
|
||||
_check(not library.has_season("2030/31"), "has_season rejects unknown")
|
||||
_check(library.get_package("2030/31") == null, "unknown season has no package")
|
||||
|
||||
|
||||
func _test_season_resolution() -> void:
|
||||
var library := RulesLibrary.scan()
|
||||
_check(
|
||||
library.get_default_season("2026-11-13") == "2026/27",
|
||||
"mid season 2026/27 is the default"
|
||||
)
|
||||
_check(
|
||||
library.get_default_season("2026-06-30") == "2025/26",
|
||||
"before July 1st the previous season is the default"
|
||||
)
|
||||
_check(
|
||||
library.get_default_season("2025-06-01") == "2026/27",
|
||||
"without a started season the newest complete season wins"
|
||||
)
|
||||
_check(
|
||||
RulesLibrary.season_to_folder("2026/27") == "2026-27",
|
||||
"season folder name uses a dash"
|
||||
)
|
||||
|
||||
|
||||
func _test_package_contents() -> void:
|
||||
var library := RulesLibrary.scan()
|
||||
|
||||
var current := library.get_package("2026/27")
|
||||
_check(current != null, "2026/27 package loads")
|
||||
if current == null:
|
||||
return
|
||||
_check(current.get_errors().is_empty(), "2026/27 package has no errors")
|
||||
_check(current.is_complete(), "2026/27 is complete")
|
||||
_check(current.season == "2026/27", "package carries its season")
|
||||
_check(current.replaces == "2025/26", "2026/27 replaces 2025/26")
|
||||
_check(current.catalog != null, "package has a catalog")
|
||||
_check(current.levels != null, "package has level rules")
|
||||
_check(current.adult != null, "package has adult categories")
|
||||
_check(current.get_notes_path().ends_with("notes.md"), "package knows its notes")
|
||||
|
||||
var policy: Variant = current.get_policy("axel_required_in_sequence", false)
|
||||
_check(policy == true, "axel policy is declared for 2026/27")
|
||||
_check(
|
||||
current.get_policy("max_features_per_foot", 0) == 0,
|
||||
"undeclared policy falls back to the caller's off value"
|
||||
)
|
||||
_check(
|
||||
not current.has_policy("feature_position_rules"),
|
||||
"undeclared policy is reported as absent"
|
||||
)
|
||||
|
||||
var previous := library.get_package("2025/26")
|
||||
_check(previous != null, "2025/26 package loads")
|
||||
if previous == null:
|
||||
return
|
||||
_check(previous.catalog != null, "2025/26 has a catalog")
|
||||
_check(previous.levels != null, "2025/26 has level rules")
|
||||
_check(previous.adult == null, "2025/26 has no adult rules")
|
||||
_check(previous.is_document_missing("adult"), "2025/26 marks adult as missing")
|
||||
_check(
|
||||
not previous.get_warnings().is_empty(),
|
||||
"2025/26 warns about the missing document"
|
||||
)
|
||||
|
||||
|
||||
func _test_real_data_passes_audit() -> void:
|
||||
var report := RulesAudit.audit_root()
|
||||
_check(report.seasons_checked == 2, "audit checks both seasons")
|
||||
_check(
|
||||
report.error_count() == 0,
|
||||
"real data passes the audit (%s)"
|
||||
% "; ".join(report.to_lines())
|
||||
)
|
||||
|
||||
|
||||
func _test_broken_fixture_is_reported() -> void:
|
||||
_cleanup()
|
||||
_copy_season("2026/27", FIXTURE_ROOT.path_join("2026-27"))
|
||||
|
||||
var manifest_path := FIXTURE_ROOT.path_join("2026-27").path_join("manifest.json")
|
||||
var manifest := _read_json(manifest_path)
|
||||
manifest["replaces"] = null
|
||||
var policies: Dictionary = manifest["policies"]
|
||||
policies["unknown_policy"] = true
|
||||
manifest["policies"] = policies
|
||||
_write_json(manifest_path, manifest)
|
||||
|
||||
var sov_path := FIXTURE_ROOT.path_join("2026-27").path_join("sov.json")
|
||||
var sov := _read_json(sov_path)
|
||||
for entry: Dictionary in sov["elements"]:
|
||||
if str(entry.get("code", "")) == "3Lz":
|
||||
entry["base_value"] = 3.0
|
||||
_write_json(sov_path, sov)
|
||||
|
||||
var levels_path := FIXTURE_ROOT.path_join("2026-27").path_join("levels.json")
|
||||
var levels := _read_json(levels_path)
|
||||
var fixed_levels: Dictionary = levels["fixed_levels"]
|
||||
fixed_levels["9Zz"] = 1
|
||||
levels["fixed_levels"] = fixed_levels
|
||||
_write_json(levels_path, levels)
|
||||
|
||||
var report := RulesAudit.audit_root(FIXTURE_ROOT)
|
||||
var codes := PackedStringArray()
|
||||
for finding: RulesAudit.Finding in report.findings:
|
||||
if not codes.has(finding.code):
|
||||
codes.append(finding.code)
|
||||
|
||||
_check(codes.has("B7"), "audit reports a broken jump order (B7)")
|
||||
_check(codes.has("C1"), "audit reports an unknown fixed level code (C1)")
|
||||
_check(codes.has("F2"), "audit reports an unknown policy (F2)")
|
||||
_check(report.error_count() >= 3, "fixture has at least three errors")
|
||||
|
||||
# A document must not be both a file and an inheritance.
|
||||
var manifest_broken := _read_json(manifest_path)
|
||||
var adult: Dictionary = manifest_broken["documents"]["adult"]
|
||||
adult["inherit_from"] = "2025/26"
|
||||
manifest_broken["documents"]["adult"] = adult
|
||||
_write_json(manifest_path, manifest_broken)
|
||||
var broken := RulesAudit.audit_root(FIXTURE_ROOT)
|
||||
var broken_codes := PackedStringArray()
|
||||
for finding: RulesAudit.Finding in broken.findings:
|
||||
broken_codes.append(finding.code)
|
||||
_check(broken_codes.has("A4"), "audit rejects file plus inherit_from (A4)")
|
||||
|
||||
|
||||
## E6: a reference routine must pass in one season and fail in the next for
|
||||
## exactly the documented reason. This is what keeps old rules from being
|
||||
## "repaired" by accident.
|
||||
func _test_season_pair_difference() -> void:
|
||||
var library := RulesLibrary.scan()
|
||||
var older := library.get_package("2025/26")
|
||||
var newer := library.get_package("2026/27")
|
||||
_check(older != null and newer != null, "both seasons load for the pair test")
|
||||
if older == null or newer == null:
|
||||
return
|
||||
|
||||
var routine := _make_pair_routine()
|
||||
var old_issues := RoutineValidator.new(
|
||||
older.catalog,
|
||||
older.levels,
|
||||
older.adult
|
||||
).validate(routine)
|
||||
var new_issues := RoutineValidator.new(
|
||||
newer.catalog,
|
||||
newer.levels,
|
||||
newer.adult
|
||||
).validate(routine)
|
||||
|
||||
_check(
|
||||
_has_message(old_issues, "nicht im Katalog"),
|
||||
"2025/26 does not know ChSp"
|
||||
)
|
||||
_check(
|
||||
not _has_message(new_issues, "nicht im Katalog"),
|
||||
"2026/27 knows ChSp"
|
||||
)
|
||||
_check(older.adult == null, "2025/26 has no adult rules")
|
||||
_check(newer.adult != null, "2026/27 has adult rules")
|
||||
|
||||
|
||||
func _make_pair_routine() -> Routine:
|
||||
var routine := Routine.new()
|
||||
routine.routine_id = "season-pair"
|
||||
routine.season = "2026/27"
|
||||
var section := RoutineSection.new()
|
||||
section.section_id = "section-001"
|
||||
section.title = "Abschnitt 1"
|
||||
section.sequence_order = 0
|
||||
routine.sections = [section]
|
||||
|
||||
var marker := PathSegment.new()
|
||||
marker.segment_id = "seg-chsp"
|
||||
var curve := Curve2D.new()
|
||||
curve.add_point(Vector2.ZERO)
|
||||
marker.curve = curve
|
||||
marker.element_type = PathSegment.ElementType.SPIN
|
||||
marker.element_code = "ChSp"
|
||||
marker.element_level = 1
|
||||
section.segments.append(marker)
|
||||
return routine
|
||||
|
||||
|
||||
func _has_message(
|
||||
issues: Array[ValidationIssue],
|
||||
fragment: String
|
||||
) -> bool:
|
||||
for issue: ValidationIssue in issues:
|
||||
if issue.message.contains(fragment):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _copy_season(season: String, target: String) -> void:
|
||||
var source := RulesLibrary.DATA_ROOT.path_join(season.replace("/", "-"))
|
||||
DirAccess.make_dir_recursive_absolute(target)
|
||||
var dir := DirAccess.open(source)
|
||||
if dir == null:
|
||||
return
|
||||
dir.list_dir_begin()
|
||||
var name := dir.get_next()
|
||||
while not name.is_empty():
|
||||
if not dir.current_is_dir():
|
||||
var data := FileAccess.get_file_as_bytes(source.path_join(name))
|
||||
var file := FileAccess.open(target.path_join(name), FileAccess.WRITE)
|
||||
if file != null:
|
||||
file.store_buffer(data)
|
||||
name = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
|
||||
|
||||
func _read_json(path: String) -> Dictionary:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
return {}
|
||||
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||||
return parsed as Dictionary if typeof(parsed) == TYPE_DICTIONARY else {}
|
||||
|
||||
|
||||
func _write_json(path: String, data: Dictionary) -> void:
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
if file == null:
|
||||
return
|
||||
file.store_string(JSON.stringify(data, " "))
|
||||
|
||||
|
||||
func _cleanup() -> void:
|
||||
_remove_dir(FIXTURE_ROOT)
|
||||
|
||||
|
||||
func _remove_dir(path: String) -> void:
|
||||
var dir := DirAccess.open(path)
|
||||
if dir == null:
|
||||
return
|
||||
dir.list_dir_begin()
|
||||
var name := dir.get_next()
|
||||
while not name.is_empty():
|
||||
if dir.current_is_dir():
|
||||
_remove_dir(path.path_join(name))
|
||||
else:
|
||||
dir.remove(name)
|
||||
name = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
DirAccess.remove_absolute(path)
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
_assertions += 1
|
||||
if not condition:
|
||||
_failures.append(message)
|
||||
|
||||
|
||||
func _finish() -> void:
|
||||
if _failures.is_empty():
|
||||
print("PASS: %d assertions" % _assertions)
|
||||
quit(0)
|
||||
return
|
||||
for failure: String in _failures:
|
||||
printerr("FAIL: %s" % failure)
|
||||
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
|
||||
quit(1)
|
||||
1
rinkplanner/tests/run_rules_audit_tests.gd.uid
Normal file
1
rinkplanner/tests/run_rules_audit_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cjl04e7kkgah8
|
||||
|
|
@ -7,6 +7,7 @@ extends SceneTree
|
|||
|
||||
const ElementDefinitionScript := preload("res://src/core/rules/element_definition.gd")
|
||||
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
|
||||
const SEASON := "2026/27"
|
||||
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
|
||||
|
||||
var _assertions: int = 0
|
||||
|
|
@ -15,7 +16,13 @@ var _catalog: ElementCatalog
|
|||
|
||||
|
||||
func _init() -> void:
|
||||
_catalog = ElementCatalogScript.load_default()
|
||||
var library := RulesLibrary.scan()
|
||||
var package := library.get_package(SEASON)
|
||||
_check(package != null, "Saison %s ist ladbar" % SEASON)
|
||||
if package == null:
|
||||
_finish()
|
||||
return
|
||||
_catalog = package.catalog
|
||||
|
||||
_test_catalog_metadata()
|
||||
_test_jump_values()
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ extends SceneTree
|
|||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_validation_tests.gd
|
||||
|
||||
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
|
||||
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
|
||||
const RoutineValidatorScript := preload("res://src/core/rules/routine_validator.gd")
|
||||
const ValidationIssueScript := preload("res://src/core/rules/validation_issue.gd")
|
||||
const RoutineModel := preload("res://src/core/model/routine.gd")
|
||||
const RoutineSectionModel := preload("res://src/core/model/routine_section.gd")
|
||||
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
|
||||
const SEASON := "2026/27"
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -21,8 +20,14 @@ var _validator: RoutineValidator
|
|||
|
||||
|
||||
func _init() -> void:
|
||||
_catalog = ElementCatalogScript.load_default()
|
||||
_rules = ElementLevelRulesScript.load_default()
|
||||
var library := RulesLibrary.scan()
|
||||
var package := library.get_package(SEASON)
|
||||
_check(package != null, "Saison %s ist ladbar" % SEASON)
|
||||
if package == null:
|
||||
_finish()
|
||||
return
|
||||
_catalog = package.catalog
|
||||
_rules = package.levels
|
||||
_validator = RoutineValidatorScript.new(_catalog, _rules)
|
||||
|
||||
_test_clean_routine()
|
||||
|
|
|
|||
|
|
@ -1675,6 +1675,75 @@ func _run() -> void:
|
|||
)
|
||||
controller.validation_dialog.hide()
|
||||
|
||||
# Season assignment: the routine carries the rule package it is checked
|
||||
# against, and a season switch must not silently rewrite its data.
|
||||
controller.new_routine()
|
||||
_check(
|
||||
controller.get_season() == "2026/27",
|
||||
"a new routine gets the default season"
|
||||
)
|
||||
_check(
|
||||
controller.get_rules_package() != null
|
||||
and controller.get_rules_package().season == "2026/27",
|
||||
"the active rule package matches the routine"
|
||||
)
|
||||
_check(
|
||||
controller.set_adult_category("gold"),
|
||||
"Gold is available in the default season"
|
||||
)
|
||||
_check(controller.set_season("2025/26"), "the season can be switched to 2025/26")
|
||||
_check(
|
||||
controller.get_rules_package().season == "2025/26",
|
||||
"the rule package follows the season"
|
||||
)
|
||||
_check(
|
||||
controller.get_routine().adult_category == "gold",
|
||||
"the category is kept when the target season lacks adult rules"
|
||||
)
|
||||
var unavailable_index := -1
|
||||
for index: int in range(controller.adult_category_option.item_count):
|
||||
if str(controller.adult_category_option.get_item_metadata(index)) == "gold":
|
||||
unavailable_index = index
|
||||
_check(unavailable_index >= 0, "the stored category stays visible")
|
||||
_check(
|
||||
controller.adult_category_option.get_item_text(unavailable_index).contains(
|
||||
"nicht verfügbar"
|
||||
),
|
||||
"an unavailable category is labelled instead of hidden"
|
||||
)
|
||||
_check(
|
||||
controller.adult_category_option.selected == unavailable_index,
|
||||
"the dropdown selects the unavailable category"
|
||||
)
|
||||
var selected_season := controller.season_option.selected
|
||||
_check(
|
||||
str(controller.season_option.get_item_metadata(selected_season)) == "2025/26",
|
||||
"the season dropdown reflects the routine"
|
||||
)
|
||||
|
||||
_check(controller.set_season(""), "the season can be cleared")
|
||||
_check(
|
||||
controller.get_rules_package() == null,
|
||||
"without a season there is no rule package"
|
||||
)
|
||||
var unassigned_issues := controller.validate_routine()
|
||||
_check(
|
||||
not unassigned_issues.is_empty(),
|
||||
"an unassigned season blocks element validation"
|
||||
)
|
||||
controller.open_validation_dialog()
|
||||
_check(
|
||||
controller.validation_text.text.contains("Saison nicht festgelegt"),
|
||||
"the dialog explains the missing season"
|
||||
)
|
||||
controller.validation_dialog.hide()
|
||||
_check(
|
||||
not controller.set_season("2030/31"),
|
||||
"an unknown season is rejected"
|
||||
)
|
||||
|
||||
controller.new_routine()
|
||||
|
||||
# Structured jump combination in the element dialog.
|
||||
controller.new_routine()
|
||||
var combo_marker := controller.add_element_marker(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue