Bind cup reports and linked competition phases to live engine data (by Codex)

This commit is contained in:
Codex committed 2026-10-28 23:03:36 +01:00
1 parent 545e16f153
commit 6b4aa9772d
26 files changed
+402 -33

No files matched your search

+3
View File
@@ -56,6 +56,9 @@ Json engine_report_projection(const Json &bundle,const Json &index,const Json &r
Json engine_report_squad(const Json &bundle,const Json &read,const std::string &team);
Json engine_fixtures_projection(const Json &bundle,const Json &index,const Json &read,const std::string &league,int round);
Json engine_other_index(const Json &bundle,const Json &read);
Json engine_other_projection(const Json &bundle,const Json &index,const Json &read,const std::string &view,int round);
// Single-session facade. Its owner serializes all calls on a background worker.
// No RmlUI objects or callbacks cross this boundary.
class EngineBridge {
+15 -3
View File
@@ -89,6 +89,7 @@ void App::engine_frame() {
if (!engine_busy_ && popup_.empty() && !focus_after_render_.empty()) {
if (auto *node = element(focus_after_render_)) {
node->Focus(keyboard_navigation_);
if(node->GetId().starts_with("report-club-")||node->GetId().starts_with("report-option-"))node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
if(menu_=="almanac"&&node->GetId().starts_with("alm-match-")) {
node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
if(auto *list=element("alm-day-list"))list->SetScrollLeft(0);
@@ -138,7 +139,7 @@ void App::engine_event(Rml::Event &event) {
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
if (engine_reports_event(event)) return;
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && (menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league") && report_picker_event(event)) return;
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && (menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other") && report_picker_event(event)) return;
if (engine_sports_event(event)) return;
Rml::ElementFormControl *range = nullptr;
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
@@ -181,6 +182,7 @@ void App::engine_event(Rml::Event &event) {
const int index = found == controls.end() ? -1 : int(found - controls.begin());
auto *next=controls[size_t((index + int(controls.size()) + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % int(controls.size()))];
next->Focus(true);
if(next->GetId().starts_with("report-club-"))next->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
if(menu_=="almanac"&&next->GetId().starts_with("alm-match-")) {
next->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
if(auto *list=element("alm-day-list"))list->SetScrollLeft(0);
@@ -199,6 +201,15 @@ void App::engine_event(Rml::Event &event) {
element("camp-value-3")->SetInnerRML("—");
element("camp-focus-3")->SetProperty("visibility", "hidden"); dirty_ = true; return;
}
if(type=="keydown") {
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE) {
for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetTagName()=="button") {
if(!node->HasAttribute("disabled"))node->DispatchEvent("click",{});
event.StopImmediatePropagation();return;
}
}
}
if (type != "click") return;
for (auto *node = target; node && node != doc_; node = node->GetParentNode()) {
if (!node->HasAttribute("data-action") || node->HasAttribute("disabled")) continue;
@@ -211,7 +222,7 @@ void App::engine_event(Rml::Event &event) {
if (engine_reports_action(action,node)) return;
if (almanac_action(action,node)) return;
if (engine_friendly_action(action, node)) return;
if ((menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league") && report_picker_action(action,node)) return;
if ((menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other") && report_picker_action(action,node)) return;
if (engine_calendar_action(action, node)) return;
if (contracts_action(action, node)) return;
if (environment_action(action, node)) return;
@@ -225,6 +236,7 @@ void App::engine_event(Rml::Event &event) {
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
}
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
else if(action=="engine-open"&&id=="other"){menu_=id;engine_reports_sync();engine_other_load(engine_other_value_.is_object()?engine_other_value_.at("viewId").get<std::string>():"",engine_other_value_.is_object()?engine_other_value_.at("round").get<int>():0);}
else if(action=="engine-open"&&id=="league"){menu_=id;engine_reports_sync();const auto league=engine_reports_state_.at("league").get<std::string>();engine_fixtures_load(league,engine_fixtures_value_.is_object()&&engine_fixtures_value_.at("leagueId")==league?engine_fixtures_value_.at("round").get<int>():0);}
else if(action=="engine-open"&&(id=="tables"||id=="strengths")){menu_=id;engine_reports_sync();engine_reports_load(engine_reports_state_.at("league"),engine_reports_state_.at("filter"));}
else if (action == "engine-open" && id == "almanac") { menu_=id;engine_almanac_sync();engine_almanac_load({{"kind","index"}}); }
@@ -252,5 +264,5 @@ void App::engine_event(Rml::Event &event) {
}
Json App::engine_snapshot() const {
return {{"mode", engine_mode_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
{"response", engine_response_}, {"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
{"response", engine_response_}, {"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
}
+31
View File
@@ -840,4 +840,35 @@ Json engine_fixtures_projection(const Json &bundle,const Json &index,const Json
}
return out;
}
Json engine_other_index(const Json &bundle,const Json &read) {
auto context=bundle;context["other-index"]=read;auto data=lineup_read(context,"other-index");
require(data.at("views").is_array(),"Wettbewerbsliste fehlt.");std::set<std::string> ids;
for(const auto &v:data.at("views")) {
const auto id=v.at("id").get<std::string>();require(!id.empty()&&ids.insert(id).second&&v.at("name").is_string(),"Doppelter oder unbenannter Wettbewerb.");
const int total=whole_in_range(v.at("rounds"),1,64);(void)whole_in_range(v.at("currentRound"),1,total);
require(v.at("knockout").is_boolean()&&v.at("twoLegs").is_boolean(),"Wettbewerbsart fehlt.");
}
require(data.at("views").empty()?data.at("defaultViewId").is_null():data.at("defaultViewId").is_string()&&ids.contains(data.at("defaultViewId").get<std::string>()),"Standardwettbewerb fehlt.");return data;
}
Json engine_other_projection(const Json &bundle,const Json &index,const Json &read,const std::string &view,int round) {
const auto catalogue=engine_other_index(bundle,index);const Json *selected=nullptr;for(const auto &v:catalogue.at("views"))if(v.at("id")==view)selected=&v;
require(selected,"Fremder Wettbewerb.");auto context=bundle;context["other-fixtures"]=read;auto data=lineup_read(context,"other-fixtures");
require(data.at("viewId")==view&&data.at("round")==round&&data.at("rounds")==selected->at("rounds")&&data.at("entry")==selected->at("entry"),"Paarungen gehören einer anderen Wettbewerbsphase.");
(void)whole_in_range(data.at("round"),1,data.at("rounds"));require(data.at("available").is_boolean()&&data.at("heading").is_string()&&data.at("matches").is_array(),"Unvollständige Pokalansicht.");
require(data.at("available").get<bool>()||data.at("matches").empty(),"Gesperrte Runde enthält Paarungen.");std::set<std::string> ids;
for(auto &m:data["matches"]) {
const auto id=m.at("id").get<std::string>();require(!id.empty()&&ids.insert(id).second,"Doppelte Pokalpaarung.");
for(const auto *side:{"home","away"}){const auto &id=m.at(side).at("id");require(id.is_string()&&!id.get_ref<const std::string &>().empty()&&m.at(side).at("name").is_string(),"Teilnehmeridentität fehlt.");}
require(m.at("home").at("id")!=m.at("away").at("id"),"Teilnehmer spielt gegen sich selbst.");
const auto status=m.at("status").get<std::string>();require(status=="played"||status=="open"||status=="scheduled","Ungültiger Pokalstatus.");
const auto score=[](const Json &v){require(v.is_array()&&v.size()==2,"Pokalergebnis fehlt.");for(const auto &n:v)(void)whole_in_range(n,0,31);};
if(status=="played")score(m.at("result"));else require(m.at("result").is_null(),"Ungespielte Partie enthält Tore.");
require(m.at("secondLegVisible").is_boolean()&&m.at("homeHasSquad").is_boolean()&&m.at("awayHasSquad").is_boolean(),"Teilnehmer-/Rückspielstatus fehlt.");
if(!m.at("secondLeg").is_null()){require(m.at("secondLegVisible").get<bool>(),"Verdecktes Rückspielergebnis.");score(m.at("secondLeg"));}
if(!m.at("date").is_null())(void)calendar_iso_day(m.at("date"));
for(const auto *key:{"phase","secondLegPhase"})if(!m.at(key).is_null())(void)whole_in_range(m.at(key),0,63);
m["home_team"]=m.at("home");m["away_team"]=m.at("away");m["home"]=m.at("home_team").at("id");m["away"]=m.at("away_team").at("id");m["home_goals"]=status=="played"?m.at("result")[0]:Json();m["away_goals"]=status=="played"?m.at("result")[1]:Json();
}
return data;
}
} // namespace bmh::modern_ui
+28 -5
View File
@@ -5,6 +5,7 @@ void App::engine_reports_sync() {
if(engine_reports_context_.is_null()||meta.at("careerId")!=engine_reports_context_.at("careerId")||meta.at("scope").at("managerId")!=engine_reports_context_.at("scope").at("managerId"))engine_reports_state_["league"]="";
engine_reports_context_=meta;engine_reports_index_=Json();engine_reports_read_=Json();engine_reports_roster_=Json();engine_reports_value_=Json();engine_reports_roster_value_=Json();
engine_fixtures_read_=Json();engine_fixtures_value_=Json();
engine_other_index_=Json();engine_other_read_=Json();engine_other_value_=Json();
report_detail_kind_.clear();report_detail_club_.clear();report_detail_player_.clear();
}
void App::engine_reports_load(const std::string &preferred,int filter) {
@@ -36,9 +37,26 @@ void App::engine_fixtures_load(const std::string &preferred,int round) {
return EngineReply{link,bundle,{{"messageType","reports_preview"},{"kind","fixtures"},{"index",index},{"read",report},{"league",id},{"filter",filter},{"fixtures",fixtures},{"round",selected}},nullptr};
});
}
void App::engine_other_load(const std::string &preferred,int round) {
if(engine_busy_||!engine_fresh_)return;
if(engine_other_value_.is_object()&&engine_other_value_.at("viewId")==preferred&&engine_other_value_.at("round")==round){refresh();return;}
auto link=engine_link_;engine_start("Wettbewerb wird geladen …",[link,preferred,round] {
const auto bundle=link->snapshot(),index=link->read({{"kind","other-index"}});const auto data=engine_other_index(bundle,index);
const Json *view=nullptr;for(const auto &v:data.at("views"))if(v.at("id")==preferred)view=&v;
if(!view)for(const auto &v:data.at("views"))if(v.at("id")==data.at("defaultViewId"))view=&v;
Json response={{"messageType","reports_preview"},{"kind","other"},{"index",index},{"read",nullptr},{"view",nullptr},{"round",0}};
if(view){const auto id=view->at("id").get<std::string>();const int total=view->at("rounds"),selected=round>0?std::clamp(round,1,total):view->at("currentRound").get<int>();response["view"]=id;response["round"]=selected;response["read"]=link->read({{"kind","other-fixtures"},{"viewId",id},{"round",selected}});}
return EngineReply{link,bundle,response,nullptr};
});
}
void App::engine_reports_poll(const EngineReply &reply) {
if(reply.bundle.at("desktop").at("meta")!=engine_reports_context_)throw editor::Error("Der Berichtskontext hat sich geändert. Bitte neu öffnen.");
const auto &r=reply.response,&read=r.at("read");
if(r.at("kind")=="other") {
(void)engine_other_index(reply.bundle,r.at("index"));
auto value=read.is_null()?Json():engine_other_projection(reply.bundle,r.at("index"),read,r.at("view"),r.at("round"));
engine_other_index_=r.at("index");engine_other_read_=read;engine_other_value_=std::move(value);engine_notice_="Wettbewerb geladen.";return;
}
if(read.value("messageType","")=="error"){engine_notice_=engine_text(read.value("message",Json()));return;}
if(r.at("kind")=="league"||r.at("kind")=="fixtures") {
auto value=engine_report_projection(reply.bundle,r.at("index"),read,r.at("league"),r.at("filter"));
@@ -53,17 +71,20 @@ void App::engine_reports_poll(const EngineReply &reply) {
engine_notice_="Ligabericht geladen.";
}
Json App::engine_reports_rows(const std::string &mode) const {
if(mode=="other")return engine_other_value_.at("matches");
if(mode=="league")return engine_fixtures_value_.at("matches");
std::vector<Json> rows;
for(const auto &r:engine_reports_value_.at(mode=="tables"?"table":"strengths"))rows.push_back(r);
return sort_report_rows(std::move(rows),engine_reports_state_.at("sorts").at(mode));
}
Json App::engine_report_team(const std::string &id) const {
if(menu_=="other"&&engine_other_value_.is_object())for(const auto &m:engine_other_value_.at("matches"))for(const auto *side:{"home_team","away_team"})if(m.at(side).at("id")==id)return m.at(side);
if(engine_reports_value_.is_object())for(const auto &r:engine_reports_value_.at("table"))if(r.at("club")==id)return r.at("team");
return Json();
}
std::vector<std::pair<std::string,std::string>> App::engine_reports_picker_items(const std::string &kind) const {
std::vector<std::pair<std::string,std::string>> out;
if(menu_=="other"){if(kind=="competition"&&engine_other_index_.is_object())for(const auto &v:engine_other_index_.at("data").at("views"))out.emplace_back(v.at("id"),v.at("name"));return out;}
if(kind=="filter"){const char* values[]={"Alle Spiele","Hinrunde","Rückrunde","Heim","Auswärts"};for(int i=0;i<5;++i)out.emplace_back(std::to_string(i),values[i]);return out;}
const auto &leagues=engine_reports_index_.at("data").at("leagues");std::set<std::string> seen;std::string nation;
for(const auto &l:leagues)if(l.at("id")==engine_reports_state_.at("league"))nation=l.at("nationId").is_string()?l.at("nationId").get<std::string>():"__other__";
@@ -79,10 +100,11 @@ std::vector<std::pair<std::string,std::string>> App::engine_reports_picker_items
return out;
}
bool App::engine_reports_action(const std::string &action,Rml::Element *target) {
if(menu_!="tables"&&menu_!="strengths"&&menu_!="league")return false;
if(menu_!="tables"&&menu_!="strengths"&&menu_!="league"&&menu_!="other")return false;
const auto id=target?target->GetAttribute<Rml::String>("data-id",""):std::string();
if(action=="report-detail-close") {focus_after_render_=report_detail_return_focus_;report_detail_kind_.clear();report_detail_club_.clear();report_detail_player_.clear();refresh();return true;}
if(engine_busy_||!engine_fresh_)return action.starts_with("report-")||action=="club-detail"||action=="player-detail";
if(action=="report-round"&&menu_=="other"){if(id!="1"&&id!="-1")return true;const int current=engine_other_value_.at("round"),total=engine_other_value_.at("rounds");focus_after_render_=target->GetId();engine_other_load(engine_other_value_.at("viewId"),std::clamp(current+std::stoi(id),1,total));return true;}
if(action=="report-round"&&menu_=="league") {if(id!="1"&&id!="-1")return true;const int current=engine_fixtures_value_.at("round"),total=engine_fixtures_value_.at("rounds");const int next=std::clamp(current+std::stoi(id),1,total);focus_after_render_=target->GetId();engine_fixtures_load(engine_reports_state_.at("league"),next);return true;}
if(action=="report-sort") {
const std::set<std::string> table{"rank","played","wins","draw","loss","form","points","gf","diff"},strength{"club","keeper","defence","midfield","attack","strength"};
@@ -107,7 +129,7 @@ bool App::engine_reports_action(const std::string &action,Rml::Element *target)
return false;
}
bool App::engine_reports_event(Rml::Event &event) {
if((menu_!="tables"&&menu_!="strengths"&&menu_!="league")||report_detail_kind_.empty())return false;
if((menu_!="tables"&&menu_!="strengths"&&menu_!="league"&&menu_!="other")||report_detail_kind_.empty())return false;
const auto type=event.GetType();
if(type=="keydown"&&event.GetParameter<int>("key_identifier",0)==Rml::Input::KI_ESCAPE){engine_reports_action("report-detail-close",nullptr);event.StopImmediatePropagation();return true;}
if(type=="keydown"&&event.GetParameter<int>("key_identifier",0)==Rml::Input::KI_TAB){Rml::ElementList nodes;if(auto *root=element("report-detail-dialog"))root->QuerySelectorAll(nodes,"button");std::erase_if(nodes,[](auto *n){return n->HasAttribute("disabled");});if(!nodes.empty()){const auto it=std::find(nodes.begin(),nodes.end(),context_->GetFocusElement());int i=it==nodes.end()?-1:int(it-nodes.begin()),n=int(nodes.size());auto *next=nodes[size_t((i+n+(event.GetParameter<int>("shift_key",0)?-1:1))%n)];next->Focus(true);next->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));}event.StopImmediatePropagation();return true;}
@@ -121,7 +143,7 @@ std::string App::engine_reports_detail() {
std::string title=engine_text(team.at("name")),body,actions=close;
if(report_detail_kind_=="club") {
std::string strength="—",manager="Computer";
for(const auto &r:engine_reports_value_.at("strengths"))if(r.at("club")==report_detail_club_)strength=report_number(r.at("strength"));
if(engine_reports_value_.is_object())for(const auto &r:engine_reports_value_.at("strengths"))if(r.at("club")==report_detail_club_)strength=report_number(r.at("strength"));
for(const auto &m:engine_data_.at("session").at("data").at("managers"))if(m.at("teamId")==report_detail_club_&&m.at("status")=="active")manager=engine_text(m.at("name"));
std::string stadium_name="—",places="—";const auto *club=world_->find("clubs",report_detail_club_);const Json *stadium=nullptr;
if(club&&club->value("stadium",Json()).is_string())stadium=world_->find("stadiums",club->at("stadium"));
@@ -130,12 +152,13 @@ std::string App::engine_reports_detail() {
const auto &live_stadium=engine_data_.at("stadium");
if(live_stadium.value("messageType","")=="snapshot"&&live_stadium.at("data").at("teamId")==report_detail_club_) {int64_t sum=0;for(const auto &block:live_stadium.at("data").at("blocks"))sum+=block.at("places").get<int64_t>();places=number(sum);}
body="<div class=\"report-detail-badge\">"+crest(world_->find("clubs",report_detail_club_),192)+"</div><p class=\"report-detail-note\">Vereinsprofil</p>"+report_detail_fields({{"Stadion",stadium_name},{"Plätze",places},{"Stärke",strength},{"Manager",manager}},72);
actions=btn("report-club-roster","Spieler","report-detail-action","id=\"report-detail-roster\"")+close;
bool has_squad=true;if(menu_=="other")for(const auto &m:engine_other_value_.at("matches")){if(m.at("home")==report_detail_club_)has_squad=m.at("homeHasSquad");if(m.at("away")==report_detail_club_)has_squad=m.at("awayHasSquad");}
actions=btn("report-club-roster","Spieler","report-detail-action",std::string("id=\"report-detail-roster\" ")+(has_squad?"":"disabled"))+close;
} else if(report_detail_kind_=="roster") {
title+=" · Kader";body="<div class=\"report-detail-roster-scroll\" id=\"report-detail-roster-scroll\"><div class=\"report-detail-table\"><div class=\"report-detail-row report-detail-table-head\">";
for(const auto *h:{"Spieler","Pos.","Stärke","Alter"})body+="<div class=\"report-detail-cell\">"+std::string(h)+"</div>";
body+="</div>";
if(!engine_reports_roster_value_.is_object())body+="<p class=\"report-detail-empty\">"+esc(engine_busy_?"Kader wird geladen …":"Kader derzeit nicht verfügbar.")+"</p>";
if(!engine_reports_roster_value_.is_object())body+="<div class=\"report-detail-row\"><div class=\"report-detail-cell\">"+esc(engine_busy_?"Kader wird geladen …":"Kader derzeit nicht verfügbar.")+"</div><div class=\"report-detail-cell\"></div><div class=\"report-detail-cell\"></div><div class=\"report-detail-cell\"></div></div>";
else {size_t n=0;for(const auto &r:engine_reports_roster_value_.at("players")){const auto i=n++;body+="<div class=\"report-detail-row "+std::string(i%2==0?"report-detail-striped":"")+"\"><div class=\"report-detail-cell\">"+btn("player-detail",esc(engine_text(r.at("player").at("name"))),"report-detail-player-link","id=\"report-detail-player-"+std::to_string(i)+"\" data-id=\""+esc(r.at("player").at("id").get<std::string>())+"\"")+"</div><div class=\"report-detail-cell\">"+esc(report_detail_position(r.at("player")))+"</div><div class=\"report-detail-cell\">"+report_number(r.at("live_strength"))+"</div><div class=\"report-detail-cell\">"+report_number(r.at("age"))+"</div></div>";}}
body+="</div></div>";
} else {
+4 -3
View File
@@ -114,11 +114,12 @@ void App::engine_render() {
const auto route = id.substr(4);
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
const bool supported = ((route=="tables"||route=="strengths"||route=="league")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
const bool supported = ((route=="tables"||route=="strengths"||route=="league"||route=="other")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
}
}
out += "</div>";
if(menu_=="other")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"<div class=\"fill center\">"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"</div>")+"</div>";
if(menu_=="league")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"<div class=\"fill center\">"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"</div>")+"</div>";
if(menu_=="tables"||menu_=="strengths")out+="<div class=\"fill\" style=\"z-index:100;\">"+window(menu_=="tables"?"Tabelle":"Stärken",engine_reports_read_.is_object()?render_reports(menu_):"<div class=\"fill center\">"+esc(engine_busy_?"Ligabericht wird geladen …":engine_notice_)+"</div>")+"</div>";
if(menu_=="almanac") out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Almanach",engine_almanac_cache_.contains("index")?render_almanac():"<div class=\"fill center\">"+esc(engine_busy_?"Spielarchiv wird geladen …":engine_notice_)+"</div>")+"</div>";
@@ -134,7 +135,7 @@ void App::engine_render() {
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
}
if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
element("canvas")->SetInnerRML(out); ++document_generation_;
scale_chalk_shadow();
@@ -157,7 +158,7 @@ void App::engine_render() {
Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, ".window>.content,.window>.titlebar");
for (auto *node : underlay) { node->SetProperty("pointer-events", "none"); node->SetProperty("filter", "blur(10dp)"); }
}
if(!report_detail_kind_.empty()&&(menu_=="tables"||menu_=="strengths"||menu_=="league")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#report-underlay button,#window-close");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
if(!report_detail_kind_.empty()&&(menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#report-underlay button,#window-close");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
if (engine_busy_) {
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input");
for (auto *node : controls) node->SetAttribute("disabled", true);
+2
View File
@@ -14,6 +14,8 @@
Json engine_reports_context_, engine_reports_index_, engine_reports_read_, engine_reports_roster_, engine_reports_value_, engine_reports_roster_value_;
Json engine_reports_state_={{"league",""},{"filter",0},{"sorts",{{"tables",{{"key","rank"},{"desc",false}}},{"strengths",{{"key","strength"},{"desc",true}}}}}};
Json engine_fixtures_read_, engine_fixtures_value_;
Json engine_other_index_, engine_other_read_, engine_other_value_;
void engine_other_load(const std::string &,int);
void engine_fixtures_load(const std::string &,int);
void engine_reports_sync();
void engine_reports_load(const std::string &,int);
+6 -4
View File
@@ -16,7 +16,7 @@ App::report_picker_items(const std::string &kind) const {
std::vector<std::pair<std::string, std::string>> items;
if (!world_ || !report_picker_kind(kind))
return items;
if (engine_mode_ && (menu_=="tables"||menu_=="strengths"||menu_=="league")) return engine_reports_picker_items(kind);
if (engine_mode_ && (menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other")) return engine_reports_picker_items(kind);
if (engine_mode_ && menu_ == "friendlies") return engine_friendly_picker_items(kind);
if (menu_ == "statistics")
return statistics_picker_items(kind);
@@ -75,7 +75,8 @@ App::report_picker_items(const std::string &kind) const {
std::string App::report_picker_value(const std::string &kind) const {
if (!world_ || !report_picker_kind(kind))
return {};
if(engine_mode_&&(menu_=="tables"||menu_=="strengths"||menu_=="league")){if(kind=="filter")return std::to_string(engine_reports_state_.at("filter").get<int>());if(kind=="league")return engine_reports_state_.at("league");const auto live_index=engine_report_index(engine_data_,engine_reports_index_);for(const auto &l:live_index.at("leagues"))if(l.at("id")==engine_reports_state_.at("league"))return l.at("nationId").is_string()?l.at("nationId").get<std::string>():"__other__";return {}; }
if(engine_mode_&&menu_=="other")return kind=="competition"&&engine_other_value_.is_object()?engine_other_value_.at("viewId").get<std::string>():"";
if(engine_mode_&&(menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other")){if(kind=="filter")return std::to_string(engine_reports_state_.at("filter").get<int>());if(kind=="league")return engine_reports_state_.at("league");const auto live_index=engine_report_index(engine_data_,engine_reports_index_);for(const auto &l:live_index.at("leagues"))if(l.at("id")==engine_reports_state_.at("league"))return l.at("nationId").is_string()?l.at("nationId").get<std::string>():"__other__";return {}; }
if (menu_ == "statistics")
return statistics_picker_value(kind);
if (kind == "year") return std::to_string(almanac_year_);
@@ -212,11 +213,12 @@ bool App::report_picker_action(const std::string &action, Rml::Element *target)
return item.first == value;
}))
return true;
const Json selection = kind == "filter" || kind == "competition"
const Json selection = kind == "filter" || (kind == "competition" && !engine_mode_)
? Json(std::stoi(value)) : Json(value);
close_report_picker(false);
// Commit even an unchanged country: the Gold resets its first league.
if(engine_mode_&&(menu_=="tables"||menu_=="strengths"||menu_=="league")){
if(engine_mode_&&menu_=="other")engine_other_load(value,0);
else if(engine_mode_&&(menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other")){
std::string league=engine_reports_state_.at("league");int filter=engine_reports_state_.at("filter");
if(kind=="league")league=value;
else if(kind=="filter")filter=std::stoi(value);
+22 -8
View File
@@ -38,7 +38,7 @@ std::string App::render_reports(const std::string &mode) {
const auto *league = world_->find("competitions", state.value("league", ""));
const int tier = league ? league->value("tier", 1) : 1;
const bool strengths = mode == "strengths", matches = mode == "league" || mode == "other";
const bool opening = mode == "other" && state.value("competition", 0) == 3 &&
const bool opening = !engine_mode_ && mode == "other" && state.value("competition", 0) == 3 &&
snapshot.state.value("opening_created", false);
const auto rows = engine_mode_?engine_reports_rows(mode):matches ? (opening ? report_opening_pairs(*world_, snapshot.state.at("opening_flow"))
: report_match_rows(*world_, state, mode == "other"))
@@ -54,9 +54,11 @@ std::string App::render_reports(const std::string &mode) {
{"rank", "Pl. / Verein"}, {"played", "Sp."}, {"wins", "S"},
{"draw", "U"}, {"loss", "N"}, {"form", "Letzte 8"},
{"points", "Punkte"}, {"gf", "Tore"}, {"diff", "Diff."}};
const bool real_other=engine_mode_&&mode=="other";
const auto &fixture=real_other?engine_other_value_:engine_fixtures_value_;
std::vector<double> widths;
if (matches)
widths = {1224, 160, 1224}; // Match card has two 2dp borders.
widths = real_other?std::vector<double>{1184,240,1184}:std::vector<double>{1224,160,1224}; // Match card has two 2dp borders.
else if (strengths) {
widths.push_back(2612 * .38);
for (int i = 0; i < 5; ++i) widths.push_back(2612 * .62 / 5);
@@ -70,10 +72,11 @@ std::string App::render_reports(const std::string &mode) {
: rows.size() >= 20 ? (1682 - heading_height) / rows.size() : 80;
std::string body = "<div id=\"report-underlay\" class=\"report-underlay\">";
if (matches) {
const int round = engine_mode_?engine_fixtures_value_.at("round").get<int>()-1:std::clamp(state.value("round", 0), 0,
const int round = engine_mode_?fixture.at("round").get<int>()-1:std::clamp(state.value("round", 0), 0,
report_round_count(*world_, state, mode == "other") - 1);
std::string subtitle;
if(engine_mode_){const auto &l=engine_fixtures_value_.at("league");subtitle=(l.at("nationId").is_string()?world_->nation_name(l.at("nationId")):std::string())+" · "+l.at("name").get<std::string>();}
if(real_other)subtitle=fixture.at("name").get<std::string>();
else if(engine_mode_){const auto &l=fixture.at("league");subtitle=(l.at("nationId").is_string()?world_->nation_name(l.at("nationId")):std::string())+" · "+l.at("name").get<std::string>();}
else if (mode == "league" || state.value("competition", 0) == 0)
subtitle = (league ? world_->nation_name(league->value("nation", "")) : "") +
" · " + (league ? world_->name(*league) : "");
@@ -82,7 +85,7 @@ std::string App::render_reports(const std::string &mode) {
subtitle = choices.at(size_t(state.value("competition", 0))).second;
}
body += "<header class=\"report-match-heading\"><h2>" +
(opening ? std::string("1. Runde") : std::to_string(round + 1) + ". Spieltag") +
(real_other?fixture.at("heading").get<std::string>():opening ? std::string("1. Runde") : std::to_string(round + 1) + ". Spieltag") +
"</h2><p>" + esc(subtitle) + "</p></header>";
}
body += "<div id=\"report-list\" class=\"report-list " +
@@ -144,13 +147,24 @@ std::string App::render_reports(const std::string &mode) {
value = report_number(row["gf"]) + ":" + report_number(row["ga"]);
else
value = report_number(row.at(headings[column].first));
body += "<span class=\"report-value\">" + esc(value) + "</span>";
if(real_other&&matches) {
const auto phase=[](const Json &v){return v==1?std::string(" n.V."):v==2?std::string(" n.E."):std::string();};
value+=phase(row.at("phase"));
std::string detail;
if(row.at("secondLegVisible").get<bool>()) {
detail="Hin: "+(row.at("secondLeg").is_null()?std::string("–"):report_number(row.at("secondLeg")[0])+":"+report_number(row.at("secondLeg")[1])+phase(row.at("secondLegPhase")));
value="Rück: "+value;
} else if(row.at("status")=="scheduled"&&row.at("date").is_string())detail=row.at("date").get<std::string>();
body+="<div class=\"report-score-lines\"><span class=\"report-value\">"+esc(value)+"</span>"+(detail.empty()?"":"<span class=\"report-score-note\">"+esc(detail)+"</span>")+"</div>";
} else body += "<span class=\"report-value\">" + esc(value) + "</span>";
}
body += "</div>";
}
body += "</div>";
}
body += "</div></div>";
body += "</div>";
if(real_other&&rows.empty())body+="<p class=\"report-detail-empty\">"+std::string(!fixture.at("available").get<bool>()?"Diese Runde ist noch nicht ausgelost oder die vorherige Phase ist noch nicht abgeschlossen.":"Keine Paarungen vorhanden.")+"</p>";
body+="</div>";
if (!matches && !strengths && !engine_mode_) {
const auto legend = tier == 1
? std::vector<std::pair<std::string, std::string>>{
@@ -172,7 +186,7 @@ std::string App::render_reports(const std::string &mode) {
body += btn("report-round", i ? "›" : "‹", "report-round",
"id=\"report-round-" + std::string(i ? "next" : "previous") +
"\" data-id=\"" + (i ? "1" : "-1") + "\" style=\"" +
rect(i * 130, 0, 110, 94) + "\" " + ((opening||(engine_mode_&&(i?engine_fixtures_value_.at("round")==engine_fixtures_value_.at("rounds"):engine_fixtures_value_.at("round")==1))) ? "disabled" : ""));
rect(i * 130, 0, 110, 94) + "\" " + ((opening||(engine_mode_&&(i?fixture.at("round")==fixture.at("rounds"):fixture.at("round")==1))) ? "disabled" : ""));
body += mode == "league" ? report_picker("country", 260, 1060) + report_picker("league", 1340, 1272)
: report_picker("competition", 260, 2352);
} else if (strengths)