Populate native desktop status, fixture and news widgets from the session (by Codex)
This commit is contained in:
1 parent
fd5c2b5330
commit
dc911f3281
21 files changed
+419
-91
No files matched your search
@@ -8984,6 +8984,37 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
context.career_ended = career_complete();
|
||||
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
|
||||
const int manager = context.manager;
|
||||
if (kind == "desktop-widgets") {
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size())
|
||||
return modern::ui_error(request_id, "no_manager", "Kein aktiver Manager.", revision, false);
|
||||
if (const auto 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);
|
||||
A warnings;
|
||||
for (const auto &value : desk.warnings)
|
||||
warnings.push_back(!desk.national_team && value ? cli::Json(*value) : cli::Json(nullptr));
|
||||
const auto summary = [&](int team, std::optional<int> rank, std::optional<int> strength) {
|
||||
const int league = team >= 0 && team < league_clubs() ? team_league(team) : -1;
|
||||
if (rank && (league < 0 || league >= kLeagueCount || *rank < 0 || *rank >= kLeagueSizes[league]))
|
||||
rank.reset(); // Packed history sentinels are not table places.
|
||||
return cli::Json(O{{"teamId", modern::ui_team_id(g_, team)},
|
||||
{"rank", rank ? cli::Json(int64_t(*rank + 1)) : cli::Json(nullptr)},
|
||||
{"strength", strength ? cli::Json(int64_t(*strength)) : cli::Json(nullptr)}});
|
||||
};
|
||||
cli::Json opponent = nullptr;
|
||||
if (desk.next_opponent && *desk.next_opponent >= 0) {
|
||||
const auto &curve = desk.rank_curves[1];
|
||||
const bool matching = curve.runtime_team == *desk.next_opponent;
|
||||
opponent = summary(*desk.next_opponent,
|
||||
matching && !desk.national_team ? curve.current_position : std::nullopt,
|
||||
matching ? curve.strength : std::nullopt);
|
||||
}
|
||||
return modern::ui_snapshot(g_, context, request_id, O{{"kind", "desktop-widgets"},
|
||||
{"own", summary(g_.manager_teams[size_t(manager)],
|
||||
desk.national_team ? std::nullopt : desk.table_position, desk.strength)},
|
||||
{"opponent", std::move(opponent)}, {"warnings", std::move(warnings)},
|
||||
{"fanCount", int64_t(desk.fans)}});
|
||||
}
|
||||
if (kind == "news" && manager >= 0 && size_t(manager) < g_.manager_teams.size()) {
|
||||
// the press events (content read) and the desk manager's mailbox: the original's messages
|
||||
// with the interface's read / folder marks (news.update; archive is the original's "keep")
|
||||
|
||||
Reference in new issue
Block a user