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,
|
||||
|
||||
@@ -834,6 +834,9 @@ public:
|
||||
// The almanac screen (index, calendar, day, match; docs/new_engine/ui-anbindung.md). Read-only.
|
||||
cli::Json read_almanac(const cli::Json& request) const { return query_almanac(g_, request); }
|
||||
// The statistics screen for the manager at the desk (docs/new_engine/ui-anbindung.md). Read-only.
|
||||
// The live ticker (DataSource::read_live): {kind: "fixture"} the recorded matches of the last
|
||||
// session.advance, {kind: "frame", sequence} one of its frames; revision/fixture_id as in the demo.
|
||||
cli::Json read_live(const cli::Json& request) const;
|
||||
// Sections 1 (transfer history) and 2 (the six curves) come from the original's own records.
|
||||
cli::Json read_statistics_screen(const cli::Json& request) const;
|
||||
// The read queries of the new interface (docs/new_engine/ui-abfragen.md): status, leagues,
|
||||
@@ -1001,6 +1004,9 @@ private:
|
||||
// ui_command: answers by requestId (the command as JSON, the answer) for repeated commands,
|
||||
// the last 64 in this process; after a restart expectedRevision prevents a second booking.
|
||||
std::map<std::string, std::pair<std::string, cli::Json>> ui_answers_;
|
||||
// the day counters around the last session.advance and the revision after it (read_live)
|
||||
std::optional<std::pair<uint32_t, uint32_t>> ui_last_advance_;
|
||||
uint64_t ui_last_advance_revision_ = 0;
|
||||
std::vector<std::string> ui_answer_order_;
|
||||
|
||||
std::filesystem::path data_directory_;
|
||||
|
||||
Reference in new issue
Block a user