Bind tactics and training drafts to confirmed engine commits (by Codex)

This commit is contained in:
Codex committed 2026-10-28 09:57:12 +01:00
1 parent 7d3b3f1101
commit f75e0f8e49
18 files changed
+398 -43

No files matched your search

+3 -3
View File
@@ -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);
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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;
+6
View File
@@ -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.
+10 -6
View File
@@ -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_}};
}
+109
View File
@@ -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
+7 -1
View File
@@ -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"); }
+107
View File
@@ -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;
}
+7 -1
View File
@@ -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;
+27 -23
View File
@@ -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() : "");
}
+1
View File
@@ -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 {