Bind the kickoff of the Modern desk to the engine and show its recording in the ticker

The kickoff button sends session.advance; the engine's recording of the
played matchday is shaped for the live ticker (phases, per-match tables,
the desk manager's squad). A contract running out on the way asks the
manager to extend at the player's demand or to release him. The UI script
driver accepts optional clicks, and modern_live_dump writes the engine's
recording for inspection.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-14 00:05:04 +01:00
1 parent 9e92d07b03
commit 7c0e66affe
15 files changed
+447 -30

No files matched your search

+79
View File
@@ -6,6 +6,50 @@ void App::engine_start(std::string label, std::function<EngineReply()> job, bool
engine_operation_ = std::move(label); engine_busy_ = true;
engine_job_ = std::async(std::launch::async, std::move(job)); refresh();
}
// Plays the next kickoff with the line-up and tactics of the desk; the ticker then shows
// the engine's recording of it. Answers to questions of the run travel in the payload.
void App::engine_kickoff() {
if (engine_busy_ || !engine_link_) return;
const auto command = engine_advance_command(engine_data_, editor::new_id("request:ui-"), engine_advance_payload_);
auto link = engine_link_;
engine_start("Der Spieltag läuft …", [link, command] {
auto response = link->command(command);
if (response.value("messageType", "") == "command_result") response["liveRecording"] = link->read_live({{"kind", "fixture"}});
else response["advanceRefused"] = true;
return EngineReply{link, link->snapshot(), response, nullptr};
}, true);
}
// A contract runs out on the way to the next desk: the manager extends at the player's
// demand, lets him go, or returns to the desk to deal with it there.
void App::engine_expiry_ask(const Json &args) {
const std::string id = args.value("playerId", std::string());
if (id.empty()) return;
std::string name = id;
try {
for (const auto &p : engine_data_.at("squad").at("data").at("players"))
if (p.at("player").at("id") == id) name = p.at("player").at("name").get<std::string>();
} catch (const std::exception &) {}
int years = 0; Json salary;
const auto demands = args.value("demands", Json::array());
for (int option : {1, 0, 2, 3})
if (!years && demands.is_array() && size_t(option) < demands.size() && demands[size_t(option)].is_object()) { years = option + 1; salary = demands[size_t(option)]; }
engine_expiry_player_ = id;
if (years) {
confirmation("Der Vertrag von " + name + " läuft aus. Er fordert " + engine_price(salary) + " monatlich für " +
std::to_string(years) + (years == 1 ? " Jahr." : " Jahre.") + " Verlängern oder freigeben?",
[this, id, years, salary] {
engine_advance_payload_["contractExpiry"][id] = {{"action", "renew"}, {"years", years}, {"monthlySalary", salary}};
engine_kickoff();
});
popup_accept_ = "Verlängern";
} else {
confirmation("Der Vertrag von " + name + " läuft aus und der Spieler verlängert nicht. Freigeben und weiter?",
[this, id] { engine_advance_payload_["contractExpiry"][id] = {{"action", "release"}}; engine_kickoff(); });
popup_accept_ = "Freigeben";
return;
}
popup_extra_ = btn("engine-expiry-release", "Freigeben");
}
void App::engine_accept(EngineReply result) {
engine_fresh_ = true;
if (result.catalog) { world_ = std::move(result.catalog); bind_world(world_); }
@@ -45,6 +89,20 @@ void App::engine_accept(EngineReply result) {
engine_focus_ = {{"condition", f.at("condition")}, {"technique", f.at("technique")}, {"play", f.at("play")}};
if (engine_camp_.empty() && !engine_data_.at("camps").at("data").at("camps").empty())
engine_camp_ = engine_data_.at("camps").at("data").at("camps").front().at("id");
if (engine_response_.value("advanceRefused", false)) {
engine_response_.erase("advanceRefused");
Json args;
try { args = engine_response_.at("message").at("args"); } catch (const std::exception &) {}
if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "contract_expiry")
engine_expiry_ask(args);
}
if (engine_response_.contains("liveRecording")) {
const Json recording = engine_response_.at("liveRecording");
engine_response_.erase("liveRecording");
engine_advance_payload_ = Json::object();
if (recording.value("ok", false)) engine_live_open(recording);
else engine_notice_ = "Weiter zum nächsten Termin · an diesem Tag gab es kein eigenes Spiel.";
}
}
void App::engine_poll() {
if (!engine_busy_ || engine_job_.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) return;
@@ -91,6 +149,10 @@ void App::engine_frame() {
engine_sports_update();
if (ticket_) ticket_->update();
render_popup(); context_->Update();
if (scene_ == "live" && live_.available()) {
if (rendered) { live_after_render(); context_->Update(); }
live_update_parts();
}
if(center_fixture_columns())context_->Update();
if (menu_ == "settings") { settings_after_render(); context_->Update(); }
if (rendered && menu_ == "friendlies") if (auto *list = element("friendly-opponents")) list->SetScrollTop(engine_friendly_scroll_);
@@ -160,6 +222,16 @@ void App::engine_event(Rml::Event &event) {
const auto type = event.GetType(); auto *target = event.GetTargetElement();
if (type == "keydown") keyboard_navigation_ = true;
if (type == "mousedown") keyboard_navigation_ = false;
if (scene_ == "live" && live_.available()) {
// The ticker of a played kickoff: only its own controls, nothing of the desk beneath.
if (live_event(event)) return;
if (type == "click")
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
if (n->HasAttribute("data-action") && !n->HasAttribute("disabled")) {
live_action(n->GetAttribute<Rml::String>("data-action", ""), n); break;
}
event.StopImmediatePropagation(); return;
}
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
if (node->GetId() == "native-ticket-layer") return; // owned by the compact control
if (ticket_ && ticket_->is_open()) return;
@@ -285,6 +357,12 @@ void App::engine_event(Rml::Event &event) {
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
if (!popup_.empty()) {
if(action=="balance-discard"){engine_balance_action(action,node);return;}
if (action == "engine-expiry-release") {
const auto player = engine_expiry_player_;
popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true;
if (!player.empty()) { engine_advance_payload_["contractExpiry"][player] = {{"action", "release"}}; engine_kickoff(); }
return;
}
if (action == "popup-close") { popup_.clear(); reset_popup(); engine_files_pending_load_.reset(); engine_exit_after_save_=false; dirty_ = true; }
if(action=="files-save-before-load"){const auto pending=engine_files_pending_load_;reset_popup();popup_.clear();engine_files_begin("save");engine_files_pending_load_=pending;return;}
if(action=="engine-save-exit"){reset_popup();popup_.clear();engine_exit_after_save_=true;try{engine_save();}catch(const std::exception &e){engine_exit_after_save_=false;message(e.what());}return;}
@@ -359,6 +437,7 @@ void App::engine_event(Rml::Event &event) {
else if (action == "engine-open" && id == "save") engine_save();
else if (action == "engine-open" && (id == "training" || id == "tactics")) { engine_sports_reset(); menu_ = id; refresh(); }
else if (action == "engine-open" && id == "lineup") { menu_ = "lineup"; lineup_selected_.clear(); lineup_reset_scroll_ = true; refresh(); }
else if (action == "engine-open" && id == "kickoff" && engine_fresh_) engine_kickoff();
else if (action == "engine-open" && id == "camp") { menu_ = "camp"; refresh(); }
else if (action == "camp-region") { selections_["camp-region"] = id; refresh(); }
else if (action == "camp-select") { engine_camp_ = id; refresh(); }