Port lineup and transfer market to the native Modern UI (by Codex)
This commit is contained in:
1 parent
ec1d804d08
commit
bf3f910437
33 files changed
+3339
-29
No files matched your search
@@ -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"}) {
|
||||
"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"}) {
|
||||
std::ifstream input(root / name);
|
||||
require(bool(input), "Production stylesheet missing");
|
||||
css << input.rdbuf() << '\n';
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <set>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool v,const char *text) {if(!v)throw std::runtime_error(text);}
|
||||
std::string id(int i) {return "player:lineup-"+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-lineup-ui-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
fs::create_directories(root/"world");
|
||||
const auto write=[&](const std::string &file,const Json &j){bmh::editor::write_atomic(root/file,j.dump());};
|
||||
write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:lineup-synthetic"},{"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:synthetic"},{"name","Synthetic league"},{"nation","nation:de"},{"type","league"}}}}});
|
||||
write("world/clubs.json",{{"items",{{{"id","club:home"},{"name","Synthetic home"},{"nation","nation:de"},{"competition","competition:synthetic"}},{{"id","club:away"},{"name","Synthetic away"},{"nation","nation:de"},{"competition","competition:synthetic"}}}}});
|
||||
Json players=Json::array();
|
||||
for(int i=0;i<count;++i) {
|
||||
Json p={{"id",id(i)},{"name","Synthetic player "+std::to_string(i)},{"team","club:home"},{"squad_order",i},{"positions",{i<2?"gk":i<7?"def":i<14?"mid":"fwd"}}};
|
||||
if(i==0){p["born"]="2000-07-02";p["nationalities"]={"nation:de"};p["attributes"]={{"strength",0},{"form",44},{"passing",3}};}
|
||||
if(i==1)p["age_at_start"]=32;
|
||||
players.push_back(p);
|
||||
}
|
||||
players.push_back({{"id","player:foreign"},{"name","Synthetic foreign"},{"team","club:away"}});
|
||||
write("world/players.json",{{"items",players}});world=Catalog::open(root);
|
||||
}
|
||||
~Fixture(){std::error_code error;fs::remove_all(root,error);}
|
||||
};
|
||||
void action(Json &s,const Catalog &w,const Json &a) {require(edit_demo_lineup(s,a,w,"club:home").empty(),"Valid lineup action rejected");require(valid_demo_lineup(s,w,"club:home"),"Action left invalid lineup");}
|
||||
void test(int count) {
|
||||
Fixture f(count);
|
||||
Json state={{"date","2026-07-01"},{"cash",12345},{"managers",{{{"club","club:home"}}}},{"unrelated",{3,4}}};
|
||||
const auto before=state;
|
||||
require(migrate_demo_lineup(state,*f.world,"club:home") && valid_demo_lineup(state,*f.world,"club:home"),"Missing lineup did not migrate, including empty/short squads");
|
||||
auto remainder=state;remainder.erase("lineup");require(remainder==before,"Migration changed unrelated state");
|
||||
const auto migrated=state;
|
||||
require(migrate_demo_lineup(state,*f.world,"club:home") && state==migrated,"Migration was not idempotent");
|
||||
require(state.at("lineup").at("order").size()==size_t(count),"Real squad was truncated or invented");
|
||||
require(demo_lineup_active(state).size()==std::min(size_t(11),size_t(count)),"Shared active eleven does not match roster");
|
||||
require(demo_lineup_active(Json::object()).empty(),"Missing lineup invented an eleven");
|
||||
const auto projection=demo_lineup_rows(state,*f.world,"club:home");
|
||||
require(projection.value("ok",false) && projection.at("rows").size()==size_t(count) && state==migrated,"Read projection mutated or truncated squad");
|
||||
if(count) {
|
||||
const auto &row=projection.at("rows")[0];
|
||||
require(row.at("id")==id(0) && row.at("age")==25 && row.at("strength")==0 && row.at("technique").is_null(),"Catalogue DOB/zero/unknown values were fabricated");
|
||||
}
|
||||
action(state,*f.world,{{"kind","weight"},{"index",0}});
|
||||
require(state.at("lineup").at("weights")[0]==2,"Weight did not cycle");
|
||||
for(int i=0;i<3;++i)action(state,*f.world,{{"kind","weight"},{"index",0}});
|
||||
require(state.at("lineup").at("weights")[0]==1,"Weight cycle failed at bounds");
|
||||
action(state,*f.world,{{"kind","formation"},{"value",2}});
|
||||
action(state,*f.world,{{"kind","custom-save"},{"index",3}});
|
||||
const auto saved=state.at("lineup").at("points");
|
||||
action(state,*f.world,{{"kind","formation"},{"value",0}});
|
||||
action(state,*f.world,{{"kind","formation"},{"value",7}});
|
||||
require(state.at("lineup").at("points")==saved,"Own formation did not round trip");
|
||||
if(count) {
|
||||
const auto first=state.at("lineup").at("order")[0];
|
||||
action(state,*f.world,{{"kind","taker"},{"index",1},{"player",first}});
|
||||
action(state,*f.world,{{"kind","order"},{"player",first},{"index",3},{"value",40}});
|
||||
action(state,*f.world,{{"kind","move"},{"player",first},{"point",{1,4}}});
|
||||
require(state.at("lineup").at("formation")==-1,"Manual position left preset selected");
|
||||
if(count>1) {
|
||||
const auto second=state.at("lineup").at("order")[1];
|
||||
const auto points=state.at("lineup").at("points");
|
||||
action(state,*f.world,{{"kind","move"},{"player",first},{"point",points[1]}});
|
||||
require(state.at("lineup").at("order")[1]==first && state.at("lineup").at("order")[0]==second && state.at("lineup").at("points")==points,"Occupied point did not swap stable players");
|
||||
}
|
||||
if(count>11) {
|
||||
const auto bench=state.at("lineup").at("order")[11];
|
||||
action(state,*f.world,{{"kind","swap"},{"a",first},{"b",bench}});
|
||||
require(state.at("lineup").at("takers")[1]=="","Benched taker remained selectable");
|
||||
require(state.at("lineup").at("orders").at(first.get<std::string>())[3]==40,"Player instructions followed slot instead of player ID");
|
||||
}
|
||||
}
|
||||
const auto stable=state;
|
||||
const std::vector<Json> bad={nullptr,Json::array(),{{"kind","unknown"}},{{"kind","weight"},{"index",true}},{{"kind","weight"},{"index",3}},{{"kind","weight"},{"index",1.0}},{{"kind","formation"},{"value",4}},{{"kind","custom-save"},{"index",4}},{{"kind","swap"},{"a","player:foreign"},{"b",id(0)}},{{"kind","move"},{"player",id(0)},{"point",{19,0}}},{{"kind","taker"},{"index",0},{"player","player:foreign"}},{{"kind","order"},{"player",id(0)},{"index",0},{"value",41}},{{"kind","weight"},{"index",1},{"cash",0}}};
|
||||
for(const auto &a:bad)require(!edit_demo_lineup(state,a,*f.world,"club:home").empty() && state==stable,"Bad action partially changed state");
|
||||
std::vector<Json> broken;
|
||||
auto b=stable;b["lineup"]["club"]="club:away";broken.push_back(b);
|
||||
b=stable;b["lineup"]["points"][1]=b["lineup"]["points"][0];broken.push_back(b);
|
||||
b=stable;b["lineup"]["custom"][0]=Json::array();broken.push_back(b);
|
||||
b=stable;b["lineup"]["weights"][0]=true;broken.push_back(b);
|
||||
b=stable;b["lineup"]["orders"]["player:foreign"]={20,20,20,20};broken.push_back(b);
|
||||
b=stable;b["lineup"]["takers"][0]="player:foreign";broken.push_back(b);
|
||||
b=stable;b["lineup"]["formation"]=0;b["lineup"]["points"]=demo_lineup_formations()[1];broken.push_back(b);
|
||||
b=stable;b["lineup"]["view"]="pitch";broken.push_back(b);
|
||||
if(count){b=stable;b["lineup"]["order"][0]="player:foreign";broken.push_back(b);}
|
||||
if(count>1){b=stable;b["lineup"]["order"][1]=b["lineup"]["order"][0];broken.push_back(b);}
|
||||
for(auto invalid:broken){const auto original=invalid;require(!valid_demo_lineup(invalid,*f.world,"club:home") && !migrate_demo_lineup(invalid,*f.world,"club:home") && invalid==original && !edit_demo_lineup(invalid,{{"kind","weight"},{"index",0}},*f.world,"club:home").empty() && invalid==original,"Broken checkpoint repaired or changed atomically");}
|
||||
require(!valid_demo_lineup(stable,*f.world,"club:away"),"Foreign manager reused home lineup");
|
||||
remainder=state;remainder.erase("lineup");require(remainder==before,"Lineup edits changed wallet or unrelated settings");
|
||||
}
|
||||
} // namespace
|
||||
int main()try{for(int count:{0,2,10,16,20,24})test(count);std::cout<<"Modern lineup preview checks passed\n";return 0;}catch(const std::exception &e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool value,const char *message){if(!value)throw std::runtime_error(message);}
|
||||
std::string pid(int team,int i){return "player:transfer-test-"+std::to_string(team)+"-"+std::to_string(i);}
|
||||
struct Fixture {
|
||||
fs::path root;std::shared_ptr<const Catalog> world;
|
||||
Fixture(int own_count=24,int precision=0,int foreign_count=30){
|
||||
root=fs::temp_directory_path()/("openbmh-transfer-ui-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));fs::create_directories(root/"world");
|
||||
const auto write=[&](const std::string&file,const Json&v){std::ofstream f(root/file);f<<v.dump();require(bool(f),"Cannot write synthetic transfer world");};
|
||||
write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:transfer-test"},{"start_date","2026-07-01"},{"currency",{{"code","EUR"},{"minor_units",precision}}},{"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:transfer-test"},{"type","league"},{"nation","nation:de"},{"name","Synthetic league"}}}}});
|
||||
Json clubs=Json::array(),players=Json::array();
|
||||
for(int team=0;team<3;++team){const auto club="club:transfer-test-"+std::to_string(team);clubs.push_back({{"id",club},{"name","Synthetic club "+std::to_string(team)},{"nation","nation:de"},{"competition","competition:transfer-test"}});
|
||||
for(int i=0;i<(team?foreign_count:own_count);++i){const auto role=std::array<const char*,4>{"gk","def","mid","fwd"}[size_t(i)%4];std::string name="Synthetic player "+std::to_string(team)+" "+std::to_string(i);if(team==1&&i==0)name="Änne Müller";if(team==2&&i==1)name="François Öztürk";
|
||||
Json p={{"id",pid(team,i)},{"team",club},{"name",name},{"positions",{role}},{"squad_order",i},{"nationalities",{"nation:de"}},{"born","1995-01-01"},{"attributes",{{"strength",70+i%15},{"condition",68+i%15},{"technique",72+i%15},{"form",70+i%15},{"corner",0},{"free_kick",0},{"tackling",0},{"passing",0},{"shooting",0},{"speed",0},{"teamplay",0}}}};
|
||||
if(team==0&&i==1){p.erase("born");p["birth_date"]="1995-01-01";p["attributes"].erase("form");}players.push_back(p);
|
||||
}
|
||||
}
|
||||
write("world/clubs.json",{{"items",clubs}});write("world/players.json",{{"items",players}});world=Catalog::open(root);
|
||||
}
|
||||
~Fixture(){std::error_code e;fs::remove_all(root,e);}
|
||||
};
|
||||
Json strip(Json state){state.erase("transfer");return state;}
|
||||
void edit(Json&s,const Json&a,const Catalog&w){auto e=edit_demo_transfer(s,a,w,"club:transfer-test-0");if(!e.empty())throw std::runtime_error("Unexpected transfer rejection "+e+" "+a.dump());require(valid_demo_transfer(s,w,"club:transfer-test-0"),"Accepted action invalidated transfer state");}
|
||||
void reject(Json&s,const Json&a,const Catalog&w){auto before=s;require(!edit_demo_transfer(s,a,w,"club:transfer-test-0").empty()&&s==before,"Rejected transfer action changed state or accepted");}
|
||||
Json quote(const Json&s,const Catalog&w,const char*kind,const std::string&id,bool poach=false){auto q=demo_transfer_quote(s,{{"kind",kind},{"player",id},{"poached",poach}},w,"club:transfer-test-0");if(!q.value("ok",false))throw std::runtime_error("Unexpected quote rejection "+q.dump());return q;}
|
||||
Json order(const Json&q,int factor){Json o={{"kind",q.at("kind")},{"player",q.at("row").at("id")},{"source_club",q.at("source_club")},{"fee",q.at("fee").get<int64_t>()/factor},{"salary",q.at("salary").get<int64_t>()/factor},{"months",q.at("months")},{"bonuses",q.at("bonuses")},{"poached",q.at("poached")}};for(auto&b:o["bonuses"])b=b.get<int64_t>()/factor;return o;}
|
||||
void check_currency(int precision){
|
||||
Fixture f(24,precision);const auto&w=*f.world;const int factor=precision?100:1;Json state={{"cash",1000000LL*factor},{"date","2026-07-01"},{"contracts",{{"players",{{pid(0,0),{{"salary",12000*factor}}}}}}},{"lineup",{{"order",Json::array()}}},{"unrelated",{1,2,3}}};const auto before=state,world_players=w.rows("players");
|
||||
require(migrate_demo_transfer(state,w,"club:transfer-test-0")&&valid_demo_transfer(state,w,"club:transfer-test-0")&&strip(state)==before,"Transfer migration failed or altered outside fields");
|
||||
auto initial=state;auto view=demo_transfer_view(state,w,"club:transfer-test-0");require(view.at("own").size()==24&&view.at("market").size()==12,"Transfer truncated own roster or invented market count");require(view.at("own")[1].at("age").is_null()&&view.at("own")[1].at("form").is_null()&&view.at("own")[0].at("age")==31&&view.at("own")[0].at("skills")[0]==0,"Unavailable fields invented or born/zero data lost");
|
||||
const auto buy=quote(state,w,"buy",pid(1,0));require(buy.at("fee")==450000*factor&&buy.at("salary")==25000*factor&&buy.at("months")==24,"Pinned Gold demand units or terms changed");const auto sell=quote(state,w,"sell",pid(0,0));require(sell.at("demand_salary")==12000*factor,"Own current contract salary missing");require(quote(state,w,"sell",pid(0,1)).at("demand_salary").is_null(),"Missing salary invented");
|
||||
auto copied=buy;copied["fee"]=1;require(quote(state,w,"buy",pid(1,0))==buy&&state==initial,"Quote aliases or mutates state");
|
||||
auto o=order(buy,factor);o["fee"]=99999999;o["bonuses"][6]=100;edit(state,{{"kind","submit"},{"order",o}},w);require(state["transfer"]["orders"][0]["fee"]==99999999LL*factor&&state["transfer"]["orders"][0]["bonuses"][6]==100*factor&&strip(state)==before,"Staging charged cash or converted fee/bonus units incorrectly");
|
||||
auto loan=order(quote(state,w,"loan",pid(1,0)),factor);edit(state,{{"kind","submit"},{"order",loan}},w);require(state["transfer"]["orders"].size()==2,"Buy/loan were merged into one order");loan["months"]=36;reject(state,{{"kind","submit"},{"order",loan}},w);
|
||||
for(int i=0;i<3;++i)edit(state,{{"kind","submit"},{"order",order(quote(state,w,i==1?"lend":"sell",pid(0,i)),factor)}},w);
|
||||
auto fourth=order(sell,factor);fourth["player"]=pid(0,3);reject(state,{{"kind","submit"},{"order",fourth}},w);require(demo_transfer_quote(state,{{"kind","sell"},{"player",pid(0,3)},{"poached",false}},w,"club:transfer-test-0").at("error")=="transfer_list_full","Quote ignored three-player listing cap");
|
||||
edit(state,{{"kind","submit"},{"order",order(quote(state,w,"lend",pid(0,0)),factor)}},w);require(state["transfer"]["listed"].size()==3&&state["transfer"]["orders"].size()==5,"Sell/lend replacement duplicated own listing");edit(state,{{"kind","unlist"},{"player",pid(0,0)}},w);require(state["transfer"]["listed"].size()==2&&state["transfer"]["orders"].size()==4,"Unlisting did not remove prospective own order");
|
||||
auto criteria=state["transfer"]["criteria"];criteria["price_max"]=criteria["price_max"].get<int64_t>()/factor;const auto orders_before=state["transfer"]["orders"],listed_before=state["transfer"]["listed"];
|
||||
for(const auto&text:{"muller","ÖZTÜRK","francois"}){edit(state,{{"kind","search"},{"query",text}},w);require(!demo_transfer_view(state,w,"club:transfer-test-0").at("market").empty(),"Accent/Unicode search failed");}
|
||||
std::string forty;for(int i=0;i<40;++i)forty+="ü";edit(state,{{"kind","search"},{"query",forty}},w);reject(state,{{"kind","search"},{"query",forty+"ü"}},w);
|
||||
criteria["price_max"]=0;edit(state,{{"kind","criteria"},{"value",criteria},{"positions",15}},w);require(demo_transfer_view(state,w,"club:transfer-test-0").at("market").empty()&&state["transfer"]["orders"]==orders_before&&state["transfer"]["listed"]==listed_before,"Filter changed orders/listings or zero price did not filter");
|
||||
Json active=Json::array();for(int i=0;i<11;++i)active.push_back(pid(0,i));auto averages=demo_transfer_strengths(state,w,"club:transfer-test-0",active);require(averages.value("ok",false)&&averages.at("active").size()==4&&averages.at("team_average").is_number_integer(),"Lineup-fed strength projection failed");
|
||||
auto bulk=demo_transfer_roster(state,w,"club:transfer-test-0","club:transfer-test-1");require(bulk.at("rows").size()==30,"Poach roster truncated to Gold twelve fixtures");
|
||||
state=initial;for(int i=0;i<50;++i){const int team=i<30?1:2,index=i<30?i:i-30;edit(state,{{"kind","submit"},{"order",order(quote(state,w,"buy",pid(team,index),true),factor)}},w);}require(state["transfer"]["orders"].size()==50,"Order list did not retain fifty distinct targets");auto extra=order(quote(state,w,"buy",pid(2,29),true),factor);reject(state,{{"kind","submit"},{"order",extra}},w);edit(state,{{"kind","submit"},{"order",order(quote(state,w,"buy",pid(1,0),true),factor)}},w);require(state["transfer"]["orders"].size()==50,"Replacement blocked or duplicated at cap");
|
||||
for(const auto&a:std::vector<Json>{nullptr,Json::array(),Json::object(),{{"kind",1}},{{"kind","unknown"}},{{"kind","positions"},{"value",0}},{{"kind","positions"},{"value",true}},{{"kind","positions"},{"value",uint64_t(-1)}},{{"kind","search"},{"query",1}},{{"kind","search"},{"query",std::string(1,char(255))}},{{"kind","remove"},{"index",50}},{{"kind","remove"},{"index",-1}},{{"kind","submit"}},{{"kind","search"},{"query",""},{"cash",0}}})reject(state,a,w);
|
||||
auto badorder=extra;badorder["fee"]=uint64_t(-1);reject(state,{{"kind","submit"},{"order",badorder}},w);badorder=extra;badorder["source_club"]="club:transfer-test-0";reject(state,{{"kind","submit"},{"order",badorder}},w);badorder=extra;badorder["salary"]=200001;reject(state,{{"kind","submit"},{"order",badorder}},w);badorder=extra;badorder["bonuses"][0]=101;reject(state,{{"kind","submit"},{"order",badorder}},w);
|
||||
std::vector<Json> corrupt;auto bad=state;bad["transfer"]["orders"].push_back(bad["transfer"]["orders"][0]);corrupt.push_back(bad);bad=state;bad["transfer"]["listed"].push_back(pid(0,0));corrupt.push_back(bad);bad=state;bad["transfer"]["criteria"]["traits"]=0;corrupt.push_back(bad);bad=state;bad["transfer"]["club"]="club:transfer-test-1";corrupt.push_back(bad);bad=state;bad["transfer"]["extra"]=true;corrupt.push_back(bad);bad=state;bad["transfer"].erase("orders");corrupt.push_back(bad);
|
||||
for(auto&v:corrupt){const auto keep=v;require(!valid_demo_transfer(v,w,"club:transfer-test-0")&&!migrate_demo_transfer(v,w,"club:transfer-test-0")&&v==keep,"Migration repaired corrupt existing transfer data");reject(v,{{"kind","search"},{"query",""}},w);}
|
||||
if(precision){state["transfer"]["orders"][0]["fee"]=123;auto keep=state;require(valid_demo_transfer(state,w,"club:transfer-test-0")&&migrate_demo_transfer(state,w,"club:transfer-test-0")&&state==keep,"Migration rounded existing cents");}
|
||||
require(valid_demo_transfer(Json::parse(state.dump()),w,"club:transfer-test-0")&&strip(state)==before&&w.rows("players")==world_players,"Roundtrip failed or transfer altered world/other model");
|
||||
}
|
||||
} // namespace
|
||||
int main()try{check_currency(0);check_currency(2);for(int count:{0,2,20}){Fixture f(count,0,0);Json state={{"date","2026-07-01"},{"cash",0}};require(migrate_demo_transfer(state,*f.world,"club:transfer-test-0")&&demo_transfer_view(state,*f.world,"club:transfer-test-0").at("own").size()==size_t(count)&&demo_transfer_view(state,*f.world,"club:transfer-test-0").at("market").empty(),"Empty/small/full real roster unsafe");}std::cout<<"Modern UI transfer checks passed\n";return 0;}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_advertising.hpp"
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -65,6 +67,54 @@ void check_club_views(const fs::path &root, std::shared_ptr<const Catalog> world
|
||||
require(migrated["environment"] == initial.state["environment"] && migrated["advertising"] == initial.state["advertising"] && migrated["toto"] == initial.state["toto"], "Legacy club fields not initialized");
|
||||
require(migrated["cash"] == changed.state["cash"] && migrated["finance"] == changed.state["finance"], "Legacy migration reset wallet");
|
||||
}
|
||||
void check_squad_source(const fs::path &root, const std::shared_ptr<const Catalog> &world) {
|
||||
DemoSource source(world);
|
||||
const auto initial = source.snapshot();
|
||||
const auto club = initial.state.at("managers")[0].at("club").get<std::string>();
|
||||
require(valid_demo_lineup(initial.state, *world, club) && valid_demo_transfer(initial.state, *world, club),
|
||||
"Lineup/transfer initialization failed for a small synthetic squad");
|
||||
require(source.apply({initial.revision, "transfer", {{"kind", "search"}, {"query", "Synthetic"}}}).ok,
|
||||
"Transfer search failed through the source boundary");
|
||||
const auto searched = source.snapshot();
|
||||
require(!source.apply({initial.revision, "lineup", {{"kind", "weight"}, {"index", 0}}}).ok &&
|
||||
source.snapshot().revision == searched.revision && source.snapshot().state == searched.state,
|
||||
"Stale lineup request changed state");
|
||||
const auto points = searched.state.at("lineup").at("points");
|
||||
const auto &order = searched.state.at("lineup").at("order");
|
||||
require(order.size() >= 2, "Synthetic roster needs two players");
|
||||
require(source.apply({searched.revision, "lineup", {{"kind", "move"}, {"player", order[1]}, {"point", {6,1}}}}).ok,
|
||||
"Lineup move failed through the source boundary");
|
||||
auto changed = source.snapshot();
|
||||
require(tactics_diagram(changed.state.at("tactics"), "midnight", points) !=
|
||||
tactics_diagram(changed.state.at("tactics"), "midnight", changed.state.at("lineup").at("points")),
|
||||
"Tactics did not reflect edited lineup positions");
|
||||
for (const auto *key : {"cash", "deposit", "debt", "training", "tactics", "calendar", "reports", "finance", "contracts"})
|
||||
require(changed.state.at(key) == initial.state.at(key), "Squad preview changed unrelated game state");
|
||||
auto bad = Json{{"kind", "move"}, {"player", order[1]}, {"point", {19,1}}};
|
||||
require(!source.apply({changed.revision, "lineup", bad}).ok && source.snapshot().state == changed.state,
|
||||
"Rejected lineup position partially committed");
|
||||
const auto file = root / "squad-checkpoint.json";
|
||||
source.save(file, default_desktop());
|
||||
require(!source.dirty(), "Squad checkpoint did not clear dirty marker");
|
||||
source.apply({source.snapshot().revision, "transfer", {{"kind", "search"}, {"query", "Different"}}});
|
||||
source.load(file);
|
||||
require(source.snapshot().state == changed.state && !source.dirty(), "Squad preview did not roundtrip");
|
||||
auto invalid = changed.state; invalid["desktop"] = default_desktop();
|
||||
invalid["lineup"]["order"][0] = invalid["lineup"]["order"][1];
|
||||
{std::ofstream out(file);out << invalid.dump();}
|
||||
const auto before = source.snapshot(); bool rejected = false;
|
||||
try {source.load(file);} catch (const std::exception &) {rejected = true;}
|
||||
require(rejected && source.snapshot().state == before.state && source.snapshot().revision == before.revision,
|
||||
"Malformed squad checkpoint partially replaced the source");
|
||||
auto legacy = changed.state; legacy["desktop"] = default_desktop();
|
||||
legacy.erase("lineup"); legacy.erase("transfer");
|
||||
{std::ofstream out(file);out << legacy.dump();}
|
||||
source.load(file);
|
||||
require(source.snapshot().state.at("lineup") == initial.state.at("lineup") &&
|
||||
source.snapshot().state.at("transfer") == initial.state.at("transfer") &&
|
||||
source.snapshot().state.at("cash") == changed.state.at("cash"),
|
||||
"Legacy squad migration reset finances or failed to initialize defaults");
|
||||
}
|
||||
void check_finance_source(const fs::path &root,
|
||||
const std::shared_ptr<const Catalog> &base) {
|
||||
const auto folder = root / "finance-source";
|
||||
@@ -168,6 +218,8 @@ void check_finance_source(const fs::path &root,
|
||||
const auto changed = source.snapshot();
|
||||
require(change.ok && changed.revision == accepted.revision + 1 &&
|
||||
changed.state["contracts"] == demo_contracts(*world, "club:finance-next") &&
|
||||
changed.state["lineup"] == demo_lineup(*world, "club:finance-next") &&
|
||||
changed.state["transfer"] == demo_transfer(*world, "club:finance-next") &&
|
||||
changed.state["contracts"]["players"].contains("player:finance-next") &&
|
||||
!changed.state["contracts"]["players"].contains("player:a") &&
|
||||
changed.state["cash"] == accepted.state["cash"] &&
|
||||
@@ -469,6 +521,18 @@ int main(int argc, char **argv) try {
|
||||
require(diagram.width == 256 && diagram.height > 0,
|
||||
"Tactic SVG failed to decode");
|
||||
}
|
||||
const Json formation_points = {{0,4},{5,1},{5,3},{5,5},{5,7},{10,1},{10,3},{10,5},{10,7},{16,3},{16,5}};
|
||||
auto moved_points = formation_points;
|
||||
moved_points[1] = {6,1};
|
||||
require(tactics_diagram(demo_tactics(), "midnight", formation_points) !=
|
||||
tactics_diagram(demo_tactics(), "midnight", moved_points),
|
||||
"Tactic projection ignored the current lineup positions");
|
||||
auto invalid_points = formation_points;
|
||||
invalid_points[1] = invalid_points[0];
|
||||
bool duplicate_rejected = false;
|
||||
try { tactics_diagram(demo_tactics(), "midnight", invalid_points); }
|
||||
catch (const bmh::editor::Error &) { duplicate_rejected = true; }
|
||||
require(duplicate_rejected, "Tactic projection silently accepted duplicate lineup positions");
|
||||
const auto leap_days = calendar_days("2027-07-01");
|
||||
require(leap_days.size() == 366 && leap_days.front().weekday == 3 &&
|
||||
leap_days.back().iso == "2028-06-30" &&
|
||||
@@ -620,6 +684,7 @@ int main(int argc, char **argv) try {
|
||||
"Old checkpoint lost league preview or failed planning/indoor migration");
|
||||
check_finance_source(root, world);
|
||||
check_club_views(root, world);
|
||||
check_squad_source(root, world);
|
||||
GuiAssets absent(root / "missing-gui");
|
||||
require(!absent.available(),
|
||||
"World resources were mistaken for GUI resources");
|
||||
|
||||
Reference in new issue
Block a user