diff --git a/docs/new_engine/README.md b/docs/new_engine/README.md index f2e7fec..f3bfb74 100644 --- a/docs/new_engine/README.md +++ b/docs/new_engine/README.md @@ -56,7 +56,7 @@ Für 0.3 gilt außerdem: | M2 | Spielpläne je Liga, Kalender mit 38 Spieltagen | Engine-Teil erledigt (Tabelle je Ligagröße, Ligatermine, Aussetzen); Test mit echten Daten in M3 | | M3 | Modern-Weltlader, Namen (Vor-/Nachname, UTF-8), Asset-Schlüssel | Weltlader erledigt: Modern-Datensatz spielt zwei Saisons; Namen/Assets für die UI liegen in `ModernState`, Spielstände folgen mit M6 | | M4 | Trainingslager: 18 Lager, drei Karten, 6-Sterne-Wirkung | Engine erledigt (Katalog, Preis, 6-Sterne-Wirkung, Test); Saisonwirkung wird in M7 gemessen | -| M5 | Datenrevision 1.4 des Modern-Datensatzes (privat), Wirtschaftsprüfung | offen | +| M5 | Datenrevision 1.4 des Modern-Datensatzes (privat), Wirtschaftsprüfung | Datensatz/Editor geprüft; Mehrsaisonprüfung offen | | M6 | Modern-Spielstände (`modern-career-v1`), Projektionen für die UI | Spielstände erledigt (Rundreise identisch); Projektionen offen | | M7 | Balance-Läufe und Anpassungen | begonnen: Spielerwerte des Datensatzes nach Rangfolge ([Balance](balance.md)); Langläufe offen | | M8 | Fußball-Almanach: alle Spiele mit Ereignissen und Aufstellungen ([Almanach](almanach.md)) | Engine erledigt (Aufzeichnung, Spielstand, IDs); UI und Projektionen offen | diff --git a/docs/new_engine/datenformat.md b/docs/new_engine/datenformat.md index 194e296..c814ad4 100644 --- a/docs/new_engine/datenformat.md +++ b/docs/new_engine/datenformat.md @@ -29,6 +29,8 @@ Status: *geplant* (noch nicht in der Engine), *umgesetzt* (Engine liest/prüft e - Das Editor-Profil bleibt `editor-world-v1`. Neu: Eine Welt mit `runtime:modern-v1` darf `x-editor.playable: true` haben, wenn sie die Modern-Prüfung (unten) besteht. - Die Datenrevision steht weiter in der Erweiterung des Datensatzes (z. B. `data_revision`). - **Editor:** Schalter „Als Modern-Welt spielbar machen“ setzt `requires` und `playable` erst nach erfolgreicher Modern-Prüfung; Entfernen setzt beides zurück. Die bisherige Bedingung `playable == false` gilt nur noch für Welten ohne `runtime:modern-v1`. +- **Editor-Kompatibilität:** Öffnen und verlustfreies Speichern von `editor-world-v1` mit `x-editor.playable: true` ist erlaubt, wenn `requires` sowohl `editor:world-v1` als auch `runtime:modern-v1` enthält. Eine gleichzeitige Classic-Laufzeitanforderung ist ungültig. Reine Editorwelten behalten die bisherige Zulassung mit `playable: false`. +- Die Editorprüfung deckt außerdem die Modern-Felder aus F4 und F9 ab. Sie ersetzt noch keine vollständige Engine-Spielbarkeitsprüfung für F2/F3/F5/F6; ein neuer GUI-Schalter zur Freigabe ist damit nicht umgesetzt. Eine fehlende Finanzzeile für zusätzliche Vereine bleibt nach F7 zulässig. ## F2 · Ligen diff --git a/docs/new_engine/phasen.md b/docs/new_engine/phasen.md index 2c75a5e..23ff8ae 100644 --- a/docs/new_engine/phasen.md +++ b/docs/new_engine/phasen.md @@ -64,6 +64,8 @@ Siehe [Trainingslager](trainingslager.md): Katalog aus den Daten, drei Regionen, **Stand Engine (erledigt):** Die Engine liest alles, was 1.4 liefern soll: `runtime:modern-v1` (F1), Ligatermine für 38 Spieltage (F3; Revision 1.3 spielt schon 38/38), den Lager-Katalog mit Karten (F4), den Schiedsrichter-Pool aus `staff` (F9). Für Finanzen (F7) braucht 0.3 nichts. +**Stand Datenpflege (25.10.2026):** Revision 1.4 ist gebaut und unabhängig geprüft (101 Prüfungen, null Fehler), zweimal bytegleich erzeugt und im ergänzten Editor verlustfrei geöffnet/gespeichert. Die Welt nennt beide Laufzeit-/Editoranforderungen, ist spielbar markiert und liefert 3 Karten, 18 Lager sowie 100 Schiedsrichter. Alle 3.414 Spieler haben `born`: bei den Originalen 2.345 aus Quellen ergänzt und 229 ausdrücklich als Simulation generiert; die 840 Ergänzungen bleiben unverändert. Original-IDs, Namen, Werte und Ressourcen bleiben erhalten. Ein Engine-Zug mit der neuen Welt ist geprüft; der unten genannte Mehrsaisontest bleibt beim Engine-Team. Der Editor-Supportfix liegt ebenfalls auf `0.3`, kein neuer Editor-Release. + **Aufgabenpaket Datenmigration 1.4 (Codex, Python-Migrationswerkzeug, privates Repo):** 1. Manifest: `requires` um `runtime:modern-v1` ergänzen, `playable: true`. `editor:world-v1` darf bleiben. 2. Trainingslager: Regel `rule:training-camps` mit `maps` (Deutschland, Europa, Naher Osten) und den 18 Lagern aus `docs/new_ui/desktop/trainingcamp` nach [F4](datenformat.md#f4--trainingslager); `x`/`y` bleiben `null`. Vorlage für Werte und IDs (`resort:0..17`): `default_camp_catalogue()` in `src/modern/game/training_camps.cpp`. diff --git a/src/editor/world.cpp b/src/editor/world.cpp index f617264..f61bc21 100644 --- a/src/editor/world.cpp +++ b/src/editor/world.cpp @@ -13,6 +13,14 @@ namespace bmh::editor { namespace { Json table(const std::string &name) { return {{"schema", name + "@1.1"}, {"items", Json::array()}}; } +bool modern_requirement(const Json &manifest) { + const auto requirements = manifest.value("requires", Json()); + return requirements.is_array() && + std::find(requirements.begin(), requirements.end(), Json("runtime:modern-v1")) != requirements.end(); +} +bool whole(const Json &value, int64_t minimum, int64_t maximum) { + return value.is_number_integer() && value >= minimum && value <= maximum; +} bool date_valid(const Json &value) { if (value.is_null()) return true; @@ -128,8 +136,10 @@ World World::open(const fs::path &source, const std::string &start_date) { if (!version.starts_with("1.")) throw Error("unsupported_version", {{"version", version}}); const bool editor = str(w.manifest.value("x-editor", Json::object()), "profile") == "editor-world-v1"; + const auto editor_fields = w.manifest.value("x-editor", Json::object()); + const auto playable = editor_fields.is_object() ? editor_fields.value("playable", Json()) : Json(); if (editor && (version != "1.1" || str(w.manifest, "min_reader") != "1.1" || - w.manifest.value("x-editor", Json::object()).value("playable", true))) + (playable != false && !(playable == true && modern_requirement(w.manifest))))) throw Error("unsupported_version"); if (!editor) { // Only bounded 1.0 Classic packages use the Classic validator. Its @@ -252,7 +262,7 @@ Json World::statistics() const { {"source", utf8(source_path)}, {"imported", imported}, {"profile", "editor-world-v1"}, - {"playable", false}}; + {"playable", manifest.value("x-editor", Json::object()).value("playable", false)}}; } Json World::query(const Json &args) const { const auto name = str(args, "table", "clubs"); @@ -347,11 +357,15 @@ Json World::validate() const { std::map ids; const auto editor = manifest.value("x-editor", Json::object()); const auto requirements = manifest.value("requires", Json::array()); + const bool modern = modern_requirement(manifest); + const auto playable = editor.is_object() ? editor.value("playable", Json()) : Json(); if (str(manifest, "format") != "openbmh-world" || str(manifest, "kind") != "world" || str(manifest, "format_version") != "1.1" || str(manifest, "min_reader") != "1.1" || !editor.is_object() || - str(editor, "profile") != "editor-world-v1" || !editor.contains("playable") || editor["playable"] != false || + str(editor, "profile") != "editor-world-v1" || + (playable != false && !(playable == true && modern)) || !requirements.is_array() || - std::find(requirements.begin(), requirements.end(), Json("editor:world-v1")) == requirements.end()) + std::find(requirements.begin(), requirements.end(), Json("editor:world-v1")) == requirements.end() || + (modern && std::find(requirements.begin(), requirements.end(), Json("runtime:classic-v1")) != requirements.end())) issue("error", "invalid_manifest", "manifest", "manifest"); if (!date_valid(manifest.value("start_date", Json()))) issue("error", "invalid_date", "manifest", "manifest"); @@ -373,7 +387,8 @@ Json World::validate() const { if (name != "assets" && name != "calendar" && name != "rules" && title(row).empty()) issue("warning", "missing_name", name, id); if (name == "players") { - if (!date_valid(row.value("born", Json()))) + if (!date_valid(row.value("born", Json())) || + (modern && row.contains("born") && row["born"].is_null())) issue("error", "invalid_date", name, id); if (!row.contains("born") && !row.contains("age_at_start")) issue("warning", "missing_birthday", name, id); @@ -402,6 +417,91 @@ Json World::validate() const { } } } + // F4/F9 checks apply only to explicitly Modern worlds. Imported editor-only + // worlds retain their original Classic camp catalogue and validation rules. + if (modern) { + for (const auto &rule : rows("rules")) { + if (str(rule, "type") != "training_camps") + continue; + const auto id = str(rule, "id"); + auto camp_issue = [&](const std::string &field, const std::string &entry = "") { + issue("error", "invalid_training_camps", "rules", id, {{"field", field}, {"entry", entry}}); + }; + const auto map_rows = rule.value("maps", Json()); + const auto resorts = rule.value("resorts", Json()); + if (!map_rows.is_array() || map_rows.empty() || !resorts.is_array() || resorts.empty()) { + camp_issue("maps/resorts"); + continue; + } + std::map> maps; + std::set nested_ids; + for (const auto &map : map_rows) { + if (!map.is_object()) { + camp_issue("maps"); + continue; + } + const auto key = str(map, "id"); + if (key.empty() || !nested_ids.insert(key).second || ids.contains(key)) + camp_issue("maps.id", key); + if (text(map.value("name", Json())).empty()) + camp_issue("maps.name", key); + const auto width = map.value("width", Json()), height = map.value("height", Json()); + if ((!width.is_null() || !height.is_null()) && + (!whole(width, 1, INT32_MAX) || !whole(height, 1, INT32_MAX))) + camp_issue("maps.size", key); + maps[key] = {width, height}; + } + for (const auto &camp : resorts) { + if (!camp.is_object()) { + camp_issue("resorts"); + continue; + } + const auto key = str(camp, "id"), map = str(camp, "map"); + if (key.empty() || !nested_ids.insert(key).second || ids.contains(key)) + camp_issue("resorts.id", key); + if (text(camp.value("name", Json())).empty() || text(camp.value("place", Json())).empty()) + camp_issue("resorts.name/place", key); + if (!find("nations", str(camp, "country"))) + camp_issue("resorts.country", key); + if (!whole(camp.value("base_price", Json()), 0, INT32_MAX)) + camp_issue("resorts.base_price", key); + const auto quality = camp.value("quality", Json()); + if (!quality.is_array() || quality.size() != 4 || + !std::all_of(quality.begin(), quality.end(), [](const auto &value) { return whole(value, 0, 6); })) + camp_issue("resorts.quality", key); + const auto x = camp.value("x", Json()), y = camp.value("y", Json()); + if (!camp.contains("x") || !camp.contains("y") || + (!x.is_null() && !whole(x, 0, INT32_MAX)) || (!y.is_null() && !whole(y, 0, INT32_MAX))) + camp_issue("resorts.coordinates", key); + const auto found = maps.find(map); + if (found == maps.end()) + camp_issue("resorts.map", key); + else if (!found->second.first.is_null() && !found->second.second.is_null() && + (!whole(x, 0, INT32_MAX) || !whole(y, 0, INT32_MAX) || + x >= found->second.first || y >= found->second.second)) + camp_issue("resorts.bounds", key); + const auto image = camp.value("image", Json()); + if (!image.is_null() && (!image.is_string() || image.get_ref().empty() || + asset_file(image.get_ref()).empty())) + camp_issue("resorts.image", key); + } + } + size_t referees = 0; + for (const auto &person : rows("staff")) { + if (str(person, "role") != "referee") + continue; + ++referees; + const auto attrs = person.value("attributes", Json::object()); + if (text(person.value("name", Json())).empty() || !attrs.is_object()) + issue("error", "invalid_referee", "staff", str(person, "id")); + else + for (const auto *field : {"strictness", "perception"}) + if (attrs.contains(field) && !whole(attrs[field], 0, 3)) + issue("error", "invalid_referee", "staff", str(person, "id"), {{"field", field}}); + } + if (referees > 255) + issue("error", "invalid_referee", "staff", "", {{"count", referees}, {"maximum", 255}}); + } for (auto &name : tables()) if (name != "review" && name != "image-edits") for (auto &row : rows(name)) diff --git a/tests/editor_core_tests.cpp b/tests/editor_core_tests.cpp index 728c8c4..88b11ba 100644 --- a/tests/editor_core_tests.cpp +++ b/tests/editor_core_tests.cpp @@ -34,6 +34,123 @@ Json update(const char *table, const char *id, Json set) { Json row(Session &session, const char *table, const char *id) { return session.execute("get", {{"table", table}, {"id", id}})["record"]; } +bool has_error(const World &world, const char *code = nullptr) { + for (const auto &diagnostic : world.validate()) + if (diagnostic["severity"] == "error" && (!code || diagnostic["code"] == code)) + return true; + return false; +} +void modern_roundtrip(const fs::path &root) { + auto world = World::blank("Synthetic Modern archive"); + world.manifest["requires"].push_back("runtime:modern-v1"); + world.manifest["x-editor"]["playable"] = true; + world.manifest["x-future"] = {{"fraction", 1.125}, {"unknown", Json::array({1, "ä", nullptr})}}; + world.rows("nations").push_back({{"id", "nation:test"}, {"name", "Test"}}); + const Json camp = {{"id", "resort:test"}, {"map", "map:test"}, {"x", nullptr}, {"y", nullptr}, + {"name", {{"default", "Camp"}}}, {"place", "Place"}, {"country", "nation:test"}, + {"base_price", 485000}, {"quality", Json::array({0, 6, 4, 4})}, + {"x-future", {{"preserve", true}}}}; + world.rows("rules").push_back({{"id", "rule:training-camps"}, {"type", "training_camps"}, + {"maps", Json::array({{{"id", "map:test"}, {"name", "Map"}}})}, + {"resorts", Json::array({camp})}}); + world.rows("staff").push_back({{"id", "staff:test"}, {"role", "referee"}, {"name", "Test"}}); + check(!has_error(world), "Modern optional GUI images, null coordinates and absent referee grades accepted"); + check(world.statistics()["playable"] == true, "Modern playable flag reported accurately"); + check(world.rows("finance").empty(), "Modern roundtrip does not require fictional finances"); + auto unknown_birthday = world; + unknown_birthday.rows("players").push_back({{"id", "player:unknown"}, + {"name", {{"first", "Test"}, {"last", "Player"}}}, + {"age_at_start", {{"on", "2026-07-01"}, {"years", 16}}}, + {"attributes", Json::object()}}); + check(!has_error(unknown_birthday), "Modern missing born retains age fallback"); + unknown_birthday.rows("players")[0]["born"] = nullptr; + check(has_error(unknown_birthday, "invalid_date"), "Modern born null rejected like the engine reader"); + unknown_birthday.manifest["requires"] = {"editor:world-v1"}; + unknown_birthday.manifest["x-editor"]["playable"] = false; + check(!has_error(unknown_birthday), "editor-only nullable born remains accepted"); + auto invalid = [&](auto change, const char *code) { + auto copy = world; + change(copy); + check(has_error(copy, code), "Modern validation reports relevant field error"); + rejects("validation_failed", [&] { copy.save(root / "invalid-modern.obw"); }); + }; + invalid([](World &w) { w.manifest["requires"] = {"editor:world-v1"}; }, "invalid_manifest"); + invalid([](World &w) { w.manifest["requires"] = {"runtime:modern-v1"}; }, "invalid_manifest"); + invalid([](World &w) { w.manifest["requires"].push_back("runtime:classic-v1"); }, "invalid_manifest"); + invalid([](World &w) { w.manifest["x-editor"]["playable"] = "true"; }, "invalid_manifest"); + invalid([](World &w) { w.manifest["x-editor"] = nullptr; }, "invalid_manifest"); + auto bad_camp = [&](const char *field, Json value) { + invalid([&](World &w) { w.rows("rules").back()["resorts"][0][field] = value; }, + "invalid_training_camps"); + }; + bad_camp("map", "map:missing"); + bad_camp("country", "nation:missing"); + bad_camp("image", "asset:missing"); + bad_camp("base_price", -1); + bad_camp("quality", Json::array({1, 2, 3, 7})); + bad_camp("quality", Json::array({1, 2, 3, 1.5})); + bad_camp("x", 1.5); + invalid([](World &w) { w.rows("rules").back()["resorts"][0].erase("x"); }, "invalid_training_camps"); + invalid([](World &w) { auto &r = w.rows("rules").back(); r["maps"].push_back(r["maps"][0]); }, + "invalid_training_camps"); + invalid([](World &w) { auto &r = w.rows("rules").back(); r["resorts"].push_back(r["resorts"][0]); }, + "invalid_training_camps"); + invalid([](World &w) { w.rows("rules").back()["maps"] = Json::array(); }, "invalid_training_camps"); + invalid([](World &w) { w.rows("rules").back()["maps"][0]["width"] = 10; }, "invalid_training_camps"); + invalid([](World &w) { + auto &r = w.rows("rules").back(); + r["maps"][0]["width"] = 10; r["maps"][0]["height"] = 20; + }, "invalid_training_camps"); + invalid([](World &w) { + auto &r = w.rows("rules").back(); + r["maps"][0]["width"] = 10; r["maps"][0]["height"] = 20; + r["resorts"][0]["x"] = 10; r["resorts"][0]["y"] = 0; + }, "invalid_training_camps"); + for (const auto *field : {"strictness", "perception"}) + for (const auto &value : {Json(-1), Json(4), Json(1.5)}) + invalid([&](World &w) { w.rows("staff")[0]["attributes"][field] = value; }, "invalid_referee"); + world.rows("assets").push_back({{"key", "asset:camp-test"}, + {"files", {{"svg", "assets/camp-test.svg"}}}}); + world.store->set("assets/camp-test.svg", std::make_shared(images::silhouette())); + auto &catalogue = world.rows("rules").back(); + catalogue["maps"][0]["width"] = 10; + catalogue["maps"][0]["height"] = 20; + catalogue["resorts"][0]["x"] = 9; + catalogue["resorts"][0]["y"] = 19; + catalogue["resorts"][0]["image"] = "asset:camp-test"; + check(!has_error(world), "Modern in-bounds coordinates and an explicit world image accepted"); + auto full = world; + for (int i = 1; i < 255; ++i) + full.rows("staff").push_back({{"id", "staff:" + std::to_string(i)}, {"role", "referee"}, + {"name", "Synthetic"}, {"attributes", {{"strictness", 0}, {"perception", 3}}}}); + check(!has_error(full), "255 Modern referees accepted"); + full.rows("staff").push_back({{"id", "staff:overflow"}, {"role", "referee"}, {"name", "Synthetic"}}); + check(has_error(full, "invalid_referee"), "256 Modern referees rejected"); + auto legacy = world; + legacy.manifest["requires"] = {"editor:world-v1"}; + legacy.manifest["x-editor"]["playable"] = false; + legacy.rows("rules").back().erase("maps"); + legacy.rows("staff")[0]["attributes"]["strictness"] = 7; + check(!has_error(legacy), "editor-only worlds retain previous camp/referee validation"); + const auto opaque = std::make_shared("opaque future data\0bytes", 24); + world.store->set("x-future/opaque.bin", opaque); + world.save(root / "modern.obw"); + auto opened = World::open(root / "modern.obw"); + opened.save(root / "modern-roundtrip.obw"); + auto reopened = World::open(root / "modern-roundtrip.obw"); + check(reopened.manifest == world.manifest, "Modern manifest semantic roundtrip"); + check(reopened.rows("rules") == world.rows("rules"), "Modern camp fields and extensions preserved"); + check(reopened.rows("staff") == world.rows("staff"), "Modern referee defaults not materialized"); + check(reopened.store->read("x-future/opaque.bin") == *opaque, "Modern opaque entry byte preservation"); + auto manifest = opened.manifest; + manifest["requires"] = {"editor:world-v1"}; + opened.store->save(root / "forbidden-playable.obw", {{"manifest.json", manifest.dump(2)}}); + rejects("unsupported_version", [&] { World::open(root / "forbidden-playable.obw"); }); + manifest = opened.manifest; + manifest["min_reader"] = "1.2"; + opened.store->save(root / "future-reader.obw", {{"manifest.json", manifest.dump(2)}}); + rejects("unsupported_version", [&] { World::open(root / "future-reader.obw"); }); +} } // namespace int main() { auto root = fs::temp_directory_path() / new_id("editor-test-"); @@ -46,6 +163,7 @@ int main() { } } cleanup{root}; try { + modern_roundtrip(root); Session s; s.execute("demo"); const auto generation = s.execute("info")["world_generation"];