Port achievements and player rankings to the Modern UI (by Codex)

This commit is contained in:
Codex committed 2026-10-25 13:51:36 +01:00
1 parent d419943e86
commit 96e88c9579
29 files changed
+1362 -17

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_career_reports.hpp"
#include <chrono>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool ok,const char *message){if(!ok)throw std::runtime_error(message);}
std::string id(int i){return "club:career-test-"+std::to_string(i);}
struct Fixture {
fs::path root;std::shared_ptr<const Catalog> world;
explicit Fixture(int count) {
root=fs::temp_directory_path()/("openbmh-career-reports-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));fs::create_directories(root/"world");
const auto write=[&](const std::string &name,const Json &value){bmh::editor::write_atomic(root/name,value.dump());};
write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:synthetic-career-reports"},{"start_date","2026-07-01"},{"requires",{"editor:world-v1"}},{"x-editor",{{"profile","editor-world-v1"}}}});
write("world/nations.json",{{"items",{{{"id","nation:de"},{"name","Synthetic nation"}}}}});
write("world/competitions.json",{{"items",{{{"id","competition:career-test"},{"type","league"},{"nation","nation:de"},{"name","Synthetic league"}}}}});
Json clubs=Json::array();for(int i=0;i<count;++i)clubs.push_back({{"id",id(i)},{"name",{{"default","Synthetic club "+std::to_string(i)}}},{"nation","nation:de"},{"competition","competition:career-test"},{"crest","asset:synthetic-crest-"+std::to_string(i)}});
clubs.push_back({{"id","nt:synthetic"},{"name","Synthetic national side"},{"type","national"}});
write("world/clubs.json",{{"items",clubs}});write("world/players.json",{{"items",Json::array()}});world=Catalog::open(root);
}
~Fixture(){std::error_code ec;fs::remove_all(root,ec);}
};
Json state(const std::string &club) {return {{"date","2027-07-07"},{"managers",{{{"name","Synthetic first manager"},{"club",club}},{{"name","Must not be used"},{"club",id(0)}}}},{"cash",123456},{"reports",{{"league","foreign"},{"filter",4}}}};}
void test_full() {
Fixture f(12);auto s=state(id(4));const auto original=s;const auto clubs=f.world->rows("clubs");
const auto current=demo_achievements(*f.world,s,0);require(current.at("ok")==true&&current.at("available")==true&&current.at("fictional")==true,"Career report unavailable for actual first-manager club");
require(current.at("club")==id(4)&&current.at("manager")=="Synthetic first manager","Career projection silently selected another manager or club");
require(current.at("first_year")==2019&&current.at("last_year")==2026&&current.at("range")=="2019/20 – 2026/27","Career window does not end at the last completed season");
require(current.at("charts").size()==3&&current.at("history").size()==12,"Expected three charts and twelve historical seasons");
for(int page=0;page<=4;++page) {
const auto view=demo_achievements(*f.world,s,page);require(view.at("last_year")==2026-page&&view.at("first_year")==2019-page,"Page must shift by one season, not eight");
require(view.at("history")==current.at("history"),"Club history changed when paging chart window");
for(const auto &chart:view.at("charts")) {
require(chart.at("seasons").size()==8,"Chart does not contain eight seasons");
for(size_t i=0;i<8;++i)require(chart.at("seasons")[i].at("year")==2019-page+int(i),"Chart years not chronological");
require(chart.at("latest")==chart.at("seasons")[7],"Latest summary disagrees with visible last season");
}
}
const auto older=demo_achievements(*f.world,s,4);std::set<int> tiers;
for(const auto &r:older.at("charts")[0].at("seasons"))tiers.insert(r.at("tier").get<int>());
require(tiers==std::set<int>({1,2,3,4}),"Four league bands were collapsed");
const auto &league=current.at("charts")[0].at("latest");require(league.at("value")==1&&league.at("winner")==true&&league.at("label")=="1. Platz"&&league.at("tier")==1,"Gold championship sample or title highlighting changed");
require(current.at("charts")[1].at("latest").at("label")=="Sieger"&&current.at("charts")[2].at("latest").at("label")=="Viertelfinale","Cup/Europe result labels changed");
bool zero=false;for(const auto &r:current.at("history"))for(const auto &value:r.at("results"))if(value.at("value")==0){zero=true;require(value.at("label")=="Nicht teilgenommen"&&value.at("caption")=="–"&&value.at("winner")==false,"Nonparticipation was fabricated into a played result or title");}
require(zero,"Historical demo lost its nonparticipation fixture");
require(demo_achievements(*f.world,s,-1).value("ok",true)==false&&demo_achievements(*f.world,s,5).value("ok",true)==false,"Out-of-range career page accepted");
const auto scores=demo_highscores(*f.world,s);require(scores.at("rows").size()==8,"Highscore must show at most eight existing clubs");std::set<std::string> seen;
for(size_t i=0;i<8;++i) {
const auto &r=scores.at("rows")[i];const auto club=r.at("club").get<std::string>();require(f.world->find("clubs",club)&&club!="nt:synthetic"&&seen.insert(club).second,"Unknown, national or duplicated club in highscore");
require(r.at("rank")==i+1&&r.at("points")==18200-int(i)*1575&&r.at("championships")==8-int(i%5)&&r.at("cups")==6-int(i%4)&&r.at("europe")==3-int(i%3)&&r.at("fictional")==true,"Highscore order/totals differ from deterministic Gold preview");
}
require(scores.at("rows")[0].at("club")==id(4)&&scores.at("rows")[0].at("manager")=="Synthetic first manager"&&scores.at("rows")[1].at("manager")=="Chris Winter","First manager or explicitly fictional manager fixtures changed");
auto other=s;other["reports"]={{"league","elsewhere"},{"filter",0}};other["cash"]=0;
require(demo_achievements(*f.world,other,0)==current&&demo_highscores(*f.world,other)==scores,"Career projection depends on unrelated filters or wallet");
other=s;other["managers"][0]["club"]=id(7);other["managers"][0]["name"]="Changed snapshot name";
require(demo_achievements(*f.world,other).at("club")==id(7)&&demo_highscores(*f.world,other).at("rows")[0].at("manager")=="Changed snapshot name","Manager switch retained a stale identity");
other=s;other["date"]="2027-06-30";require(demo_achievements(*f.world,other).at("last_year")==2025,"June incorrectly treated the current season as completed");
other["date"]="2028-02-29";require(demo_achievements(*f.world,other).at("last_year")==2026,"Valid leap date was rejected");
other["date"]="2027-02-29";require(demo_achievements(*f.world,other).at("last_year")==2025,"Invalid date did not use the deterministic manifest reference");
require(s==original&&f.world->rows("clubs")==clubs&&demo_achievements(*f.world,s)==current&&demo_highscores(*f.world,s)==scores,"Read-only projections mutated source/catalogue or were nondeterministic");
}
void test_short(int n) {
Fixture f(n);auto s=state(n?id(n-1):"club:missing");const auto before=s;
const auto a=demo_achievements(*f.world,s),h=demo_highscores(*f.world,s);
require(a.at("available")==bool(n)&&h.at("available")==bool(n)&&h.at("rows").size()==size_t(n),"Short catalogue invented extra clubs");
if(!n)require(a.at("charts").empty()&&a.at("history").empty()&&a.at("club").is_null(),"Empty catalogue invented an own club or historical identity");
if(n){s["managers"][0]["name"]="";require(demo_highscores(*f.world,s).at("rows")[0].at("manager")=="—","Missing current manager received a fictional name");s=before;}
for(const auto &bad:std::vector<Json>{nullptr,Json::array(),Json::object(),Json{{"managers",Json::array()}},state("club:missing"),state("nt:synthetic")}) {
const auto aa=demo_achievements(*f.world,bad),hh=demo_highscores(*f.world,bad);require(aa.at("ok")==true&&aa.at("available")==false&&aa.at("history").empty()&&hh.at("rows").empty(),"Missing/invalid first-manager identity silently fell back to another club");
}
require(s==before,"Short catalogue projection changed state");
}
} // namespace
int main()try{test_full();test_short(0);test_short(1);test_short(3);std::cout<<"Modern career report checks passed\n";return 0;}catch(const std::exception &e){std::cerr<<e.what()<<'\n';return 1;}
+1 -1
View File
@@ -100,7 +100,7 @@ int main(int argc, char **argv) try {
std::ostringstream css;
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
"calendar.rcss", "reports.rcss", "report_details.rcss",
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss"}) {
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss"}) {
std::ifstream input(root / name);
require(bool(input), "Production stylesheet missing");
css << input.rdbuf() << '\n';
+124
View File
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_rankings.hpp"
#include <algorithm>
#include <array>
#include <chrono>
#include <fstream>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool ok, const char *why) { if (!ok) throw std::runtime_error(why); }
struct Fixture {
fs::path root;
std::shared_ptr<const Catalog> world;
Fixture(int clubs = 20, int field_players = 12, bool german = true) {
root = fs::temp_directory_path() / ("openbmh-rankings-test-" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(root / "world");
const auto write = [&](const std::string &path, const Json &value) {
std::ofstream file(root / path); file << value.dump();
require(bool(file), "Cannot write synthetic rankings fixture");
};
write("manifest.json", {{"format", "openbmh-world"}, {"kind", "world"},
{"format_version", "1.1"}, {"id", "world:rankings-test"},
{"requires", {"runtime:modern-v1"}}, {"start_date", "2026-07-01"}});
Json competitions = Json::array(), nations = Json::array(), teams = Json::array(), players = Json::array();
for (int group = 0; group < 2; ++group) {
const std::string nation = group == 0 && german ? "nation:de" : "nation:synthetic-" + std::to_string(group);
nations.push_back({{"id", nation}, {"name", "Synthetic nation " + std::to_string(group)}});
const auto league = "competition:rankings-" + std::to_string(group);
competitions.push_back({{"id", league}, {"type", "league"}, {"nation", nation}, {"name", "Synthetic league " + std::to_string(group)}});
for (int i = 0; i < (group ? 3 : clubs); ++i) {
const auto club = "club:rankings-" + std::to_string(group) + "-" + std::to_string(i);
teams.push_back({{"id", club}, {"name", "Synthetic team " + std::to_string(group) + " " + std::to_string(i)}, {"competition", league}, {"nation", nation}, {"crest", "asset:synthetic-crest-" + std::to_string(group) + "-" + std::to_string(i)}});
for (int p = 0; p < field_players + 2; ++p) {
const auto id = "player:rankings-" + std::to_string(group) + "-" + std::to_string(i) + "-" + std::to_string(p);
players.push_back({{"id", id}, {"name", "Synthetic player " + std::to_string(group) + " " + std::to_string(i) + " " + std::to_string(p)}, {"team", club}, {"positions", {p < 2 ? "gk" : std::array<const char *, 3>{"def", "mid", "fwd"}[size_t(p - 2) % 3]}}, {"squad_order", p}, {"photo", "asset:synthetic-photo-" + id}});
}
}
}
write("world/nations.json", {{"items", nations}});
write("world/competitions.json", {{"items", competitions}});
write("world/clubs.json", {{"items", teams}});
write("world/players.json", {{"items", players}});
world = Catalog::open(root);
}
~Fixture() { std::error_code error; fs::remove_all(root, error); }
};
void check_rows(const Catalog &world, const Json &rows, int kind,
const std::string &league, const std::string &own, int scope) {
std::set<std::string> seen;
const std::array<const char *, 4> metrics{"goals", "assists", "yellow", "red"};
for (size_t i = 0; i < rows.size(); ++i) {
const auto &row = rows[i];
const auto player = row.at("player").get<std::string>();
const auto *p = world.find("players", player);
const auto *club = world.find("clubs", row.at("club").get<std::string>());
require(p && club && p->at("team") == club->at("id"), "Invented or incorrectly bound ranking identity");
require(seen.insert(player).second, "Duplicate ranking player");
require(scope ? p->at("team") == own : club->at("competition") == league, "Ranking crossed requested club/league");
require(p->at("positions")[0] != "gk", "Goalkeeper substituted for an actual outfield player");
require(row.at("name") == world.name(*p) && row.at("club_name") == world.name(*club) && row.at("photo") == p->at("photo") && row.at("crest") == club->at("crest"), "Historical identity or asset reference invented");
require(row.at("value").get<int>() > 0 && row.at("value") == row.at(metrics[size_t(kind)]), "Zero value survived or category metric mismatched");
const int expected_rank = i && row.at("value") == rows[i - 1].at("value") ? rows[i - 1].at("rank").get<int>() : int(i + 1);
require(row.at("rank") == expected_rank, "Competition ranking mishandled a tie");
if (i) require(rows[i - 1].at("value").get<int>() >= row.at("value").get<int>(), "Ranking not sorted by active metric");
}
}
void full_world() {
Fixture fixture; const auto &world = *fixture.world;
const auto players_before = world.rows("players"), clubs_before = world.rows("clubs"), manifest_before = world.manifest();
const std::string league = "competition:rankings-0", own = "club:rankings-0-7";
for (int scope = 0; scope < 2; ++scope) {
const auto goals = demo_scorer_rows(world, league, own, scope, 0);
require(goals.size() == 10 && goals[0].at("value") == 19 && goals[9].at("value") == 10, "Gold ten-player goals fixture changed");
for (int kind = 0; kind < 4; ++kind) {
const auto rows = demo_scorer_rows(world, league, own, scope, kind);
check_rows(world, rows, kind, league, own, scope);
for (const auto &r : rows) {
const auto at = r.at("original").get<size_t>();
require(r.at("player") == goals[at].at("player"), "Tabs used different player cohorts");
for (const char *key : {"goals", "assists", "yellow", "red"}) require(r.at(key) == goals[at].at(key), "Statistics changed while selecting category");
}
if (kind == 1) require(rows[0].at("original") == 1 && rows[0].at("value") == 12, "Assists retained goal order");
if (kind == 2) require(rows[0].at("original") == 9 && rows[0].at("value") == 10, "Yellow retained goal order");
if (kind == 3) {
require(rows.size() == 7, "Red zero filter changed");
const std::array<int, 7> ranks{1, 2, 2, 4, 4, 4, 4}, values{3, 2, 2, 1, 1, 1, 1};
for (size_t i = 0; i < 7; ++i) require(rows[i].at("rank") == ranks[i] && rows[i].at("value") == values[i], "Red ties not 1/2/2/4/4/4/4");
}
auto detached = rows; detached[0]["name"] = "Changed returned projection";
require(demo_scorer_rows(world, league, own, scope, kind) == rows, "Projection aliases shared state");
}
}
const auto fair = demo_fairplay_rows(world);
require(fair.size() == 20 && fair[0].at("club") == "club:rankings-0-0", "Fairplay cut domestic clubs or selected foreign league");
std::set<std::string> fair_clubs;
for (size_t i = 0; i < fair.size(); ++i) {
const auto &r = fair[i];
require(fair_clubs.insert(r.at("club").get<std::string>()).second && r.at("rank") == i + 1, "Fairplay duplicated club or changed Gold ordinal ranks");
require(r.at("points").get<int>() == r.at("yellow").get<int>() + 4 * r.at("red").get<int>(), "Fairplay penalty weight wrong");
if (i) require(fair[i - 1].at("points").get<int>() <= r.at("points").get<int>(), "Fairplay not ascending");
}
require(fair[1].at("original") == 1 && fair[2].at("original") == 5 && fair[1].at("points") == fair[2].at("points"), "Fairplay stable tie order changed");
require(demo_scorer_rows(world, "missing", own).empty() && demo_scorer_rows(world, league, "missing", 1).empty() && demo_scorer_rows(world, league, own, -1).empty() && demo_scorer_rows(world, league, own, 0, 4).empty(), "Invalid selection invented replacement players");
require(world.rows("players") == players_before && world.rows("clubs") == clubs_before && world.manifest() == manifest_before, "Read-only rankings mutated catalogue");
}
} // namespace
int main() try {
full_world();
for (int count : {0, 1, 2, 5}) {
Fixture f(1, count); const std::string league = "competition:rankings-0", club = "club:rankings-0-0";
for (int scope = 0; scope < 2; ++scope) {
const auto rows = demo_scorer_rows(*f.world, league, club, scope);
require(rows.size() == size_t(count), "Short/empty outfield squad invented phantom rows");
check_rows(*f.world, rows, 0, league, club, scope);
}
}
Fixture no_clubs(0); require(demo_scorer_rows(*no_clubs.world, "competition:rankings-0", "").empty() && demo_fairplay_rows(*no_clubs.world).empty(), "Empty domestic league unsafe");
Fixture no_de(4, 4, false); require(demo_fairplay_rows(*no_de.world).empty(), "Fairplay silently substituted non-German league");
std::cout << "Modern UI rankings checks passed\n"; return 0;
} catch (const std::exception &error) { std::cerr << error.what() << '\n'; return 1; }