Modern UI contract: postmatch read

The after-match steps of the last kickoff: every match of it, the matches of
human managers for the report, the Sportschau's eleven of the day as the
engine chooses it (captured during session.advance, only with its replay
option), and the current tables of the day's leagues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:08:08 +01:00
1 parent b845bbfcbc
commit 10a8f0b881
6 files changed
+80 -1

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung |
| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) |
| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; Kredite noch `unavailable` (folgen), der Aktientipp zieht Zufall und kommt als `quote.request` |
| `postmatch` | das Nachspiel des letzten `session.advance` (auch am Bundestrainer-Schreibtisch): `steps` (`results`, `report`, `team_of_the_day`, `overview`, `table` je mit `available`), `matches` (alle Spiele des Anstoßes im Almanach-Format), `reportMatchIds` (Spiele menschlicher Manager), `teamOfTheDay` (die Sportschau-Elf der Engine je Wettbewerb mit Spieler, Verein, Wertung; nur mit der Sportschau-Option der EXE, sonst leer und `team_of_the_day` nicht verfügbar), `tables` (die aktuellen Tabellen der Ligen des Spieltags). Rückblick und Abspielen ändern nichts; weiter geht es mit `session.advance` |
Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`.
+56 -1
View File
@@ -8855,10 +8855,46 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
const int manager = context.manager;
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
kind != "advertising" && kind != "stadium" && kind != "transfer"))
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch"))
return modern::ui_read(g_, context, request);
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
if (kind == "postmatch") {
// the after-match steps of the interface for the last session.advance: results (every match
// of the kickoff), report (the matches of human managers), the eleven of the day (the
// Sportschau's choice; only with its replay option), overview, the league tables now
if (!ui_last_advance_)
return modern::ui_error(request_id, "postmatch_unavailable", "Es wurde noch kein Spieltag gespielt.", revision, false);
cli::Json matches = modern::almanac_matches_between(g_, ui_last_advance_->first, ui_last_advance_->second);
A report;
std::set<int> leagues;
for (const auto& m : *matches.array()) {
const auto& o = *m.object();
const bool human = !std::holds_alternative<std::nullptr_t>(o.at("home").object()->at("manager").value) ||
!std::holds_alternative<std::nullptr_t>(o.at("away").object()->at("manager").value);
if (human) report.push_back(o.at("id"));
const auto& c = *o.at("competition").object();
if (*c.at("type").string() == "league")
for (int l = 0; l < kLeagueCount; ++l)
if (l < int(g_.world_league_id.size()) ? g_.world_league_id[size_t(l)] == *c.at("id").string()
: "league:" + std::to_string(l) == *c.at("id").string()) leagues.insert(l);
}
A tables;
for (int l : leagues) {
cli::Json t = modern::query_projection(g_, manager, O{{"kind", "table"}, {"league", l}});
if (auto* to = std::get_if<O>(&t.value)) { to->erase("ok"); tables.push_back(std::move(t)); }
}
const auto step = [](const char* id, bool ok) {
return cli::Json(O{{"id", id}, {"available", ok}, {"reasonCode", ok ? cli::Json(nullptr) : cli::Json("not_recorded")}});
};
const bool any = !matches.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()),
step("overview", any), step("table", !tables.empty())}},
{"matches", std::move(matches)}, {"reportMatchIds", std::move(report)}, {"teamOfTheDay", ui_last_awards_},
{"tables", std::move(tables)}});
}
const int team = g_.manager_teams[size_t(manager)];
if (team < 0 || team >= league_clubs())
return modern::ui_error(request_id, "no_club", "Am Schreibtisch des Bundestrainers gibt es das nicht.", revision, false);
@@ -9350,7 +9386,25 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
kickoff.kind = ui::DeskRequestKind::advance_turn;
kickoff.manager_slot = manager;
kickoff.revision = revision;
// the Sportschau's eleven of the day, as the engine chooses it (only with its replay option)
cli::Json::Array awards;
const SportschauPresentationHooks previous_sportschau = turn_driver_.sportschau;
turn_driver_.sportschau.awards = [&, inner = previous_sportschau.awards](const GameState& state, const SportschauAwardsView& v) {
const auto& modern_state = static_cast<const modern::ModernState&>(state);
cli::Json::Array players;
for (const auto& p : v.players) {
if (p.player_id == 0x0fff) continue;
const std::string club = p.team_id >= 0 ? modern::ui_team_id(modern_state, p.team_id) : std::string{};
players.push_back(cli::Json::Object{{"playerId", modern::ui_player_id(modern_state, p.player_id)},
{"name", ui::original_to_utf8(p.player_name)},
{"teamId", club.empty() ? cli::Json(nullptr) : cli::Json(club)},
{"club", ui::original_to_utf8(p.club_name)}, {"score", int(p.score)}});
}
awards.push_back(cli::Json::Object{{"competition", ui::original_to_utf8(v.competition_title)}, {"players", std::move(players)}});
if (inner) inner(state, v);
};
const TurnAdvanceResult r = dispatch_kickoff(kickoff, revision, error);
turn_driver_.sportschau = previous_sportschau;
g_.contract_screen = previous_hook; // the session's own presenter again
contract_expiry_presenter_installed_ = previous_installed;
if (r.kind == TurnDeskKind::Failed || r.kind == TurnDeskKind::WaitingAtDesk) {
@@ -9370,6 +9424,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
revision = previous + 1;
ui_last_advance_ = std::make_pair(saved_state.date, g_.date); // what read_live replays
ui_last_advance_revision_ = revision;
ui_last_awards_ = std::move(awards);
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,
+2
View File
@@ -1008,6 +1008,8 @@ private:
// 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;
// the Sportschau elevens of the last session.advance (postmatch "team of the day")
cli::Json::Array ui_last_awards_;
std::vector<std::string> ui_answer_order_;
std::filesystem::path data_directory_;
+8
View File
@@ -887,4 +887,12 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
{"notice", "Aufzeichnung der Engine: die Spiele des letzten Anstoßes"}};
}
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)
if (s.matches[i].date >= from_date && s.matches[i].date < until_date) out.push_back(almanac_match(g, s, i));
return out;
}
} // namespace bmh::modern
+3
View File
@@ -42,4 +42,7 @@ cli::Json query_statistics_screen(const ModernState& g, int manager, const cli::
// 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);
// All recorded matches with from_date <= date < until_date in the almanac form (the matches of a kickoff).
cli::Json almanac_matches_between(const ModernState& g, uint32_t from_date, uint32_t until_date);
} // namespace bmh::modern
+10
View File
@@ -448,6 +448,16 @@ int main(int argc, char** argv) {
at(fixture, "conference").array() ? at(fixture, "conference").array()->size() : 0, cli::dump_json(m).c_str());
}
check(s(at(session.read_live(O{{"kind", "frame"}, {"sequence", 99999}}), "error")) == "invalid_live_sequence", "bad sequence");
// the after-match steps of that kickoff
const J post = session.ui_read(O{{"kind", "postmatch"}}, rev);
const J& pd = at(post, "data");
const auto* steps = at(pd, "steps").array();
check(s(at(post, "messageType")) == "snapshot" && steps && steps->size() == 5 && truth(at((*steps)[0], "available")) &&
at(pd, "matches").array() && !at(pd, "matches").array()->empty() && at(pd, "reportMatchIds").array() &&
!at(pd, "reportMatchIds").array()->empty(), "postmatch with results and report");
std::printf("(postmatch: %zu matches, %zu tables, %zu elevens)\n", at(pd, "matches").array()->size(),
at(pd, "tables").array() ? at(pd, "tables").array()->size() : 0,
at(pd, "teamOfTheDay").array() ? at(pd, "teamOfTheDay").array()->size() : 0);
}
// almanac view after the kickoffs: index, calendar, day, match
{