203 lines
21 KiB
C++
203 lines
21 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
||
namespace {
|
||
std::string live_text(const std::string &value, const std::string &css = {}) {
|
||
return "<span" + (css.empty() ? std::string() : " class=\"" + css + "\"") + ">" + esc(value) + "</span>";
|
||
}
|
||
std::string live_score_text(const Json &score) {
|
||
return std::to_string(score[0].get<int>()) + " : " + std::to_string(score[1].get<int>());
|
||
}
|
||
const Json &live_match_by_id(const Json &rows, const Json &id) {
|
||
for (const auto &row : rows) if (row.at("id") == id) return row;
|
||
throw editor::Error("live_match_unavailable");
|
||
}
|
||
const Json &live_score_by_id(const Json &frame, const Json &id) {
|
||
for (const auto &row : frame.at("matches")) if (row.at("match_id") == id) return row;
|
||
throw editor::Error("live_score_unavailable");
|
||
}
|
||
} // namespace
|
||
|
||
Json App::live_owner() const {
|
||
for (const auto &owner : live_.fixture().at("owners")) if (owner.at("id") == live_.owner()) return owner;
|
||
return Json();
|
||
}
|
||
Json App::live_owner_state(const Json &owner) const {
|
||
const auto id = owner.at("id").get<std::string>();
|
||
return live_drafts_.contains(id) ? live_drafts_.at(id) : owner.at("view").at("edit_state");
|
||
}
|
||
Json App::live_owner_rows(const Json &owner) const {
|
||
if (!live_world_) return Json::array();
|
||
const auto view = live_owner_state(owner);
|
||
const auto projection = demo_lineup_rows(view, *live_world_, owner.at("view").at("club_basis"));
|
||
if (!projection.value("ok", false)) return Json::array();
|
||
auto rows = projection.at("rows");
|
||
for (auto &row : rows) {
|
||
row["caps"] = nullptr; row["international_goals"] = nullptr;
|
||
for (const auto &base : owner.at("view").at("rows")) if (base.at("id") == row.at("id")) {
|
||
row["caps"] = base.at("caps"); row["international_goals"] = base.at("international_goals");
|
||
}
|
||
}
|
||
return rows;
|
||
}
|
||
std::string App::live_badge(const Json &team, double size) {
|
||
std::string art;
|
||
if (team.value("role", "club") == "national") {
|
||
auto nation = team.value("nation", team.value("id", "") == "national-de" ? "nation:de" : "");
|
||
if (nation.starts_with("nation:")) nation = nation.substr(7);
|
||
const auto flag = ui_nation_flag_svg(nation);
|
||
if (!flag.empty()) art = picture(renderer_.diagram("live-flag-" + nation, flag, int(size * 2)), size, size * .7);
|
||
} else if (live_world_) {
|
||
if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty()) art = crest(club, size);
|
||
}
|
||
if (art.empty()) art = glyph(team.value("role", "club") == "national" ? "world" : "shirt", size);
|
||
return "<div class=\"live-badge\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;\">" + art + "</div>";
|
||
}
|
||
std::string App::live_roster(const Json &owner) {
|
||
const bool national = live_.fixture().at("role") == "national";
|
||
const int field_count = live_.fixture().at("field_count");
|
||
std::string out = "<div class=\"live-roster\"><div class=\"live-roster-row heading\">" +
|
||
live_text("Nr.", "live-roster-number") + live_text(owner.at("team").at("name"), "live-roster-name") +
|
||
live_text(national ? "Caps" : "Stä.", "live-roster-stat") + live_text(national ? "Tore" : "Ko.", "live-roster-stat") + "</div>";
|
||
const auto rows = live_owner_rows(owner);
|
||
if (national) out += "<p class=\"live-roster-note\">" + live_text("Demokader auf Vereinsbasis · keine Nationalkaderberufung") + "</p>";
|
||
for (size_t i = 0; i < rows.size(); ++i) {
|
||
if (int(i) == field_count) out += "<p class=\"live-roster-note\">" + live_text(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : "Reserven · Demovorschau") + "</p>";
|
||
if (field_count == 6 && i == 11) out += "<p class=\"live-roster-note\">" + live_text("Weitere Kaderreserven") + "</p>";
|
||
const auto &row = rows[i];
|
||
out += "<div class=\"live-roster-row\" data-live-player=\"" + esc(row.at("id").get<std::string>()) + "\">" +
|
||
live_text(std::to_string(i + 1), "live-roster-number") + live_text(row.at("name"), "live-roster-name") +
|
||
live_text(lineup_value(row.at(national ? "caps" : "strength")), "live-roster-stat") +
|
||
live_text(lineup_value(row.at(national ? "international_goals" : "condition")), "live-roster-stat") + "</div>";
|
||
}
|
||
if (rows.empty()) out += "<p class=\"live-note\">" + live_text("Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "</p>";
|
||
return out + "</div>";
|
||
}
|
||
std::string App::live_detail(const Json &owner, const Json &frame) {
|
||
const auto &fixture = live_.fixture();
|
||
const auto &match = live_match_by_id(fixture.at("matches"), owner.at("match_id"));
|
||
const auto &score = live_score_by_id(frame, match.at("id"));
|
||
if (live_tab_ == "team") return live_roster(owner);
|
||
if (live_tab_ == "table") {
|
||
if (fixture.at("role") == "national") return "<p class=\"live-note\">" + live_text("Dieses Demo-Länderspiel gehört zu keiner Liga. Der Spielstand steht links; eine Vereins-Live-Tabelle wird nicht eingeblendet.") + "</p>";
|
||
std::string out = "<p class=\"live-note\">" + live_text("Vorgegebene Demo-Tabelle · keine echte Saisonwertung") + "</p><div class=\"live-table\" role=\"table\" aria-label=\"Demo-Live-Tabelle\"><div class=\"live-table-row heading\">" +
|
||
live_text("Pl.", "live-table-pos") + "<div class=\"live-table-team\">" + live_text("Verein") + "</div>" + live_text("Sp.", "live-table-number") +
|
||
live_text("Tore", "live-table-number live-table-goals") + live_text("Diff.", "live-table-number") + live_text("Pkt.", "live-table-number") + "</div>";
|
||
for (const auto &row : score.at("standings")) {
|
||
const bool own = row.at("team").at("id") == owner.at("team").at("id");
|
||
const int difference = row.at("gf").get<int>() - row.at("ga").get<int>();
|
||
out += "<div class=\"live-table-row " + std::string(own ? "own" : "") + "\" data-live-table-team=\"" + esc(row.at("team").at("id").get<std::string>()) + "\"" + (own ? " aria-current=\"true\"" : "") + ">" +
|
||
live_text(std::to_string(row.at("position").get<int>()), "live-table-pos") +
|
||
"<div class=\"live-table-team\">" + live_badge(row.at("team"), 48) + live_text(row.at("team").at("name")) + "</div>" +
|
||
live_text(std::to_string(row.at("played").get<int>()), "live-table-number") +
|
||
live_text(std::to_string(row.at("gf").get<int>()) + ":" + std::to_string(row.at("ga").get<int>()), "live-table-number live-table-goals") +
|
||
live_text((difference > 0 ? "+" : "") + std::to_string(difference), "live-table-number") +
|
||
live_text(std::to_string(row.at("points").get<int>()), "live-table-number") + "</div>";
|
||
}
|
||
return out + "</div>";
|
||
}
|
||
if (live_tab_ == "tactics") {
|
||
const auto state = live_owner_state(owner), board = demo_lineup_visible(state);
|
||
Json points = Json::array(); const int count = fixture.at("field_count");
|
||
for (int i = 0; i < count; ++i) points.push_back(board.at("points")[size_t(i)]);
|
||
return "<div class=\"live-context\"><h3>" + live_text("Aktuelle Demoaufstellung") + "</h3><p>" + live_text(std::to_string(count) + " Spieler auf dem Feld · unabhängige Manageransicht") + "</p><div class=\"live-pitch\">" +
|
||
picture(renderer_.diagram("live-formation", lineup_mini(points, theme_), 1200), 1140, 684) + "</div>" +
|
||
btn("live-intervene-tactics", "Taktik als Demo bearbeiten", "", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) +
|
||
"<p>" + live_text("Die Vorschau verändert weder diese feste Ereignisfolge noch Spiel- oder Saisonwerte.") + "</p></div>";
|
||
}
|
||
std::string out;
|
||
if (live_tab_ == "opponent") {
|
||
const auto &opponent = match.at(owner.at("team").at("id") == match.at("home").at("id") ? "away" : "home");
|
||
out = "<div class=\"live-context\"><h3>" + live_text(opponent.at("name")) + "</h3><p>" + live_text("Gegner dieser vorgegebenen Demopartie. Es werden keine unbekannten Gegneranweisungen behauptet.") + "</p></div>";
|
||
}
|
||
const std::array<std::pair<const char *, const char *>, 5> fields{{{"Tore", "score"}, {"Chancen", "chances"}, {"Gelbe Karten", "yellow"}, {"Rote Karten", "red"}, {"Spieler auf dem Feld", "players"}}};
|
||
for (const auto &[label, key] : fields) {
|
||
const auto &pair = score.at(key); const int a = pair[0], b = pair[1];
|
||
const double percent = a + b ? 100.0 * a / (a + b) : 50;
|
||
out += "<div class=\"live-stat\"><div class=\"live-stat-label\">" + live_text(std::to_string(a)) + live_text(label, "stat-title") + live_text(std::to_string(b)) +
|
||
"</div><div class=\"live-stat-bar\"><div class=\"home\" style=\"width:" + scalar(percent) + "%;\"></div><div class=\"away\"></div></div></div>";
|
||
}
|
||
return out + "<p class=\"live-note\">" + live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>() + " · vorgegebene Demowerte") + "</p>";
|
||
}
|
||
std::string App::live_dialog_markup(const Json &owner) {
|
||
if (live_dialog_.empty()) return "";
|
||
const auto rows = live_owner_rows(owner);
|
||
std::string body = "<h2 id=\"live-dialog-heading\">" + live_text(live_dialog_ == "lineup" ? "Aufstellung & Wechsel · Demo" : "Taktik · Demo") + "</h2><p>" + live_text("Nur lokale Vorschau für " + owner.at("name").get<std::string>() + " · " + owner.at("team").at("name").get<std::string>() + ". Keine Änderung an der Partie; der feste Spielverlauf bleibt unverändert.") + "</p>";
|
||
if (live_dialog_ == "lineup") {
|
||
std::vector<std::pair<std::string, std::string>> active, bench;
|
||
for (size_t i = 0; i < rows.size(); ++i) (i < size_t(live_.fixture().at("field_count").get<int>()) ? active : bench).emplace_back(rows[i].at("id"), rows[i].at("name"));
|
||
body += "<label for=\"live-player-out\">" + live_text("Vom Feld") + select("live-player-out", active, live_out_) + "</label><label for=\"live-player-in\">" + live_text("Von der Ersatzbank") + select("live-player-in", bench, live_in_) + "</label>";
|
||
if (active.empty() || bench.empty()) body += "<p>" + live_text("Für diese Demokaderbasis ist kein Wechselpaar verfügbar.") + "</p>";
|
||
} else {
|
||
const std::array<const char *, 8> names{"Defensiv / offensiv", "Pass-/Schussbild unten", "Pass-/Schussbild Mitte", "Pass-/Schussbild links", "Flache / hohe Bälle", "Flügelbild links", "Flügelbild rechts", "Einsatz"};
|
||
const auto &values = live_dialog_draft_.at("tactics").at("values");
|
||
for (size_t i = 0; i < names.size(); ++i)
|
||
body += "<div class=\"live-tactic-row\">" + live_text(names[i]) + btn("live-tactic-cycle", "Wert " + std::to_string(values[i].get<int>()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "</div>";
|
||
}
|
||
body += "<div class=\"live-dialog-actions\">" + btn("live-dialog-cancel", "Abbrechen", "", "id=\"live-dialog-cancel\"") +
|
||
btn("live-dialog-apply", "Demovorschau anzeigen", "", "id=\"live-dialog-apply\" " + std::string(live_dialog_ == "lineup" && (live_out_.empty() || live_in_.empty()) ? "disabled" : "")) + "</div>";
|
||
return "<div class=\"live-dialog-layer\"><div id=\"live-dialog\" class=\"live-dialog\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"live-dialog-heading\">" + body + "</div></div>";
|
||
}
|
||
std::string App::render_live() {
|
||
if(live_review_) return render_postmatch();
|
||
if (!live_.available()) return "";
|
||
if (auto *node = element("live-ticker")) live_ticker_scroll_ = live_reset_ticker_ ? 0 : node->GetScrollTop();
|
||
if (auto *node = element("live-detail-body")) live_detail_scroll_ = live_reset_detail_ ? 0 : node->GetScrollTop();
|
||
live_reset_detail_ = live_reset_ticker_ = false;
|
||
live_restore_scroll_ = true;
|
||
const auto &fixture = live_.fixture(); const auto frame = live_.frame(); const auto owner = live_owner();
|
||
const int minute = frame.at("minute"); const auto phase = frame.at("phase").get<std::string>();
|
||
const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? "Aufzeichnung läuft" : "Gemeinsam pausiert";
|
||
const auto arrow = [&](bool right) { const auto color = theme_ == "silver" ? "#376b84" : theme_ == "matchday" ? "#efb2aa" : "#b5dbd2"; return picture(renderer_.diagram(right ? "live-arrow-right" : "live-arrow-left", "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\"><path d=\"" + std::string(right ? "M7 4l6 6-6 6" : "M13 4l-6 6 6 6") + "\" fill=\"none\" stroke=\"" + color + "\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", 72), 36, 36); };
|
||
std::string out = "<section id=\"live-stage\" class=\"live-stage\" data-source=\"ui-demo-fixture\" data-fixture-id=\"" + esc(fixture.at("fixture_id").get<std::string>()) + "\"><header class=\"live-header\"><div>" + live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow") +
|
||
"<h1>" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : "Gemeinsamer Spieltag") + "</h1></div>" + live_text("UI-Demo · vorgegebene Ergebnisse", "live-demo-tag") + "</header>";
|
||
const auto scoreline = [&](const Json &match) {
|
||
const auto &value = live_score_by_id(frame, match.at("id"));
|
||
return "<div class=\"live-scoreline\">" + live_text(match.at("home").at("name"), "live-team-name home") + live_badge(match.at("home"), 58) + live_text(live_score_text(value.at("score")), "live-score") + live_badge(match.at("away"), 58) + live_text(match.at("away").at("name"), "live-team-name away") + "</div>";
|
||
};
|
||
out += "<div id=\"live-underlay\" class=\"live-body\"><div class=\"live-left\"><section class=\"live-panel live-overview\"><nav class=\"live-coverage\">";
|
||
for (const auto &[id, text] : std::array<std::pair<const char *, const char *>, 3>{{{"all", "Alle Spiele"}, {"single", "Einzelspiel"}, {"conference", "Konferenz"}}})
|
||
out += btn("live-coverage", text, live_coverage_ == id ? "selected" : "", "id=\"live-coverage-" + std::string(id) + "\" data-id=\"" + id + "\"");
|
||
if (live_coverage_ == "single" && fixture.at("matches").size() > 1) out += btn("live-match-prev", arrow(false), "live-match-arrow", "id=\"live-match-prev\" aria-label=\"Vorherige Tickerpartie\"") + btn("live-match-next", arrow(true), "live-match-arrow", "id=\"live-match-next\" aria-label=\"Nächste Tickerpartie\"");
|
||
out += live_text(std::to_string(minute) + ":00", "live-clock") + "</nav><div class=\"live-cards " + std::string(fixture.at("matches").size() == 1 || live_coverage_ == "single" ? "single" : "") + "\">";
|
||
for (const auto &match : fixture.at("matches")) {
|
||
if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue;
|
||
std::string names;
|
||
for (const auto &id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == id) { if (!names.empty()) names += " · "; names += person.at("name").get<std::string>(); }
|
||
out += "<button data-action=\"live-match\" class=\"live-game " + std::string(match.at("id") == live_selected_match_ ? "active" : "") + "\" data-live-match=\"" + esc(match.at("id").get<std::string>()) + "\" data-id=\"" + esc(match.at("id").get<std::string>()) + "\">" + live_text(names, "live-owners") + scoreline(match) + live_text(std::to_string(minute) + "′ · " + (match.at("owners").size() > 1 ? "Zwei menschliche Manager" : "Eine menschliche Mannschaft"), "live-card-caption") + live_text(live_match_info_text(match, fixture.at("surface") == "indoor"), "live-match-info") + "</button>";
|
||
}
|
||
out += "</div></section><section class=\"live-panel live-ticker\"><header class=\"live-panel-heading\"><h2>" + live_text("Gemeinsamer Live-Ticker") + "</h2>" + live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small") + "</header><nav class=\"live-filters\">";
|
||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 4>{{{"all", "Alles"}, {"highlights", "Highlights"}, {"goal", "Tore"}, {"yellow", "Karten"}}}) out += btn("live-filter", label, live_filter_ == id ? "selected" : "", "id=\"live-filter-" + std::string(id) + "\" data-id=\"" + id + "\"");
|
||
out += "</nav><div id=\"live-ticker\" class=\"live-event-list\" tabindex=\"0\" aria-label=\"Gemeinsamer Ereignisverlauf\">";
|
||
size_t shown = 0;
|
||
for (auto i = frame.at("events").rbegin(); i != frame.at("events").rend(); ++i) {
|
||
const auto &event = *i; const auto kind = event.value("kind", "");
|
||
if (live_coverage_ == "single" && event.at("match_id") != live_selected_match_) continue;
|
||
if (live_filter_ == "goal" && kind != "goal") continue;
|
||
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red") continue;
|
||
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "red") continue;
|
||
const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id"));
|
||
out += "<article class=\"live-event " + std::string(kind == "goal" ? "is-goal" : "") + "\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\">" + live_text(std::to_string(event.at("minute").get<int>()) + "′", "live-event-time") + live_badge(match.at(event.at("side").get<std::string>()), 54) +
|
||
"<div class=\"live-event-copy\">" + live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>(), "live-event-owners") + "<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" + live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
|
||
++shown;
|
||
}
|
||
if (!shown) out += "<p class=\"live-note\">" + live_text("Für diesen Filter liegt noch keine Demomeldung vor.") + "</p>";
|
||
out += "</div><footer class=\"live-ticker-footer\">" + live_text(std::to_string(shown) + " Meldungen · feste Aufzeichnung", "live-small") + "<span id=\"live-phase-status\" class=\"live-small\">" + esc(phase_text) + "</span></footer></section></div><aside id=\"live-detail\" class=\"live-detail live-panel\"><header class=\"live-panel-heading\"><div class=\"live-detail-heading\"><h2>" + live_text(owner.at("team").at("name")) + "</h2><p>" + live_text(owner.at("name")) + "</p></div><nav class=\"live-team-switch\" aria-label=\"Managerdetails wechseln\">" +
|
||
btn("live-owner-prev", arrow(false), "", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + btn("live-owner-next", arrow(true), "", "id=\"live-owner-next\" aria-label=\"Nächster Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + "</nav></header><nav class=\"live-tabs\">";
|
||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", "Gegner"}, {"table", "Live-Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
|
||
out += "</nav><div id=\"live-detail-body\" class=\"live-detail-body\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"live-detail-footer\">" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() ? "disabled" : "")) + "</footer></aside></div>";
|
||
out += "<div class=\"live-speed\">" + live_text("+") + "<input id=\"live-speed\" type=\"range\" orientation=\"vertical\" min=\"0\" max=\"4\" step=\"1\" value=\"" + std::to_string(4 - live_.speed()) + "\" aria-label=\"Wiedergabegeschwindigkeit; unten Pause\" aria-valuenow=\"" + std::to_string(live_.speed()) + "\" " + (live_.finished() ? "disabled" : "") + "/><span id=\"live-speed-value\" class=\"live-speed-value\">" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "</span></div>";
|
||
out += "<footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "</div><span id=\"live-playback-status\" class=\"live-bottom-note\">" + esc(live_feedback_.empty() ? std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung" : live_feedback_) + "</span>" +
|
||
btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "</footer>";
|
||
return out + live_dialog_markup(owner) + "</section>";
|
||
}
|
||
void App::live_after_render() {
|
||
if(live_review_){postmatch_after_render();return;}
|
||
if (scene_ != "live" || !live_restore_scroll_) return;
|
||
live_restore_scroll_ = false;
|
||
if (auto *node = element("live-ticker")) node->SetScrollTop(live_ticker_scroll_);
|
||
if (auto *node = element("live-detail-body")) node->SetScrollTop(live_detail_scroll_);
|
||
if (!live_dialog_.empty()) {
|
||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#live-underlay button,#live-speed,.live-bottom button");
|
||
for (auto *node : controls) { node->SetProperty("pointer-events", "none"); node->SetAttribute("tabindex", "-1"); }
|
||
}
|
||
}
|