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

+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_;