// SPDX-License-Identifier: GPL-3.0-only namespace { std::string live_text(const std::string &value, const std::string &css = {}) { return "" + esc(value) + ""; } std::string live_score_text(const Json &score) { return std::to_string(score[0].get()) + " : " + std::to_string(score[1].get()); } 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(); 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 "
" + art + "
"; } 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 = "
" + 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") + "
"; const auto rows = live_owner_rows(owner); if (national) out += "

" + live_text("Demokader auf Vereinsbasis · keine Nationalkaderberufung") + "

"; for (size_t i = 0; i < rows.size(); ++i) { if (int(i) == field_count) out += "

" + live_text(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : "Reserven · Demovorschau") + "

"; if (field_count == 6 && i == 11) out += "

" + live_text("Weitere Kaderreserven") + "

"; const auto &row = rows[i]; out += "
()) + "\">" + 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") + "
"; } if (rows.empty()) out += "

" + live_text("Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "

"; return out + "
"; } 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 "

" + live_text("Dieses Demo-Länderspiel gehört zu keiner Liga. Der Spielstand steht links; eine Vereins-Live-Tabelle wird nicht eingeblendet.") + "

"; std::string out = "

" + live_text("Vorgegebene Demo-Tabelle · keine echte Saisonwertung") + "

" + live_text("Pl.", "live-table-pos") + "
" + live_text("Verein") + "
" + 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") + "
"; 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() - row.at("ga").get(); out += "
()) + "\"" + (own ? " aria-current=\"true\"" : "") + ">" + live_text(std::to_string(row.at("position").get()), "live-table-pos") + "
" + live_badge(row.at("team"), 48) + live_text(row.at("team").at("name")) + "
" + live_text(std::to_string(row.at("played").get()), "live-table-number") + live_text(std::to_string(row.at("gf").get()) + ":" + std::to_string(row.at("ga").get()), "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()), "live-table-number") + "
"; } return out + "
"; } 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 "

" + live_text("Aktuelle Demoaufstellung") + "

" + live_text(std::to_string(count) + " Spieler auf dem Feld · unabhängige Manageransicht") + "

" + picture(renderer_.diagram("live-formation", lineup_mini(points, theme_), 1200), 1140, 684) + "
" + btn("live-intervene-tactics", "Taktik als Demo bearbeiten", "", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) + "

" + live_text("Die Vorschau verändert weder diese feste Ereignisfolge noch Spiel- oder Saisonwerte.") + "

"; } 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 = "

" + live_text(opponent.at("name")) + "

" + live_text("Gegner dieser vorgegebenen Demopartie. Es werden keine unbekannten Gegneranweisungen behauptet.") + "

"; } const std::array, 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 += "
" + live_text(std::to_string(a)) + live_text(label, "stat-title") + live_text(std::to_string(b)) + "
"; } return out + "

" + live_text(match.at("home").at("name").get() + " · " + match.at("away").at("name").get() + " · vorgegebene Demowerte") + "

"; } std::string App::live_dialog_markup(const Json &owner) { if (live_dialog_.empty()) return ""; const auto rows = live_owner_rows(owner); std::string body = "

" + live_text(live_dialog_ == "lineup" ? "Aufstellung & Wechsel · Demo" : "Taktik · Demo") + "

" + live_text("Nur lokale Vorschau für " + owner.at("name").get() + " · " + owner.at("team").at("name").get() + ". Keine Änderung an der Partie; der feste Spielverlauf bleibt unverändert.") + "

"; if (live_dialog_ == "lineup") { std::vector> active, bench; for (size_t i = 0; i < rows.size(); ++i) (i < size_t(live_.fixture().at("field_count").get()) ? active : bench).emplace_back(rows[i].at("id"), rows[i].at("name")); body += ""; if (active.empty() || bench.empty()) body += "

" + live_text("Für diese Demokaderbasis ist kein Wechselpaar verfügbar.") + "

"; } else { const std::array 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 += "
" + live_text(names[i]) + btn("live-tactic-cycle", "Wert " + std::to_string(values[i].get()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "
"; } body += "
" + 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" : "")) + "
"; return "
" + body + "
"; } 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(); 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", "", 72), 36, 36); }; std::string out = "
()) + "\">
" + live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow") + "

" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : "Gemeinsamer Spieltag") + "

" + live_text("UI-Demo · vorgegebene Ergebnisse", "live-demo-tag") + "
"; const auto scoreline = [&](const Json &match) { const auto &value = live_score_by_id(frame, match.at("id")); return "
" + 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") + "
"; }; out += "
"; 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(); } out += ""; } out += "

" + live_text("Gemeinsamer Live-Ticker") + "

" + live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small") + "
"; 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 += "
()) + "\">" + live_text(std::to_string(event.at("minute").get()) + "′", "live-event-time") + live_badge(match.at(event.at("side").get()), 54) + "
" + live_text(match.at("home").at("name").get() + " · " + match.at("away").at("name").get(), "live-event-owners") + "

" + live_text(event.at("headline")) + "

" + live_text(event.at("body")) + "

" + live_text(live_score_text(event.at("score")), "live-event-score") + "
"; ++shown; } if (!shown) out += "

" + live_text("Für diesen Filter liegt noch keine Demomeldung vor.") + "

"; out += "
" + live_text(std::to_string(shown) + " Meldungen · feste Aufzeichnung", "live-small") + "" + esc(phase_text) + "
"; out += "
" + live_text("+") + "" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "
"; out += ""; return out + live_dialog_markup(owner) + "
"; } 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"); } } }