Bind tactics and training drafts to confirmed engine commits (by Codex)
This commit is contained in:
1 parent
7d3b3f1101
commit
f75e0f8e49
18 files changed
+398
-43
No files matched your search
@@ -6,7 +6,7 @@ Die normale Classic-Konfiguration bleibt unverändert; die neue Oberfläche
|
||||
wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
|
||||
|
||||
Der [opt-in Engine-Einstieg](integration/ENGINE_ENTRY.md) lädt inzwischen eine
|
||||
echte Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager und Aufstellung an die
|
||||
echte Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager, Aufstellung, Taktik und Training an die
|
||||
Session. Kader und Profile zeigen die tatsächlichen Sessionwerte; Spielertausch
|
||||
verwendet die bestätigte Engineaktion. Preisbestätigung, Buchung und Speichern als neue OBS-Datei sind echte
|
||||
Engineoperationen. Dieser Einstieg ist auf diesen Umfang begrenzt; die übrigen
|
||||
|
||||
@@ -50,3 +50,16 @@ Linux/OpenGL wurde tatsächlich gerendert. Windows/macOS haben CI-Builds und
|
||||
synthetische Tests; ihre visuelle Laufzeitabnahme ist damit nicht erledigt.
|
||||
Kleine Schrift-/Kantenrasterungsunterschiede bleiben protokolliert.
|
||||
Siehe [wiederholbare Menü-QA](../../menu-qa.md).
|
||||
|
||||
|
||||
## Echter Engine-Einstieg
|
||||
|
||||
Über `--ui-career` verwendet derselbe Presenter jetzt die passenden Engine-Reads.
|
||||
Änderungen bleiben im lokalen Entwurf bis „Anwenden“ und dessen Bestätigung.
|
||||
Zurücksetzen, Abbruch und Schließen verändern den Spielstand nicht. Die Bridge
|
||||
verwendet die echten Commit-Befehle mit stabilen IDs und Revisionsschutz; Werte,
|
||||
Bereiche und Budgets werden nicht aus Demoformeln ergänzt. Bestätigte Änderungen
|
||||
werden als neue OBS-Datei gespeichert und nach Neustart wieder eingelesen.
|
||||
Nicht im Commit-Vertrag verfügbare Automatiken und Spielerschwerpunkte bleiben
|
||||
im echten Trainingsmenü schreibgeschützt. Der bisherige Demomodus bleibt separat.
|
||||
Private Nachweise: `bmh_4k_ui/docs/qa/engine-sports-2026-10-28/`.
|
||||
@@ -73,3 +73,16 @@ Synthetische Tests ergänzen atomare Ablehnung, Revisionen und Migration.
|
||||
Die gemeinsame Dropdown-Markierungsspalte und geringe Unterschiede der
|
||||
Kantenglättung bleiben dokumentierte Abweichungen. Screenshots, Eingaben und
|
||||
passende Demostände: [wiederholbare Menü-QA](../../menu-qa.md).
|
||||
|
||||
|
||||
## Echter Engine-Einstieg
|
||||
|
||||
Über `--ui-career` verwendet derselbe Presenter jetzt die passenden Engine-Reads.
|
||||
Änderungen bleiben im lokalen Entwurf bis „Anwenden“ und dessen Bestätigung.
|
||||
Zurücksetzen, Abbruch und Schließen verändern den Spielstand nicht. Die Bridge
|
||||
verwendet die echten Commit-Befehle mit stabilen IDs und Revisionsschutz; Werte,
|
||||
Bereiche und Budgets werden nicht aus Demoformeln ergänzt. Bestätigte Änderungen
|
||||
werden als neue OBS-Datei gespeichert und nach Neustart wieder eingelesen.
|
||||
Nicht im Commit-Vertrag verfügbare Automatiken und Spielerschwerpunkte bleiben
|
||||
im echten Trainingsmenü schreibgeschützt. Der bisherige Demomodus bleibt separat.
|
||||
Private Nachweise: `bmh_4k_ui/docs/qa/engine-sports-2026-10-28/`.
|
||||
@@ -1,5 +1,5 @@
|
||||
<!-- SPDX-License-Identifier: GPL-3.0-only -->
|
||||
# Nativer Engine-Einstieg: Schreibtisch, Trainingslager und Aufstellung
|
||||
# Nativer Engine-Einstieg: Schreibtisch, Trainingslager, Aufstellung und Vorbereitung
|
||||
|
||||
Der opt-in Einstieg lädt eine bestehende Modern-Karriere aus einer OBS-Datei.
|
||||
Er ist ein erster vertikaler Integrationsschritt, kein vollständiger spielbarer
|
||||
@@ -17,7 +17,7 @@ werden. Die Quelle wird nicht in DemoSource überführt.
|
||||
|
||||
## Gebundener Umfang
|
||||
|
||||
- `ModernSession::ui_read`: `session`, `desktop`, `camps`, `squad`, `lineup`. Karriere, Manager,
|
||||
- `ModernSession::ui_read`: `session`, `desktop`, `camps`, `squad`, `lineup`, `tactics`, `training`. Karriere, Manager,
|
||||
Mannschaft, Datum, Saison, Geld, Lagerqualitäten und Angebote kommen aus der
|
||||
Engine. Katalog und Engine müssen dieselbe Welt-ID und Datenrevision haben.
|
||||
- Der bestehende RmlUI-Schreibtisch verwendet die gemeinsamen App-Buttons und
|
||||
@@ -59,6 +59,36 @@ bleiben in diesem echten Einstieg bis zu ihren eigenen Engineanschlüssen
|
||||
unverfügbar; die vollständige Demo behält ihre getrennte Bedienung.
|
||||
Die erweiterten Nachweise liegen unter `bmh_4k_ui/docs/qa/engine-lineup-2026-10-28/`.
|
||||
|
||||
## Taktik und Training
|
||||
|
||||
Beide bestehenden Presenter sind im echten Einstieg angebunden. Ihre Werte,
|
||||
Bereiche und Ballbudgets stammen aus den jeweiligen Engine-Reads. Die Taktiktafel
|
||||
verwendet die tatsächlich gelieferten Aufstellungskoordinaten einschließlich
|
||||
`depthMax`/`laneMax`; eine unbekannte Formation wird nicht ersetzt. Die neutralen
|
||||
Taktikbezeichnungen des Vertrags bleiben erhalten.
|
||||
|
||||
Änderungen sind zunächst lokale Entwürfe. „Zurücksetzen“ verwirft sie, Schließen
|
||||
übernimmt nichts. „Anwenden“ fragt nach Bestätigung und sendet dann
|
||||
`tactics.commit` beziehungsweise `training.commit` mit Karriere, Manager,
|
||||
erwarteter Revision und neuer requestId. Der Client prüft die vom Read genannten
|
||||
Bereiche/Budgets; die maßgebliche Anwendung und weitere Prüfung bleiben bei der
|
||||
Engine. Bei noch nicht eingerichtetem Training weist die UI auf die erstmalige
|
||||
Einrichtung mit Anwenden hin. Öffnen des Menüs initialisiert es nicht heimlich.
|
||||
|
||||
Training zeigt den aktuellen Engine-Kader und dessen Stärke statt der statischen
|
||||
Katalogwerte. Typen, Bereiche und Spielerintensität sind bearbeitbar. Die vier
|
||||
Automatikschalter spiegeln die gespeicherten Bildschirmflags, sind hier aber
|
||||
schreibgeschützt; ihr Byte wird vom Client nicht geschrieben. Auch die vorhandenen
|
||||
Spielerschwerpunkte bleiben bis zu einem entsprechenden Commit-Vertrag
|
||||
schreibgeschützt. Unbelegte Überlastungsschwellen aus der Demo werden im echten
|
||||
Einstieg nicht als neue Engine-Regeln eingeführt.
|
||||
|
||||
Die Hintergrundaufträge liefern nach dem Commit einen neuen zusammenhängenden
|
||||
Snapshot. Rückmeldung und Änderungsstatus folgen der Engineantwort; ein bestätigter
|
||||
No-op wird nicht als neue ungespeicherte Änderung ausgegeben. Taktik und Training
|
||||
bleiben in einer neuen OBS-Datei und nach Prozessneustart erhalten. Private Belege:
|
||||
`bmh_4k_ui/docs/qa/engine-sports-2026-10-28/`.
|
||||
|
||||
## Ausführung und Dateien
|
||||
|
||||
Laden, Reads nach einer Aktion, Buchen und Speichern laufen seriell über einen
|
||||
@@ -81,10 +111,11 @@ Die Demoabläufe sind davon ausdrücklich getrennt.
|
||||
|
||||
`modern_engine_dto_tests` ist synthetisch und prüft Kontextschutz, exakte große
|
||||
Geld-/Revisionswerte, fremde/veraltete Angebote, National-Sperre und ungültige
|
||||
Schwerpunkte. Der opt-in `modern_engine_bridge_probe prepare|verify|verify-lineup <world.obw>
|
||||
Schwerpunkte. Der opt-in `modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports <world.obw>
|
||||
<new-output-directory>` prüft mit privat bereitgestellten Weltdaten tatsächliche
|
||||
Buchung, Preisabzug, Anfragewiederholung und OBS-Speicherrundreise. `verify-lineup` prüft zusätzlich tatsächlichen Tausch,
|
||||
Wiederholung, abgewiesene alte Revision und gespeicherte Aufstellung. Er ist kein
|
||||
Wiederholung, abgewiesene alte Revision und gespeicherte Aufstellung. `verify-sports` prüft Taktik/Training, Anfragewiederholung,
|
||||
alte Revision und gespeicherte Pläne. Er ist kein
|
||||
bedingungsloser CTest und verteilt keine Originaldaten.
|
||||
|
||||
`--ui-script` unterstützt `engine-wait` zum Abwarten realer Hintergrundaufträge.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
Stand: 28. Oktober 2026. Neben der UI-Demo gibt es jetzt einen getrennten
|
||||
[opt-in Engine-Einstieg](ENGINE_ENTRY.md) für echte OBS-Karrieren mit Schreibtisch,
|
||||
Trainingslager und Aufstellung. Die übrigen hier genannten Presenter laufen weiterhin als
|
||||
Trainingslager, Aufstellung, Taktik und Training. Die übrigen hier genannten Presenter laufen weiterhin als
|
||||
UI-Demo. Diese Übersicht ergänzt den [gestuften Einstieg](MVP_FOR_CLAUDE.md)
|
||||
um die tatsächlich vorhandenen C++-Anschlussstellen; sie definiert kein weiteres
|
||||
Protokoll und verlangt keine neue Enginearchitektur.
|
||||
|
||||
@@ -181,7 +181,7 @@ std::string edit_demo_tactics(Json &state, const Json &action) {
|
||||
return {};
|
||||
}
|
||||
std::string tactics_diagram(const Json &state, const std::string &theme,
|
||||
const Json &lineup_points) {
|
||||
const Json &lineup_points, int depth_max, int lane_max) {
|
||||
const auto values = state.at("values").get<std::array<int, 8>>();
|
||||
const std::string line = theme == "silver" ? "#536f66" : "#dfe8bf";
|
||||
const auto field_line = theme == "silver" ? "#536f66" : "#d7edbf",
|
||||
@@ -236,7 +236,7 @@ std::string tactics_diagram(const Json &state, const std::string &theme,
|
||||
for (size_t i = 0; i < lineup_points.size(); ++i) {
|
||||
const auto &p = lineup_points[i];
|
||||
if (!p.is_array() || p.size() != 2 || !p[0].is_number_integer() ||
|
||||
!p[1].is_number_integer() || p[0] < 0 || p[0] > 18 || p[1] < 0 || p[1] > 8)
|
||||
!p[1].is_number_integer() || p[0] < 0 || p[0] > depth_max || p[1] < 0 || p[1] > lane_max)
|
||||
throw editor::Error("invalid_lineup_points");
|
||||
const std::pair point{p[0].get<int>(), p[1].get<int>()};
|
||||
if (!occupied.insert(point).second) throw editor::Error("invalid_lineup_points");
|
||||
@@ -244,7 +244,7 @@ std::string tactics_diagram(const Json &state, const std::string &theme,
|
||||
}
|
||||
}
|
||||
for (const auto &[x, y] : formation) {
|
||||
const double px = 25 + x / 18.0 * 82, py = 16 + y / 8.0 * 49;
|
||||
const double px = 25 + x / double(depth_max) * 82, py = 16 + y / double(lane_max) * 49;
|
||||
arrow(px, py, std::array<int, 4>{-16, -7, 7, 16}[size_t(values[0])], 0);
|
||||
dot(px, py);
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ Json demo_tactics();
|
||||
bool valid_demo_tactics(const Json &);
|
||||
std::string edit_demo_tactics(Json &, const Json &action);
|
||||
std::string tactics_diagram(const Json &, const std::string &theme,
|
||||
const Json &lineup_points = Json());
|
||||
const Json &lineup_points = Json(), int depth_max = 18, int lane_max = 8);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -30,7 +30,7 @@ std::shared_ptr<EngineBridge> EngineBridge::open(const fs::path &world, const fs
|
||||
}
|
||||
Json EngineBridge::snapshot() const {
|
||||
Json bundle = Json::object();
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup"})
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training"})
|
||||
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
|
||||
validate_engine_desk(bundle);
|
||||
return bundle;
|
||||
|
||||
@@ -13,6 +13,12 @@ Json engine_camp_command(const Json &bundle, const std::string &camp,
|
||||
Json engine_lineup_projection(const Json &bundle);
|
||||
Json engine_lineup_command(const Json &bundle, const Json &order,
|
||||
const std::string &request_id);
|
||||
Json engine_tactics_projection(const Json &bundle);
|
||||
Json engine_training_projection(const Json &bundle);
|
||||
Json engine_tactics_command(const Json &bundle, const Json &values,
|
||||
const std::string &request_id);
|
||||
Json engine_training_command(const Json &bundle, const Json &draft,
|
||||
const std::string &request_id);
|
||||
|
||||
// Single-session facade. Its owner serializes all calls on a background worker.
|
||||
// No RmlUI objects or callbacks cross this boundary.
|
||||
|
||||
@@ -17,16 +17,15 @@ void App::engine_poll() {
|
||||
engine_link_ = std::move(result.connection); engine_data_ = std::move(result.bundle);
|
||||
engine_response_ = std::move(result.response);
|
||||
if (engine_response_.value("messageType", "") == "command_result") {
|
||||
engine_dirty_ = true;
|
||||
const auto changed = engine_response_.value("changedReadKinds", Json::array());
|
||||
const bool lineup_changed = std::find(changed.begin(), changed.end(), Json("lineup")) != changed.end();
|
||||
engine_notice_ = lineup_changed ? "Aufstellung übernommen · Änderungen noch nicht gespeichert." : "Trainingslager gebucht · Änderungen noch nicht gespeichert.";
|
||||
engine_dirty_ = engine_base_dirty_ || engine_response_.at("newRevision") != engine_response_.at("previousRevision");
|
||||
engine_notice_ = engine_text(engine_response_.at("feedback")) + (engine_dirty_ ? " · Änderungen noch nicht gespeichert." : "");
|
||||
} else if (engine_response_.value("messageType", "") == "error") {
|
||||
engine_dirty_ = engine_base_dirty_;
|
||||
engine_notice_ = "Änderung abgewiesen: " + engine_response_.value("code", "unknown_error");
|
||||
} else if (engine_response_.value("messageType", "") == "saved") {
|
||||
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
|
||||
} else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
|
||||
engine_sports_reset();
|
||||
const auto &f = engine_data_.at("camps").at("data").at("focus");
|
||||
engine_focus_ = {{"condition", f.at("condition")}, {"technique", f.at("technique")}, {"play", f.at("play")}};
|
||||
if (engine_camp_.empty() && !engine_data_.at("camps").at("data").at("camps").empty())
|
||||
@@ -37,7 +36,9 @@ void App::engine_poll() {
|
||||
void App::engine_frame() {
|
||||
engine_poll();
|
||||
if (needs_render_) engine_render();
|
||||
engine_sports_update();
|
||||
render_popup(); context_->Update();
|
||||
if (center_selects(*doc_)) context_->Update();
|
||||
if (menu_ == "lineup" && lineup_roster_scroll_) {
|
||||
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
|
||||
lineup_roster_scroll_.reset();
|
||||
@@ -71,6 +72,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
const auto type = event.GetType(); auto *target = event.GetTargetElement();
|
||||
if (type == "keydown") keyboard_navigation_ = true;
|
||||
if (type == "mousedown") keyboard_navigation_ = false;
|
||||
if (engine_sports_event(event)) return;
|
||||
Rml::ElementFormControl *range = nullptr;
|
||||
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
|
||||
if (node->GetId().starts_with("camp-focus-") && !node->HasAttribute("disabled")) {
|
||||
@@ -96,7 +98,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) {
|
||||
if (!popup_.empty()) { popup_.clear(); confirm_ = {}; dirty_ = true; }
|
||||
else if (!engine_busy_ && !engine_player_.empty()) { focus_after_render_ = "lineup-detail-" + engine_player_ + "-0"; engine_player_.clear(); refresh(); }
|
||||
else if (!engine_busy_ && !menu_.empty()) { menu_.clear(); refresh(); }
|
||||
else if (!engine_busy_ && !menu_.empty()) { if (menu_ == "training" || menu_ == "tactics") engine_sports_reset(); menu_.clear(); refresh(); }
|
||||
else engine_quit();
|
||||
event.StopImmediatePropagation(); return;
|
||||
}
|
||||
@@ -132,9 +134,11 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
|
||||
return;
|
||||
}
|
||||
if (engine_sports_action(action, id, node)) return;
|
||||
if (engine_lineup_action(action, id, node)) return;
|
||||
if (action == "close") { menu_.clear(); refresh(); }
|
||||
else if (action == "engine-open" && id == "save") engine_save();
|
||||
else if (action == "engine-open" && (id == "training" || id == "tactics")) { engine_sports_reset(); menu_ = id; refresh(); }
|
||||
else if (action == "engine-open" && id == "lineup") { menu_ = "lineup"; lineup_selected_.clear(); lineup_reset_scroll_ = true; refresh(); }
|
||||
else if (action == "engine-open" && id == "camp") { menu_ = "camp"; refresh(); }
|
||||
else if (action == "camp-region") { selections_["camp-region"] = id; refresh(); }
|
||||
@@ -153,5 +157,5 @@ void App::engine_event(Rml::Event &event) {
|
||||
}
|
||||
Json App::engine_snapshot() const {
|
||||
return {{"mode", engine_mode_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"response", engine_response_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
{"response", engine_response_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <set>
|
||||
|
||||
@@ -168,4 +169,112 @@ Json engine_lineup_command(const Json &bundle, const Json &order, const std::str
|
||||
{"expectedRevision", meta.at("stateRevision")}, {"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", "lineup.commit"}, {"payload", {{"order", order}}}};
|
||||
}
|
||||
|
||||
namespace {
|
||||
Json sports_command(const Json &bundle, const char *kind, const Json &payload, const std::string &id) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
require(!id.empty() && commands.is_array() && std::find(commands.begin(), commands.end(), Json(kind)) != commands.end(),
|
||||
"Diese Änderung ist im aktuellen Kontext nicht verfügbar.");
|
||||
return {{"messageType", "command"}, {"requestId", id}, {"careerId", meta.at("careerId")},
|
||||
{"expectedRevision", meta.at("stateRevision")}, {"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", kind}, {"payload", payload}};
|
||||
}
|
||||
int whole_in_range(const Json &v, int lo, int hi) {
|
||||
require(v.is_number_integer() && v.get<int64_t>() >= lo && v.get<int64_t>() <= hi,
|
||||
"Wert außerhalb des verfügbaren Bereichs.");
|
||||
return v.get<int>();
|
||||
}
|
||||
}
|
||||
Json engine_tactics_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &data = lineup_read(bundle, "tactics");
|
||||
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Taktik gehört einer anderen Mannschaft.");
|
||||
require(data.at("controls").is_array() && data.at("controls").size() == 8, "Unvollständige Taktikeinstellungen.");
|
||||
Json out = {{"values", Json::array()}, {"limits", Json::array()}, {"minima", Json::array()}, {"labels", Json::array()}};
|
||||
// These bounds describe the existing board's visual capacity, not engine rules.
|
||||
const std::array<int, 8> visual_limits{3,3,3,3,1,1,1,11};
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
const Json *control = nullptr;
|
||||
for (const auto &item : data.at("controls")) if (item.at("id") == "tactic:" + std::to_string(i)) {
|
||||
require(!control, "Doppelte Taktik-ID."); control = &item;
|
||||
}
|
||||
require(control, "Taktikeinstellung fehlt.");
|
||||
const auto &range = control->at("range");
|
||||
const int lo = whole_in_range(range.at("min"), 0, visual_limits[size_t(i)]);
|
||||
const int hi = whole_in_range(range.at("max"), lo, visual_limits[size_t(i)]);
|
||||
require(range.at("step") == 1, "Diese Taktikschrittweite wird noch nicht dargestellt.");
|
||||
out["values"].push_back(whole_in_range(control->at("value"), lo, hi));
|
||||
out["limits"].push_back(hi); out["minima"].push_back(lo);
|
||||
out["labels"].push_back(control->at("label").at("text"));
|
||||
}
|
||||
const auto board = engine_lineup_projection(bundle).at("board");
|
||||
require(board.at("points").size() == 11, "Die Taktiktafel benötigt gelieferte Spielfeldpositionen.");
|
||||
std::set<std::string> occupied;
|
||||
for (const auto &point : board.at("points")) require(point.is_array() && occupied.insert(point.dump()).second, "Spielfeldpositionen sind nicht vollständig bekannt.");
|
||||
out["board"] = board;
|
||||
return out;
|
||||
}
|
||||
Json engine_tactics_command(const Json &bundle, const Json &values, const std::string &id) {
|
||||
const auto base = engine_tactics_projection(bundle);
|
||||
require(values.is_array() && values.size() == 8, "Acht Taktikwerte werden benötigt.");
|
||||
for (size_t i = 0; i < 8; ++i) (void)whole_in_range(values[i], base.at("minima")[i], base.at("limits")[i]);
|
||||
return sports_command(bundle, "tactics.commit", {{"values", values}}, id);
|
||||
}
|
||||
Json engine_training_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &data = lineup_read(bundle, "training"), &squad = lineup_read(bundle, "squad");
|
||||
const auto &team = bundle.at("desktop").at("meta").at("scope").at("teamId");
|
||||
require(data.at("teamId") == team && squad.at("team").at("id") == team, "Training gehört einer anderen Mannschaft.");
|
||||
Json out = {{"club", team}, {"types", Json::array()}, {"areas", Json::array()}, {"players", Json::object()},
|
||||
{"roster", Json::array()}, {"initialized", data.at("initialized")}, {"limits", data.at("limits")}};
|
||||
const auto group = [&](const char *name, const std::vector<std::string> &ids) {
|
||||
require(data.at(name).is_array() && data.at(name).size() == ids.size(), "Unvollständiger Trainingsplan.");
|
||||
for (const auto &id : ids) {
|
||||
const Json *chosen = nullptr;
|
||||
for (const auto &item : data.at(name)) if (item.at("id") == id) { require(!chosen, "Doppelte Trainings-ID."); chosen = &item; }
|
||||
require(chosen && chosen->at("min") == 1 && chosen->at("max") == 3, "Trainingsgruppe wird nicht unterstützt.");
|
||||
out[name].push_back(whole_in_range(chosen->at("allocation"), 1, 3));
|
||||
}
|
||||
};
|
||||
group("types", {"training:type/goalkeepers", "training:type/defence", "training:type/midfield", "training:type/attack"});
|
||||
group("areas", {"training:area/fitness", "training:area/skill", "training:area/corner", "training:area/free_kick", "training:area/tackling", "training:area/pass", "training:area/shot", "training:area/speed", "training:area/game"});
|
||||
std::map<std::string, Json> people;
|
||||
for (const auto &row : squad.at("players")) require(people.emplace(row.at("player").at("id").get<std::string>(), row).second, "Doppelter Kaderspieler.");
|
||||
for (const auto &row : data.at("players")) {
|
||||
const auto id = row.at("playerId").get<std::string>();
|
||||
require(people.contains(id) && !out.at("players").contains(id), "Fremder oder doppelter Trainingsspieler.");
|
||||
const auto &person = people.at(id);
|
||||
out["players"][id] = {{"intensity", whole_in_range(row.at("intensity"), 0, 3)}, {"focus", whole_in_range(row.at("focus"), 0, 7)}};
|
||||
out["roster"].push_back({{"id", id}, {"name", person.at("player").at("name")}, {"positions", person.at("player").at("positions")},
|
||||
{"attributes", {{"strength", metric_value(person, "strength")}}}});
|
||||
}
|
||||
require(out.at("players").size() == people.size(), "Trainingskader ist unvollständig.");
|
||||
const int automation = whole_in_range(data.at("automation"), 0, 255);
|
||||
// Reflect the original screen's four stored subordinate flags. This client
|
||||
// never writes the automation byte; only the engine changes it on commit.
|
||||
out["autos"] = Json::array({bool(automation & 2), bool(automation & 4), bool(automation & 8), bool(automation & 16)});
|
||||
out["master_auto"] = bool(automation & 1);
|
||||
return out;
|
||||
}
|
||||
Json engine_training_command(const Json &bundle, const Json &draft, const std::string &id) {
|
||||
const auto base = engine_training_projection(bundle);
|
||||
for (const auto *group : {"types", "areas"}) {
|
||||
require(draft.at(group).is_array() && draft.at(group).size() == base.at(group).size(), "Trainingsplan ist unvollständig.");
|
||||
for (const auto &n : draft.at(group)) (void)whole_in_range(n, 1, 3);
|
||||
}
|
||||
int types = 0, fitness = 0, areas = 0;
|
||||
for (const auto &v : draft.at("types")) types += v.get<int>();
|
||||
for (size_t i = 0; i < 9; ++i) (i < 2 ? fitness : areas) += draft.at("areas")[i].get<int>();
|
||||
require(types <= base.at("limits").at("types").get<int>() && fitness <= base.at("limits").at("fitnessAndSkill").get<int>() && areas <= base.at("limits").at("otherAreas").get<int>(), "Ballbudget überschritten.");
|
||||
require(draft.at("players").is_object() && draft.at("players").size() == base.at("players").size(), "Trainingskader ist unvollständig.");
|
||||
Json changed = Json::array();
|
||||
for (const auto &[pid, row] : draft.at("players").items()) {
|
||||
require(base.at("players").contains(pid) && row.at("focus") == base.at("players").at(pid).at("focus"), "Spielerschwerpunkte sind noch schreibgeschützt.");
|
||||
if (row.at("intensity") != base.at("players").at(pid).at("intensity"))
|
||||
changed.push_back({{"playerId", pid}, {"intensity", whole_in_range(row.at("intensity"), 1, 3)}});
|
||||
}
|
||||
return sports_command(bundle, "training.commit", {{"types", draft.at("types")}, {"areas", draft.at("areas")}, {"players", changed}}, id);
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -56,6 +56,9 @@ void App::engine_render() {
|
||||
esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div></div>";
|
||||
bool lineup_available = false;
|
||||
try { (void)engine_lineup_projection(engine_data_); lineup_available = true; } catch (const std::exception &) {}
|
||||
bool training_available = false, tactics_available = false;
|
||||
try { (void)engine_training_projection(engine_data_); training_available = true; } catch (const std::exception &) {}
|
||||
try { (void)engine_tactics_projection(engine_data_); tactics_available = true; } catch (const std::exception &) {}
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
@@ -88,16 +91,19 @@ void App::engine_render() {
|
||||
const auto route = id.substr(4);
|
||||
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
const bool supported = (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
const bool supported = (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
|
||||
}
|
||||
}
|
||||
out += "</div>";
|
||||
if (menu_ == "training") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Training", render_training()) + "</div>";
|
||||
if (menu_ == "tactics") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Taktik", render_tactics()) + "</div>";
|
||||
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
|
||||
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
|
||||
}
|
||||
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
element("canvas")->SetInnerRML(out); ++document_generation_;
|
||||
scale_chalk_shadow();
|
||||
if (!engine_player_.empty()) {
|
||||
Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, "#lineup-underlay button,#window-close");
|
||||
for (auto *node : underlay) { node->SetAttribute("disabled", true); node->SetProperty("pointer-events", "none"); }
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::engine_sports_reset() {
|
||||
try { engine_training_draft_ = engine_training_projection(engine_data_); } catch (const std::exception &) { engine_training_draft_ = Json(); }
|
||||
try { engine_tactics_draft_ = engine_tactics_projection(engine_data_); } catch (const std::exception &) { engine_tactics_draft_ = Json(); }
|
||||
}
|
||||
bool App::engine_sports_dirty() const {
|
||||
if (menu_ == "training") return !engine_training_draft_.is_null() &&
|
||||
(!engine_training_draft_.at("initialized").get<bool>() || engine_training_draft_ != engine_training_projection(engine_data_));
|
||||
if (menu_ == "tactics") return !engine_tactics_draft_.is_null() &&
|
||||
engine_tactics_draft_.at("values") != engine_tactics_projection(engine_data_).at("values");
|
||||
return false;
|
||||
}
|
||||
std::string App::engine_sports_footer() {
|
||||
const bool training = menu_ == "training";
|
||||
return "<p id=\"sports-note\" class=\"small muted\" style=\"position:absolute;" +
|
||||
(training ? rect(0, 1580, 1060, 112) : rect(0, 1514, 2300, 112)) + "\"></p>"
|
||||
"<div class=\"row\" style=\"position:absolute;" +
|
||||
(training ? rect(0, 1720, 1060, 94) : rect(0, 1650, 2300, 94)) + "\">" +
|
||||
btn("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\" style=\"width:440dp;height:94dp;\"") +
|
||||
btn("sports-apply", "Anwenden", "primary", "id=\"sports-apply\" style=\"width:440dp;height:94dp;\"") + "</div>";
|
||||
}
|
||||
void App::engine_sports_update() {
|
||||
if (menu_ != "training" && menu_ != "tactics") return;
|
||||
bool changed = false, valid = false; std::string note;
|
||||
try {
|
||||
changed = engine_sports_dirty();
|
||||
if (menu_ == "training") (void)engine_training_command(engine_data_, engine_training_draft_, "request:validate-only");
|
||||
else (void)engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), "request:validate-only");
|
||||
valid = true;
|
||||
note = changed ? "Entwurf · Änderungen werden erst mit Anwenden übernommen." : engine_notice_;
|
||||
if (menu_ == "training" && !engine_training_draft_.at("initialized").get<bool>()) note = "Mit Anwenden wird das Training erstmals eingerichtet.";
|
||||
} catch (const std::exception &e) { note = e.what(); }
|
||||
if (auto *button = element("sports-apply")) {
|
||||
if (valid && changed && engine_fresh_ && !engine_busy_) button->RemoveAttribute("disabled");
|
||||
else button->SetAttribute("disabled", true);
|
||||
}
|
||||
if (auto *button = element("sports-reset")) {
|
||||
if (changed && !engine_busy_) button->RemoveAttribute("disabled");
|
||||
else button->SetAttribute("disabled", true);
|
||||
}
|
||||
if (auto *text = element("sports-note")) {
|
||||
const auto value = esc(engine_busy_ ? engine_operation_ : note);
|
||||
if (text->GetInnerRML() != value) text->SetInnerRML(value);
|
||||
text->SetProperty("color", valid ? "var(--muted)" : "var(--danger)");
|
||||
}
|
||||
}
|
||||
bool App::engine_sports_action(const std::string &action, const std::string &id, Rml::Element *target) {
|
||||
if (menu_ != "training" && menu_ != "tactics") return false;
|
||||
if (action == "close") { engine_sports_reset(); menu_.clear(); refresh(); return true; }
|
||||
if (action == "sports-reset") { engine_sports_reset(); focus_after_render_ = "sports-reset"; refresh(); return true; }
|
||||
if (action == "sports-apply" && engine_fresh_ && engine_sports_dirty()) {
|
||||
const auto command = menu_ == "training"
|
||||
? engine_training_command(engine_data_, engine_training_draft_, editor::new_id("request:ui-"))
|
||||
: engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), editor::new_id("request:ui-"));
|
||||
confirmation(menu_ == "training" ? "Diesen Trainingsplan übernehmen?" : "Diese Taktikeinstellungen übernehmen?", [this, command] {
|
||||
auto link = engine_link_;
|
||||
engine_start("Änderungen werden übernommen …", [link, command] {
|
||||
auto response = link->command(command); return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
}, true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "tactic-cycle" && menu_ == "tactics" && engine_fresh_) {
|
||||
const int i = std::stoi(id); if (i < 0 || i > 6) return true;
|
||||
const int lo = engine_tactics_draft_.at("minima")[size_t(i)], hi = engine_tactics_draft_.at("limits")[size_t(i)];
|
||||
auto &v = engine_tactics_draft_["values"][size_t(i)]; v = v.get<int>() == hi ? lo : v.get<int>() + 1;
|
||||
last_tactic_ = i; focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
if (action == "training-ball" && menu_ == "training" && engine_fresh_) {
|
||||
const auto group = target->GetAttribute<Rml::String>("data-group", "");
|
||||
const int i = std::stoi(id), value = target->GetAttribute<int>("data-value", 0);
|
||||
if (value < 1 || value > 3) return true;
|
||||
if ((group == "type" && i >= 0 && i < 4) || (group == "area" && i >= 0 && i < 9))
|
||||
engine_training_draft_[group == "type" ? "types" : "areas"][size_t(i)] = value;
|
||||
else if (group == "player") {
|
||||
const auto player = target->GetAttribute<Rml::String>("data-player", "");
|
||||
if (engine_training_draft_.at("players").contains(player)) engine_training_draft_["players"][player]["intensity"] = value;
|
||||
}
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
return action.starts_with("training-") || action.starts_with("sports-");
|
||||
}
|
||||
bool App::engine_sports_event(Rml::Event &event) {
|
||||
if (menu_ != "tactics" || !popup_.empty() || engine_busy_) return false;
|
||||
Rml::ElementFormControl *range = nullptr;
|
||||
for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode())
|
||||
if (node->GetId() == "tactic-effort") { range = dynamic_cast<Rml::ElementFormControl *>(node); break; }
|
||||
if (!range) return false;
|
||||
const auto type = event.GetType();
|
||||
int value = std::stoi(range->GetValue()); bool change = type == "input" || type == "change";
|
||||
if (type == "mouseup") { focus_after_render_ = "tactic-effort"; dirty_ = true; }
|
||||
if (type == "keydown") {
|
||||
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
const int lo = engine_tactics_draft_.at("minima")[7], hi = engine_tactics_draft_.at("limits")[7];
|
||||
if (key == Rml::Input::KI_HOME) value = lo;
|
||||
else if (key == Rml::Input::KI_END) value = hi;
|
||||
else if (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN) value = std::max(lo, value - 1);
|
||||
else if (key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_UP) value = std::min(hi, value + 1);
|
||||
else return false;
|
||||
event.StopImmediatePropagation(); range->SetValue(std::to_string(value)); change = true;
|
||||
}
|
||||
if (!change) return false;
|
||||
engine_tactics_draft_["values"][7] = value; last_tactic_ = 7;
|
||||
element("tactic-effort-value")->SetInnerRML(std::string(size_t(value), '!'));
|
||||
element("tactic-hint")->SetInnerRML(esc(engine_tactics_draft_.at("labels")[7].get<std::string>() + ": " + std::to_string(value) + " / " + std::to_string(engine_tactics_draft_.at("limits")[7].get<int>())));
|
||||
engine_sports_update(); dirty_ = true; return true;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
bool engine_mode_ = false, engine_busy_ = false, engine_dirty_ = false, engine_fresh_ = false, engine_base_dirty_ = false;
|
||||
std::shared_ptr<EngineBridge> engine_link_;
|
||||
std::future<EngineReply> engine_job_;
|
||||
Json engine_data_, engine_response_, engine_focus_;
|
||||
Json engine_data_, engine_response_, engine_focus_, engine_training_draft_, engine_tactics_draft_;
|
||||
std::string engine_camp_, engine_operation_, engine_notice_, engine_player_;
|
||||
void engine_start(std::string, std::function<EngineReply()>, bool mutating = false);
|
||||
void engine_poll();
|
||||
@@ -15,4 +15,10 @@
|
||||
std::string engine_lineup_controls();
|
||||
std::string engine_player_profile(const Json &);
|
||||
bool engine_lineup_action(const std::string &, const std::string &, Rml::Element *);
|
||||
void engine_sports_reset();
|
||||
bool engine_sports_dirty() const;
|
||||
void engine_sports_update();
|
||||
std::string engine_sports_footer();
|
||||
bool engine_sports_action(const std::string &, const std::string &, Rml::Element *);
|
||||
bool engine_sports_event(Rml::Event &);
|
||||
Json engine_snapshot() const;
|
||||
@@ -1,4 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
std::string sports_number(const Json &v) { return v.is_number_integer() ? number(v.get<int64_t>()) : "—"; }
|
||||
}
|
||||
std::string App::training_balls(const std::string &group, int index, int value,
|
||||
bool automatic, const std::string &player,
|
||||
int size, int gap, bool overtraining) {
|
||||
@@ -20,8 +23,8 @@ std::string App::training_balls(const std::string &group, int index, int value,
|
||||
return body + "</div>";
|
||||
}
|
||||
std::string App::render_training() {
|
||||
const auto s = snap();
|
||||
const auto &t = s.state.at("training"), &automatic = t.at("autos");
|
||||
const auto t = engine_mode_ ? engine_training_draft_ : snap().state.at("training");
|
||||
const auto &automatic = t.at("autos");
|
||||
const std::array<const char *, 9> skills = {
|
||||
"Kondition", "Technik", "Eckball", "Freistoß", "Zweikampf",
|
||||
"Pass", "Schuss", "Schnelligkeit", "Teamplay"};
|
||||
@@ -43,8 +46,8 @@ std::string App::render_training() {
|
||||
"</span><span style=\"width:35dp;\">:</span><div "
|
||||
"style=\"width:220dp;\">" +
|
||||
training_balls("area", int(i), t["areas"][i].get<int>(),
|
||||
automatic[i < 2 ? 1 : 2].get<bool>(), {}, 56, 10,
|
||||
i >= 2 && skill_total > 14) +
|
||||
!engine_mode_ && automatic[i < 2 ? 1 : 2].get<bool>(), {}, 56, 10,
|
||||
!engine_mode_ && i >= 2 && skill_total > 14) +
|
||||
"</div></div>";
|
||||
body += "</div><div class=\"training-pitch\">";
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@@ -59,7 +62,7 @@ std::string App::render_training() {
|
||||
std::to_string(30 + (i % 2) * 277) +
|
||||
"dp;top:" + std::to_string(26 + (i / 2) * 176) + "dp;\">" +
|
||||
training_balls("type", i, t["types"][size_t(i)].get<int>(),
|
||||
automatic[0].get<bool>(), {}, 48, 5) +
|
||||
!engine_mode_ && automatic[0].get<bool>(), {}, 48, 5) +
|
||||
"</div>";
|
||||
body += "</div>";
|
||||
const std::array<const char *, 4> auto_names = {
|
||||
@@ -78,19 +81,19 @@ std::string App::render_training() {
|
||||
(automatic[i].get<bool>() ? "primary" : ""),
|
||||
"id=\"training-auto-" + std::to_string(i) + "\" data-id=\"" +
|
||||
std::to_string(i) + "\" style=\"position:absolute;" +
|
||||
rect(a[0], a[1], a[2], a[3]) + "\"");
|
||||
rect(a[0], a[1], a[2], a[3]) + "\" " + (engine_mode_ ? "disabled" : ""));
|
||||
}
|
||||
const bool all_auto = std::all_of(automatic.begin(), automatic.end(),
|
||||
const bool all_auto = engine_mode_ ? t.at("master_auto").get<bool>() : std::all_of(automatic.begin(), automatic.end(),
|
||||
[](const auto &v) { return v == true; });
|
||||
body += btn("training-auto-all", "Automatisch",
|
||||
std::string("training-auto ") + (all_auto ? "primary" : ""),
|
||||
"id=\"training-auto-all\" style=\"position:absolute;" +
|
||||
rect(604, 1232, 440, 76) + "\"");
|
||||
rect(604, 1232, 440, 76) + "\" " + (engine_mode_ ? "disabled" : ""));
|
||||
body += "<p class=\"training-budget\">Arten: " + std::to_string(type_total) +
|
||||
" / 8 Bälle ·<br/>Kondition/Technik: " +
|
||||
" / " + std::to_string(engine_mode_ ? t.at("limits").at("types").get<int>() : 8) + " Bälle ·<br/>Kondition/Technik: " +
|
||||
std::to_string(t["areas"][0].get<int>() + t["areas"][1].get<int>()) +
|
||||
" / 4 ·<br/>Fertigkeiten: " + std::to_string(skill_total) + " / 18" +
|
||||
(skill_total > 14 ? " · hohe<br/>Belastung" : "") +
|
||||
" / " + std::to_string(engine_mode_ ? t.at("limits").at("fitnessAndSkill").get<int>() : 4) + " ·<br/>Fertigkeiten: " + std::to_string(skill_total) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("otherAreas").get<int>() : 18) +
|
||||
(!engine_mode_ && skill_total > 14 ? " · hohe<br/>Belastung" : "") +
|
||||
"</p><div id=\"training-roster\" class=\"training-roster\"><div "
|
||||
"class=\"training-row "
|
||||
"training-header\">";
|
||||
@@ -102,7 +105,9 @@ std::string App::render_training() {
|
||||
"\" style=\"width:" + std::to_string(widths[i]) + "dp;\">" +
|
||||
headings[i] + "</div>";
|
||||
body += "</div>";
|
||||
const auto players = world_->squad(t.value("club", ""));
|
||||
std::vector<const Json *> players;
|
||||
if (engine_mode_) { for (const auto &p : t.at("roster")) players.push_back(&p); }
|
||||
else players = world_->squad(t.value("club", ""));
|
||||
for (size_t i = 0; i < players.size(); ++i) {
|
||||
const auto *p = players[i];
|
||||
const auto id = p->value("id", "");
|
||||
@@ -121,30 +126,29 @@ std::string App::render_training() {
|
||||
"class=\"training-name-text\" title=\"" +
|
||||
esc(world_->name(*p)) + "\">" + esc(world_->name(*p)) +
|
||||
"</span></div><div style=\"width:95dp;\">" +
|
||||
std::to_string(
|
||||
p->value("attributes", Json::object()).value("strength", 0)) +
|
||||
sports_number(p->value("attributes", Json::object()).value("strength", Json())) +
|
||||
"</div><div style=\"width:330dp;\">";
|
||||
auto selector =
|
||||
select("training-focus-" + std::to_string(i), focuses,
|
||||
std::to_string(row.value("focus", 0)), "training-focus");
|
||||
const auto end = selector.find('>');
|
||||
selector.insert(end, " data-player=\"" + esc(id) + "\" " +
|
||||
(automatic[3] == true ? "disabled" : ""));
|
||||
(engine_mode_ || automatic[3] == true ? "disabled" : ""));
|
||||
body += selector + "</div><div style=\"width:217dp;\">" +
|
||||
training_balls("player", int(i), row.value("intensity", 0),
|
||||
automatic[3].get<bool>(), id, 50, 9) +
|
||||
!engine_mode_ && automatic[3].get<bool>(), id, 50, 9) +
|
||||
"</div></div>";
|
||||
}
|
||||
return body + "</div>";
|
||||
return body + "</div>" + (engine_mode_ ? engine_sports_footer() : "");
|
||||
}
|
||||
std::string App::render_tactics() {
|
||||
const auto t = snap().state.at("tactics");
|
||||
const std::array<const char *, 8> names = {
|
||||
const auto t = engine_mode_ ? engine_tactics_draft_ : snap().state.at("tactics");
|
||||
const std::array<std::string, 8> names = engine_mode_ ? t.at("labels").get<std::array<std::string, 8>>() : std::array<std::string, 8>{
|
||||
"Defensiv / offensiv", "Pass-/Schussbild unten",
|
||||
"Pass-/Schussbild Mitte", "Pass-/Schussbild links",
|
||||
"Flache / hohe Bälle", "Flügelbild links",
|
||||
"Flügelbild rechts", "Einsatz"};
|
||||
const std::array<int, 8> limits = {3, 3, 3, 3, 1, 1, 1, 11};
|
||||
const std::array<int, 8> limits = engine_mode_ ? t.at("limits").get<std::array<int, 8>>() : std::array<int, 8>{3, 3, 3, 3, 1, 1, 1, 11};
|
||||
const std::array<std::array<int, 4>, 7> areas = {{{19, 9, 104, 62},
|
||||
{61, 108, 50, 34},
|
||||
{63, 84, 54, 30},
|
||||
@@ -154,7 +158,7 @@ std::string App::render_tactics() {
|
||||
{205, 10, 58, 37}}};
|
||||
std::string body =
|
||||
"<div class=\"tactics-board\"><div class=\"tactics-surface\"></div>" +
|
||||
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, snap().state.value("lineup", Json::object()).value("points", Json()))), 2300,
|
||||
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, engine_mode_ ? t.at("board").at("points") : snap().state.value("lineup", Json::object()).value("points", Json()), engine_mode_ ? t.at("board").at("depth_max").get<int>() : 18, engine_mode_ ? t.at("board").at("lane_max").get<int>() : 8)), 2300,
|
||||
1864);
|
||||
for (size_t i = 0; i < 7; ++i) {
|
||||
const auto a = areas[i];
|
||||
@@ -173,11 +177,11 @@ std::string App::render_tactics() {
|
||||
"id=\"tactic-effort-value\" class=\"tactic-effort-marks\">" +
|
||||
std::string(size_t(effort), '!') +
|
||||
"</span></div><input type=\"range\" id=\"tactic-effort\" "
|
||||
"data-input=\"tactic-effort\" min=\"0\" max=\"11\" step=\"1\" value=\"" +
|
||||
"data-input=\"tactic-effort\" min=\"" + std::to_string(engine_mode_ ? t.at("minima")[7].get<int>() : 0) + "\" max=\"" + std::to_string(limits[7]) + "\" step=\"1\" value=\"" +
|
||||
std::to_string(effort) +
|
||||
"\"/></div><p id=\"tactic-hint\" class=\"tactic-hint\">" +
|
||||
esc(names[size_t(last_tactic_)]) + ": " +
|
||||
std::to_string(t["values"][size_t(last_tactic_)].get<int>()) + " / " +
|
||||
std::to_string(limits[size_t(last_tactic_)]) + "</p></div>";
|
||||
return body;
|
||||
return body + (engine_mode_ ? engine_sports_footer() : "");
|
||||
}
|
||||
@@ -1514,6 +1514,7 @@ public:
|
||||
#include "modern/ui/engine_screens.inc"
|
||||
#include "modern/ui/engine_controls.inc"
|
||||
#include "modern/ui/engine_lineup.inc"
|
||||
#include "modern/ui/engine_sports.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,7 @@ using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup <world.obw> <new-output-directory>");
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports <world.obw> <new-output-directory>");
|
||||
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
|
||||
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
|
||||
if (std::string(argv[1]) == "prepare") {
|
||||
@@ -57,6 +57,29 @@ int main(int argc, char **argv) {
|
||||
link = EngineBridge::open(world, out / "lineup.obs"); const auto loaded = link->snapshot(); write("lineup-loaded.json", loaded);
|
||||
if (loaded.at("lineup").at("data").at("order") != order) throw std::runtime_error("lineup lost during OBS round trip");
|
||||
}
|
||||
if (std::string(argv[1]) == "verify-sports") {
|
||||
auto tactics = engine_tactics_projection(before); tactics["values"][0] = 1; tactics["values"][7] = 7;
|
||||
const auto tc = engine_tactics_command(before, tactics.at("values"), "request:sports-tactics");
|
||||
const auto tr = link->command(tc); write("tactics-command.json", tc); write("tactics-response.json", tr);
|
||||
if (tr.value("messageType", "") != "command_result" || link->command(tc) != tr) throw std::runtime_error(tr.dump());
|
||||
const auto tactic_after = link->snapshot(); write("tactics-after.json", tactic_after);
|
||||
if (engine_tactics_projection(tactic_after).at("values") != tactics.at("values")) throw std::runtime_error("tactics not applied");
|
||||
auto training = engine_training_projection(tactic_after);
|
||||
training["types"] = Json::array({1,3,2,2}); training["areas"] = Json::array({1,3,3,1,2,2,2,2,2});
|
||||
const auto player = training.at("roster")[0].at("id").get<std::string>(); training["players"][player]["intensity"] = 3;
|
||||
const auto pc = engine_training_command(tactic_after, training, "request:sports-training");
|
||||
const auto pr = link->command(pc); write("training-command.json", pc); write("training-response.json", pr);
|
||||
if (pr.value("messageType", "") != "command_result" || link->command(pc) != pr) throw std::runtime_error(pr.dump());
|
||||
const auto after = link->snapshot(); write("sports-after.json", after); const auto actual = engine_training_projection(after);
|
||||
if (actual.at("types") != training.at("types") || actual.at("areas") != training.at("areas") || actual.at("players").at(player).at("intensity") != 3 || !actual.at("initialized").get<bool>()) throw std::runtime_error("training not applied");
|
||||
if (after.at("desktop").at("data").at("accounts") != before.at("desktop").at("data").at("accounts")) throw std::runtime_error("sports changed account");
|
||||
auto stale = pc; stale["requestId"] = "request:stale-sports";
|
||||
const auto rejected = link->command(stale); write("sports-rejected.json", rejected);
|
||||
if (rejected.value("code", "") != "stale_revision" || link->snapshot() != after) throw std::runtime_error("stale sports request changed state");
|
||||
write("sports-saved.json", link->save_copy(out / "sports.obs")); link.reset();
|
||||
link = EngineBridge::open(world, out / "sports.obs"); const auto loaded = link->snapshot(); write("sports-loaded.json", loaded);
|
||||
if (engine_tactics_projection(loaded).at("values") != tactics.at("values") || engine_training_projection(loaded).at("types") != training.at("types") || engine_training_projection(loaded).at("areas") != training.at("areas")) throw std::runtime_error("sports lost in OBS round trip");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
@@ -98,6 +99,37 @@ int main() {
|
||||
require(engine_lineup_projection(hidden_metric).at("rows")[0].at("strength").is_null(), "unavailable metric exposed its stale numeric value");
|
||||
auto unknown_point = squad_bundle; unknown_point["lineup"]["data"]["positions"][0]["depth"] = -1;
|
||||
require(engine_lineup_projection(unknown_point).at("board").at("points")[0].is_null(), "unknown pitch position was fabricated");
|
||||
auto sports = squad_bundle;
|
||||
for (auto &item : sports) { item["meta"]["scope"]["allowedCommands"].push_back("training.commit"); item["meta"]["scope"]["allowedCommands"].push_back("tactics.commit"); }
|
||||
const auto sports_meta = sports.at("desktop").at("meta");
|
||||
// Eleven real identifiers/positions are required by the existing tactical board.
|
||||
auto &sl = sports["lineup"]["data"]; auto &sp = sports["squad"]["data"]["players"];
|
||||
for (int i = 4; i < 11; ++i) { auto p = sp[0]; p["player"]["id"] = "player:" + std::to_string(i); sp.push_back(p); sl["order"].push_back(p["player"]["id"]); sl["rows"].push_back({{"playerId",p["player"]["id"]},{"role","starter"}}); }
|
||||
sl["positions"] = Json::array();
|
||||
for (int i = 0; i < 11; ++i) sl["positions"].push_back({{"playerId","player:"+std::to_string(i)},{"depth",i},{"lane",i%9}});
|
||||
Json controls = Json::array(); const std::array<int,8> ranges{3,3,3,3,1,1,1,11};
|
||||
for (int i = 0; i < 8; ++i) controls.push_back({{"id","tactic:"+std::to_string(i)},{"label",{{"text","Backend label "+std::to_string(i)}}},{"value",0},{"range",{{"min",0},{"max",ranges[size_t(i)]},{"step",1}}}});
|
||||
sports["tactics"] = {{"messageType","snapshot"},{"meta",sports_meta},{"data",{{"kind","tactics"},{"teamId","club:6"},{"controls",controls}}}};
|
||||
Json types = Json::array(), areas = Json::array(), training_players = Json::array();
|
||||
for (const auto &name : {"goalkeepers","defence","midfield","attack"}) types.push_back({{"id",std::string("training:type/")+name},{"allocation",2},{"min",1},{"max",3}});
|
||||
for (const auto &name : {"fitness","skill","corner","free_kick","tackling","pass","shot","speed","game"}) areas.push_back({{"id",std::string("training:area/")+name},{"allocation",2},{"min",1},{"max",3}});
|
||||
for (const auto &p : sports.at("squad").at("data").at("players")) training_players.push_back({{"playerId",p["player"]["id"]},{"focus",0},{"intensity",2}});
|
||||
sports["training"] = {{"messageType","snapshot"},{"meta",sports_meta},{"data",{{"kind","training"},{"teamId","club:6"},{"types",types},{"areas",areas},{"players",training_players},{"limits",{{"types",8},{"fitnessAndSkill",4},{"otherAreas",18}}},{"initialized",false},{"automation",0}}}};
|
||||
const auto sports_original = sports;
|
||||
auto tactics = engine_tactics_projection(sports);
|
||||
require(tactics.at("labels")[3] == "Backend label 3" && tactics.at("values")[0] == 0, "tactics invented labels or discarded known zero");
|
||||
tactics["values"][7] = 11;
|
||||
require(engine_tactics_command(sports,tactics.at("values"),"request:t").at("payload").at("values")[7] == 11,"tactics payload wrong");
|
||||
tactics["values"][7] = 12; rejects([&] { engine_tactics_command(sports,tactics.at("values"),"request:t"); });
|
||||
auto training = engine_training_projection(sports);
|
||||
require(training.at("roster").size() == 11 && training.at("roster")[0].at("attributes").at("strength") == 91,"training used catalogue values or a guessed roster");
|
||||
training["types"][0] = 1; training["players"]["player:0"]["intensity"] = 3;
|
||||
auto training_cmd = engine_training_command(sports,training,"request:p");
|
||||
require(training_cmd.at("payload").at("players").size() == 1 && training_cmd.at("owner").at("managerId") == "manager:99" && sports == sports_original,"training query mutated source or payload lost identities");
|
||||
training["types"] = Json::array({3,3,3,3}); rejects([&] { engine_training_command(sports,training,"request:p"); });
|
||||
training = engine_training_projection(sports); training["players"]["player:0"]["focus"] = 1; rejects([&] { engine_training_command(sports,training,"request:p"); });
|
||||
training = engine_training_projection(sports); training["players"]["foreign"] = {{"focus",0},{"intensity",2}}; rejects([&] { engine_training_command(sports,training,"request:p"); });
|
||||
auto different = sports; different["training"]["meta"]["scope"]["managerId"] = "manager:1"; rejects([&] { engine_training_projection(different); });
|
||||
std::cout << "engine DTO, exact money, scope and booking tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
|
||||
Reference in new issue
Block a user