// 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()); } // A value of the engine's tactics board in words: the attitude (item 0, lowest = most // defensive), the commitment (item 7) and the numbered variants of the play patterns. std::string live_tactic_value(size_t index, int value, int maximum) { return tactic_value_text(index, value, maximum); } 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"); } // Relative luminance and contrast of "#rrggbb" colours, for type on a club's colour. double mv_lum(const std::string &colour) { if (colour.size() < 7) return 0; double v[3]; for (size_t i = 0; i < 3; ++i) { const double x = std::stoi(colour.substr(1 + i * 2, 2), nullptr, 16) / 255.0; v[i] = x <= .03928 ? x / 12.92 : std::pow((x + .055) / 1.055, 2.4); } return .2126 * v[0] + .7152 * v[1] + .0722 * v[2]; } double mv_contrast(const std::string &a, const std::string &b) { const double x = mv_lum(a), y = mv_lum(b); return (std::max(x, y) + .05) / (std::min(x, y) + .05); } std::string mv_ink(const std::string &colour) { return mv_lum(colour) > .4 ? "#1d1611" : "#fffdf6"; } // A player's position as the three letters of the squad lists. std::string live_position_text(const Json &value) { if (!value.is_string()) return {}; std::string code = value.get(); for (auto &c : code) c = char(std::toupper(static_cast(c))); if (code == "TW" || code == "T" || code == "GK") return "TW"; if (code == "ABW" || code == "A" || code == "AB" || code == "DEF") return "ABW"; if (code == "MIT" || code == "M" || code == "MF" || code == "MID") return "MIT"; if (code == "STU" || code == "S" || code == "ST" || code == "FWD") return "STU"; return code; } 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 { if (owner.at("view").value("engine", false)) return Json::object(); 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 (owner.at("view").value("engine", false)) return owner.at("view").at("rows"); 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 + "
"; } // The small signs of the ticker and the squad list, drawn in the paper's ink. std::string App::live_icon(const std::string &kind, double size) { const bool dark = theme_ != "silver" && theme_ != "matchday"; const std::string ink = dark ? "#f0ece2" : "#2a211a", paper = dark ? "#2a2d34" : "#fffdf6"; std::string g; if (kind == "goal") g = ""; else if (kind == "chance" || kind == "save") g = ""; else if (kind == "miss") g = ""; else if (kind == "yellow") g = ""; else if (kind == "second_yellow") g = ""; else if (kind == "red") g = ""; else if (kind == "injury") g = ""; else if (kind == "up") g = ""; else if (kind == "down") g = ""; else if (kind == "same") g = ""; else if (kind == "substitution") g = ""; else g = ""; return picture(renderer_.diagram("mv-icon-" + kind + (dark ? "-d" : "-l"), "" + g + "", 96), size, size); } // The weather of a match as a picture; the code is the engine's weather picture 0-7. std::string App::live_weather_icon(int code, double size) { const std::string sun = ""; const auto cloud = [](const char *colour) { return std::string(""; }; std::string g; if (code <= 0) g = "" + sun + ""; else if (code == 1) g = "" + sun + "" + cloud("#cfc7b8"); else if (code <= 3) g = cloud("#b9b1a3"); else if (code <= 5) g = cloud("#9aa3a8") + ""; else g = cloud("#aeb6ba") + ""; return picture(renderer_.diagram("mv-weather-" + std::to_string(std::clamp(code, 0, 7)), "" + g + "", 160), size, size); } // The picture behind the match sheet. In fair weather it is one of the pitch photographs and // the home club keeps its picture; in rain it is one of the rain photographs, in snow the one // with sleet on the pane. Empty when the match is played in a hall or no picture is installed. std::string App::live_backdrop() const { if (scene_ != "live" || !live_.available()) return {}; try { const auto &fixture = live_.fixture(); if (live_indoor()) return {}; const auto owner = live_owner(); const Json *match = &fixture.at("matches").front(); if (owner.is_object()) for (const auto &row : fixture.at("matches")) if (row.at("id") == owner.at("match_id")) match = &row; int code = 0; if (match->contains("weather") && match->at("weather").is_object() && match->at("weather").value("rain", Json()).is_number_integer()) code = match->at("weather").at("rain").get(); const auto installed = [&](const char *family, std::initializer_list numbers) { std::vector keys; for (const int number : numbers) if (const std::string key = std::string(family) + std::to_string(number); gui_.contains(key)) keys.push_back(key); return keys; }; std::vector pictures; if (code >= 6) pictures = installed("match.rain-", {4}); if (pictures.empty() && code >= 4) pictures = installed("match.rain-", {1, 2, 3, 4, 5}); if (pictures.empty()) pictures = installed("match.pitch-", {1, 3, 4, 5, 6, 7, 8, 9}); if (pictures.empty()) return {}; size_t hash = 2166136261u; for (const unsigned char c : match->at("home").at("id").get()) hash = (hash ^ c) * 16777619u; return pictures[hash % pictures.size()]; } catch (const std::exception &) { return {}; } } // Played in a hall: the fixture says so, or the engine named the competition a hall tournament. bool App::live_indoor() const { if (!live_.available()) return false; const auto &fixture = live_.fixture(); if (fixture.at("surface") == "indoor") return true; for (const auto &match : fixture.at("matches")) if (match.value("competition", std::string()).find("Halle") != std::string::npos) return true; return false; } 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"); const auto rows = live_owner_rows(owner); const bool recorded = live_.fixture().at("source") == "engine-recording"; // what the match has brought each player so far: goals, a yellow card, a knock std::map> marks; const auto frame = live_.frame(); for (const auto &event : frame.at("events")) { if (!event.contains("player") || !event.at("player").is_object()) continue; const std::string id = event.at("player").value("id", std::string()), kind = event.value("kind", std::string()); if (id.empty()) continue; if (kind == "goal") ++marks[id][0]; if (kind == "yellow") ++marks[id][1]; if (kind == "injury") ++marks[id][2]; } const auto cell = [](const std::string &text, const char *css) { return "" + esc(text) + ""; }; const auto section = [](const std::string &text) { return "
" + esc(pg_upper(text)) + "
"; }; std::string out = "
" + cell("NR.", "w1") + cell("POS.", "w2 l") + cell("SPIELER", "g") + cell(national ? "CAPS" : "STÄRKE", "w3") + cell(national ? "TORE" : "KONDITION", "w4") + "
"; if (national && !recorded) out += section("Demokader auf Vereinsbasis · keine Nationalkaderberufung"); for (size_t i = 0; i < rows.size(); ++i) { if (int(i) == field_count) out += section(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : recorded ? "Ersatzbank und Reserve" : "Reserven · Demovorschau"); if (field_count == 6 && i == 11) out += section("Weitere Kaderreserven"); const auto &row = rows[i]; const std::string id = row.at("id").get(); std::string badges; if (const auto at = marks.find(id); at != marks.end()) { if (at->second[0]) badges += live_icon("goal", 31) + (at->second[0] > 1 ? "×" + std::to_string(at->second[0]) + "" : std::string()); if (at->second[1]) badges += ""; if (at->second[2]) badges += live_icon("injury", 27); } std::string last = cell(lineup_value(row.at(national ? "international_goals" : "condition")), "w4"); if (!national && row.at("condition").is_number()) { const int value = std::clamp(int(row.at("condition").get()), 0, 100); last = "
70 ? "#56874a" : value > 50 ? "#d9a441" : "#c8372d") + ";\">
" + std::to_string(value) + "
"; } out += "
" + cell(engine_shirt(id, i + 1), "w1") + cell(live_position_text(row.value("position", Json())), "w2 l pos") + "" + esc(row.at("name").get()) + "" + badges + "" + cell(lineup_value(row.at(national ? "caps" : "strength")), "w3") + last + "
"; } if (rows.empty()) out += "

" + esc(recorded ? "Für diese Mannschaft liegt keine Kaderansicht vor." : "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); const bool recorded = fixture.at("source") == "engine-recording"; const auto note = [](const std::string &text) { return "

" + esc(text) + "

"; }; const auto cell = [](const std::string &text, const char *css) { return "" + esc(text) + ""; }; if (live_tab_ == "table") { if (recorded && score.at("standings").empty()) return note("Diese Partie gehört zu keiner Ligatabelle."); if (fixture.at("role") == "national") return note("Dieses Länderspiel gehört zu keiner Liga."); // where every club stood at the kickoff, for the arrows std::map before; try { for (const auto &row : live_score_by_id(fixture.at("frames").front(), match.at("id")).at("standings")) before[row.at("team").at("id").get()] = row.at("position").get(); } catch (const std::exception &) {} bool results = false; for (const auto &row : score.at("standings")) results = results || (row.contains("won") && row.at("won").is_number_integer()); std::string out = "
" + cell("PL.", "w1") + cell("", "w0") + cell("VEREIN", "g") + cell("SP.", "w1") + (results ? cell("S", "w1") + cell("U", "w1") + cell("N", "w1") : std::string()) + cell("TORE", "w3") + cell("DIFF.", "w2") + cell("PKT.", "w2") + "
"; const auto colours = live_colours(match); for (const auto &row : score.at("standings")) { const std::string id = row.at("team").at("id").get(); const bool own = row.at("team").at("id") == owner.at("team").at("id"); const int position = row.at("position").get(), difference = row.at("gf").get() - row.at("ga").get(); const int was = before.contains(id) ? before.at(id) : position; const std::string colour = colours[match.at("home").at("id") == owner.at("team").at("id") ? 0 : 1]; const auto count = [&](const char *key) { return cell(row.contains(key) && row.at(key).is_number_integer() ? std::to_string(row.at(key).get()) : "–", "w1"); }; out += "
" + cell(std::to_string(position), "w1") + "" + (own ? std::string() : live_icon(position < was ? "up" : position > was ? "down" : "same", 22)) + "" + "" + live_badge(row.at("team"), 40) + "" + esc(row.at("team").at("name").get()) + "" + cell(std::to_string(row.at("played").get()), "w1") + (results ? count("won") + count("drawn") + count("lost") : std::string()) + cell(std::to_string(row.at("gf").get()) + ":" + std::to_string(row.at("ga").get()), "w3") + cell((difference > 0 ? "+" : "") + std::to_string(difference), "w2") + cell(std::to_string(row.at("points").get()), "w2") + "
"; } return out; } if (live_tab_ == "tactics" && live_.running() && engine_live_tactics_.size() == 8) { std::string out; for (size_t i = 0; i < engine_live_tactics_.size(); ++i) out += "
" + esc(engine_live_tactics_[i].at("label").get()) + "" + esc(i == 0 && engine_live_assistant_ ? std::string("Assistent passt an") : live_tactic_value(i, engine_live_tactics_[i].at("value").get(), engine_live_tactics_[i].at("max").get())) + "
"; return out + "
" + btn("live-intervene-tactics", "Taktik ändern", "mv-btn sm", "id=\"live-tactics-edit\"") + "
"; } if (live_tab_ == "tactics" && recorded) return note("Dieser Spieltag wurde mit der Aufstellung und Taktik vom Schreibtisch gespielt."); 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 "

" + esc(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", "mv-btn sm", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) + "
"; } if (live_tab_ == "opponent" && recorded) { // the other matches of the day, own competition first; known once the day is played if (!live_.finished() || !fixture.contains("conference") || !fixture.at("conference").is_array() || fixture.at("conference").empty()) return note(live_.finished() ? "An diesem Tag gab es keine weiteren Spiele." : "Die Ergebnisse der anderen Spiele stehen nach dem Abpfiff hier."); const std::string own = match.value("competition", std::string()); std::vector order; std::map groups; for (const auto &other : fixture.at("conference")) { const std::string name = other.at("competition").value("name", std::string("Weitere Spiele")); if (!groups.contains(name)) order.push_back(name); const auto &result = other.at("result").at("final"); Json home = other.at("home"), away = other.at("away"); if (!home.contains("role")) home["role"] = "club"; if (!away.contains("role")) away["role"] = "club"; groups[name] += "
" + esc(home.value("name", std::string())) + "" + live_badge(home, 40) + "" + std::to_string(result[0].get()) + " : " + std::to_string(result[1].get()) + "" + live_badge(away, 40) + "" + esc(away.value("name", std::string())) + "
"; } std::stable_sort(order.begin(), order.end(), [&](const std::string &a, const std::string &b) { return (a == own) > (b == own); }); std::string list; for (const auto &name : order) list += "
" + esc(pg_upper(name)) + "
" + groups.at(name); return list; } std::string out; if (live_tab_ == "opponent") { const auto &opponent = match.at(owner.at("team").at("id") == match.at("home").at("id") ? "away" : "home"); return "

" + esc(pg_upper("Gegner")) + "

" + esc(opponent.at("name").get()) + "

"; } const auto colours = live_colours(match); out = "
" + live_badge(match.at("home"), 58) + "" + esc(match.at("home").at("name").get()) + "
VERGLEICH
" + esc(match.at("away").at("name").get()) + "" + live_badge(match.at("away"), 58) + "
"; 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 += "
" + esc(pg_upper(label)) + "
" + std::to_string(a) + "
" + (a + b ? "
" : std::string()) + "
" + std::to_string(b) + "
"; } return out; } std::string App::live_dialog_markup(const Json &owner) { if (live_dialog_.empty()) return ""; const auto rows = live_owner_rows(owner); const bool lineup = live_dialog_ == "lineup"; const std::string team = owner.at("team").at("name").get(); std::string body = "
" + esc(pg_upper(live_.running() ? team : team + " · Demo")) + "

" + esc(lineup ? "Aufstellung & Wechsel" : "Taktik") + "

"; std::string hint; if (lineup) { const size_t count = size_t(live_.fixture().at("field_count").get()); std::string lists[2], names[2]; for (size_t i = 0; i < rows.size(); ++i) { const bool bench = i >= count; const std::string id = rows[i].at("id").get(); const bool chosen = id == (bench ? live_in_ : live_out_); if (chosen) names[bench] = rows[i].at("name").get(); const std::string strength = lineup_value(rows[i].value("strength", Json())), condition = lineup_value(rows[i].value("condition", Json())); lists[bench] += btn(bench ? "live-pick-in" : "live-pick-out", "" + engine_shirt(id, i + 1) + "" + esc(live_position_text(rows[i].value("position", Json()))) + "" + esc(rows[i].at("name").get()) + "" + esc(strength + " · " + condition) + "", std::string("mv-pick") + (chosen ? " selected" : ""), "id=\"live-pick-" + std::to_string(i) + "\" data-id=\"" + esc(id) + "\" aria-pressed=\"" + (chosen ? "true" : "false") + "\""); } for (auto &list : lists) if (list.empty()) list = "

" + esc("Niemand verfügbar.") + "

"; body += "
VOM FELD
" + lists[0] + "
VON DER ERSATZBANK
" + lists[1] + "
"; hint = !names[0].empty() && !names[1].empty() ? names[1] + " kommt für " + names[0] + "." : live_.running() ? "Wähle einen Spieler vom Feld und einen von der Bank. Das Spiel steht so lange." : "Nur lokale Vorschau; der feste Spielverlauf bleibt unverändert."; } 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 bool engine_board = live_.running() && engine_live_tactics_.size() == 8; const auto &values = engine_board ? live_dialog_draft_.at("values") : live_dialog_draft_.at("tactics").at("values"); body += "
"; for (size_t i = 0; i < names.size(); ++i) body += btn("live-tactic-cycle", "" + esc(engine_board ? engine_live_tactics_[i].at("label").get() : std::string(names[i])) + "" + esc(engine_board ? live_tactic_value(i, values[i].get(), engine_live_tactics_[i].at("max").get()) : "Wert " + std::to_string(values[i].get())) + "›", "mv-trow", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\""); body += "

" + esc((engine_board ? tactic_effect_text(size_t(std::clamp(last_tactic_, 0, 7))) + " " : std::string()) + "Ein Klick auf eine Zeile schaltet den Wert weiter.") + "

"; } body += "
" + (hint.empty() ? std::string() : "" + esc(hint) + "") + btn("live-dialog-cancel", "Abbrechen", "mv-btn", "id=\"live-dialog-cancel\"") + btn("live-dialog-apply", live_.running() ? (lineup ? "Wechsel ausführen" : "Taktik übernehmen") : "Demovorschau anzeigen", "mv-btn primary", "id=\"live-dialog-apply\" " + std::string(lineup && (live_out_.empty() || live_in_.empty()) ? "disabled" : "")) + "
"; return "
" + body + "
"; } std::string App::live_ticker_events(const Json &frame, size_t &shown) { const auto &fixture = live_.fixture(); const bool recorded = fixture.at("source") == "engine-recording"; const bool several = fixture.at("matches").size() > 1; const bool dark = theme_ != "silver" && theme_ != "matchday"; const std::string paper = dark ? "#2a2d34" : "#fffdf6"; shown = 0; std::string out; 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" && kind != "second_yellow") continue; if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "miss" && kind != "red" && kind != "second_yellow") continue; const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id")); const bool whistle = kind == "kickoff" || kind == "interval" || kind == "fulltime" || kind == "restart"; const auto side = event.at("side").get(); // one line per report: minute, what happened, the club, the wording, the score std::string head_style; if (kind == "goal") { const std::string colour = live_colours(match)[side == "away" ? 1 : 0]; if (mv_contrast(colour, paper) >= (dark ? 4.5 : 3)) head_style = " style=\"color:" + colour + ";\""; } out += "
()) + "\">" + "" + std::to_string(event.at("minute").get()) + "′" + live_icon(whistle ? "time" : kind, 40) + "" + (whistle ? std::string() : live_badge(match.at(side), 50)) + "
" + (several || !recorded ? "" + esc(match.at("home").at("name").get() + " – " + match.at("away").at("name").get()) + "" : std::string()) + "

" + esc(event.at("headline").get()) + "

" + esc(event.at("body").get()) + "

" + std::to_string(event.at("score")[0].get()) + ":" + std::to_string(event.at("score")[1].get()) + "
"; ++shown; } if (!shown && recorded && live_filter_ == "all" && frame.at("events").empty()) { // before the first report: who starts for (const auto &match : fixture.at("matches")) { if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue; if (!match.contains("lineups") || !match.at("lineups").is_object()) continue; std::string columns; for (const auto *side : {"home", "away"}) { const auto names = match.at("lineups").value(side, Json()); columns += "

" + esc(match.at(side).at("name").get()) + "

"; if (names.is_array() && !names.empty()) { size_t number = 0; for (const auto &name : names) columns += "
" + std::to_string(++number) + "" + esc(name.get()) + "
"; } else columns += "

" + esc("Aufstellung nicht bekannt.") + "

"; columns += "
"; } out += "
" + columns + "
"; } if (!out.empty()) return out; } if (!shown) out += "

" + esc(frame.at("events").empty() ? "Noch ist nichts passiert." : "Keine Meldungen in dieser Auswahl.") + "

"; return out; } std::array App::live_colours(const Json &match) { // from the crests; a club without one, or a national side, plays in slate. Two sides in // nearly the same colour: the guests change into a dark neutral. const auto colour = [&](const Json &team) { std::string value; if (team.value("role", "club") != "national" && live_world_) if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty()) value = renderer_.crest_colour(club->value("crest", "")); return value; }; std::array out{colour(match.at("home")), colour(match.at("away"))}; const auto channel = [](const std::string &c, size_t at) { return std::stoi(c.substr(at, 2), nullptr, 16); }; if (out[0].empty()) out[0] = "#3d5a73"; if (out[1].empty()) out[1] = "#7a4a3a"; int distance = 0; for (size_t at : {1u, 3u, 5u}) distance += std::abs(channel(out[0], at) - channel(out[1], at)); if (distance < 110) out[1] = "#3a4148"; return out; } // One match on the sheet: crests, the score tiles in the clubs' colours, the clock, who is // pressing, and the time line with every goal, card and injury so far. `layout` is solo // (one match), duo (two) or quad (three or four). std::string App::live_card(const Json &match, const Json &frame, const std::string &layout, size_t index) { const auto &fixture = live_.fixture(); const bool recorded = fixture.at("source") == "engine-recording"; const auto &value = live_score_by_id(frame, match.at("id")); const int minute = frame.at("minute"), duration = std::max(1, fixture.value("duration", 90)); const auto colours = live_colours(match); const bool quad = layout == "quad", solo = layout == "solo"; const bool dark = theme_ != "silver" && theme_ != "matchday"; const std::string ink = dark ? "#f0ece2" : "#2a211a", paper = dark ? "#2a2d34" : "#fffdf6"; const auto id = match.at("id").get(); // the clock: a ring that fills with the minutes const double round = 2 * 3.14159265 * 13, turn = std::clamp(double(minute) / duration, 0.0, 1.0) * round; const std::string ring = ""; // the time line: grass in bands of fifteen minutes, the home side's marks above, the guests' below const double W = solo ? 868 : 421, H = quad ? 34 : 76, y0 = quad ? 10 : 22, sh = quad ? 14 : 32, away_y = y0 + sh + (quad ? 5 : 12), home_y = y0 - (quad ? 5 : 12); const auto X = [&](double at) { return 10 + at / duration * (W - 20); }; int press[2] = {0, 0}; std::string marks, bands; for (int from = 0; from < duration; from += 15) bands += ""; for (const auto &event : frame.at("events")) { if (event.at("match_id") != match.at("id")) continue; const auto kind = event.value("kind", std::string()); const size_t side = event.value("side", std::string("home")) == "away" ? 1 : 0; const int at = event.at("minute").get(); if ((kind == "goal" || kind == "chance" || kind == "miss") && at > minute - 10) press[side] += kind == "goal" ? 3 : 1; const double x = X(std::clamp(at, 0, duration)), y = side ? away_y : home_y; if (kind == "goal") marks += ""; else if (kind == "yellow" || kind == "red" || kind == "second_yellow") marks += ""; else if (kind == "injury") { const double arm = quad ? 3.5 : 5.5; marks += ""; } } const double now = X(std::clamp(minute, 0, duration)); const std::string timeline = "" + bands + "" + "" + (live_.finished() || minute < 1 ? std::string() : "") + marks + ""; const int total = press[0] + press[1]; const double share = total ? 100.0 * press[0] / total : 50; const auto phase = frame.at("phase").get(); const std::string status = live_.finished() ? "Abpfiff" : phase == "interval" ? "Halbzeit" : minute < 1 ? "Anpfiff" : std::to_string(minute) + "′"; std::string names; for (const auto &owner_id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == owner_id) { if (!names.empty()) names += " · "; names += person.at("name").get(); } const bool several = fixture.at("owners").size() > 1; const std::string competition = recorded ? match.value("competition", std::string("Spieltag")) : std::string("Demospiel"); const double crest = solo ? 86 : quad ? 34 : 50; const auto team = [&](size_t side) { const auto &club = match.at(side ? "away" : "home"); const int players = value.at("players")[side].get(); return "
" + live_badge(club, crest * 2.25) + "
" + esc(club.at("name").get()) + "" + esc(std::string(side ? "Gast" : "Heim") + (players < int(fixture.value("field_count", 11)) ? " · " + std::to_string(players) + " Spieler" : std::string())) + "
"; }; const auto tile = [&](size_t side) { return "
" + std::to_string(value.at("score")[side].get()) + "
"; }; std::string out = ""; } std::string App::render_live() { if(live_review_) return render_postmatch(); return live_sheet({}); } // The match sheet; `over` replaces the sheet's own notes (substitution, tactics) on top of it. std::string App::live_sheet(const std::string &over) { 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 bool recorded = fixture.at("source") == "engine-recording"; const size_t count = fixture.at("matches").size(); const std::string layout = count == 1 ? "solo" : count == 2 ? "duo" : "quad"; const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? (recorded ? (phase == "extra_time" ? "Verlängerung" : phase == "shootout" ? "Elfmeterschießen" : "Spiel läuft") : "Aufzeichnung läuft") : (recorded ? "Pausiert" : "Gemeinsam pausiert"); const bool indoor = live_indoor(); const std::string title = fixture.at("role") == "national" ? "Länderspiel" : indoor ? "Hallenturnier" : recorded && count == 1 ? fixture.at("matches").front().value("competition", std::string("Spieltag")) : std::string("Spieltag"); const auto tab = [](const char *action, const std::string &id, const std::string &text, bool selected, const std::string &prefix) { return btn(action, text, std::string("mv-tab") + (selected ? " selected" : ""), "id=\"" + prefix + id + "\" data-id=\"" + id + "\" aria-pressed=\"" + (selected ? "true" : "false") + "\""); }; // an open match sheet in front of the stadium: on the left page the cards of the human // managers' matches and the ticker, on the right the ground, the weather and the manager's // team; the controls run along the foot std::string out = "
()) + "\">"; out += "
" + esc(pg_upper("Spieltag · Textmodus")) + "

" + esc(title) + "

" + esc(recorded ? ui_long_date(fixture.value("date", std::string())) : std::string("Demo · vorgegebene Ergebnisse")) + "
"; out += "
"; size_t index = 0; for (const auto &match : fixture.at("matches")) out += live_card(match, frame, layout, index++); out += "
"; size_t shown = 0; out += live_ticker_events(frame, shown); out += "
" + esc(std::to_string(shown) + (shown == 1 ? " Meldung" : " Meldungen")) + "" + esc(phase_text) + "
"; // the right page: the ground and the weather, then the manager's team out += "
"; out += "
" + btn("live-back", live_.running() ? "Zu Ende spielen" : recorded ? "Zum Schreibtisch" : "Zum Desktop", "mv-btn", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "mv-btn play", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")); out += "
"; for (int step = 0; step <= 4; ++step) out += btn("live-speed-set", step ? std::to_string(step) + "×" : std::string("II"), live_.speed() == step ? "selected" : "", "id=\"live-speed-" + std::to_string(step) + "\" data-id=\"" + std::to_string(step) + "\" aria-pressed=\"" + (live_.speed() == step ? "true" : "false") + "\" aria-label=\"" + (step ? "Tempo " + std::to_string(step) : std::string("Pause")) + "\" " + (live_.finished() ? "disabled" : "")); out += "
"; if (live_.running()) { const auto halt = [](const char *id, const char *label, bool on) { return btn("live-halt", "" + std::string(label) + "", std::string("mv-sw") + (on ? " selected" : ""), "id=\"live-halt-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (on ? "true" : "false") + "\""); }; out += halt("interval", "Zur Halbzeit anhalten", live_halt_interval_) + halt("behind", "Bei Rückstand anhalten", live_halt_behind_); } out += "" + esc(live_feedback_.empty() ? (recorded ? std::string() : std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung") : live_feedback_) + "" + btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : live_.running() ? "Nächste Minute" : "Nächste Meldung", "mv-btn primary", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "
"; return out + (over.empty() ? live_dialog_markup(owner) : over) + "
"; } 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-stage .mv-bar button"); for (auto *node : controls) { node->SetProperty("pointer-events", "none"); node->SetAttribute("tabindex", "-1"); } } } // Apply local navigation only after event dispatch. The untouched match cards, // ticker and speed input retain their DOM identity, focus and pointer capture. void App::live_update_parts() { if (!live_detail_pending_ && !live_ticker_pending_ && focus_after_render_.empty()) return; if (scene_ != "live" || live_review_ || !live_.available() || !live_dialog_.empty() || !popup_.empty()) { live_detail_pending_ = live_ticker_pending_ = false; return; } const auto frame = live_.frame(); if (live_detail_pending_) { const auto owner = live_owner(); auto *body = element("live-detail-body"); auto *team = element("live-owner-team"); auto *name = element("live-owner-name"); if (!body || !team || !name) { refresh(); return; } team->SetInnerRML(esc(owner.at("team").at("name").get())); name->SetInnerRML(esc(owner.at("name").get())); body->SetInnerRML(live_detail(owner, frame)); body->SetScrollTop(0); live_detail_scroll_ = 0; live_reset_detail_ = false; Rml::ElementList tabs; doc_->QuerySelectorAll(tabs, "#live-detail .mv-tab"); for (auto *tab : tabs) { const bool selected = tab->GetAttribute("data-id", "") == live_tab_; tab->SetClass("selected", selected); tab->SetAttribute("aria-pressed", selected ? "true" : "false"); } ++live_detail_updates_; } if (live_ticker_pending_) { auto *list = element("live-ticker"); auto *count = element("live-event-count"); if (!list || !count) { refresh(); return; } size_t shown = 0; list->SetInnerRML(live_ticker_events(frame, shown)); count->SetInnerRML(esc(std::to_string(shown) + (shown == 1 ? " Meldung" : " Meldungen"))); list->SetScrollTop(0); live_ticker_scroll_ = 0; live_reset_ticker_ = false; Rml::ElementList filters; doc_->QuerySelectorAll(filters, "#live-filters .mv-tab"); for (auto *filter : filters) { const bool selected = filter->GetAttribute("data-id", "") == live_filter_; filter->SetClass("selected", selected); filter->SetAttribute("aria-pressed", selected ? "true" : "false"); } ++live_ticker_updates_; } live_detail_pending_ = live_ticker_pending_ = false; if (!focus_after_render_.empty()) { if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_); focus_after_render_.clear(); } dirty_ = true; }