Modern UI contract: nations, crests, photos, employments, allowed commands

TeamRef carries the world's nation and crest asset key, squad rows the
player's photo key. The manager's employments come from the almanac
(clubs and national team side by side), the desk's allowed commands
follow the desk kind. modern_world_info reports the asset coverage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 18:32:43 +01:00
1 parent 055b48697e
commit 6570384642
8 files changed
+102 -5

No files matched your search

+32 -4
View File
@@ -98,8 +98,13 @@ J team_ref(const ModernState& g, int team, const std::string& as_of) {
if (name.empty()) name = almanac_utf8(g.club_name(team));
if (short_name.empty()) short_name = name;
const bool national = team >= no_team();
// nation and crest as the world names them (the asset key is passed through, the UI draws it)
const World* world = current_world();
const WorldClub* club = world ? world->club(team_id(g, team)) : nullptr;
const auto text_or_null = [](const std::string* s) { return s && !s->empty() ? J(*s) : J(nullptr); };
return O{{"id", team_id(g, team)}, {"kind", national ? "national" : "club"}, {"name", name},
{"shortName", short_name}, {"nationId", nullptr}, {"crestAssetId", nullptr}, {"nameAsOf", as_of}};
{"shortName", short_name}, {"nationId", text_or_null(club ? &club->nation : nullptr)},
{"crestAssetId", text_or_null(club ? &club->crest : nullptr)}, {"nameAsOf", as_of}};
}
std::string manager_id(const ModernState& g, int manager) {
@@ -115,7 +120,25 @@ J manager_json(const ModernState& g, int manager, bool at_desk) {
{"control", "human"}, {"status", at_desk ? "active" : "waiting"},
{"teamId", team >= 0 ? J(team_id(g, team)) : J(nullptr)},
{"portraitGuiKey", "gui:manager/photo/" + std::to_string(portrait)}, {"portraitStyle", "photo"},
{"strengthChoice", nullptr}, {"employments", A{}}};
{"strengthChoice", nullptr}, {"employments", manager_employments(g, manager)}};
}
// The commands the desk accepts now (the session refuses the others): none after the career's
// end; the national coach's desk has no toto, bank, camp, training, stadium, advertising,
// transfers, contracts or surroundings (ui/desk_state.cpp).
A allowed_commands(const ModernState& g, const UiContext& c) {
if (c.career_ended) return {};
const int team = team_of(g, c.manager);
const bool national = team == no_team();
static constexpr const char* kAll[] = {
"session.advance", "lineup.commit", "tactics.commit", "friendly.book", "manager.resign.commit",
"training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer",
"stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit",
"sponsor.answer", "environment.commit", "fixture.reschedule"};
A out;
for (size_t i = 0; i < std::size(kAll); ++i)
if (!national || i < 5) out.push_back(kAll[i]);
return out;
}
J meta(const ModernState& g, const UiContext& c) {
@@ -139,7 +162,7 @@ J meta(const ModernState& g, const UiContext& c) {
{"teamId", team >= 0 ? J(team_id(g, team)) : J(nullptr)},
{"role", national ? "national" : "club"},
{"scopeId", "scope:desk-" + revision + "-" + std::to_string(c.manager)},
{"allowedCommands", A{}}}},
{"allowedCommands", allowed_commands(g, c)}}},
{"availability", available()},
{"currency", O{{"code", "EUR"}, {"minorUnits", 2}}}};
}
@@ -226,11 +249,16 @@ J squad_data(const ModernState& g, const UiContext& c, int team, const std::stri
std::string last = entry(g.player_last, size_t(id));
if (last.empty()) last = almanac_utf8(g.player_name(id));
const std::string& nation = entry(g.player_nation, size_t(id));
const auto photo_of = [](const std::string& player) -> J {
const World* world = current_world();
const WorldPlayer* wp = world ? world->player(player) : nullptr;
return wp && !wp->photo.empty() ? J(wp->photo) : J(nullptr);
};
const uint32_t absence = p.w364 >> 16 & 0x1f; // weeks out; bit 4: banned instead of injured
const int injured = (absence & 0x10) ? 0 : int(absence), banned = (absence & 0x10) ? int(absence & 0xf) : 0;
O skills;
for (int k = 0; k < 7; ++k) skills[kSkills[k]] = int(p.w368 >> (2 * k) & 3);
O row{{"player", O{{"id", pid}, {"name", first.empty() ? last : first + " " + last}, {"photoAssetId", nullptr},
O row{{"player", O{{"id", pid}, {"name", first.empty() ? last : first + " " + last}, {"photoAssetId", photo_of(pid)},
{"nationIds", nation.empty() ? A{} : A{J(nation)}}, {"positions", A{J(kPositions[p.position()])}},
{"shirtNumber", nullptr}}},
{"clubId", team < league_clubs() ? J(team_id(g, team)) : J(nullptr)},