Bind cup reports and linked competition phases to live engine data (by Codex)
This commit is contained in:
1 parent
545e16f153
commit
6b4aa9772d
26 files changed
+402
-33
No files matched your search
@@ -15,6 +15,9 @@
|
||||
#include "modern/game/almanac.hpp"
|
||||
#include "modern/game/desk_actions.hpp"
|
||||
#include "modern/game/matchday.hpp"
|
||||
#include "modern/game/other_games.hpp"
|
||||
#include "modern/game/cup.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
@@ -156,6 +159,104 @@ J table(const ModernState& g, int league) {
|
||||
return O{{"ok", true}, {"league", league_json(g, league)}, {"played", played}, {"rows", std::move(rows)}};
|
||||
}
|
||||
|
||||
std::string cup_view_id(int competition, int page) {
|
||||
return "cup-view:" + std::to_string(competition) + ":" + std::to_string(page);
|
||||
}
|
||||
J cup_view(const OtherGamesProjection& p, int page, bool linked) {
|
||||
std::string name = p.competition == 11 ? "Hallenturnier" : almanac_utf8(p.title);
|
||||
if (linked) {
|
||||
std::string stage = almanac_utf8(p.round_heading);
|
||||
if (stage.starts_with(name)) stage.erase(0, name.size());
|
||||
while (!stage.empty() && (stage.front() == ' ' || stage.front() == '-')) stage.erase(0, 1);
|
||||
name += " · " + stage;
|
||||
}
|
||||
return O{{"id", cup_view_id(p.competition, page)}, {"name", name},
|
||||
{"competition", p.competition}, {"page", page}, {"entry", p.entry_index},
|
||||
{"rounds", p.rounds}, {"currentRound", p.round + 1},
|
||||
{"knockout", p.knockout}, {"twoLegs", p.two_legs}};
|
||||
}
|
||||
J other_index(const ModernState& g) {
|
||||
if (!g.texts) return error("unavailable");
|
||||
A views; std::set<int> seen; std::string selected;
|
||||
for (int slot = 0; slot < 8; ++slot) {
|
||||
const int competition = g.memory.u8(::bmh::layout::ActiveSelectors + uint32_t(slot));
|
||||
if (competition == 0x14 || !seen.insert(competition).second) continue;
|
||||
const auto current = modern::other_games_from_game(g, *g.texts, competition, 0, -1,
|
||||
OtherGamesDisplayMode::compact, 0, true, false);
|
||||
if (current.linked_pages.empty()) {
|
||||
views.push_back(cup_view(current, 0, false));
|
||||
if (selected.empty()) selected = cup_view_id(competition, 0);
|
||||
} else {
|
||||
for (const auto& page : current.linked_pages) {
|
||||
const auto p = modern::other_games_from_game(g, *g.texts, competition, page.ordinal, -1,
|
||||
OtherGamesDisplayMode::compact, 0, false, false);
|
||||
views.push_back(cup_view(p, page.ordinal, true));
|
||||
if (selected.empty() && p.entry_index == current.entry_index)
|
||||
selected = cup_view_id(competition, page.ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected.empty() && !views.empty()) selected = *views.front().object()->at("id").string();
|
||||
return O{{"ok", true}, {"kind", "other-index"}, {"views", std::move(views)}, {"defaultViewId", selected.empty() ? J(nullptr) : J(selected)}};
|
||||
}
|
||||
J cup_score(uint16_t value) {
|
||||
return value == 0xcccc ? J(nullptr) : J(A{J(int((value >> 5) & 31)), J(int(value & 31))});
|
||||
}
|
||||
J other_fixtures(const ModernState& g, const J& request) {
|
||||
const J* view = field(request, "viewId"), *round = field(request, "round");
|
||||
if (!view || !view->string() || (round && (!round->integer() || *round->integer() < 1 || *round->integer() > 64)))
|
||||
return error("invalid_request");
|
||||
const auto index = other_index(g); const auto* object = index.object();
|
||||
if (!object || !object->count("views")) return index;
|
||||
const J* chosen = nullptr;
|
||||
for (const auto& v : *object->at("views").array())
|
||||
if (*v.object()->at("id").string() == *view->string()) chosen = &v;
|
||||
if (!chosen) return error("invalid_competition");
|
||||
const auto& v = *chosen->object();
|
||||
const int requested = round ? int(*round->integer()) - 1 : -1;
|
||||
const auto p = modern::other_games_from_game(g, *g.texts, int(*v.at("competition").integer()),
|
||||
int(*v.at("page").integer()), requested, OtherGamesDisplayMode::compact, 0, false);
|
||||
A matches;
|
||||
for (const auto& row : p.rows) {
|
||||
const bool scheduled = row.kind == OtherGamesRowKind::scheduled_competition;
|
||||
O m{{"id", "fixture:cup-" + std::to_string(p.entry_index) + "-" + std::to_string(p.round + 1) + "-" + std::to_string(row.source_match)},
|
||||
{"home", club_json(g, row.home_team)}, {"away", club_json(g, row.away_team)},
|
||||
{"status", scheduled ? "scheduled" : row.played ? "played" : "open"},
|
||||
{"result", scheduled ? J(nullptr) : cup_score(row.source_result)},
|
||||
{"phase", !scheduled && row.played ? J(int(row.source_result >> 10)) : J(nullptr)},
|
||||
{"secondLeg", nullptr}, {"secondLegPhase", nullptr}, {"secondLegVisible", row.second_leg_visible}, {"date", nullptr},
|
||||
{"homeHasSquad", row.home_team < league_clubs()}, {"awayHasSquad", row.away_team < league_clubs()}};
|
||||
if (row.second_leg_visible && row.second_leg_array_present) {
|
||||
// The source second-leg word is reversed relative to this row's sides.
|
||||
if (row.source_second_leg != 0xcccc) {
|
||||
m["secondLeg"] = A{J(int(row.source_second_leg & 31)), J(int((row.source_second_leg >> 5) & 31))};
|
||||
m["secondLegPhase"] = int(row.source_second_leg >> 10);
|
||||
}
|
||||
}
|
||||
if (scheduled && row.scheduled_source_day != 0xffff) {
|
||||
const auto date = almanac_date(row.scheduled_source_day, g.display_start_year);
|
||||
char iso[16]; std::snprintf(iso, sizeof iso, "%04d-%02d-%02d", date.year, date.month, date.day); m["date"] = iso;
|
||||
}
|
||||
matches.push_back(std::move(m));
|
||||
}
|
||||
O out = v;
|
||||
out["ok"] = true; out["kind"] = "other-fixtures"; out["viewId"] = *view;
|
||||
out["name"] = p.competition == 11 ? "Hallenturnier" : almanac_utf8(p.title);
|
||||
out["round"] = p.round + 1;
|
||||
std::string heading = almanac_utf8(p.round_heading);
|
||||
const auto& title = *out.at("name").string();
|
||||
if (heading.starts_with(title)) {
|
||||
heading.erase(0, title.size());
|
||||
while (!heading.empty() && (heading.front() == ' ' || heading.front() == '-')) heading.erase(0, 1);
|
||||
}
|
||||
if (!p.knockout && p.rounds > 1) heading += " · " + std::to_string(p.round + 1) + ". Spieltag";
|
||||
out["heading"] = heading;
|
||||
out["available"] = p.fixtures_available;
|
||||
out["reason"] = p.fixtures_available ? J(nullptr) : J(p.unfinished_predecessor ? "stage_pending" : "round_pending");
|
||||
out["matches"] = std::move(matches);
|
||||
return out;
|
||||
}
|
||||
|
||||
J fixtures(const ModernState& g, int league, int matchday) {
|
||||
const int matchdays = league_matchdays(league);
|
||||
if (matchday < 1 || matchday > matchdays) return error("invalid_matchday");
|
||||
@@ -277,6 +378,8 @@ cli::Json query_projection(const ModernState& g, int manager, const cli::Json& r
|
||||
if (!kind || !kind->string()) return error("invalid_request");
|
||||
const std::string& k = *kind->string();
|
||||
try {
|
||||
if (k == "other-index") return other_index(g);
|
||||
if (k == "other-fixtures") return other_fixtures(g, request);
|
||||
if (k == "status") return status(g, manager);
|
||||
if (k == "toto") return toto(g, manager);
|
||||
if (k == "sponsor") return sponsor(g, manager);
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// Each match has a stable id, home/away club refs, status and result.
|
||||
// Only played matches have [home, away] scores; open/postponed/rescheduled/
|
||||
// unavailable matches have null results, including packed status variants.
|
||||
// {kind: "other-index"} active cups and linked groups/stages
|
||||
// {kind: "other-fixtures", viewId, round?} actual cup pairings; 1-based round
|
||||
// {kind: "squad", club?} a squad with names, values and fitness
|
||||
|
||||
#include "cli/json.hpp"
|
||||
|
||||
@@ -483,6 +483,13 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
|
||||
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
|
||||
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
|
||||
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
|
||||
if (kind == "other-index" || kind == "other-fixtures") {
|
||||
J data = query_projection(g, c.manager, request);
|
||||
auto* values = std::get_if<O>(&data.value);
|
||||
if (!values || !values->count("ok") || !std::holds_alternative<bool>(values->at("ok").value) || !std::get<bool>(values->at("ok").value))
|
||||
return failure(request_id, "other_reports_unavailable", "Wettbewerb oder Runde ist derzeit nicht verfügbar.", c.state_revision);
|
||||
values->erase("ok"); return snapshot(request_id, std::move(m), std::move(data));
|
||||
}
|
||||
if(kind=="report-index") {
|
||||
A leagues;for(int l=0;l<kLeagueCount;++l)leagues.push_back(report_league(g,l,team_of(g,c.manager)));
|
||||
return snapshot(request_id,std::move(m),O{{"kind","report-index"},{"leagues",std::move(leagues)}});
|
||||
|
||||
Reference in new issue
Block a user