Modern UI contract: press journal for business events

Business events cannot be derived from the almanac later, so a saved
journal notes them once: squad changes of the human clubs at a kickoff
(signed, free, sold, contract ended; clubs compared by identity across
the season's new draw positions), toto settlements, season change,
contract renewals and resigning. The news read merges it with the
almanac events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 18:22:50 +01:00
1 parent 9c436c753e
commit 651d262546
9 files changed
+318 -4

No files matched your search

+46
View File
@@ -6,10 +6,12 @@
#include <map>
#include <set>
#include <string>
#include <utility>
#include <variant>
#include "cli/json.hpp"
#include "modern/app/modern_session.hpp"
#include "modern/content/press_journal.hpp"
#include "modern/content/ui_contract.hpp"
#include "modern/game/save.hpp"
@@ -717,6 +719,50 @@ int main(int argc, char** argv) {
check(s(at(news, "messageType")) == "snapshot" && events && ids.size() == events->size(), "news with unique ids");
check(cli::dump_json(at(news, "data")) == cli::dump_json(at(again, "data")), "news the same on every read");
check(types["match.result"] > 0 && types["league.position"] > 0 && facts, "match results and the season's end in the news");
{
std::map<std::string, int> journal;
for (const auto& e : std::as_const(session).state().press) ++journal[e.type + "@" + e.team];
std::string all;
for (const auto& [t, n] : journal) all += t + " " + std::to_string(n) + ", ";
std::printf("(journal: %s)\n", all.c_str());
}
// the journal: the new season (noted at the kickoff that changed it)
check(types["career.season_started"] > 0, "business events from the journal");
// the journal's squad comparison on copies: a player of another club joins the human
// club (a signing), then goes back (a sale)
{
const modern::ModernState& start = std::as_const(session).state();
const int club = start.manager_teams.empty() ? -1 : start.manager_teams[0];
if (club >= 0 && club < modern::league_clubs()) {
const int other = club == 0 ? 1 : 0;
const SquadRange mine = squad_range(club), theirs = squad_range(other);
size_t free_row = mine.count, from_row = theirs.count;
for (size_t row = 0; row < mine.count && free_row == mine.count; ++row)
if ((start.squad_slots[mine.first + row] & 0x0fff) == 0x0fff) free_row = row;
for (size_t row = 0; row < theirs.count && from_row == theirs.count; ++row)
if ((start.squad_slots[theirs.first + row] & 0x0fff) != 0x0fff) from_row = row;
if (free_row < mine.count && from_row < theirs.count) {
const int p = start.squad_slots[theirs.first + from_row] & 0x0fff;
modern::ModernState joined = start;
joined.squad_slots[mine.first + free_row] = uint16_t((joined.squad_slots[mine.first + free_row] & 0xf000) | p);
joined.squad_slots[theirs.first + from_row] = uint16_t(joined.squad_slots[theirs.first + from_row] | 0x0fff);
modern::journal_advance(joined, start);
modern::ModernState back = joined;
back.squad_slots[mine.first + free_row] = start.squad_slots[mine.first + free_row];
back.squad_slots[theirs.first + from_row] = start.squad_slots[theirs.first + from_row];
modern::journal_advance(back, joined);
std::vector<std::string> types;
for (size_t k = start.press.size(); k < back.press.size(); ++k) types.push_back(back.press[k].type);
check(types == std::vector<std::string>{"transfer.signed", "transfer.sold"}, "journal: a signing and a sale");
const J ev = J(modern::journal_events(back, modern::ui_team_id(back, club), "0000", "9999"));
check(ev.array() && ev.array()->size() >= 2 &&
s(at(at(at(ev.array()->back(), "data"), "toClub"), "id")) == modern::ui_team_id(back, other),
"journal events readable");
}
} else {
std::printf("(journal test skipped: national desk)\n");
}
}
const J few = session.ui_read(O{{"kind", "news"}, {"limit", 3}}, rev);
check(at(at(few, "data"), "events").array() && at(at(few, "data"), "events").array()->size() == 3, "news limit");
}