Modern UI: the live ticker replays the last kickoff's matches
ModernSession::read_live answers the ticker's fixture and frame queries with the engine's recording of the last session.advance: the matches of human managers with their owners, frames in minute order (kickoff, every event, half time, the end) with score, chances, cards and players on the pitch, the event lines, and the day's other matches as the conference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1400848387
commit
fda4b72967
6 files changed
+213
No files matched your search
@@ -8752,6 +8752,29 @@ std::string ui_text(const cli::Json& j, const char* key) {
|
||||
|
||||
} // namespace
|
||||
|
||||
cli::Json ModernSession::read_live(const cli::Json& request) const {
|
||||
using O = cli::Json::Object;
|
||||
const auto fail = [](const char* e) { return cli::Json(O{{"ok", false}, {"error", e}}); };
|
||||
if (!request.object()) return fail("invalid_live_query");
|
||||
for (const auto& [key, value] : *request.object())
|
||||
if (key != "kind" && key != "revision" && key != "sequence" && key != "fixture_id") return fail("invalid_live_query");
|
||||
if (!ui_last_advance_) return fail("live_unavailable");
|
||||
if (const cli::Json* r = ui_field(request, "revision"); r && (!r->integer() || uint64_t(*r->integer()) != ui_last_advance_revision_))
|
||||
return fail("stale_live_revision");
|
||||
cli::Json fixture = modern::live_fixture(g_, ui_last_advance_->first, ui_last_advance_->second, ui_last_advance_revision_);
|
||||
const auto* f = std::get_if<O>(&fixture.value);
|
||||
if (!f || !std::holds_alternative<bool>(f->at("ok").value) || !std::get<bool>(f->at("ok").value)) return fixture;
|
||||
if (const cli::Json* id = ui_field(request, "fixture_id"); id && (!id->string() || *id->string() != *f->at("fixture_id").string()))
|
||||
return fail("stale_live_fixture");
|
||||
const std::string kind = ui_text(request, "kind").empty() ? "fixture" : ui_text(request, "kind");
|
||||
if (kind == "fixture") return ui_field(request, "sequence") ? fail("invalid_live_query") : fixture;
|
||||
if (kind != "frame") return fail("invalid_live_query");
|
||||
const cli::Json* seq = ui_field(request, "sequence");
|
||||
const auto& frames = *f->at("frames").array();
|
||||
if (!seq || !seq->integer() || *seq->integer() < 0 || size_t(*seq->integer()) >= frames.size()) return fail("invalid_live_sequence");
|
||||
return O{{"ok", true}, {"fixture_id", f->at("fixture_id")}, {"frame", frames[size_t(*seq->integer())]}};
|
||||
}
|
||||
|
||||
cli::Json ModernSession::read_statistics_screen(const cli::Json& request) const {
|
||||
using O = cli::Json::Object;
|
||||
using A = cli::Json::Array;
|
||||
@@ -9337,6 +9360,8 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
}
|
||||
modern::ensure_ui_identities(g_);
|
||||
revision = previous + 1;
|
||||
ui_last_advance_ = std::make_pair(saved_state.date, g_.date); // what read_live replays
|
||||
ui_last_advance_revision_ = revision;
|
||||
const char* what = r.kind == TurnDeskKind::SeasonEndDesk ? "Saisonende." : r.kind == TurnDeskKind::CareerComplete
|
||||
? "Die Karriere ist zu Ende." : "Weiter zum nächsten Termin.";
|
||||
answer = modern::ui_command_result(request_id, previous, revision,
|
||||
|
||||
Reference in new issue
Block a user