Modern UI live: the events so far while a live matchday stands still

read_live during a pause lists each live match's goals, misses, cards and
injuries so far from the group's log, as the almanac reads it at the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:36:37 +01:00
1 parent 822331f045
commit 7c5030ca4b
3 files changed
+30 -2

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
- `frames` in Minutenfolge: Anpfiff, jedes Ereignis (Tor, Chance, Karten, Verletzung, Wechsel, Elfmeter), Halbzeit, Wiederanpfiff, Abpfiff; je Spiel Stand, Chancen, Gelb, Rot, Elfmeter, Spieler auf dem Feld. `events` (fortlaufend) mit Überschrift und Satz, Spieler, Seite, Stand.
- `conference`: die übrigen Spiele des Tages im Almanach-Format.
- Noch leer: `standings` (Live-Tabelle). Fehler: `live_unavailable` (noch kein Anstoß), `live_no_human_match`, `stale_live_revision`, `stale_live_fixture`, `invalid_live_sequence`.
- **Live mit Eingriffen:** `session.advance {live: true}` startet den Anstoß in einem eigenen Ablauf, der nach der ersten Minute eines laufenden Live-Spiels eines Menschen anhält (eine gewertete Partie, z. B. ein Forfeit, läuft ohne Halt durch). Solange er steht, liefert `read_live` `{live: true, status: "paused", minute, matches}` (Stand je Live-Spiel, Manager je Seite); die vollständige Aufzeichnung folgt nach dem Abpfiff. Alle anderen Befehle antworten `live_running`, bis der Spieltag vorbei ist.
- **Live mit Eingriffen:** `session.advance {live: true}` startet den Anstoß in einem eigenen Ablauf, der nach der ersten Minute eines laufenden Live-Spiels eines Menschen anhält (eine gewertete Partie, z. B. ein Forfeit, läuft ohne Halt durch). Solange er steht, liefert `read_live` `{live: true, status: "paused", minute, matches}`: je Live-Spiel Stand, Manager je Seite und die bisherigen Ereignisse (`goal`, `miss`, `yellow`, `second_yellow`, `red`, `injury` mit Minute, Seite, Spieler, Vorlage); Wechsel zeigt der `lineup`-Read. Die vollständige Aufzeichnung folgt nach dem Abpfiff. Alle anderen Befehle antworten `live_running`, bis der Spieltag vorbei ist.
## Commands
+23 -1
View File
@@ -8781,7 +8781,29 @@ cli::Json ModernSession::read_live(const cli::Json& request) const {
h = grp.cup_results[size_t(m)] >> 5 & 0x1f, a = grp.cup_results[size_t(m)] & 0x1f;
if (h >= 0xc || a >= 0xc) h = a = 0; // not under way yet
const int hm = g_.manager_of(home), am = g_.manager_of(away);
matches.push_back(O{{"home", O{{"id", modern::ui_team_id(g_, home)}, {"name", ui::original_to_utf8(g_.club_name(home))}}},
// the events so far, from the group's log as the almanac reads it at the end:
// goal/miss (+ assistant pair), 3 yellow, 4 second yellow, 5 red, 6 injury
static constexpr const char* kKinds[7] = {"goal", "miss", "", "yellow", "second_yellow", "red", "injury"};
const auto person = [this](int p) -> cli::Json {
if (p < 0 || p >= 0x0fff || size_t(p) >= g_.players.size()) return nullptr;
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 O{{"id", modern::ui_player_id(g_, p)}, {"name", first.empty() ? last : first + " " + last}};
};
cli::Json::Array events;
const auto& log = grp.log;
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;
events.push_back(O{{"minute", value}, {"kind", kKinds[code]}, {"side", side_team == home ? "home" : "away"},
{"player", person(player)}, {"other", person(assistant)}});
}
matches.push_back(O{{"events", std::move(events)},
{"home", O{{"id", modern::ui_team_id(g_, home)}, {"name", ui::original_to_utf8(g_.club_name(home))}}},
{"away", O{{"id", modern::ui_team_id(g_, away)}, {"name", ui::original_to_utf8(g_.club_name(away))}}},
{"homeManagerId", hm >= 0 ? cli::Json(modern::ui_manager_id(g_, hm)) : cli::Json(nullptr)},
{"awayManagerId", am >= 0 ? cli::Json(modern::ui_manager_id(g_, am)) : cli::Json(nullptr)},
+6
View File
@@ -422,6 +422,12 @@ int main(int argc, char** argv) {
check(s(at(stepped, "messageType")) == "command_result" && at(state, "minute").integer() &&
*at(state, "minute").integer() >= 30, "thirty minutes on");
std::printf("(live state: %s)\n", cli::dump_json(state).substr(0, 400).c_str());
if (const auto* live = at(state, "matches").array(); live && !live->empty()) {
int goals = 0;
for (const auto& e : *at((*live)[0], "events").array()) goals += s(at(e, "kind")) == "goal";
const auto* score = at((*live)[0], "score").array();
check(score && goals == *(*score)[0].integer() + *(*score)[1].integer(), "the live goals match the score");
}
// a substitution: the last field row for the first bench row
const J lineup = session.ui_read(O{{"kind", "lineup"}}, rev);
const auto* order = at(at(lineup, "data"), "order").array();