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

+39
View File
@@ -1101,3 +1101,42 @@ cli::Json query_news(const ModernState& g, const std::string& team, const std::s
}
} // namespace bmh::modern
namespace bmh::modern {
cli::Json manager_employments(const ModernState& g, int manager) {
// the teams a human manager led, from the recorded matches: a new employment begins when
// the team of his matches changes (a club and the national team run side by side)
struct Stint { std::string team, name, kind; uint32_t from = 0, until = 0; int display_year = 0; };
std::vector<Stint> stints;
for (const AlmanacSeason& s : seasons_of(g))
for (const AlmanacMatch& m : s.matches)
for (int side = 0; side < 2; ++side) {
const int8_t mi = side ? m.away_manager : m.home_manager;
if (mi < 0 || size_t(mi) >= s.managers.size() || s.managers[size_t(mi)].index != manager) continue;
const AlmanacClub& c = s.clubs[side ? m.away : m.home];
// national: a world's nt: id, or without a world a runtime number from no_team() on
bool national = c.id.starts_with("nt:");
if (c.id.starts_with("team:")) try { national = std::stoi(c.id.substr(5)) >= no_team(); } catch (const std::exception&) {}
const std::string kind = national ? "national" : "club";
// the same team: by its world id, without a world by its name (runtime numbers change)
const auto same = [&](const Stint& st) { return c.id.starts_with("team:") ? st.name == c.name : st.team == c.id; };
Stint* open = nullptr;
for (auto it = stints.rbegin(); it != stints.rend() && !open; ++it)
if (it->kind == kind) open = &*it;
if (open && same(*open)) { open->until = m.date, open->team = c.id; continue; } // the id as last seen
stints.push_back({c.id, c.name, kind, m.date, m.date, s.display_start_year});
}
A out;
for (size_t i = 0; i < stints.size(); ++i) {
const Stint& st = stints[i];
bool current = true; // the last stint of its kind is still running
for (size_t k = i + 1; k < stints.size(); ++k) current &= stints[k].kind != st.kind;
out.push_back(O{{"teamId", st.team}, {"teamName", st.name}, {"role", st.kind},
{"from", iso_date(st.from, st.display_year)},
{"until", current ? J(nullptr) : J(iso_date(st.until, st.display_year))}});
}
return out;
}
} // namespace bmh::modern