Connect Almanac UI to revision-bound career history (by Codex)
This commit is contained in:
1 parent
4b6c18f654
commit
959154c3c0
18 files changed
+405
-44
No files matched your search
@@ -428,6 +428,16 @@ 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 == "almanac") {
|
||||
const J* query = field(request, "query");
|
||||
if (!query || !query->object())
|
||||
return failure(request_id, "invalid_almanac_request", "Eine Almanachabfrage wird benötigt.", c.state_revision);
|
||||
J result = query_almanac(g, *query);
|
||||
const J* ok = field(result, "ok");
|
||||
if (!ok || !std::holds_alternative<bool>(ok->value) || !std::get<bool>(ok->value))
|
||||
return failure(request_id, text_field(result, "error").c_str(), "Der Spielarchiv-Eintrag ist nicht verfügbar.", c.state_revision);
|
||||
return snapshot(request_id, std::move(m), O{{"kind", "almanac"}, {"query", *query}, {"result", std::move(result)}});
|
||||
}
|
||||
if (kind == "news") {
|
||||
// the press events of a team (teamId, default the desk's team) from `from` to `until` (ISO,
|
||||
// default everything up to today), newest last, at most `limit` (default 50) of the newest
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::almanac_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("alm-")) return false;
|
||||
if (engine_mode_) return engine_almanac_action(action,target);
|
||||
if (menu_ != "almanac" || !source_) return true;
|
||||
const auto id = target ? target->GetAttribute<Rml::String>("data-id", "") : "";
|
||||
if (action == "alm-year-cancel" || (action == "alm-back" && report_picker_ == "year")) {
|
||||
|
||||
@@ -74,6 +74,11 @@ std::string almanac_competition_label(const Json &record) {
|
||||
(almanac_text(almanac_field(competition, "type"), "") == "league"
|
||||
? "Spieltag" : "Runde");
|
||||
}
|
||||
bool almanac_phases_known(const Json &result) {
|
||||
if(!almanac_flag(result,"penalties_played"))return true;
|
||||
const auto &score=almanac_field(result,"penalties");
|
||||
return score.is_array()&&score.size()==2&&score[0].is_number_integer()&&score[1].is_number_integer()&&score[0]!=score[1];
|
||||
}
|
||||
std::string almanac_event_kind(const std::string &kind) {
|
||||
if (kind == "goal") return "Tor";
|
||||
if (kind == "miss") return "Fehlschuss";
|
||||
@@ -90,7 +95,7 @@ std::string almanac_event_kind(const std::string &kind) {
|
||||
std::string App::render_almanac() {
|
||||
const auto query = [&](const Json &request) -> Json {
|
||||
try {
|
||||
return source_ ? source_->read_almanac(request)
|
||||
return engine_mode_ ? engine_almanac_read(request) : source_ ? source_->read_almanac(request)
|
||||
: Json{{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
} catch (const std::exception &) {
|
||||
return {{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
@@ -106,8 +111,7 @@ std::string App::render_almanac() {
|
||||
years.push_back(value.get<int>());
|
||||
std::sort(years.begin(), years.end());
|
||||
years.erase(std::unique(years.begin(), years.end()), years.end());
|
||||
const auto snapshot = snap();
|
||||
const auto &reference = almanac_field(snapshot.state, "date");
|
||||
const auto reference = engine_mode_ ? engine_data_.at("desktop").at("meta").at("date") : snap().state.at("date");
|
||||
const auto date = almanac_date_parts(reference);
|
||||
if (almanac_year_ == 0 ||
|
||||
std::find(years.begin(), years.end(), almanac_year_) == years.end()) {
|
||||
@@ -140,11 +144,12 @@ std::string App::render_almanac() {
|
||||
: day_view ? almanac_date_label(almanac_day_)
|
||||
: "Spielarchiv" + (almanac_year_ ? " · " + std::to_string(almanac_year_) : "");
|
||||
const auto crest_image = [&](const Json &team, double size) {
|
||||
const auto &key = almanac_field(team, "crest");
|
||||
auto key = almanac_field(team, "crest");
|
||||
if (engine_mode_ && key.is_null()) if (const auto *club = world_->find("clubs", almanac_text(almanac_field(team,"id"),""))) key=club->value("crest",Json());
|
||||
return "<div class=\"alm-crest\" style=\"width:" + scalar(size) +
|
||||
"dp;height:" + scalar(size) + "dp;\">" +
|
||||
(key.is_string() && !key.get_ref<const std::string &>().empty()
|
||||
? img(key.get<std::string>(), size, size, true)
|
||||
? picture(renderer_.crest(key.get<std::string>(), theme_ == "silver"),size,size)
|
||||
: "<span class=\"alm-no-crest\">—</span>") + "</div>";
|
||||
};
|
||||
const auto team_label = [&](const Json &team, bool home) {
|
||||
@@ -176,7 +181,8 @@ std::string App::render_almanac() {
|
||||
for (size_t i = 0; i < matches.size(); ++i) {
|
||||
const auto &match = matches[i], &result = almanac_field(match, "result");
|
||||
const auto id = almanac_text(almanac_field(match, "id"), "");
|
||||
const bool penalties = almanac_flag(result, "penalties_played"), extra = almanac_flag(result, "extra_played");
|
||||
const bool known=almanac_phases_known(result);
|
||||
const bool penalties = known && almanac_flag(result, "penalties_played"), extra = known && almanac_flag(result, "extra_played");
|
||||
const auto description = almanac_name(almanac_field(match, "home")) + " " +
|
||||
almanac_score(almanac_field(result, "final")) + " " +
|
||||
almanac_name(almanac_field(match, "away")) + " · Spielbericht öffnen";
|
||||
@@ -186,7 +192,7 @@ std::string App::render_almanac() {
|
||||
"<div class=\"alm-row-score alm-list-score\"><span class=\"alm-list-score-value\">" +
|
||||
esc(almanac_score(almanac_field(result, penalties ? "penalties" : "final"))) +
|
||||
"</span><span class=\"alm-list-score-phase\">" +
|
||||
(penalties ? "i. E." : extra ? "n. V." : "") + "</span></div>"
|
||||
(!known ? "unklar" : penalties ? "i. E." : extra ? "n. V." : "") + "</span></div>"
|
||||
"<div class=\"alm-row-away\">" + team_label(almanac_field(match, "away"), false) +
|
||||
"</div></div><div class=\"alm-match-meta\"><span>" +
|
||||
esc(almanac_competition_label(match) + " · Saison " +
|
||||
@@ -260,11 +266,13 @@ std::string App::render_almanac() {
|
||||
} else {
|
||||
const auto &result = almanac_field(record, "result"), &weather = almanac_field(record, "weather");
|
||||
const bool extra = almanac_flag(result, "extra_played"), penalties = almanac_flag(result, "penalties_played");
|
||||
const auto phase = std::string(extra ? "Nach Verlängerung" : "Nach regulärer Spielzeit") +
|
||||
const bool known=almanac_phases_known(result);
|
||||
const auto phase = !known ? std::string("Endstand") : std::string(extra ? "Nach Verlängerung" : "Nach regulärer Spielzeit") +
|
||||
(penalties ? " · Entscheidung i. E." : "");
|
||||
std::string phases = "Reguläre Zeit: " + almanac_score(almanac_field(result, "regulation"));
|
||||
if (extra) phases += " · Verlängerung: " + almanac_score(almanac_field(result, "extra"));
|
||||
if (penalties) phases += " · i. E.: " + almanac_score(almanac_field(result, "penalties"));
|
||||
if (!known) phases="Spielphasen nicht eindeutig überliefert.";
|
||||
output += "<section class=\"alm-summary\"><div class=\"alm-summary-teams\">";
|
||||
const auto summary_team = [&](const char *side, const std::string &css) {
|
||||
const auto &team = almanac_field(record, side), &manager = almanac_field(team, "manager");
|
||||
@@ -390,3 +398,16 @@ std::string App::render_almanac() {
|
||||
output += btn("alm-year-cancel", "", "alm-picker-shield", "id=\"alm-year-shield\" aria-label=\"Jahresauswahl schließen\"");
|
||||
return output + "</div>";
|
||||
}
|
||||
|
||||
bool App::almanac_layout_update() {
|
||||
if (auto *history=element("alm-day-list")) if (auto *content=doc_->QuerySelector(".window .content")) {
|
||||
const float width=content->GetBox().GetSize(Rml::BoxArea::Content).x;
|
||||
if(std::abs(width-almanac_list_width_)>=.001f) {
|
||||
almanac_list_width_=width;history->SetProperty("width",scalar(width)+"px");
|
||||
Rml::ElementList rows;history->QuerySelectorAll(rows,".alm-list-head,.alm-match-row");
|
||||
for(auto *row:rows)row->SetProperty("width",scalar(width)+"px");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::engine_almanac_sync() {
|
||||
const auto &meta=engine_data_.at("desktop").at("meta");
|
||||
if(meta==engine_almanac_context_)return;
|
||||
engine_almanac_context_=meta;engine_almanac_cache_=Json::object();
|
||||
almanac_year_=0;almanac_day_.clear();almanac_match_.clear();almanac_tab_="lineups";
|
||||
}
|
||||
Json App::engine_almanac_read(const Json &query) const {
|
||||
if(engine_almanac_context_==engine_data_.at("desktop").at("meta")) {
|
||||
const auto it=engine_almanac_cache_.find(engine_almanac_key(query));
|
||||
if(it!=engine_almanac_cache_.end())return *it;
|
||||
}
|
||||
return {{"ok",false},{"error","almanac_not_loaded"}};
|
||||
}
|
||||
void App::engine_almanac_select(const Json &query) {
|
||||
const auto kind=query.at("kind").get<std::string>();
|
||||
const auto data=engine_almanac_read(query);
|
||||
if(!data.value("ok",false))return;
|
||||
if(kind=="calendar") {
|
||||
almanac_year_=query.at("year");almanac_day_.clear();almanac_match_.clear();almanac_tab_="lineups";
|
||||
focus_after_render_="report-picker-year";
|
||||
} else if(kind=="day") {
|
||||
almanac_day_=query.at("date");almanac_match_.clear();almanac_tab_="lineups";focus_after_render_="alm-heading";
|
||||
} else if(kind=="match") {
|
||||
if(data.at("match").at("date")!=almanac_day_)throw editor::Error("Spielbericht gehört einem anderen Archivtag.");
|
||||
almanac_match_=query.at("id");almanac_tab_="lineups";focus_after_render_="alm-heading";
|
||||
}
|
||||
close_report_picker(false);refresh();
|
||||
}
|
||||
void App::engine_almanac_load(const Json &query) {
|
||||
if(engine_busy_||!engine_fresh_)return;
|
||||
if(engine_almanac_read(query).value("ok",false)){engine_almanac_select(query);refresh();return;}
|
||||
auto link=engine_link_;
|
||||
engine_start("Spielarchiv wird geladen …",[link,query] {
|
||||
const auto bundle=link->snapshot();
|
||||
Json queries=Json::array({query}),reads=Json::array({link->read({{"kind","almanac"},{"query",query}})});
|
||||
if(query.at("kind")=="index"&&reads[0].value("messageType","")=="snapshot") {
|
||||
const auto index=engine_almanac_projection(bundle,reads[0],query);
|
||||
const int year=index.at("years").empty()?std::stoi(bundle.at("desktop").at("meta").at("date").get<std::string>().substr(0,4)):index.at("years").back().get<int>();
|
||||
const Json calendar={{"kind","calendar"},{"year",year}};
|
||||
queries.push_back(calendar);reads.push_back(link->read({{"kind","almanac"},{"query",calendar}}));
|
||||
}
|
||||
return EngineReply{link,bundle,{{"messageType","almanac_preview"},{"queries",queries},{"reads",reads}},nullptr};
|
||||
});
|
||||
}
|
||||
void App::engine_almanac_poll(const EngineReply &reply) {
|
||||
if(reply.bundle.at("desktop").at("meta")!=engine_almanac_context_)
|
||||
throw editor::Error("Der Archivkontext hat sich geändert. Bitte das Archiv erneut öffnen.");
|
||||
const auto &queries=reply.response.at("queries"),&reads=reply.response.at("reads");
|
||||
if(queries.empty()||queries.size()!=reads.size())throw editor::Error("Unvollständige Archivantwort.");
|
||||
auto cache=engine_almanac_cache_;
|
||||
for(size_t i=0;i<queries.size();++i) {
|
||||
if(reads[i].value("messageType","")=="error") {
|
||||
engine_notice_=engine_text(reads[i].value("message",Json()));
|
||||
if(engine_notice_.empty()||engine_notice_=="—")engine_notice_="Das Spielarchiv ist derzeit nicht verfügbar.";
|
||||
return;
|
||||
}
|
||||
const auto result=engine_almanac_projection(reply.bundle,reads[i],queries[i]);
|
||||
const auto key=engine_almanac_key(queries[i]);
|
||||
// Keep one index, calendar, day and detail. Back navigation is immediate;
|
||||
// opening many seasons cannot accumulate entire archives in UI memory.
|
||||
const auto kind=queries[i].at("kind").get<std::string>();
|
||||
for(auto it=cache.begin();it!=cache.end();) {
|
||||
if(it.key()==kind||it.key().starts_with(kind+":"))it=cache.erase(it);else ++it;
|
||||
}
|
||||
cache[key]=result;
|
||||
}
|
||||
if(queries.back().at("kind")=="match"&&cache.at(engine_almanac_key(queries.back())).at("match").at("date")!=almanac_day_)
|
||||
throw editor::Error("Spielbericht gehört einem anderen Archivtag.");
|
||||
engine_almanac_cache_=std::move(cache);
|
||||
engine_notice_="Spielarchiv geladen.";
|
||||
if(menu_=="almanac")engine_almanac_select(queries.back());
|
||||
}
|
||||
bool App::engine_almanac_action(const std::string &action,Rml::Element *target) {
|
||||
if(!action.starts_with("alm-"))return false;
|
||||
if(menu_!="almanac"||engine_busy_||!engine_fresh_)return true;
|
||||
const auto id=target?target->GetAttribute<Rml::String>("data-id",""):std::string();
|
||||
if(action=="alm-year-cancel"||(action=="alm-back"&&report_picker_=="year")){close_report_picker(true);return true;}
|
||||
if(action=="alm-back") {
|
||||
if(!almanac_match_.empty()){focus_after_render_="alm-match-"+almanac_match_;almanac_match_.clear();}
|
||||
else if(!almanac_day_.empty()){focus_after_render_="alm-day-"+almanac_day_;almanac_day_.clear();}
|
||||
else{menu_.clear();focus_after_render_="object-app-almanac";}
|
||||
} else if(action=="alm-day") {
|
||||
const auto calendar=engine_almanac_read({{"kind","calendar"},{"year",almanac_year_}});
|
||||
if(calendar.value("ok",false))for(const auto &d:calendar.at("days"))if(d.at("date")==id){engine_almanac_load({{"kind","day"},{"date",id}});break;}
|
||||
return true;
|
||||
} else if(action=="alm-match") {
|
||||
const auto day=engine_almanac_read({{"kind","day"},{"date",almanac_day_}});
|
||||
if(day.value("ok",false))for(const auto &m:day.at("matches"))if(m.at("id")==id){engine_almanac_load({{"kind","match"},{"id",id}});break;}
|
||||
return true;
|
||||
} else if(action=="alm-tab") {
|
||||
if(almanac_match_.empty()||(id!="lineups"&&id!="events"))return true;
|
||||
almanac_tab_=id;focus_after_render_="alm-tab-"+id;
|
||||
} else return false;
|
||||
close_report_picker(false);refresh();return true;
|
||||
}
|
||||
@@ -47,6 +47,10 @@ Json engine_friendly_plan(const Json &bundle);
|
||||
Json engine_friendly_projection(const Json &bundle, const Json &read, const std::string &opponent, bool home);
|
||||
Json engine_friendly_command(const Json &bundle, const Json &read, const std::string &opponent, bool home, const std::string &date, bool accept_cost, bool opponent_consent, const std::string &request_id);
|
||||
|
||||
// Archive requests and immutable replies; no live-roster or current-name fallback.
|
||||
std::string engine_almanac_key(const Json &query);
|
||||
Json engine_almanac_projection(const Json &bundle, const Json &read, const Json &query);
|
||||
|
||||
// Single-session facade. Its owner serializes all calls on a background worker.
|
||||
// No RmlUI objects or callbacks cross this boundary.
|
||||
class EngineBridge {
|
||||
|
||||
@@ -12,6 +12,7 @@ void App::engine_poll() {
|
||||
try {
|
||||
auto result = engine_job_.get();
|
||||
validate_engine_desk(result.bundle);
|
||||
if(result.response.value("messageType","")=="almanac_preview"){engine_almanac_poll(result);refresh();return;}
|
||||
if (result.response.value("messageType", "") == "friendly_preview") {
|
||||
const auto &read = result.response.at("read");
|
||||
if (read.value("messageType", "") == "error") {
|
||||
@@ -52,6 +53,7 @@ void App::engine_poll() {
|
||||
} else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
|
||||
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
|
||||
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
|
||||
engine_almanac_sync();
|
||||
engine_ticket_bind();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
@@ -71,6 +73,7 @@ void App::engine_frame() {
|
||||
engine_sports_update();
|
||||
if (ticket_) ticket_->update();
|
||||
render_popup(); context_->Update();
|
||||
if(almanac_layout_update())context_->Update();
|
||||
if (rendered && menu_ == "friendlies") if (auto *list = element("friendly-opponents")) list->SetScrollTop(engine_friendly_scroll_);
|
||||
if (menu_ == "contracts" && engine_contract_scroll_) {
|
||||
if (auto *roster = element("contracts-roster-scroll")) roster->SetScrollTop(*engine_contract_scroll_);
|
||||
@@ -82,7 +85,13 @@ void App::engine_frame() {
|
||||
lineup_roster_scroll_.reset();
|
||||
}
|
||||
if (!engine_busy_ && popup_.empty() && !focus_after_render_.empty()) {
|
||||
if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_);
|
||||
if (auto *node = element(focus_after_render_)) {
|
||||
node->Focus(keyboard_navigation_);
|
||||
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);
|
||||
}
|
||||
}
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
if (amount_select_all_) {
|
||||
@@ -126,7 +135,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (!engine_busy_ && advertising_event(event)) return;
|
||||
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
|
||||
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
|
||||
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && menu_ == "friendlies" && report_picker_event(event)) return;
|
||||
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && (menu_ == "friendlies" || menu_ == "almanac") && 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())
|
||||
@@ -151,8 +160,10 @@ void App::engine_event(Rml::Event &event) {
|
||||
}
|
||||
}
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) {
|
||||
if (menu_ == "almanac" && engine_busy_) { event.StopImmediatePropagation(); return; }
|
||||
if (!popup_.empty()) { popup_.clear(); confirm_ = {}; dirty_ = true; }
|
||||
else if (!engine_busy_ && !engine_player_.empty()) { focus_after_render_ = "lineup-detail-" + engine_player_ + "-0"; engine_player_.clear(); refresh(); }
|
||||
else if (!engine_busy_ && menu_ == "almanac") engine_almanac_action("alm-back",nullptr);
|
||||
else if (!engine_busy_ && !menu_.empty()) { if (menu_ == "training" || menu_ == "tactics") engine_sports_reset(); menu_.clear(); refresh(); }
|
||||
else engine_quit();
|
||||
event.StopImmediatePropagation(); return;
|
||||
@@ -165,7 +176,12 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (!controls.empty()) {
|
||||
const auto found = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
||||
const int index = found == controls.end() ? -1 : int(found - controls.begin());
|
||||
controls[size_t((index + int(controls.size()) + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % int(controls.size()))]->Focus(true);
|
||||
auto *next=controls[size_t((index + int(controls.size()) + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % int(controls.size()))];
|
||||
next->Focus(true);
|
||||
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);
|
||||
}
|
||||
}
|
||||
event.StopImmediatePropagation(); return;
|
||||
}
|
||||
@@ -189,8 +205,9 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
|
||||
return;
|
||||
}
|
||||
if (almanac_action(action,node)) return;
|
||||
if (engine_friendly_action(action, node)) return;
|
||||
if (menu_ == "friendlies" && report_picker_action(action,node)) return;
|
||||
if ((menu_ == "friendlies" || menu_ == "almanac") && 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;
|
||||
@@ -204,6 +221,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 == "almanac") { menu_=id;engine_almanac_sync();engine_almanac_load({{"kind","index"}}); }
|
||||
else if (action == "engine-open" && id == "friendlies") { menu_ = id; planning_dialog_.clear(); engine_friendly_sync(); refresh(); }
|
||||
else if (action == "engine-open" && (id == "calendar" || id == "postpone")) { menu_ = id; engine_move_id_.clear(); engine_calendar_sync(); refresh(); }
|
||||
else if (action == "engine-open" && id == "contracts") { menu_ = id; engine_contracts_clear(false); contracts_player_.clear(); engine_contract_scroll_ = 0.f; refresh(); }
|
||||
@@ -228,5 +246,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_}, {"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_}, {"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_}};
|
||||
}
|
||||
@@ -721,4 +721,54 @@ Json engine_friendly_command(const Json &bundle,const Json &read,const std::stri
|
||||
const auto &dates=quote.at("dates");require(std::find(dates.begin(),dates.end(),Json(date))!=dates.end(),"Dieser Termin wird nicht mehr angeboten.");
|
||||
return sports_command(bundle,"friendly.book",{{"opponentId",opponent},{"home",home},{"date",date},{"acceptCost",true},{"opponentConsent",!quote.at("other_manager").is_null()&&consent}},request_id);
|
||||
}
|
||||
std::string engine_almanac_key(const Json &query) {
|
||||
require(query.is_object(),"Ungültige Archivabfrage.");
|
||||
const auto kind=query.at("kind").get<std::string>();
|
||||
if(kind=="index")return kind;
|
||||
if(kind=="calendar")return kind+":"+std::to_string(whole_in_range(query.at("year"),1,9999));
|
||||
if(kind=="day") { (void)calendar_iso_day(query.at("date"));return kind+":"+query.at("date").get<std::string>(); }
|
||||
if(kind=="match") {const auto id=query.at("id").get<std::string>();require(!id.empty()&&id.size()<=512,"Ungültige Archivspiel-ID.");return kind+":"+id;}
|
||||
throw editor::Error("Unbekannte Archivabfrage.");
|
||||
}
|
||||
Json engine_almanac_projection(const Json &bundle,const Json &read,const Json &query) {
|
||||
validate_engine_desk(bundle);auto context=bundle;context["almanac"]=read;
|
||||
const auto &data=lineup_read(context,"almanac");
|
||||
const auto key=engine_almanac_key(query);
|
||||
require(engine_almanac_key(data.at("query"))==key,"Archivantwort gehört einer anderen Abfrage.");
|
||||
const auto &result=data.at("result");require(result.at("ok")==true,"Archivantwort ist nicht verfügbar.");
|
||||
const auto today=calendar_iso_day(bundle.at("desktop").at("meta").at("date"));
|
||||
const auto date=[&](const Json &v){const auto d=calendar_iso_day(v);require(d<=today,"Archiv enthält eine zukünftige Partie.");};
|
||||
const auto text=[](const Json &v){require(v.is_string()&&!v.get_ref<const std::string &>().empty(),"Archividentität oder Name fehlt.");};
|
||||
const auto score=[](const Json &v){require(v.is_array()&&v.size()==2,"Ungültiges Archiv-Ergebnis.");for(const auto &n:v)(void)whole_in_range(n,0,10000);};
|
||||
const auto record=[&](const Json &r) {
|
||||
text(r.at("id"));date(r.at("date"));text(r.at("season"));
|
||||
require(r.at("home").at("id")!=r.at("away").at("id"),"Archivpaarung spielt gegen sich selbst.");
|
||||
for(const auto *side:{"home","away"}) {
|
||||
const auto &t=r.at(side);text(t.at("id"));text(t.at("name"));
|
||||
require(t.at("manager").is_null()||t.at("manager").is_object(),"Ungültiger archivierter Manager.");
|
||||
if(t.at("manager").is_object()){text(t.at("manager").at("id"));text(t.at("manager").at("name"));}
|
||||
const auto &lineup=r.at("lineups").at(side);
|
||||
if(!lineup.is_null()) {for(const auto *part:{"starters","bench"}){require(lineup.at(part).is_array(),"Archivaufstellung fehlt.");for(const auto &p:lineup.at(part)){if(p.is_null())continue;text(p.at("id"));text(p.at("name"));}}}
|
||||
}
|
||||
const auto &scores=r.at("result");score(scores.at("final"));
|
||||
for(const auto *phase:{"regulation","extra","penalties"})if(!scores.at(phase).is_null())score(scores.at(phase));
|
||||
require(scores.at("extra_played").is_boolean()&&scores.at("penalties_played").is_boolean(),"Archiv-Spielphasen fehlen.");
|
||||
require(r.at("events").is_array(),"Archivereignisse fehlen.");
|
||||
for(const auto &e:r.at("events")){text(e.at("kind"));(void)whole_in_range(e.at("minute"),0,1000);require(e.at("side")=="home"||e.at("side")=="away","Unbekannte Ereignisseite.");for(const auto *who:{"player","other"})if(!e.at(who).is_null()){text(e.at(who).at("id"));text(e.at(who).at("name"));}}
|
||||
};
|
||||
if(key=="index") {
|
||||
const auto &years=result.at("years");require(years.is_array(),"Archivjahre fehlen.");int last=0;
|
||||
for(const auto &year:years){const int y=whole_in_range(year,1,9999);require(y>last,"Doppelte oder unsortierte Archivjahre.");last=y;}
|
||||
const int count=whole_in_range(result.at("match_count"),0,std::numeric_limits<int>::max());
|
||||
if(!count)require(years.empty()&&result.at("first_date").is_null()&&result.at("last_date").is_null(),"Unvollständiges leeres Archiv.");
|
||||
else {date(result.at("first_date"));date(result.at("last_date"));require(!years.empty()&&result.at("first_date")<=result.at("last_date"),"Ungültiger Archivzeitraum.");}
|
||||
} else if(query.at("kind")=="calendar") {
|
||||
require(result.at("year")==query.at("year")&&result.at("days").is_array(),"Archivjahr stimmt nicht überein.");std::set<std::string> seen;
|
||||
for(const auto &d:result.at("days")){date(d.at("date"));const auto iso=d.at("date").get<std::string>();require(std::stoi(iso.substr(0,4))==query.at("year").get<int>()&&seen.insert(iso).second,"Doppelter oder falsch zugeordneter Archivtag.");const int n=whole_in_range(d.at("count"),1,std::numeric_limits<int>::max());require(d.at("highlights").is_array()&&d.at("highlights").size()<=size_t(n),"Ungültige Archiv-Highlights.");std::set<std::string> ids;for(const auto &id:d.at("highlights")){text(id);require(ids.insert(id.get<std::string>()).second,"Doppelte Highlight-ID.");}}
|
||||
} else if(query.at("kind")=="day") {
|
||||
require(result.at("date")==query.at("date")&&result.at("matches").is_array(),"Archivtag stimmt nicht überein.");std::set<std::string> ids;
|
||||
for(const auto &m:result.at("matches")){record(m);require(m.at("date")==query.at("date")&&ids.insert(m.at("id").get<std::string>()).second,"Partie steht am falschen Tag oder doppelt im Archiv.");}
|
||||
} else {record(result.at("match"));require(result.at("match").at("id")==query.at("id"),"Archivantwort gehört einer anderen Partie.");}
|
||||
return result;
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -37,6 +37,7 @@ Json App::engine_camp_view() const {
|
||||
}
|
||||
void App::engine_render() {
|
||||
if (ticket_) ticket_->close(false);
|
||||
almanac_list_width_=-1.f;
|
||||
if (menu_ == "friendlies") if (auto *list = element("friendly-opponents")) engine_friendly_scroll_ = list->GetScrollTop();
|
||||
if (menu_ == "contracts") if (auto *roster = element("contracts-roster-scroll")) engine_contract_scroll_ = roster->GetScrollTop();
|
||||
if (menu_ == "lineup") {
|
||||
@@ -112,11 +113,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 == "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 == "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_=="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>";
|
||||
if (menu_ == "friendlies") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Freundschaftsspiel", friendlies_available ? render_friendlies() : "<div class=\"fill center\">Freundschaftsplanung ist derzeit nicht verfügbar.</div>") + "</div>";
|
||||
if (menu_ == "calendar") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Kalender", calendar_available ? render_calendar() : "<div class=\"fill center\">Der Saisonkalender ist derzeit nicht verfügbar.</div>") + "</div>";
|
||||
if (menu_ == "postpone") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Verlegen", scheduling_available ? render_postpone() : "<div class=\"fill center\">Die Spielverlegung ist derzeit nicht verfügbar.</div>") + "</div>";
|
||||
@@ -129,7 +131,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") && !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") && !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();
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
void engine_contracts_poll();
|
||||
void engine_contracts_clear(bool focus = true);
|
||||
void engine_contracts_close(bool focus = true);
|
||||
Json engine_almanac_context_, engine_almanac_cache_ = Json::object();
|
||||
void engine_almanac_sync();
|
||||
void engine_almanac_load(const Json &);
|
||||
void engine_almanac_select(const Json &);
|
||||
void engine_almanac_poll(const EngineReply &);
|
||||
Json engine_almanac_read(const Json &) const;
|
||||
bool engine_almanac_action(const std::string &, Rml::Element *);
|
||||
int engine_calendar_day_ = -1;
|
||||
std::string engine_move_id_, engine_calendar_season_;
|
||||
bool engine_schedule_pending_ = false;
|
||||
|
||||
@@ -25,8 +25,8 @@ App::report_picker_items(const std::string &kind) const {
|
||||
return items;
|
||||
}
|
||||
if (kind == "year") {
|
||||
if (!source_) return items;
|
||||
const auto index = source_->read_almanac({{"kind", "index"}});
|
||||
if (!source_ && !engine_mode_) return items;
|
||||
const auto index = engine_mode_ ? engine_almanac_read({{"kind","index"}}) : source_->read_almanac({{"kind", "index"}});
|
||||
if (!index.value("ok", false)) return items;
|
||||
for (const auto &year : index.at("years"))
|
||||
items.emplace_back(std::to_string(year.get<int>()), std::to_string(year.get<int>()));
|
||||
@@ -218,6 +218,8 @@ bool App::report_picker_action(const std::string &action, Rml::Element *target)
|
||||
engine_friendly_filter(kind, value);
|
||||
} else if (menu_ == "statistics") {
|
||||
statistics_picker_select(kind, value);
|
||||
} else if (kind == "year" && menu_ == "almanac" && engine_mode_) {
|
||||
engine_almanac_load({{"kind","calendar"},{"year",std::stoi(value)}});
|
||||
} else if (kind == "year" && menu_ == "almanac") {
|
||||
almanac_year_ = std::stoi(value);
|
||||
almanac_day_.clear();
|
||||
|
||||
+3
-13
@@ -787,6 +787,7 @@ class App final : public Rml::EventListener {
|
||||
bool stadium_event(Rml::Event &);
|
||||
std::string render_almanac();
|
||||
bool almanac_action(const std::string &, Rml::Element *);
|
||||
bool almanac_layout_update();
|
||||
std::string render_indoor();
|
||||
bool indoor_action(const std::string &, Rml::Element *);
|
||||
std::string training_balls(const std::string &, int, int, bool,
|
||||
@@ -1084,19 +1085,7 @@ class App final : public Rml::EventListener {
|
||||
bool changed = false;
|
||||
// History can contain every competition on one date. Keep its whole-row
|
||||
// buttons on the same centre even when the long list gains a scrollbar.
|
||||
if (auto *history = element("alm-day-list")) {
|
||||
if (auto *content = doc_->QuerySelector(".window .content")) {
|
||||
const float width = content->GetBox().GetSize(Rml::BoxArea::Content).x;
|
||||
if (std::abs(width - almanac_list_width_) >= .001f) {
|
||||
almanac_list_width_ = width;
|
||||
history->SetProperty("width", scalar(width) + "px");
|
||||
Rml::ElementList rows;
|
||||
history->QuerySelectorAll(rows, ".alm-list-head,.alm-match-row");
|
||||
for (auto *row : rows) row->SetProperty("width", scalar(width) + "px");
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
changed |= almanac_layout_update();
|
||||
auto *list = element("report-list");
|
||||
if (!list || !list->IsClassSet("match-list"))
|
||||
return changed;
|
||||
@@ -1541,6 +1530,7 @@ public:
|
||||
#include "modern/ui/engine_contracts.inc"
|
||||
#include "modern/ui/engine_calendar.inc"
|
||||
#include "modern/ui/engine_friendlies.inc"
|
||||
#include "modern/ui/engine_almanac.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user