From 1732a2477bd75351db87818cf8bb1bd79f67398d Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sat, 14 Nov 2026 11:34:47 +0100 Subject: [PATCH] Liven up the match day: varied ticker wording, whistles, results of the day, eleven of the day The ticker picks its sentence from several variants by the event's facts and names equalisers, leads and late goals; kickoff, half time and the final whistle are reported, with the same wording while the kickoff runs live. The ticker's third tab lists the other results of the day. Modern chooses an eleven of the day per league from the recorded match facts and the review shows it. Co-Authored-By: Claude Fable 5.2 --- docs/DIFFERENCES.md | 1 + src/modern/app/modern_session.cpp | 25 +++- src/modern/content/statistics.cpp | 175 ++++++++++++++++++++++++--- src/modern/content/statistics.hpp | 10 ++ src/modern/ui/engine_controls.inc | 3 + src/modern/ui/engine_live.cpp | 55 +++++++++ src/modern/ui/engine_live.hpp | 3 + src/modern/ui/live_controls.inc | 2 +- src/modern/ui/live_screens.inc | 29 ++++- src/modern/ui/live_state.inc | 1 + src/modern/ui/postmatch_controls.inc | 8 ++ 11 files changed, 288 insertions(+), 24 deletions(-) diff --git a/docs/DIFFERENCES.md b/docs/DIFFERENCES.md index 1479cb9..dc75164 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -43,6 +43,7 @@ describe deliberate changes; they are not a list of every known compatibility li - [src/modern/game/desk_actions.hpp](../src/modern/game/desk_actions.hpp): supports designated set-piece records and the supported transfer-editor rules. - [src/modern/game/environment.hpp](../src/modern/game/environment.hpp): uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands. - [src/modern/game/highscore.cpp](../src/modern/game/highscore.cpp): reads the supported edition-specific high-score format from the loaded image. +- [src/modern/content/statistics.cpp](../src/modern/content/statistics.cpp): Modern chooses its own eleven of the day per league from the recorded facts of the matchday (goals, assists, cards, result, clean sheets) instead of the original's Sportschau rating, and words the ticker from several variants per event. - [src/modern/game/matchday_setup.cpp](../src/modern/game/matchday_setup.cpp): in Modern worlds a referee may take a second match on a day with more matches than referees. - [src/modern/game/month.cpp](../src/modern/game/month.cpp): in Modern every manager receives the monthly dividend of his own shares; the price product is kept in 64 bits until the division. - [src/modern/game/season.cpp](../src/modern/game/season.cpp): retains the enhanced academy player-generation strength bands with monthly youth budgets. diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index b5fc639..97f6474 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -8730,14 +8730,28 @@ cli::Json ModernSession::read_live(const cli::Json& request) const { }; cli::Json::Array events; const auto& log = grp.log; + // the ticker's wording, as the recording will carry it after the final whistle + int goals_home = 0, goals_away = 0; + const auto plain_name = [this](int p) -> std::string { + if (p < 0 || p >= 0x0fff || size_t(p) >= g_.players.size()) return {}; + const std::string first = size_t(p) < g_.player_first.size() ? g_.player_first[size_t(p)] : std::string{}; + std::string last = size_t(p) < g_.player_last.size() ? g_.player_last[size_t(p)] : std::string{}; + if (last.empty()) last = ui::original_to_utf8(g_.player_name(p)); + return first.empty() ? last : first + " " + last; + }; for (size_t w = 0; w + 1 < log.size(); w += 2) { const int code = log[w] >> 12, player = log[w] & 0x0fff; const int side_team = log[w + 1] >> 7, value = log[w + 1] & 0x7f; int assistant = 0x0fff; if ((code == 0 || code == 1) && w + 3 < log.size()) assistant = log[w + 2] & 0x0fff, w += 2; if ((side_team != home && side_team != away) || code > 6 || code == 2) continue; + const bool away_side = side_team != home; + if (code == 0) ++(away_side ? goals_away : goals_home); + static constexpr int kAlmanacKind[7] = {0, 7, 0, 1, 3, 2, 4}; // log code -> AlmanacEventKind + const auto [headline, body] = modern::ticker_phrase(kAlmanacKind[code], club_label(side_team), plain_name(player), + plain_name(assistant), 0, value, goals_home, goals_away, away_side); events.push_back(O{{"minute", value}, {"kind", kKinds[code]}, {"side", side_team == home ? "home" : "away"}, - {"player", person(player)}, {"other", person(assistant)}}); + {"player", person(player)}, {"other", person(assistant)}, {"headline", headline}, {"body", body}}); } matches.push_back(O{{"events", std::move(events)}, {"home", O{{"id", modern::ui_team_id(g_, home)}, {"name", club_label(home)}}}, @@ -9119,11 +9133,16 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co return cli::Json(O{{"id", id}, {"available", ok}, {"reasonCode", ok ? cli::Json(nullptr) : cli::Json("not_recorded")}}); }; const bool any = !matches.array()->empty(); + // Modern chooses its own eleven from the recorded day; the original's Sportschau choice + // (only with its replay option) takes precedence when it exists + cli::Json eleven = !ui_last_awards_.empty() ? cli::Json(ui_last_awards_) + : modern::team_of_the_day(g_, ui_last_advance_->first, ui_last_advance_->second); + const bool has_eleven = eleven.array() && !eleven.array()->empty(); return modern::ui_snapshot(g_, context, request_id, O{{"kind", "postmatch"}, {"presentationId", "presentation:postmatch-" + std::to_string(ui_last_advance_revision_)}, - {"steps", A{step("results", any), step("report", !report.empty()), step("team_of_the_day", !ui_last_awards_.empty()), + {"steps", A{step("results", any), step("report", !report.empty()), step("team_of_the_day", has_eleven), step("overview", any), step("table", !tables.empty())}}, - {"matches", std::move(matches)}, {"reportMatchIds", std::move(report)}, {"teamOfTheDay", ui_last_awards_}, + {"matches", std::move(matches)}, {"reportMatchIds", std::move(report)}, {"teamOfTheDay", std::move(eleven)}, {"tables", std::move(tables)}}); } const int team = g_.manager_teams[size_t(manager)]; diff --git a/src/modern/content/statistics.cpp b/src/modern/content/statistics.cpp index f20f647..8a671a4 100644 --- a/src/modern/content/statistics.cpp +++ b/src/modern/content/statistics.cpp @@ -850,29 +850,75 @@ cli::Json query_rankings(const ModernState& g, int manager, const cli::Json& req // --- the live ticker of the Modern UI: the recorded matches of the last kickoff --------------- +// The ticker's wording of one event. The sentence is picked from a few variants by the +// event's own facts (minute, side, kind), so the same match always reads the same and no +// random number of the game is drawn. `home`/`away` is the score after the event. +std::pair ticker_phrase(int kind, const std::string& team, const std::string& who, + const std::string& other, int detail, int minute, int home, int away, + bool away_side) { + const std::string score = std::to_string(home) + ":" + std::to_string(away); + const std::string player = who.empty() ? team : who; + const auto pick = [&](std::initializer_list variants) { + const size_t n = variants.size(); + uint32_t hash = 2166136261u; // FNV-1a over the player's name, the minute, the kind and the side + for (unsigned char c : player) hash = (hash ^ c) * 16777619u; + for (unsigned v : {unsigned(minute), unsigned(kind), away_side ? 1u : 0u}) hash = (hash ^ v) * 16777619u; + const size_t at = size_t(hash >> 7) % n; + return std::string(*(variants.begin() + at)); + }; + const auto fill = [&](std::string text) { + for (const auto& [key, value] : {std::pair{"%p", player}, {"%t", team}, {"%s", score}, {"%o", other}}) + for (size_t at = text.find(key); at != std::string::npos; at = text.find(key, at + value.size())) text.replace(at, 2, value); + return text; + }; + switch (AlmanacEventKind(kind)) { + case AlmanacEventKind::Goal: { + const int own = away_side ? away : home, theirs = away_side ? home : away; + std::string headline = own == theirs ? "Ausgleich für " + team + : own == theirs + 1 ? "Führung für " + team + : own > theirs + 2 ? team + " zieht davon" + : own == theirs - 1 ? "Anschlusstreffer für " + team + : "Tor für " + team; + std::string body = detail == 1 ? pick({"%p verwandelt den ruhenden Ball zum %s.", "%p trifft nach einem Standard zum %s."}) + : detail == 2 ? pick({"%p staubt zum %s ab.", "%p ist beim Nachschuss zur Stelle: %s."}) + : detail == 3 ? pick({"%p trifft nach einer Ecke zum %s.", "Ecke, Abschluss, Tor: %p erzielt das %s."}) + : pick({"%p trifft zum %s.", "%p vollendet zum %s.", "%p lässt dem Torwart keine Chance: %s.", + "%p schließt zum %s ab."}); + if (!other.empty()) body += pick({" Vorlage: %o.", " %o hatte aufgelegt.", " Die Vorarbeit kam von %o."}); + if (minute >= 88 && own == theirs + 1) body += " Ein später Treffer."; + return {headline, fill(body)}; + } + case AlmanacEventKind::Miss: + return {"Chance für " + team, + fill(detail == 1 ? pick({"%p vergibt den Standard.", "%p setzt den ruhenden Ball neben das Tor."}) + : detail == 3 ? pick({"Nach einer Ecke kommt %p zum Abschluss, ohne Erfolg.", "%p köpft nach der Ecke vorbei."}) + : pick({"%p vergibt.", "%p scheitert am Torwart.", "%p zielt zu ungenau.", "%p bringt den Ball nicht im Tor unter."}))}; + case AlmanacEventKind::YellowCard: + return {"Gelbe Karte", fill(pick({"%p (%t) sieht Gelb.", "Gelb für %p (%t).", "%p (%t) wird verwarnt."}))}; + case AlmanacEventKind::SecondYellow: + return {"Gelb-Rot", fill(pick({"%p (%t) sieht Gelb-Rot und muss vom Platz.", "Zweite Verwarnung für %p: %t spielt in Unterzahl weiter."}))}; + case AlmanacEventKind::RedCard: + return {"Rote Karte", fill(pick({"%p (%t) sieht Rot.", "Platzverweis für %p: %t spielt in Unterzahl weiter."}))}; + case AlmanacEventKind::Injury: + return {"Verletzung", fill(pick({"%p (%t) muss behandelt werden.", "%p (%t) bleibt verletzt liegen."}))}; + case AlmanacEventKind::Substitution: + return {"Wechsel bei " + team, + fill(other.empty() ? "%p kommt ins Spiel." : pick({"%p kommt für %o.", "%o geht, %p kommt.", "%p ersetzt %o."}))}; + case AlmanacEventKind::ShootoutKick: + return {"Elfmeterschießen", fill(detail ? pick({"%p verwandelt.", "%p trifft sicher."}) : pick({"%p verschießt.", "%p scheitert."}))}; + } + return {"", ""}; +} + namespace { // The ticker's lines for an event of the almanac (German, as the interface's demo). std::pair ticker_text(const AlmanacSeason& s, const AlmanacMatch& m, const AlmanacEvent& e, int home, int away) { const std::string team = s.clubs[e.side ? m.away : m.home].name; - const std::string who = e.player != kAlmanacNone && e.player < s.players.size() ? player_name(s.players[e.player]) : team; + const std::string who = e.player != kAlmanacNone && e.player < s.players.size() ? player_name(s.players[e.player]) : std::string{}; const std::string other = e.other != kAlmanacNone && e.other < s.players.size() ? player_name(s.players[e.other]) : std::string{}; - const std::string score = std::to_string(home) + ":" + std::to_string(away); - switch (e.kind) { - case AlmanacEventKind::Goal: - return {"Tor für " + team, who + " trifft zum " + score + "." + (other.empty() ? "" : " Vorlage: " + other + ".")}; - case AlmanacEventKind::Miss: return {"Chance für " + team, who + " vergibt."}; - case AlmanacEventKind::YellowCard: return {"Gelbe Karte", who + " (" + team + ") sieht Gelb."}; - case AlmanacEventKind::SecondYellow: return {"Gelb-Rot", who + " (" + team + ") muss vom Platz."}; - case AlmanacEventKind::RedCard: return {"Rote Karte", who + " (" + team + ") fliegt vom Platz."}; - case AlmanacEventKind::Injury: return {"Verletzung", who + " (" + team + ") ist verletzt."}; - case AlmanacEventKind::Substitution: - return {"Wechsel bei " + team, who + (other.empty() ? " kommt ins Spiel." : " kommt für " + other + ".")}; - case AlmanacEventKind::ShootoutKick: - return {"Elfmeterschießen", who + (e.detail ? " verwandelt." : " verschießt.")}; - } - return {"", ""}; + return ticker_phrase(int(e.kind), team, who, other, e.detail, e.minute, home, away, e.side != 0); } const char* event_kind(AlmanacEventKind k) { @@ -1045,6 +1091,27 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until {"body", body}, {"score", A{J(t.score[0]), J(t.score[1])}}, {"side", side ? "away" : "home"}, {"player", almanac_person(s, e.player)}, {"other", almanac_person(s, e.other)}}); } + if (!mo.event && mo.phase) { + // the whistle: kickoff, half time and the end of each ticker match, with the score then + const std::string phase = mo.phase; + const char* kind = phase == "kickoff" ? "kickoff" : phase == "interval" ? "interval" + : phase == "fulltime" || phase == "shootout_end" ? "fulltime" : nullptr; + for (size_t k = 0; kind && k < human.size(); ++k) { + const AlmanacSeason& s = *human[k].season; + const AlmanacMatch& m = s.matches[human[k].index]; + const Tally& t = tally[k]; + const std::string mid = match_id(s, human[k].index); + const std::string score = std::to_string(t.score[0]) + ":" + std::to_string(t.score[1]); + const std::string headline = phase == "kickoff" ? "Anpfiff" : phase == "interval" ? "Halbzeit" : "Abpfiff"; + const std::string body = phase == "kickoff" ? s.clubs[m.home].name + " gegen " + s.clubs[m.away].name + ": Der Ball rollt." + : phase == "interval" ? "Zur Pause steht es " + score + "." + : phase == "shootout_end" ? "Das Elfmeterschießen ist entschieden." + : mo.minute > 90 ? "Endstand nach Verlängerung: " + score + "." : "Endstand: " + score + "."; + events.push_back(O{{"id", mid + ":event:" + std::to_string(events.size())}, {"sequence", int64_t(frames.size())}, + {"match_id", mid}, {"minute", mo.minute}, {"kind", kind}, {"headline", headline}, {"body", body}, + {"score", A{J(t.score[0]), J(t.score[1])}}, {"side", "home"}, {"player", nullptr}, {"other", nullptr}}); + } + } A scores; for (size_t k = 0; k < human.size(); ++k) { const Tally& t = tally[k]; @@ -1074,7 +1141,83 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until {"notice", "Aufzeichnung der Engine: die Spiele des letzten Anstoßes"}}; } +// Modern's eleven of the day: for every league with a match of a human manager in the kickoff, +// the best starters of that league's matches by what the almanac recorded (goals, assists, +// cards, the result, clean sheets), one goalkeeper, three defenders, four midfielders and +// three forwards. Nothing is drawn at random and no rating of the original is used; the +// current strength of a player only breaks ties. +cli::Json team_of_the_day(const ModernState& g, uint32_t from_date, uint32_t until_date) { + std::map runtime; // world player id -> runtime index + for (size_t p = 0; p < g.world_player_id.size(); ++p) + if (!g.world_player_id[p].empty()) runtime[g.world_player_id[p]] = int(p); + A out; + const auto seasons = seasons_of(g); + for (const auto& s : seasons) { + std::set leagues; + for (const auto& m : s.matches) + if (m.date >= from_date && m.date <= until_date && m.type == 0 && m.league < kLeagueCount && + (m.home_manager >= 0 || m.away_manager >= 0)) leagues.insert(m.league); + for (const int league : leagues) { + struct Candidate { int score = 0, strength = 0, position = 0; uint16_t player = 0, club = 0; }; + std::vector candidates; + for (const auto& m : s.matches) { + if (m.date < from_date || m.date > until_date || m.type != 0 || m.league != league) continue; + for (int side = 0; side < 2; ++side) { + const int scored = side ? m.away_goals : m.home_goals, conceded = side ? m.home_goals : m.away_goals; + const auto& lineup = m.lineup[size_t(side)]; + for (size_t i = 0; i < lineup.size() && i < 11; ++i) { + const uint16_t player = lineup[i]; + if (player == kAlmanacNone || player >= s.players.size()) continue; + const auto at = runtime.find(s.players[player].id); + if (at == runtime.end() || size_t(at->second) >= g.players.size()) continue; + const Player& now = g.players[size_t(at->second)]; + Candidate c; + c.player = player, c.club = side ? m.away : m.home; + c.position = std::clamp(int(now.position()), 0, 3), c.strength = int(now.strength()); + c.score = 10 + (scored > conceded ? 4 : scored == conceded ? 1 : 0); + if (conceded == 0) c.score += c.position == 0 ? 8 : c.position == 1 ? 5 : 0; + if (c.position == 0) c.score -= 2 * conceded; + for (const auto& e : m.events) { + if (e.kind == AlmanacEventKind::Goal && e.side == side && e.player == player) c.score += 12; + if (e.kind == AlmanacEventKind::Goal && e.side == side && e.other == player) c.score += 6; + if (e.kind == AlmanacEventKind::YellowCard && e.side == side && e.player == player) c.score -= 4; + if ((e.kind == AlmanacEventKind::RedCard || e.kind == AlmanacEventKind::SecondYellow) && e.side == side && + e.player == player) c.score -= 12; + } + candidates.push_back(c); + } + } + } + std::stable_sort(candidates.begin(), candidates.end(), [&](const Candidate& a, const Candidate& b) { + if (a.score != b.score) return a.score > b.score; + if (a.strength != b.strength) return a.strength > b.strength; + return s.players[a.player].id < s.players[b.player].id; + }); + static constexpr int kWanted[4] = {1, 3, 4, 3}; + static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"}; + A players; + bool complete = true; + for (int position = 0; position < 4; ++position) { + int taken = 0; + for (const Candidate& c : candidates) { + if (c.position != position || taken == kWanted[position]) continue; + ++taken; + players.push_back(O{{"playerId", s.players[c.player].id}, {"name", player_name(s.players[c.player])}, + {"teamId", s.clubs[c.club].id}, {"club", s.clubs[c.club].name}, + {"position", kPositions[position]}, {"score", c.score}}); + } + complete = complete && taken == kWanted[position]; + } + if (!complete) continue; + const Competition c = league_competition(s, league); + out.push_back(O{{"competitionId", c.id}, {"competition", c.name}, {"formation", "3-4-3"}, {"players", std::move(players)}}); + } + } + return out; +} + cli::Json almanac_matches_between(const ModernState& g, uint32_t from_date, uint32_t until_date) { + A out; for (const auto& s : seasons_of(g)) for (size_t i = 0; i < s.matches.size(); ++i) diff --git a/src/modern/content/statistics.hpp b/src/modern/content/statistics.hpp index d4962dc..fb4d180 100644 --- a/src/modern/content/statistics.hpp +++ b/src/modern/content/statistics.hpp @@ -12,6 +12,8 @@ // goals, assists, cards per player in one competition, // of one season ("2026/27") or all seasons +#include +#include #include #include "cli/json.hpp" @@ -45,6 +47,14 @@ cli::Json query_statistics_screen(const ModernState& g, int manager, const cli:: // score, chances, cards and players per match, the event lines, and the other matches of the // day as the conference. source: "engine-recording". cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until_date, uint64_t revision); +// Modern's eleven of the day per league with a human match in the kickoff (3-4-3), chosen from +// the recorded facts of that league's matches; empty when a line is short of players. +cli::Json team_of_the_day(const ModernState& g, uint32_t from_date, uint32_t until_date); +// The ticker's headline and sentence for one event (kind as AlmanacEventKind); `home`/`away` is the +// score after it. Deterministic: the variant follows from the event's facts. +std::pair ticker_phrase(int kind, const std::string& team, const std::string& who, + const std::string& other, int detail, int minute, int home, int away, + bool away_side); // The press events of a team (contract team id) with from <= date <= until (ISO dates), derived // from the almanac and so the same on every read: match.result, cup.round_result / diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 583a624..1c30503 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -48,6 +48,7 @@ void App::engine_kickoff() { return EngineReply{link, desk, response, nullptr}; } response["liveRecording"] = state; + response["postmatch"] = link->read({{"kind", "postmatch"}}); auto after = link->snapshot(); engine_attach_opening(*link, engine_season_id(desk), after, response); return EngineReply{link, std::move(after), response, nullptr}; @@ -148,6 +149,8 @@ void App::engine_accept(EngineReply result) { engine_live_begin(state, engine_response_.value("newRevision", std::string())); } if (engine_response_.contains("liveRecording")) { + engine_postmatch_read_ = engine_response_.value("postmatch", Json()); + engine_response_.erase("postmatch"); const Json recording = engine_response_.at("liveRecording"); engine_response_.erase("liveRecording"); engine_advance_payload_ = Json::object(); diff --git a/src/modern/ui/engine_live.cpp b/src/modern/ui/engine_live.cpp index 3262401..049b223 100644 --- a/src/modern/ui/engine_live.cpp +++ b/src/modern/ui/engine_live.cpp @@ -207,7 +207,40 @@ Json engine_live_command(const Json &bundle, const std::string &revision, const {"kind", kind}, {"payload", payload.is_object() ? payload : Json::object()}}; } +Json engine_post_match_records(const Json &read, const Json &fixture) { + try { + if (!read.is_object() || read.value("messageType", "") != "snapshot") return Json(); + const auto &elevens = read.at("data").at("teamOfTheDay"); + if (!elevens.is_array() || elevens.empty()) return Json(); + // club names as the recording spells them (its matches and final tables) + std::map clubs; + for (const auto &match : fixture.at("matches")) + for (auto side : {"home", "away"}) clubs[match.at(side).at("id")] = match.at(side).at("name"); + for (const auto &snapshot : fixture.at("frames").back().at("matches")) + for (const auto &row : snapshot.at("standings")) clubs[row.at("team").at("id")] = row.at("team").at("name"); + for (const auto &eleven : elevens) { + if (!eleven.contains("players") || !eleven.at("players").is_array() || eleven.at("players").size() != 11) continue; + Json rows = Json::array(); + for (const auto &p : eleven.at("players")) { + const auto club = clubs.find(p.value("teamId", std::string())); + if (club == clubs.end()) break; + rows.push_back({{"player", {{"id", p.at("playerId")}, {"name", p.at("name")}}}, + {"team", {{"id", club->first}, {"name", club->second}, {"role", "club"}}}, + {"position", p.at("position")}, {"rating", nullptr}}); + } + if (rows.size() != 11) continue; + return {{"schema", "openbmh-post-match-records@1"}, {"fixture_id", fixture.at("fixture_id")}, + {"source_revision", fixture.at("source_revision")}, + {"eleven", {{"available", true}, {"source", "supplied-records"}, + {"notice", eleven.value("competition", std::string("Liga")) + " · nach Toren, Vorlagen, Karten und Ergebnis des Spieltags"}, + {"formation", "3-4-3"}, {"rows", rows}}}}; + } + return Json(); + } catch (const std::exception &) { return Json(); } +} + Json engine_live_roster(const Json &bundle) { + Json rows = Json::array(); try { const auto &players = bundle.at("squad").at("data").at("players"); @@ -324,6 +357,10 @@ Json engine_live_progress(const Json &previous, const Json &state, const Json &b } else if (kind == "injury") { headline = "Verletzung"; body = (player.empty() ? "Ein Spieler" : player) + " (" + team + ") muss behandelt werden."; } else continue; + if (e.contains("headline") && e.at("headline").is_string() && e.contains("body") && e.at("body").is_string() && + !e.at("headline").get().empty()) { + headline = e.at("headline").get(); body = e.at("body").get(); + } const std::string event_id = id + ":event:" + std::to_string(index++); const auto at = known.find(event_id); events.push_back(at != known.end() ? at->second @@ -332,6 +369,24 @@ Json engine_live_progress(const Json &previous, const Json &state, const Json &b {"headline", headline}, {"body", body}, {"score", {goals[0], goals[1]}}, {"side", side ? "away" : "home"}, {"player", e.at("player")}, {"other", e.value("other", Json())}}); } + { + // the whistle, as in the recording: kickoff, and half time once the second half runs + const auto whistle = [&](const char *suffix, int64_t at, const char *kind, const std::string &headline, const std::string &body, int h, int a) { + const std::string event_id = id + suffix; + const auto known_at = known.find(event_id); + events.push_back(known_at != known.end() ? known_at->second + : Json{{"id", event_id}, {"sequence", sequence}, {"match_id", id}, {"minute", at}, {"kind", kind}, + {"headline", headline}, {"body", body}, {"score", {h, a}}, {"side", "home"}, + {"player", nullptr}, {"other", nullptr}}); + }; + whistle(":kickoff", 0, "kickoff", "Anpfiff", m.at("home").at("name").get() + " gegen " + m.at("away").at("name").get() + ": Der Ball rollt.", 0, 0); + if (minute > 45) { + int h = 0, a = 0; + for (const auto &e : m.at("events")) + if (e.value("kind", std::string()) == "goal" && e.value("minute", int64_t(0)) <= 45) ++(e.value("side", std::string("home")) == "away" ? a : h); + whistle(":interval", 45, "interval", "Halbzeit", "Zur Pause steht es " + std::to_string(h) + ":" + std::to_string(a) + ".", h, a); + } + } Json score = m.value("score", Json::array({goals[0], goals[1]})); Json standings = Json::array(); if (role == "club" && state.contains("standings")) diff --git a/src/modern/ui/engine_live.hpp b/src/modern/ui/engine_live.hpp index 8b40020..765e0f0 100644 --- a/src/modern/ui/engine_live.hpp +++ b/src/modern/ui/engine_live.hpp @@ -17,6 +17,9 @@ Json engine_live_command(const Json &bundle, const std::string &revision, const const std::string &kind, const Json &payload); // The desk manager's squad in line-up order, as the ticker's team tab lists it. Json engine_live_roster(const Json &bundle); +// The engine's eleven of the day (post-match read) as review records for this recording; +// null when the read has none for the league of the ticker's match. +Json engine_post_match_records(const Json &postmatch_read, const Json &fixture); // One more frame for the standing kickoff (`state` is the paused read_live answer). Json engine_live_progress(const Json &previous, const Json &state, const Json &bundle, const Json &roster); } // namespace bmh::modern_ui diff --git a/src/modern/ui/live_controls.inc b/src/modern/ui/live_controls.inc index f0e1870..c5c9abf 100644 --- a/src/modern/ui/live_controls.inc +++ b/src/modern/ui/live_controls.inc @@ -167,7 +167,7 @@ void App::engine_live_poll() { engine_live_at_end_ = true; const std::string season = engine_season_id(engine_data_); engine_start("Abpfiff …", [link, state, season] { - Json finished = {{"messageType", "live_finished"}, {"liveRecording", state}}; + Json finished = {{"messageType", "live_finished"}, {"liveRecording", state}, {"postmatch", link->read({{"kind", "postmatch"}})}}; auto after = link->snapshot(); engine_attach_opening(*link, season, after, finished); return EngineReply{link, std::move(after), finished, nullptr}; diff --git a/src/modern/ui/live_screens.inc b/src/modern/ui/live_screens.inc index 2e6c45f..b21216c 100644 --- a/src/modern/ui/live_screens.inc +++ b/src/modern/ui/live_screens.inc @@ -128,6 +128,27 @@ std::string App::live_detail(const Json &owner, const Json &frame) { 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.") + "

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

" + live_text(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"); + groups[name] += "
" + + live_text(other.at("home").value("name", std::string()) + " – " + other.at("away").value("name", std::string()), "live-roster-name") + + live_text(std::to_string(result[0].get()) + ":" + std::to_string(result[1].get()), "live-roster-stat") + "
"; + } + 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 += "
" + live_text(name, "live-roster-name") + live_text("", "live-roster-stat") + "
" + 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"); @@ -170,11 +191,11 @@ std::string App::live_ticker_events(const Json &frame, size_t &shown) { 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; + 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")); 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") + "
"; + "
" + (fixture.at("source") == "engine-recording" && fixture.at("matches").size() == 1 ? std::string() : 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(fixture.at("source") == "engine-recording" ? "Noch keine Meldungen." : "Für diesen Filter liegt noch keine Demomeldung vor.") + "

"; @@ -217,7 +238,7 @@ std::string App::render_live() { out += live_ticker_events(frame, shown); out += "
" "" + esc(std::to_string(shown) + (live_.fixture().at("source") == "engine-recording" ? (shown == 1 ? " Meldung" : " Meldungen") : " Meldungen · feste Aufzeichnung")) + "" + "" + esc(phase_text) + "
"; out += "
" + live_text("+") + "" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "
"; out += "