diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index a205dd7..546dcb2 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9923,6 +9923,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision answers[id] = x; } std::string pending_player; + std::array pending_demands{}; auto previous_hook = g_.contract_screen; const bool previous_installed = contract_expiry_presenter_installed_; set_contract_expiry_presenter([&](modern::ModernState& state, WatcomRandom& random, int m, int row) -> int { @@ -9931,7 +9932,11 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision const int p = size_t(row) < range.count ? state.squad_slots[range.first + size_t(row)] & 0x0fff : 0x0fff; const std::string id = p == 0x0fff ? std::string{} : modern::ui_player_id(state, p); const auto it = answers.find(id); - if (it == answers.end()) { pending_player = id; return -2; } // ask the interface + if (it == answers.end()) { // ask the interface; the run is rolled back, so this draw is repeated later + pending_player = id; + try { pending_demands = modern::contract_demands(state, m, row, false, random); } catch (const std::exception&) { pending_demands = {}; } + return -2; + } if (!it->second.renew) return 0; // released try { const auto demands = modern::contract_demands(state, m, row, false, random); @@ -9973,7 +9978,9 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision if (!pending_player.empty()) { cli::Json pending = refuse("decision_pending", "Ein Vertrag läuft aus: Verlängern oder freigeben?"); auto& message = std::get(std::get(pending.value)["message"].value); - message["args"] = cli::Json::Object{{"decision", "contract_expiry"}, {"playerId", pending_player}}; + cli::Json::Array demands; + for (const uint32_t d : pending_demands) demands.push_back(d == 0 || d == UINT32_MAX ? cli::Json(nullptr) : modern::ui_money(int64_t(d))); + message["args"] = cli::Json::Object{{"decision", "contract_expiry"}, {"playerId", pending_player}, {"demands", std::move(demands)}}; return pending; } const std::string reason = r.reason.empty() ? error : r.reason; diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 4755f9b..9cae906 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-only -add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp engine_transfer.cpp engine_achievements.cpp engine_news.cpp engine_balance.cpp engine_widgets.cpp engine_indoor.cpp engine_settings.cpp engine_managers.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp) +add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_live.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp engine_transfer.cpp engine_achievements.cpp engine_news.cpp engine_balance.cpp engine_widgets.cpp engine_indoor.cpp engine_settings.cpp engine_managers.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp) target_include_directories(bmh_modern_ui_core PUBLIC ../..) target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io) add_library(bmh_modern_ui_mods STATIC mod_library.cpp) @@ -161,9 +161,12 @@ target_link_libraries(modern_engine_dto_tests PRIVATE bmh_modern_ui_core) add_test(NAME modern_engine_dto_tests COMMAND modern_engine_dto_tests) add_executable(modern_engine_bridge_probe ../../../tests/modern_engine_bridge_probe.cpp) target_link_libraries(modern_engine_bridge_probe PRIVATE bmh_modern_ui_engine bmh_modern_session) +add_executable(modern_live_dump ../../../tests/modern_live_dump.cpp) +target_link_libraries(modern_live_dump PRIVATE bmh_modern_ui_engine bmh_modern_session) if(MSVC) target_compile_options(modern_engine_dto_tests PRIVATE /utf-8) target_compile_options(modern_engine_bridge_probe PRIVATE /utf-8 /bigobj) + target_compile_options(modern_live_dump PRIVATE /utf-8 /bigobj) endif() add_executable(modern_managers_projection_tests "${CMAKE_SOURCE_DIR}/tests/modern_managers_projection_tests.cpp") diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 68d0630..2c32141 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -914,6 +914,12 @@ void App::script() { const auto end=SDL_GetTicks64()+command.value("timeout_ms",uint64_t(300000)); while(front_busy_&&SDL_GetTicks64()Update(); + auto *node = doc_->QuerySelector(command.at("selector").get()); + return !node || !node->IsVisible(true) || node->HasAttribute("disabled"); + }()) { + // An optional step whose element is absent, hidden or disabled is skipped. } else if (type == "click" || type == "right") { const auto point = locate(command); const int button = type == "right" ? 1 : 0; diff --git a/src/modern/ui/demo_live.cpp b/src/modern/ui/demo_live.cpp index 39767f3..af8b649 100644 --- a/src/modern/ui/demo_live.cpp +++ b/src/modern/ui/demo_live.cpp @@ -3,6 +3,7 @@ #include "modern/ui/demo_career.hpp" #include "modern/ui/demo_lineup.hpp" #include "modern/ui/demo_sports.hpp" +#include "modern/ui/engine_live.hpp" #include #include #include @@ -215,6 +216,8 @@ Json make_demo_live(const Catalog &world, const Json &state, uint64_t revision) bool valid_live_fixture(const Json &v) { try { + // A recording of the engine has its own, engine-shaped rules. + if (v.is_object() && v.value("source", "") == "engine-recording") return valid_engine_live_fixture(v); if (!v.is_object() || !v.value("ok", false) || v.at("schema") != "openbmh-live-fixture@1" || v.at("source") != "ui-demo-fixture" || !v.at("fixture_id").is_string() || !uint_value(v.at("source_revision"), UINT64_MAX) || !v.at("owners").is_array() || @@ -383,7 +386,7 @@ bool LivePlayback::cycle_owner(int direction) { } Json LivePlayback::frame() const { return available() ? live_fixture_frame(fixture_, sequence_) : failure("live_unavailable"); } Json LivePlayback::status() const { - return {{"source", available() ? Json("ui-demo-fixture") : Json()}, {"available", available()}, + return {{"source", available() ? fixture_.at("source") : Json()}, {"available", available()}, {"fixture_id", available() ? fixture_.at("fixture_id") : Json()}, {"source_revision", available() ? fixture_.at("source_revision") : Json()}, {"sequence", sequence_}, {"speed", speed_}, {"owner", owner_}, {"finished", finished()}}; diff --git a/src/modern/ui/engine_bridge.cpp b/src/modern/ui/engine_bridge.cpp index 5422e81..95dd73f 100644 --- a/src/modern/ui/engine_bridge.cpp +++ b/src/modern/ui/engine_bridge.cpp @@ -83,6 +83,9 @@ Json EngineBridge::command(const Json &request) { Json EngineBridge::read(const Json &request) const { return from_engine(impl_->session->ui_read(cli::parse_json(request.dump()), impl_->revision)); } +Json EngineBridge::read_live(const Json &request) const { + return from_engine(impl_->session->read_live(cli::parse_json(request.dump()))); +} CareerFiles make_career_files(const fs::path &directory,const fs::path &world) { const auto model=modern::open_world_package(world).world; return CareerFiles(directory,[model](const fs::path &file){ diff --git a/src/modern/ui/engine_bridge.hpp b/src/modern/ui/engine_bridge.hpp index 12a81a8..a3eb87d 100644 --- a/src/modern/ui/engine_bridge.hpp +++ b/src/modern/ui/engine_bridge.hpp @@ -104,6 +104,8 @@ public: ~EngineBridge(); Json snapshot() const; Json read(const Json &request) const; + // The recording of the last kickoff (or the paused live state); never starts a match. + Json read_live(const Json &request) const; Json command(const Json &request); Json save_copy(const fs::path &path); Json file_metadata() const; diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 96cbcf8..92887a2 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -6,6 +6,50 @@ void App::engine_start(std::string label, std::function 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(); + } 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("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("data-action", ""), id = node->GetAttribute("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(); } diff --git a/src/modern/ui/engine_live.cpp b/src/modern/ui/engine_live.cpp new file mode 100644 index 0000000..c2e0183 --- /dev/null +++ b/src/modern/ui/engine_live.cpp @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-3.0-only +// The engine's kickoff recording, shaped for the live ticker. Nothing here simulates or +// estimates: the recording is copied, its phases and tables are renamed to the ticker's +// vocabulary and the desk manager's squad is attached for the team tab. +#include "modern/ui/engine_live.hpp" + +#include +#include +#include + +namespace bmh::modern_ui { +namespace { +Json failure(const std::string &error) { return {{"ok", false}, {"error", error}}; } +bool text(const Json &v, size_t max = 400) { return v.is_string() && v.get_ref().size() <= max; } +bool count(const Json &v, uint64_t max = 1000000) { return v.is_number_integer() && v.get() >= 0 && uint64_t(v.get()) <= max; } +bool team_ok(const Json &v) { return v.is_object() && text(v.at("id")) && !v.at("id").get_ref().empty() && text(v.at("name")); } +Json metric(const Json &player, const char *key) { + try { + const auto &value = player.at("metrics").at(key).at("value"); + return value.is_number_integer() ? value : Json(); + } catch (const std::exception &) { return Json(); } +} +} // namespace + +Json engine_advance_command(const Json &bundle, const std::string &request_id, const Json &payload) { + validate_engine_desk(bundle); + if (request_id.empty()) throw editor::Error("Anfrage-ID fehlt."); + const auto &meta = bundle.at("desktop").at("meta"); + const auto commands = meta.at("scope").value("allowedCommands", Json::array()); + if (!commands.is_array() || std::find(commands.begin(), commands.end(), Json("session.advance")) == commands.end()) + throw editor::Error("Der Anstoß ist in diesem Kontext gesperrt."); + return {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")}, {"requestId", request_id}, + {"careerId", meta.at("careerId")}, {"expectedRevision", meta.at("stateRevision")}, + {"owner", {{"managerId", meta.at("scope").at("managerId")}}}, + {"kind", "session.advance"}, {"payload", payload.is_object() ? payload : Json::object()}}; +} + +bool valid_engine_live_fixture(const Json &v) { + try { + if (!v.is_object() || !v.value("ok", false) || v.at("schema") != "openbmh-live-fixture@1" || + v.at("source") != "engine-recording" || !text(v.at("fixture_id")) || !count(v.at("source_revision"), UINT64_MAX >> 1) || + !v.at("owners").is_array() || v.at("owners").empty() || v.at("owners").size() > 4 || + !v.at("matches").is_array() || v.at("matches").empty() || v.at("matches").size() > 16 || + !v.at("frames").is_array() || v.at("frames").size() < 2 || v.at("frames").size() > 2000 || + !count(v.at("duration"), 200) || !count(v.at("field_count"), 11) || + (v.at("role") != "club" && v.at("role") != "national") || + (v.at("surface") != "outdoor" && v.at("surface") != "indoor")) return false; + std::set match_ids, owner_ids; + for (const auto &match : v.at("matches")) { + if (!text(match.at("id")) || !match_ids.insert(match.at("id")).second || !team_ok(match.at("home")) || + !team_ok(match.at("away")) || !match.at("owners").is_array()) return false; + for (const auto &id : match.at("owners")) if (!id.is_string()) return false; + } + for (const auto &owner : v.at("owners")) { + if (!text(owner.at("id")) || !owner_ids.insert(owner.at("id")).second || !text(owner.at("name")) || + !count(owner.at("portrait"), 11) || !team_ok(owner.at("team")) || !match_ids.contains(owner.at("match_id")) || + !owner.at("view").is_object() || owner.at("view").at("engine") != true || !owner.at("view").at("rows").is_array() || + owner.at("view").at("rows").size() > 64) return false; + for (const auto &row : owner.at("view").at("rows")) + if (!text(row.at("id")) || !text(row.at("name")) || !row.contains("strength") || !row.contains("condition")) return false; + } + const int64_t duration = v.at("duration"); + int64_t minute = -1; size_t sequence = 0; + for (const auto &frame : v.at("frames")) { + if (frame.at("sequence") != sequence++ || !count(frame.at("minute"), uint64_t(duration)) || frame.at("minute").get() < minute || + !frame.at("events").is_array() || frame.at("events").size() > 8000 || !frame.at("matches").is_array() || + frame.at("matches").size() != match_ids.size()) return false; + minute = frame.at("minute"); + const auto phase = frame.value("phase", ""); + if (phase != "first_half" && phase != "interval" && phase != "second_half" && phase != "extra_time" && + phase != "shootout" && phase != "finished") return false; + if ((phase == "finished") != (sequence == v.at("frames").size())) return false; + std::set scored; + for (const auto &m : frame.at("matches")) { + if (!match_ids.contains(m.at("match_id")) || !scored.insert(m.at("match_id")).second) return false; + for (auto key : {"score", "chances", "yellow", "red", "players"}) + if (!m.at(key).is_array() || m.at(key).size() != 2 || !count(m.at(key)[0], 1000) || !count(m.at(key)[1], 1000)) return false; + if (!m.at("standings").is_array() || m.at("standings").size() > 128) return false; + for (const auto &row : m.at("standings")) { + if (!team_ok(row.at("team"))) return false; + for (auto key : {"position", "played", "gf", "ga", "points"}) if (!count(row.at(key))) return false; + } + } + for (const auto &event : frame.at("events")) + if (!text(event.at("id")) || !match_ids.contains(event.at("match_id")) || !count(event.at("minute"), 200) || + !text(event.at("headline")) || !text(event.at("body"), 2200) || !text(event.at("kind"), 40) || + (event.at("side") != "home" && event.at("side") != "away") || !event.at("score").is_array() || + event.at("score").size() != 2 || !count(event.at("score")[0], 1000) || !count(event.at("score")[1], 1000)) return false; + } + return true; + } catch (const std::exception &) { return false; } +} + +Json engine_live_fixture(const Json &recording, const Json &bundle) { + try { + if (!recording.is_object()) return failure("live_unavailable"); + if (!recording.value("ok", false)) return failure(recording.value("error", "live_unavailable")); + Json out = recording; + out["source"] = "engine-recording"; + const std::string role = out.value("role", "club") == "national" ? "national" : "club"; + out["role"] = role; + if (!out.contains("surface")) out["surface"] = "outdoor"; + + // The desk manager's squad in line-up order (the squad after the kickoff). + std::string desk_team; + Json rows = Json::array(); + try { + desk_team = bundle.at("desktop").at("meta").at("scope").at("teamId").get(); + const auto &players = bundle.at("squad").at("data").at("players"); + std::map by_id; + std::vector listed; + for (const auto &p : players) { + const std::string id = p.at("player").at("id"); + by_id[id] = &p; listed.push_back(id); + } + std::vector order; + try { + for (const auto &id : bundle.at("lineup").at("data").at("order")) if (id.is_string()) order.push_back(id); + } catch (const std::exception &) {} + std::set seen; + const auto add = [&](const std::string &id) { + const auto at = by_id.find(id); + if (at == by_id.end() || !seen.insert(id).second) return; + const auto &p = *at->second; + rows.push_back({{"id", id}, {"name", p.at("player").at("name")}, {"slot", rows.size()}, + {"strength", metric(p, "strength")}, {"condition", metric(p, "condition")}, + {"caps", nullptr}, {"international_goals", nullptr}}); + }; + for (const auto &id : order) add(id); + for (const auto &id : listed) add(id); + } catch (const std::exception &) { rows = Json::array(); } + + if (!out.at("owners").is_array() || out.at("owners").empty()) return failure("live_no_human_match"); + std::set portraits; + for (auto &owner : out.at("owners")) { + int portrait = owner.value("portrait", 0); + portrait = std::clamp(portrait, 0, 11); + for (int tries = 0; tries < 12 && portraits.contains(portrait); ++tries) portrait = (portrait + 1) % 12; + portraits.insert(portrait); + owner["portrait"] = portrait; + if (!owner.at("team").contains("role")) owner["team"]["role"] = role; + const bool own = owner.at("team").at("id") == desk_team; + owner["view"] = {{"ok", true}, {"engine", true}, {"rows", own ? rows : Json::array()}, + {"field_count", out.value("field_count", 11)}}; + } + for (auto &match : out.at("matches")) { + for (auto side : {"home", "away"}) if (!match.at(side).contains("role")) match[side]["role"] = role; + if (!match.contains("owners") || !match.at("owners").is_array()) match["owners"] = Json::array(); + } + + // Tables arrive on the frame when they change; the ticker wants each match's table. + std::map tables; // competition id -> ticker rows + const int64_t duration = out.value("duration", 90); + auto &frames = out.at("frames"); + for (size_t i = 0; i < frames.size(); ++i) { + auto &frame = frames[i]; + const std::string phase = frame.value("phase", ""); + const bool last = i + 1 == frames.size(); + frame["phase"] = last ? "finished" + : phase == "kickoff" ? "first_half" + : phase == "restart" ? "second_half" + : phase == "fulltime" || phase == "shootout_end" || phase == "finished" ? "second_half" + : phase; + if (frame.at("minute").is_number_integer()) frame["minute"] = std::clamp(frame.at("minute").get(), 0, duration); + if (frame.contains("standings") && frame.at("standings").is_array()) + for (const auto &table : frame.at("standings")) { + if (!table.is_object() || !table.contains("rows")) continue; + Json converted = Json::array(); + for (const auto &row : table.at("rows")) { + Json team = row.at("team"); + team["role"] = "club"; + converted.push_back({{"team", team}, {"position", row.at("rank")}, {"played", row.at("played")}, + {"gf", row.at("goalsFor")}, {"ga", row.at("goalsAgainst")}, {"points", row.at("points")}}); + } + tables[table.value("competitionId", std::string("table"))] = std::move(converted); + } + for (auto &score : frame.at("matches")) { + score["standings"] = Json::array(); + for (auto key : {"score", "chances", "yellow", "red", "players"}) + for (auto &value : score.at(key)) if (value.is_number_integer() && value.get() < 0) value = 0; + const Json *home = nullptr; + for (const auto &match : out.at("matches")) if (match.at("id") == score.at("match_id")) home = &match.at("home").at("id"); + if (!home || role == "national") continue; + for (const auto &[id, table] : tables) { + (void)id; + const bool has = std::any_of(table.begin(), table.end(), [&](const Json &row) { return row.at("team").at("id") == *home; }); + if (has) { score["standings"] = table; break; } + } + } + } + if (!valid_engine_live_fixture(out)) return failure("invalid_live_fixture"); + return out; + } catch (const std::exception &) { return failure("invalid_live_fixture"); } +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/engine_live.hpp b/src/modern/ui/engine_live.hpp new file mode 100644 index 0000000..8890dc9 --- /dev/null +++ b/src/modern/ui/engine_live.hpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/engine_bridge.hpp" + +namespace bmh::modern_ui { +// The command that plays the next kickoff (or moves to the next desk day). `payload` carries +// answers the engine asked for, such as contract decisions. +Json engine_advance_command(const Json &bundle, const std::string &request_id, const Json &payload); +// Shapes the engine's recording of the last kickoff for the live ticker. `bundle` is the +// desk snapshot read after the kickoff; it supplies the desk manager's squad. +// Returns {ok:false,error} when there is nothing to show. +Json engine_live_fixture(const Json &recording, const Json &bundle); +bool valid_engine_live_fixture(const Json &); +} // namespace bmh::modern_ui diff --git a/src/modern/ui/engine_screens.inc b/src/modern/ui/engine_screens.inc index e58ebb5..8ee873e 100644 --- a/src/modern/ui/engine_screens.inc +++ b/src/modern/ui/engine_screens.inc @@ -54,6 +54,8 @@ void App::engine_render() { if (engine_data_.empty()) { out = "

OpenBMH

" + esc(engine_busy_ ? "Spielstand wird geladen …" : engine_notice_) + "

"; + } else if (scene_ == "live" && live_.available()) { + out = render_live(); } else if(engine_opening_active()&&menu_.empty()) { out=main_menu()+"
"+render_opening()+"
"; } else { @@ -132,7 +134,7 @@ 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=="newplayer"&&engine_fresh_&&engine_manager_value_.is_object()) || (route=="settings"&&engine_fresh_&&engine_settings_value_.is_object()) || (route=="indoor"&&engine_fresh_&&engine_indoor_value_.is_object()) || ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&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=="balance"&&engine_fresh_&&engine_data_.at("balance").value("messageType","")=="snapshot") || (route=="news"&&engine_fresh_&&engine_news_value_.is_object()) || (route=="achievements"&&engine_fresh_&&engine_data_.at("achievements").value("messageType","")=="snapshot"&&engine_data_.at("achievements").at("data").at("available")==true) || (route=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end()); + const bool supported = (route=="newplayer"&&engine_fresh_&&engine_manager_value_.is_object()) || (route=="settings"&&engine_fresh_&&engine_settings_value_.is_object()) || (route=="indoor"&&engine_fresh_&&engine_indoor_value_.is_object()) || ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&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=="balance"&&engine_fresh_&&engine_data_.at("balance").value("messageType","")=="snapshot") || (route=="news"&&engine_fresh_&&engine_news_value_.is_object()) || (route=="achievements"&&engine_fresh_&&engine_data_.at("achievements").value("messageType","")=="snapshot"&&engine_data_.at("achievements").at("data").at("available")==true) || (route=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "kickoff" && engine_fresh_ && std::find(commands.begin(), commands.end(), Json("session.advance")) != commands.end()) || (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_ && (!engine_manager_value_.is_object() || engine_manager_value_.at("ended")!=true || route=="save" || route=="load" || route=="newplayer")); } } @@ -167,10 +169,11 @@ void App::engine_render() { if (menu_ == "camp") out += "
" + window("Trainingslager", render_camp()) + "
"; } if ((menu_ == "stadium" || menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="fairplay") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; - if (menu_.empty() || engine_data_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; + if ((menu_.empty() || engine_data_.empty()) && !(scene_ == "live" && live_.available())) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; if(menu_=="statistics")out+=render_statistics_trophy(); element("canvas")->SetProperty("overflow",statistics_trophy_.contains("asset")?"visible":"hidden"); element("canvas")->SetInnerRML(out); ++document_generation_; + live_detail_pending_ = live_ticker_pending_ = false; scale_chalk_shadow(); if (!engine_player_.empty()) { Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, "#lineup-underlay button,#window-close"); diff --git a/src/modern/ui/live_controls.inc b/src/modern/ui/live_controls.inc index d0860c4..c7d2f68 100644 --- a/src/modern/ui/live_controls.inc +++ b/src/modern/ui/live_controls.inc @@ -24,11 +24,37 @@ bool App::live_open() { focus_after_render_ = "live-next"; refresh(); return true; } +bool App::engine_live_open(const Json &recording) { + const auto fixture = engine_live_fixture(recording, engine_data_); + if (!fixture.value("ok", false) || !live_.open(fixture, "")) { + engine_notice_ = "Spieltag gespielt · Der Ticker kann diese Aufzeichnung nicht zeigen (" + + fixture.value("error", std::string("invalid_live_fixture")) + ")."; + return false; + } + try { live_.owner(engine_data_.at("desktop").at("meta").at("scope").at("managerId").get()); } + catch (const std::exception &) {} + live_source_ = nullptr; live_world_ = world_; + postmatch_data_=Json::object();postmatch_scrolls_=Json::object();postmatch_playing_=false; + live_drafts_ = Json::object(); live_dialog_.clear(); live_dialog_draft_ = Json(); + live_coverage_ = "all"; live_filter_ = "all"; live_tab_ = "team"; + live_selected_match_ = fixture.at("matches").front().at("id"); + for (const auto &owner : fixture.at("owners")) if (owner.at("id") == live_.owner()) live_selected_match_ = owner.at("match_id"); + live_ticker_scroll_ = live_detail_scroll_ = 0; + live_reset_ticker_ = live_reset_detail_ = true; + live_feedback_.clear(); live_resume_speed_ = 0; + live_review_ = false; live_speed_dragging_ = false; + if (scene_ != "live") live_return_scene_ = scene_; + scene_ = "live"; menu_.clear(); + live_.speed(2); live_last_tick_ = SDL_GetTicks64(); + focus_after_render_ = "live-pause"; + return true; +} void App::live_close() { live_review_=false;postmatch_playing_=false; live_.speed(0); live_dialog_.clear(); live_dialog_draft_ = Json(); live_resume_speed_ = 0; live_speed_dragging_ = false; - scene_ = "desktop"; menu_.clear(); focus_after_render_ = "object-app-kickoff"; refresh(); + if (engine_mode_) { scene_ = live_return_scene_; live_.close(); } else scene_ = "desktop"; + menu_.clear(); focus_after_render_ = "object-app-kickoff"; refresh(); } void App::live_set_speed(int value) { if (!live_.speed(value)) return; @@ -43,9 +69,10 @@ void App::live_set_speed(int value) { if (auto *node = element("live-speed-value")) node->SetInnerRML(esc(value ? std::to_string(value) + "×" : "Pause")); if (auto *node = element("live-pause")) node->SetInnerRML(live_text(value ? "Pause" : "Abspielen", "control-label")); const auto &frame = live_.fixture().at("frames")[live_.sequence()]; - const std::string phase = live_.finished() ? "Beendet" : frame.at("phase") == "interval" ? "Halbzeit" : value ? "Aufzeichnung läuft" : "Gemeinsam pausiert"; + const bool recorded = live_.fixture().at("source") == "engine-recording"; + const std::string phase = live_.finished() ? "Beendet" : frame.at("phase") == "interval" ? "Halbzeit" : value ? (recorded ? "Spiel läuft" : "Aufzeichnung läuft") : (recorded ? "Pausiert" : "Gemeinsam pausiert"); if (auto *node = element("live-phase-status")) node->SetInnerRML(esc(phase)); - if (auto *node = element("live-playback-status")) node->SetInnerRML(esc(phase + " · " + std::to_string(frame.at("minute").get()) + "′ · keine Spielwertänderung")); + if (auto *node = element("live-playback-status")) node->SetInnerRML(esc(phase + " · " + std::to_string(frame.at("minute").get()) + (recorded ? "′" : "′ · keine Spielwertänderung"))); dirty_ = true; } void App::live_tick() { @@ -53,9 +80,9 @@ void App::live_tick() { const auto now = SDL_GetTicks64(), elapsed = now - live_last_tick_; live_last_tick_ = now; if(live_review_){postmatch_tick(now);return;} if (!popup_.empty() || !live_dialog_.empty() || live_speed_dragging_ || live_review_) return; - const auto current = source_ ? source_->snapshot() : Snapshot(); - if (!source_ || source_.get() != live_source_ || current.world != live_world_ || - current.revision != live_.fixture().at("source_revision").get()) { + const auto current = source_ && !engine_mode_ ? source_->snapshot() : Snapshot(); + if (!engine_mode_ && (!source_ || source_.get() != live_source_ || current.world != live_world_ || + current.revision != live_.fixture().at("source_revision").get())) { live_.speed(0); if (live_feedback_ != "Die Quelle hat sich geändert. Diese Aufzeichnung bleibt pausiert; öffne Anstoß erneut.") { live_feedback_ = "Die Quelle hat sich geändert. Diese Aufzeichnung bleibt pausiert; öffne Anstoß erneut."; needs_render_ = true; } return; @@ -120,11 +147,12 @@ bool App::live_action(const std::string &action, Rml::Element *target) { } else if (action == "live-pause") { live_set_speed(live_.speed() ? 0 : 1); return true; } else if (action == "live-review" && live_.finished()) { - postmatch_open();return true; + if (live_.fixture().at("source") == "engine-recording") live_close(); else postmatch_open(); + return true; } else if (action == "live-review-back") { postmatch_action("postmatch-ticker",target);return true; } else if (action == "live-intervene-lineup" || action == "live-intervene-tactics") { - if (live_.finished()) return true; + if (live_.finished() || live_.fixture().at("source") == "engine-recording") return true; const auto owner = live_owner(); live_dialog_draft_ = live_owner_state(owner); live_dialog_ = action == "live-intervene-lineup" ? "lineup" : "tactics"; live_resume_speed_ = live_.speed(); live_.speed(0); live_last_tick_ = SDL_GetTicks64(); diff --git a/src/modern/ui/live_screens.inc b/src/modern/ui/live_screens.inc index 8a8bc2b..a4dffdb 100644 --- a/src/modern/ui/live_screens.inc +++ b/src/modern/ui/live_screens.inc @@ -21,10 +21,12 @@ Json App::live_owner() const { return Json(); } Json App::live_owner_state(const Json &owner) const { + if (owner.at("view").value("engine", false)) return Json::object(); const auto id = owner.at("id").get(); return live_drafts_.contains(id) ? live_drafts_.at(id) : owner.at("view").at("edit_state"); } Json App::live_owner_rows(const Json &owner) const { + if (owner.at("view").value("engine", false)) return owner.at("view").at("rows"); if (!live_world_) return Json::array(); const auto view = live_owner_state(owner); const auto projection = demo_lineup_rows(view, *live_world_, owner.at("view").at("club_basis")); @@ -58,9 +60,10 @@ std::string App::live_roster(const Json &owner) { live_text("Nr.", "live-roster-number") + live_text(owner.at("team").at("name"), "live-roster-name") + live_text(national ? "Caps" : "Stä.", "live-roster-stat") + live_text(national ? "Tore" : "Ko.", "live-roster-stat") + ""; const auto rows = live_owner_rows(owner); - if (national) out += "

" + live_text("Demokader auf Vereinsbasis · keine Nationalkaderberufung") + "

"; + const bool recorded = live_.fixture().at("source") == "engine-recording"; + if (national && !recorded) out += "

" + live_text("Demokader auf Vereinsbasis · keine Nationalkaderberufung") + "

"; for (size_t i = 0; i < rows.size(); ++i) { - if (int(i) == field_count) out += "

" + live_text(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : "Reserven · Demovorschau") + "

"; + if (int(i) == field_count) out += "

" + live_text(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : recorded ? "Ersatzbank und Reserve" : "Reserven · Demovorschau") + "

"; if (field_count == 6 && i == 11) out += "

" + live_text("Weitere Kaderreserven") + "

"; const auto &row = rows[i]; out += "
()) + "\">" + @@ -68,7 +71,7 @@ std::string App::live_roster(const Json &owner) { live_text(lineup_value(row.at(national ? "caps" : "strength")), "live-roster-stat") + live_text(lineup_value(row.at(national ? "international_goals" : "condition")), "live-roster-stat") + "
"; } - if (rows.empty()) out += "

" + live_text("Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "

"; + if (rows.empty()) out += "

" + live_text(recorded ? "Für diese Mannschaft liegt keine Kaderansicht vor." : "Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "

"; return out + ""; } std::string App::live_detail(const Json &owner, const Json &frame) { @@ -76,9 +79,11 @@ std::string App::live_detail(const Json &owner, const Json &frame) { const auto &match = live_match_by_id(fixture.at("matches"), owner.at("match_id")); const auto &score = live_score_by_id(frame, match.at("id")); if (live_tab_ == "team") return live_roster(owner); + const bool recorded = fixture.at("source") == "engine-recording"; if (live_tab_ == "table") { + if (recorded && score.at("standings").empty()) return "

" + live_text("Diese Partie gehört zu keiner Ligatabelle.") + "

"; if (fixture.at("role") == "national") return "

" + live_text("Dieses Demo-Länderspiel gehört zu keiner Liga. Der Spielstand steht links; eine Vereins-Live-Tabelle wird nicht eingeblendet.") + "

"; - std::string out = "

" + live_text("Vorgegebene Demo-Tabelle · keine echte Saisonwertung") + "

" + + std::string out = "

" + live_text(recorded ? "Tabelle zum Stand dieser Spielminute" : "Vorgegebene Demo-Tabelle · keine echte Saisonwertung") + "

" + live_text("Pl.", "live-table-pos") + "
" + live_text("Verein") + "
" + live_text("Sp.", "live-table-number") + live_text("Tore", "live-table-number live-table-goals") + live_text("Diff.", "live-table-number") + live_text("Pkt.", "live-table-number") + "
"; for (const auto &row : score.at("standings")) { @@ -94,6 +99,8 @@ std::string App::live_detail(const Json &owner, const Json &frame) { } return out + "
"; } + if (live_tab_ == "tactics" && recorded) + return "

" + live_text("Taktik") + "

" + live_text("Dieser Spieltag wurde mit der Aufstellung und Taktik vom Schreibtisch gespielt. Eingriffe während des Spiels folgen mit dem Live-Modus.") + "

"; if (live_tab_ == "tactics") { const auto state = live_owner_state(owner), board = demo_lineup_visible(state); Json points = Json::array(); const int count = fixture.at("field_count"); @@ -106,7 +113,7 @@ std::string App::live_detail(const Json &owner, const Json &frame) { std::string out; if (live_tab_ == "opponent") { const auto &opponent = match.at(owner.at("team").at("id") == match.at("home").at("id") ? "away" : "home"); - out = "

" + live_text(opponent.at("name")) + "

" + live_text("Gegner dieser vorgegebenen Demopartie. Es werden keine unbekannten Gegneranweisungen behauptet.") + "

"; + out = "

" + live_text(opponent.at("name")) + "

" + live_text(recorded ? "Gegner dieser Partie." : "Gegner dieser vorgegebenen Demopartie. Es werden keine unbekannten Gegneranweisungen behauptet.") + "

"; } const std::array, 5> fields{{{"Tore", "score"}, {"Chancen", "chances"}, {"Gelbe Karten", "yellow"}, {"Rote Karten", "red"}, {"Spieler auf dem Feld", "players"}}}; for (const auto &[label, key] : fields) { @@ -115,7 +122,7 @@ std::string App::live_detail(const Json &owner, const Json &frame) { out += "
" + live_text(std::to_string(a)) + live_text(label, "stat-title") + live_text(std::to_string(b)) + "
"; } - return out + "

" + live_text(match.at("home").at("name").get() + " · " + match.at("away").at("name").get() + " · vorgegebene Demowerte") + "

"; + return out + "

" + live_text(match.at("home").at("name").get() + " · " + match.at("away").at("name").get() + (recorded ? "" : " · vorgegebene Demowerte")) + "

"; } std::string App::live_dialog_markup(const Json &owner) { if (live_dialog_.empty()) return ""; @@ -151,7 +158,7 @@ std::string App::live_ticker_events(const Json &frame, size_t &shown) { "
" + live_text(match.at("home").at("name").get() + " · " + match.at("away").at("name").get(), "live-event-owners") + "

" + live_text(event.at("headline")) + "

" + live_text(event.at("body")) + "

" + live_text(live_score_text(event.at("score")), "live-event-score") + ""; ++shown; } - if (!shown) out += "

" + live_text("Für diesen Filter liegt noch keine Demomeldung vor.") + "

"; + if (!shown) out += "

" + live_text(fixture.at("source") == "engine-recording" ? "Für diesen Filter liegt noch keine Meldung vor." : "Für diesen Filter liegt noch keine Demomeldung vor.") + "

"; return out; } std::string App::render_live() { @@ -163,10 +170,11 @@ std::string App::render_live() { live_restore_scroll_ = true; const auto &fixture = live_.fixture(); const auto frame = live_.frame(); const auto owner = live_owner(); const int minute = frame.at("minute"); const auto phase = frame.at("phase").get(); - const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? "Aufzeichnung läuft" : "Gemeinsam pausiert"; + const bool recorded = fixture.at("source") == "engine-recording"; + const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? (recorded ? (phase == "extra_time" ? "Verlängerung" : phase == "shootout" ? "Elfmeterschießen" : "Spiel läuft") : "Aufzeichnung läuft") : (recorded ? "Pausiert" : "Gemeinsam pausiert"); const auto arrow = [&](bool right) { const auto color = theme_ == "silver" ? "#376b84" : theme_ == "matchday" ? "#efb2aa" : "#b5dbd2"; return picture(renderer_.diagram(right ? "live-arrow-right" : "live-arrow-left", "", 72), 36, 36); }; - std::string out = "
()) + "\">
" + live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow") + - "

" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : "Gemeinsamer Spieltag") + "

" + live_text("UI-Demo · vorgegebene Ergebnisse", "live-demo-tag") + "
"; + std::string out = "
()) + "\">
" + live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow") + + "

" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : recorded ? fixture.at("matches").front().value("competition", std::string("Spieltag")) : std::string("Gemeinsamer Spieltag")) + "

" + live_text(recorded ? fixture.value("date", std::string()) : std::string("UI-Demo · vorgegebene Ergebnisse"), "live-demo-tag") + "
"; const auto scoreline = [&](const Json &match) { const auto &value = live_score_by_id(frame, match.at("id")); return "
" + live_text(match.at("home").at("name"), "live-team-name home") + live_badge(match.at("home"), 58) + live_text(live_score_text(value.at("score")), "live-score") + live_badge(match.at("away"), 58) + live_text(match.at("away").at("name"), "live-team-name away") + "
"; @@ -180,20 +188,20 @@ std::string App::render_live() { if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue; std::string names; for (const auto &id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == id) { if (!names.empty()) names += " · "; names += person.at("name").get(); } - out += ""; + out += ""; } out += "

" + live_text("Gemeinsamer Live-Ticker") + "

" + live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small") + "
"; size_t shown = 0; out += live_ticker_events(frame, shown); - out += "
" "" + esc(std::to_string(shown) + " Meldungen · feste Aufzeichnung") + "" + "" + esc(phase_text) + "
"; out += "
" + live_text("+") + "" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "
"; - out += "
" + btn("live-back", "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "
" + esc(live_feedback_.empty() ? std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung" : live_feedback_) + "" + - btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "
"; + out += "
" + btn("live-back", recorded ? "Zum Schreibtisch" : "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "
" + esc(live_feedback_.empty() ? std::string(phase_text) + " · " + std::to_string(minute) + (recorded ? "′" : "′ · keine Spielwertänderung") : live_feedback_) + "" + + btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? (recorded ? "Zum Schreibtisch" : "Zur Auswertung") : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "
"; return out + live_dialog_markup(owner) + ""; } void App::live_after_render() { @@ -239,7 +247,7 @@ void App::live_update_parts() { auto *list = element("live-ticker"); auto *count = element("live-event-count"); if (!list || !count) { refresh(); return; } size_t shown = 0; list->SetInnerRML(live_ticker_events(frame, shown)); - count->SetInnerRML(esc(std::to_string(shown) + " Meldungen · feste Aufzeichnung")); + count->SetInnerRML(esc(std::to_string(shown) + (live_.fixture().at("source") == "engine-recording" ? " Meldungen" : " Meldungen · feste Aufzeichnung"))); list->SetScrollTop(0); live_ticker_scroll_ = 0; live_reset_ticker_ = false; Rml::ElementList filters; doc_->QuerySelectorAll(filters, ".live-filters button"); for (auto *filter : filters) diff --git a/src/modern/ui/live_state.inc b/src/modern/ui/live_state.inc index e03962b..f03e2fd 100644 --- a/src/modern/ui/live_state.inc +++ b/src/modern/ui/live_state.inc @@ -24,6 +24,13 @@ Json live_owner_rows(const Json &) const; Json live_owner_state(const Json &) const; bool live_open(); + // Engine career: shows the recording of the kickoff that was just played. + bool engine_live_open(const Json &recording); + std::string live_return_scene_; + Json engine_advance_payload_ = Json::object(); + std::string engine_expiry_player_; + void engine_kickoff(); + void engine_expiry_ask(const Json &args); void live_close(); bool live_action(const std::string &, Rml::Element *); bool live_event(Rml::Event &); diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 3275580..7077aaf 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -7,6 +7,7 @@ #include "modern/ui/controls.hpp" #include "modern/ui/crest_contrast.hpp" #include "modern/ui/engine_bridge.hpp" +#include "modern/ui/engine_live.hpp" #include "modern/ui/news_catalog.hpp" #include "modern/ui/career_files.hpp" #include "modern/ui/live_match_info.hpp" diff --git a/tests/modern_live_dump.cpp b/tests/modern_live_dump.cpp new file mode 100644 index 0000000..a815358 --- /dev/null +++ b/tests/modern_live_dump.cpp @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Developer probe: advances a Modern career through the UI command path and writes the +// engine's kickoff recording, post-match read and line-up read as JSON files. +// usage: modern_live_dump [kickoffs] +#include "modern/ui/engine_bridge.hpp" + +#include +#include +#include + +using bmh::modern_ui::EngineBridge; +using bmh::modern_ui::Json; +namespace fs = std::filesystem; + +int main(int argc, char **argv) { + if (argc < 4) { std::cerr << "usage: modern_live_dump [kickoffs]\n"; return 2; } + try { + const fs::path out = argv[3]; + fs::create_directories(out); + const int wanted = argc > 4 ? std::atoi(argv[4]) : 1; + auto link = EngineBridge::open(argv[1], argv[2]); + const auto write = [&](const std::string &name, const Json &value) { + std::ofstream(out / name, std::ios::binary) << value.dump(1); + }; + int found = 0; + Json expiry = Json::object(); + for (int step = 0; step < 400 && found < wanted; ++step) { + const auto bundle = link->snapshot(); + const auto &meta = bundle.at("desktop").at("meta"); + if (step == 0) write("bundle.json", bundle); + const Json command = {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")}, + {"requestId", "request:dump-" + std::to_string(step)}, {"careerId", meta.at("careerId")}, + {"expectedRevision", meta.at("stateRevision")}, + {"owner", {{"managerId", meta.at("scope").at("managerId")}}}, + {"kind", "session.advance"}, {"payload", {{"contractExpiry", expiry}}}}; + const auto reply = link->command(command); + write("advance-" + std::to_string(step) + ".json", reply); + if (reply.value("messageType", "") != "command_result") { + if (reply.value("code", "") == "decision_pending") { + expiry[reply.at("message").at("args").at("playerId").get()] = {{"action", "release"}}; + continue; + } + std::cerr << "advance refused: " << reply.dump() << "\n"; + return 1; + } + const auto fixture = link->read_live({{"kind", "fixture"}}); + std::cout << "step " << step << ": " << (fixture.value("ok", false) ? "fixture" : fixture.value("error", "?")) << "\n"; + if (!fixture.value("ok", false)) continue; + const std::string tag = std::to_string(found++); + write("fixture-" + tag + ".json", fixture); + write("postmatch-" + tag + ".json", link->read({{"kind", "postmatch"}})); + write("lineup-" + tag + ".json", link->read({{"kind", "lineup"}})); + write("tactics-" + tag + ".json", link->read({{"kind", "tactics"}})); + } + std::cout << found << " recordings written\n"; + return found ? 0 : 1; + } catch (const std::exception &e) { std::cerr << e.what() << "\n"; return 1; } +}