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

+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)},