Bind squad and lineup views to confirmed engine player swaps (by Codex)
This commit is contained in:
1 parent
94dc5ecbc4
commit
7d3b3f1101
15 files changed
+340
-36
No files matched your search
@@ -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"})
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup"})
|
||||
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
|
||||
validate_engine_desk(bundle);
|
||||
return bundle;
|
||||
|
||||
@@ -9,6 +9,10 @@ void validate_engine_desk(const Json &bundle);
|
||||
int64_t engine_money_minor(const Json &money);
|
||||
Json engine_camp_command(const Json &bundle, const std::string &camp,
|
||||
const Json &focus, const std::string &request_id);
|
||||
// Pure presentation of the authoritative squad/board; absent statistics stay null.
|
||||
Json engine_lineup_projection(const Json &bundle);
|
||||
Json engine_lineup_command(const Json &bundle, const Json &order,
|
||||
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,10 +17,13 @@ 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; engine_notice_ = "Trainingslager gebucht · Änderungen noch nicht gespeichert.";
|
||||
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.";
|
||||
} else if (engine_response_.value("messageType", "") == "error") {
|
||||
engine_dirty_ = engine_base_dirty_;
|
||||
engine_notice_ = "Buchung abgewiesen: " + engine_response_.value("code", "unknown_error");
|
||||
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.";
|
||||
@@ -35,6 +38,10 @@ void App::engine_frame() {
|
||||
engine_poll();
|
||||
if (needs_render_) engine_render();
|
||||
render_popup(); context_->Update();
|
||||
if (menu_ == "lineup" && lineup_roster_scroll_) {
|
||||
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
|
||||
lineup_roster_scroll_.reset();
|
||||
}
|
||||
if (popup_.empty() && !focus_after_render_.empty()) {
|
||||
if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_);
|
||||
focus_after_render_.clear();
|
||||
@@ -88,12 +95,13 @@ 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 engine_quit();
|
||||
event.StopImmediatePropagation(); return;
|
||||
}
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_TAB) {
|
||||
auto *root = !popup_.empty() ? element("popup") : !menu_.empty() ? doc_->QuerySelector(".window") : element("canvas"); Rml::ElementList controls;
|
||||
auto *root = !popup_.empty() ? element("popup") : !engine_player_.empty() ? element("engine-player-dialog") : !menu_.empty() ? doc_->QuerySelector(".window") : element("canvas"); Rml::ElementList controls;
|
||||
if (!root) return;
|
||||
root->QuerySelectorAll(controls, "button,input");
|
||||
controls.erase(std::remove_if(controls.begin(), controls.end(), [](auto *node) { return !node->IsVisible(true) || node->HasAttribute("disabled"); }), controls.end());
|
||||
@@ -124,8 +132,10 @@ 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_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 == "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(); }
|
||||
else if (action == "camp-select") { engine_camp_ = id; refresh(); }
|
||||
@@ -143,5 +153,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_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
{"response", engine_response_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
}
|
||||
@@ -84,4 +84,88 @@ Json engine_camp_command(const Json &bundle, const std::string &id,
|
||||
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", "camp.book"}, {"payload", {{"campId", id}, {"focus", focus}}}};
|
||||
}
|
||||
|
||||
namespace {
|
||||
const Json &lineup_read(const Json &bundle, const char *kind) {
|
||||
const auto &read = bundle.at(kind), &meta = bundle.at("desktop").at("meta");
|
||||
require(read.value("messageType", "") == "snapshot" && read.at("data").value("kind", "") == kind,
|
||||
"Kader oder Aufstellung sind in diesem Kontext nicht verfügbar.");
|
||||
for (const auto *key : {"contractVersion", "careerId", "worldId", "worldRevision", "stateRevision", "scope"})
|
||||
require(read.at("meta").at(key) == meta.at(key), "Kader und Aufstellung haben unterschiedliche Kontexte.");
|
||||
return read.at("data");
|
||||
}
|
||||
Json metric_value(const Json &row, const char *key) {
|
||||
const auto &metrics = row.at("metrics");
|
||||
if (!metrics.contains(key) || !metrics.at(key).is_object()) return nullptr;
|
||||
const auto &metric = metrics.at(key);
|
||||
if (metric.contains("availability") && metric.at("availability").value("status", "") != "available") return nullptr;
|
||||
const auto value = metric.value("value", Json());
|
||||
return value.is_number_integer() ? value : Json();
|
||||
}
|
||||
}
|
||||
Json engine_lineup_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &squad = lineup_read(bundle, "squad"), &lineup = lineup_read(bundle, "lineup");
|
||||
const auto &team = bundle.at("desktop").at("meta").at("scope").at("teamId");
|
||||
require(squad.at("team").at("id") == team && lineup.at("teamId") == team,
|
||||
"Aufstellung gehört einer anderen Mannschaft.");
|
||||
require(lineup.at("order").is_array() && lineup.at("rows").is_array() && lineup.at("positions").is_array(),
|
||||
"Ungültige Aufstellungsdaten.");
|
||||
std::map<std::string, Json> members, roles, positions;
|
||||
for (const auto &row : squad.at("players")) {
|
||||
const auto id = row.at("player").at("id").get<std::string>();
|
||||
require(!id.empty() && members.emplace(id, row).second, "Doppelte Spieler-ID im Kader.");
|
||||
}
|
||||
for (const auto &row : lineup.at("rows"))
|
||||
require(roles.emplace(row.at("playerId").get<std::string>(), row.at("role")).second, "Doppelte Aufstellungszeile.");
|
||||
for (const auto &point : lineup.at("positions")) {
|
||||
const auto id = point.at("playerId").get<std::string>();
|
||||
require(members.contains(id) && positions.emplace(id, point).second, "Unbekannte oder doppelte Spielfeldposition.");
|
||||
}
|
||||
const auto depth_max = lineup.at("depthMax").get<int>(), lane_max = lineup.at("laneMax").get<int>();
|
||||
require(depth_max > 0 && lane_max > 0, "Ungültige Spielfeldkoordinaten.");
|
||||
Json rows = Json::array(), points = Json::array(); std::set<std::string> ids;
|
||||
for (const auto &value : lineup.at("order")) {
|
||||
const auto id = value.get<std::string>();
|
||||
require(members.contains(id) && roles.contains(id) && ids.insert(id).second, "Aufstellung enthält fremde oder doppelte Spieler.");
|
||||
const auto &raw = members.at(id), &person = raw.at("player");
|
||||
Json row = {{"id", id}, {"name", person.at("name")}, {"slot", rows.size()},
|
||||
{"position", person.at("positions").empty() ? Json() : person.at("positions")[0]},
|
||||
{"nation", person.at("nationIds").empty() ? Json() : person.at("nationIds")[0]},
|
||||
{"role", roles.at(id)}, {"availability", raw.at("availability")}, {"age", raw.at("age")}};
|
||||
for (const auto *key : {"condition", "technique", "form", "strength"}) row[key] = metric_value(raw, key);
|
||||
for (const auto *key : {"corner", "free_kick", "tackling", "passing", "shooting", "speed", "teamplay"})
|
||||
row[key] = raw.at("skills").value(key, Json());
|
||||
for (const auto *key : {"motivation", "goals", "assists", "games", "grade"}) row[key] = nullptr;
|
||||
const auto role = roles.at(id).get<std::string>();
|
||||
require(role == "starter" || role == "bench" || role == "reserve", "Unbekannter Kaderstatus.");
|
||||
row["status"] = role == "starter" ? "Startelf" : role == "bench" ? "Ersatzbank" : "—";
|
||||
rows.push_back(std::move(row));
|
||||
if (points.size() < lineup.at("positions").size()) {
|
||||
if (!positions.contains(id)) points.push_back(nullptr);
|
||||
else {
|
||||
const auto &point = positions.at(id); const int x = point.at("depth"), y = point.at("lane");
|
||||
points.push_back(x >= 0 && x <= depth_max && y >= 0 && y <= lane_max ? Json::array({x, y}) : Json());
|
||||
}
|
||||
}
|
||||
}
|
||||
require(ids.size() == members.size() && ids.size() == roles.size(), "Aufstellung enthält nicht den vollständigen Kader.");
|
||||
return {{"ok", true}, {"rows", rows}, {"field_count", points.size()},
|
||||
{"board", {{"order", lineup.at("order")}, {"points", points}, {"depth_max", depth_max}, {"lane_max", lane_max}}}};
|
||||
}
|
||||
Json engine_lineup_command(const Json &bundle, const Json &order, const std::string &request_id) {
|
||||
const auto projection = engine_lineup_projection(bundle);
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
require(!request_id.empty() && commands.is_array() && std::find(commands.begin(), commands.end(), Json("lineup.commit")) != commands.end(),
|
||||
"Aufstellungsänderungen sind in diesem Kontext gesperrt.");
|
||||
require(order.is_array() && order.size() == projection.at("board").at("order").size(), "Der vollständige Kader wird benötigt.");
|
||||
std::set<std::string> expected, proposed;
|
||||
for (const auto &id : projection.at("board").at("order")) expected.insert(id.get<std::string>());
|
||||
for (const auto &id : order) require(id.is_string() && proposed.insert(id.get<std::string>()).second, "Doppelte oder ungültige Spieler-ID.");
|
||||
require(proposed == expected, "Die Aufstellung enthält fremde oder fehlende Spieler.");
|
||||
return {{"messageType", "command"}, {"requestId", request_id}, {"careerId", meta.at("careerId")},
|
||||
{"expectedRevision", meta.at("stateRevision")}, {"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", "lineup.commit"}, {"payload", {{"order", order}}}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,82 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Presentation and selection only. The existing session validates each swap.
|
||||
std::string App::engine_lineup_controls() {
|
||||
return "<div class=\"lineup-orders\" style=\"position:relative;width:100%;height:100%;\"><h2>Aufstellung</h2>"
|
||||
"<p class=\"lineup-order-name\">Zwei Spieler zum Tauschen anklicken.</p>"
|
||||
"<p class=\"lineup-hint\">Der Tausch wird erst nach Bestätigung übernommen. "
|
||||
"Formationen, Anweisungen und Schützen sind hier noch nicht angebunden.</p>"
|
||||
"<p class=\"small muted\" style=\"position:absolute;left:0;right:0;bottom:0;\">" +
|
||||
esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</p></div>";
|
||||
}
|
||||
std::string App::engine_player_profile(const Json &projection) {
|
||||
if (engine_player_.empty()) return {};
|
||||
const Json *row = nullptr;
|
||||
for (const auto &member : engine_data_.at("squad").at("data").at("players"))
|
||||
if (member.at("player").at("id") == engine_player_) row = &member;
|
||||
if (!row) return {};
|
||||
Json strength;
|
||||
for (const auto &entry : projection.at("rows")) if (entry.at("id") == engine_player_) strength = entry.at("strength");
|
||||
const auto &person = row->at("player");
|
||||
const auto photo = person.at("photoAssetId").is_string()
|
||||
? person.at("photoAssetId").get<std::string>()
|
||||
: "asset:player/" + engine_player_ + "/photo";
|
||||
const auto position = person.at("positions").empty() ? Json() : person.at("positions")[0];
|
||||
const auto salary = row->at("salaryMonthly").is_null() ? std::string("—") : engine_price(row->at("salaryMonthly"));
|
||||
const auto availability = row->value("availability", "");
|
||||
const auto status = availability == "fit" ? "Einsatzbereit" : availability == "injured" ? "Verletzt" : availability == "suspended" ? "Gesperrt" : "—";
|
||||
const auto fields = report_detail_fields({
|
||||
{"Position", lineup_position(position)}, {"Alter", lineup_value(row->at("age"))},
|
||||
{"Stärke", lineup_value(strength)},
|
||||
{"Status", status}, {"Verein", engine_text(engine_data_.at("desktop").at("data").at("team").at("name"))},
|
||||
{"Monatsgehalt", salary}}, 73);
|
||||
return "<div class=\"report-detail-layer\"><section id=\"engine-player-dialog\" "
|
||||
"class=\"report-detail-card report-detail-player\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"engine-player-name\">"
|
||||
"<h2 id=\"engine-player-name\">" + esc(person.at("name").get<std::string>()) + "</h2>"
|
||||
"<div class=\"report-detail-portrait\">" + img(photo, 496, 662.667, true, true, 1024) + "</div>" + fields +
|
||||
"<nav class=\"report-detail-actions\">" + btn("engine-player-close", "Schließen", "report-detail-action", "id=\"engine-player-close\"") + "</nav></section></div>";
|
||||
}
|
||||
bool App::engine_lineup_action(const std::string &action, const std::string &id, Rml::Element *target) {
|
||||
if (!engine_player_.empty()) {
|
||||
if (action == "engine-player-close") {
|
||||
focus_after_render_ = "lineup-detail-" + engine_player_ + "-0";
|
||||
engine_player_.clear(); refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (menu_ != "lineup") return false;
|
||||
if (action == "lineup-data" || action == "lineup-view") {
|
||||
if (action == "lineup-data") lineup_data_ = 1 - lineup_data_;
|
||||
else { lineup_pitch_ = !lineup_pitch_; lineup_reset_scroll_ = true; }
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
if (action != "lineup-player" && action != "player-detail") return action.starts_with("lineup-");
|
||||
const auto projection = engine_lineup_projection(engine_data_);
|
||||
auto order = projection.at("board").at("order");
|
||||
auto chosen = std::find(order.begin(), order.end(), Json(id));
|
||||
if (chosen == order.end()) return true;
|
||||
if (action == "player-detail") {
|
||||
engine_player_ = id; focus_after_render_ = "engine-player-close"; refresh(); return true;
|
||||
}
|
||||
if (lineup_selected_.empty() || lineup_selected_ == id) {
|
||||
lineup_selected_ = lineup_selected_ == id ? "" : id;
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
const auto first = std::find(order.begin(), order.end(), Json(lineup_selected_));
|
||||
if (first == order.end() || !engine_fresh_) return true;
|
||||
std::iter_swap(first, chosen);
|
||||
const auto command = engine_lineup_command(engine_data_, order, editor::new_id("request:ui-"));
|
||||
std::string first_name, second_name;
|
||||
for (const auto &row : projection.at("rows")) {
|
||||
if (row.at("id") == lineup_selected_) first_name = row.at("name");
|
||||
if (row.at("id") == id) second_name = row.at("name");
|
||||
}
|
||||
confirmation(first_name + " und " + second_name + " in der Aufstellung tauschen?", [this, command, id] {
|
||||
lineup_selected_.clear(); focus_after_render_ = "lineup-name-" + id;
|
||||
auto link = engine_link_;
|
||||
engine_start("Aufstellung wird übernommen …", [link, command] {
|
||||
auto response = link->command(command);
|
||||
return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
}, true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -36,6 +36,10 @@ Json App::engine_camp_view() const {
|
||||
return {{"maps", maps}, {"training_camps", camps}};
|
||||
}
|
||||
void App::engine_render() {
|
||||
if (menu_ == "lineup") {
|
||||
if (auto *roster = element("lineup-roster-scroll")) lineup_roster_scroll_ = lineup_reset_scroll_ ? 0.f : roster->GetScrollTop();
|
||||
lineup_reset_scroll_ = false;
|
||||
}
|
||||
doc_->SetClassNames(theme_);
|
||||
std::string out;
|
||||
if (engine_data_.empty()) {
|
||||
@@ -50,6 +54,8 @@ void App::engine_render() {
|
||||
"</small></span></div><div class=\"info-date\">" + esc(meta.at("date").get<std::string>()) + "<small>" +
|
||||
esc(meta.at("season").at("label").get<std::string>()) + "</small></div><div class=\"info-cash\"><small>Guthaben</small><strong id=\"engine-cash\" class=\"" + money_classes(engine_money_minor(desk.at("accounts").at("cash"))) + "\">" +
|
||||
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 &) {}
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
@@ -82,15 +88,20 @@ 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 == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
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());
|
||||
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
|
||||
}
|
||||
}
|
||||
out += "</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_;
|
||||
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"); }
|
||||
}
|
||||
const auto size = context_->GetDimensions();
|
||||
element("background")->SetInnerRML(img("background", size.x / scale_, size.y / scale_, false, true, 2048));
|
||||
element("background")->SetProperty("filter", theme_ == "silver" ? "saturate(0.2) brightness(0.9)" : theme_ == "matchday" ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
std::shared_ptr<EngineBridge> engine_link_;
|
||||
std::future<EngineReply> engine_job_;
|
||||
Json engine_data_, engine_response_, engine_focus_;
|
||||
std::string engine_camp_, engine_operation_, engine_notice_;
|
||||
std::string engine_camp_, engine_operation_, engine_notice_, engine_player_;
|
||||
void engine_start(std::string, std::function<EngineReply()>, bool mutating = false);
|
||||
void engine_poll();
|
||||
void engine_render();
|
||||
@@ -12,4 +12,7 @@
|
||||
void engine_save();
|
||||
void engine_quit();
|
||||
Json engine_camp_view() const;
|
||||
std::string engine_lineup_controls();
|
||||
std::string engine_player_profile(const Json &);
|
||||
bool engine_lineup_action(const std::string &, const std::string &, Rml::Element *);
|
||||
Json engine_snapshot() const;
|
||||
@@ -151,18 +151,19 @@ std::string lineup_zone(const Json &l, const std::string &id) {
|
||||
} // namespace
|
||||
|
||||
std::string App::render_lineup() {
|
||||
const auto s = snap();
|
||||
const auto s = engine_mode_ ? Snapshot{0, world_, Json()} : snap();
|
||||
if (!s.world)
|
||||
return "<p class=\"lineup-empty\">Die Aufstellung ist derzeit nicht "
|
||||
"verfügbar.</p>";
|
||||
const auto projection =
|
||||
demo_lineup_rows(s.state, *s.world, lineup_managed(s));
|
||||
engine_mode_ ? engine_lineup_projection(engine_data_) : demo_lineup_rows(s.state, *s.world, lineup_managed(s));
|
||||
if (!projection.value("ok", false))
|
||||
return "<p class=\"lineup-empty\">Die Aufstellung ist derzeit nicht "
|
||||
"verfügbar.</p>";
|
||||
const auto &l = demo_lineup_visible(s.state), &rows = projection.at("rows");
|
||||
const int field_count = demo_career_field_count(s.state);
|
||||
const bool indoor = field_count == 6;
|
||||
const auto &l = engine_mode_ ? projection.at("board") : demo_lineup_visible(s.state);
|
||||
const auto &rows = projection.at("rows");
|
||||
const int field_count = engine_mode_ ? projection.at("field_count").get<int>() : demo_career_field_count(s.state);
|
||||
const bool indoor = !engine_mode_ && field_count == 6;
|
||||
if (lineup_slot(l, lineup_selected_) < 0)
|
||||
lineup_selected_.clear();
|
||||
lineup_data_ = lineup_data_ == 1 ? 1 : 0;
|
||||
@@ -217,7 +218,7 @@ std::string App::render_lineup() {
|
||||
lineup_value(row.at("technique")),
|
||||
lineup_value(row.at("form")),
|
||||
lineup_value(row.at("strength")),
|
||||
lineup_status(size_t(slot), indoor),
|
||||
engine_mode_ ? row.at("status").get<std::string>() : lineup_status(size_t(slot), indoor),
|
||||
row.at("nation").is_string()
|
||||
? row.at("nation").get<std::string>()
|
||||
: "—",
|
||||
@@ -296,23 +297,23 @@ std::string App::render_lineup() {
|
||||
"aria-label=\"Spielfeldvariante\">" +
|
||||
btn("lineup-surface", "Rasen · 11", indoor ? "" : "selected",
|
||||
"id=\"lineup-surface-outdoor\" data-id=\"outdoor\" aria-pressed=\"" +
|
||||
(indoor ? std::string("false") : "true") + "\"") +
|
||||
(indoor ? std::string("false") : "true") + "\" " + (engine_mode_ ? "disabled" : "")) +
|
||||
btn("lineup-surface", "Halle · 6", indoor ? "selected" : "",
|
||||
"id=\"lineup-surface-indoor\" data-id=\"indoor\" aria-pressed=\"" +
|
||||
(indoor ? std::string("true") : "false") + "\" " +
|
||||
(s.state.at("career").value("role", "club") == "national"
|
||||
(engine_mode_ || s.state.at("career").value("role", "club") == "national"
|
||||
? "disabled"
|
||||
: "")) +
|
||||
"</nav>";
|
||||
if (lineup_pitch_) {
|
||||
out += "<div id=\"lineup-pitch\" class=\"lineup-pitch\" role=\"group\" "
|
||||
"aria-label=\"Spielfeld, Spieler auswählen oder ziehen\"><div "
|
||||
"aria-label=\"" + std::string(engine_mode_ ? "Spielfeld, Spieler auswählen" : "Spielfeld, Spieler auswählen oder ziehen") + "\"><div "
|
||||
"class=\"lineup-field-art\">" +
|
||||
picture(renderer_.diagram("lineup-field", lineup_field(indoor),
|
||||
lineup_pitch_raster_px),
|
||||
lineup_art_width_dp, lineup_art_height_dp) +
|
||||
"</div>";
|
||||
if (lineup_side_ == "orders" && !lineup_selected_.empty()) {
|
||||
if (!engine_mode_ && lineup_side_ == "orders" && !lineup_selected_.empty()) {
|
||||
const auto zone = lineup_zone(l, lineup_selected_);
|
||||
if (!zone.empty())
|
||||
out += "<div id=\"lineup-zone\" class=\"lineup-order-zone\">" +
|
||||
@@ -323,12 +324,13 @@ std::string App::render_lineup() {
|
||||
}
|
||||
for (size_t i = 0; i < std::min(size_t(field_count), rows.size()); ++i) {
|
||||
const auto &row = rows[i], &point = l.at("points")[i];
|
||||
if (point.is_null()) continue;
|
||||
const bool selected = lineup_selected_ == row.at("id").get<std::string>();
|
||||
const auto x =
|
||||
(8 + point[0].get<int>() / 18.0 * 84) * lineup_art_width_dp / 100.0 -
|
||||
(8 + point[0].get<int>() / double(l.value("depth_max", 18)) * 84) * lineup_art_width_dp / 100.0 -
|
||||
lineup_player_anchor_x_dp;
|
||||
const auto y =
|
||||
(10 + point[1].get<int>() / 8.0 * 80) * lineup_art_height_dp / 100.0 -
|
||||
(10 + point[1].get<int>() / double(l.value("lane_max", 8)) * 80) * lineup_art_height_dp / 100.0 -
|
||||
lineup_player_anchor_y_dp;
|
||||
out +=
|
||||
btn("lineup-player",
|
||||
@@ -356,9 +358,10 @@ std::string App::render_lineup() {
|
||||
"lineup-side", label, "lineup-tab",
|
||||
attr("id", "lineup-side-" + std::string(side)) +
|
||||
attr("data-id", side) +
|
||||
attr("aria-pressed", lineup_side_ == side ? "true" : "false"));
|
||||
attr("aria-pressed", lineup_side_ == side ? "true" : "false") + (engine_mode_ ? " disabled" : ""));
|
||||
out += "</nav><div class=\"lineup-side\" id=\"lineup-side\">";
|
||||
if (lineup_side_ == "formations") {
|
||||
if (engine_mode_) out += engine_lineup_controls();
|
||||
else if (lineup_side_ == "formations") {
|
||||
for (int slot = 0; slot < 4; ++slot) {
|
||||
const int i = slot + lineup_page_ * 4;
|
||||
const auto point = i < 4 ? demo_lineup_formations(indoor)[size_t(i)]
|
||||
@@ -534,11 +537,11 @@ std::string App::render_lineup() {
|
||||
}
|
||||
out += "</div></aside>";
|
||||
} else {
|
||||
const auto bench = std::min(indoor ? size_t(5) : lineup_bench_limit,
|
||||
const auto bench = engine_mode_ ? size_t(std::count_if(rows.begin(), rows.end(), [](const auto &r) { return r.at("role") == "bench"; })) : std::min(indoor ? size_t(5) : lineup_bench_limit,
|
||||
rows.size() > size_t(field_count)
|
||||
? rows.size() - size_t(field_count)
|
||||
: 0);
|
||||
const auto reserves = rows.size() > size_t(field_count) + bench
|
||||
const auto reserves = engine_mode_ ? size_t(std::count_if(rows.begin(), rows.end(), [](const auto &r) { return r.at("role") == "reserve"; })) : rows.size() > size_t(field_count) + bench
|
||||
? rows.size() - size_t(field_count) - bench
|
||||
: 0;
|
||||
out += "<footer class=\"lineup-team-actions\">" + data_btn() + view_btn() +
|
||||
@@ -549,5 +552,5 @@ std::string App::render_lineup() {
|
||||
std::to_string(reserves) + " Reserve</span></footer>";
|
||||
}
|
||||
out += "</div>";
|
||||
return out + render_report_detail();
|
||||
return out + (engine_mode_ ? engine_player_profile(projection) : render_report_detail());
|
||||
}
|
||||
@@ -1513,6 +1513,7 @@ public:
|
||||
#include "modern/ui/postmatch_controls.inc"
|
||||
#include "modern/ui/engine_screens.inc"
|
||||
#include "modern/ui/engine_controls.inc"
|
||||
#include "modern/ui/engine_lineup.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user