From a5810b15aebaf5a20fb0048f15f524c3ccdee371 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sat, 14 Nov 2026 00:49:51 +0100 Subject: [PATCH] Play the Modern kickoff live: minute steps, substitutions and tactics from the ticker A rehearsal (session.advance with dryRun) settles questions of the run before the kickoff; an extension answered there is agreed at the player's demand of that moment. With an own match the kickoff runs live: one live.step per beat of the speed control, substitutions and the tactics board through live.substitute and live.tactics, and leaving the ticker plays the match to its end. After the final whistle the engine's recording replaces the frames composed on the way. The paused live read names clubs in the world's spelling, and the review table shows wins, draws and losses. Co-Authored-By: Claude Fable 5.2 --- docs/new_engine/ui-anbindung.md | 1 + .../integration/NATIVE_ENGINE_COVERAGE.md | 5 +- src/modern/app/modern_session.cpp | 21 +- src/modern/ui/controls.inc | 2 +- src/modern/ui/demo_live.cpp | 13 +- src/modern/ui/demo_live.hpp | 4 + src/modern/ui/engine_controls.inc | 37 +++- src/modern/ui/engine_live.cpp | 164 ++++++++++++++- src/modern/ui/engine_live.hpp | 8 + src/modern/ui/engine_screens.inc | 2 + src/modern/ui/live_controls.inc | 188 +++++++++++++++++- src/modern/ui/live_screens.inc | 24 ++- src/modern/ui/live_state.inc | 12 ++ src/modern/ui/postmatch_screens.inc | 6 +- 14 files changed, 456 insertions(+), 31 deletions(-) diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index 1d9c216..4762309 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -96,6 +96,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `quote.request` (Stadion) | `kind: periphery`, `objectId`; oder `kind: facility`, `facilityId`, `increment` 1–3; oder `kind: block`, `blockId` (`block:a`–`block:h`), `places` (Ziel insgesamt), optional `seats`, `roof` | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen bzw. stellt den Tribünenausbau zusammen (Plätze, Sitzplätze, Dach; vorhandene Ausstattung bleibt; Angebot mit Aufschlüsselung Plätze/Sitze/Dach); `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) | | `stadium.commit` | `quoteId`, `accept`, bei Anlagen und Blöcken `tip` | baut (Anlagen und Blöcke mit oder ohne Trinkgeld für schnelleres Bauen, wie das Original fragt) oder lehnt ab und schließt den Dialog; Fehler `stale_quote`, `stadium_refused` | | `session.advance` mit `live: true` | wie oben, dazu `contractExpiry` | Live-Spieltag: hält in der ersten Minute eines Live-Spiels an (`changedReadKinds: ["live"]`); läuft kein Live-Spiel, endet er sofort wie ein normaler Anstoß | +| `session.advance` mit `dryRun: true` | wie `session.advance` | Probelauf: der Anstoß wird gespielt und vollständig zurückgenommen (`outcome: rehearsed`, Revision unverändert). Eine offene Rückfrage kommt wie sonst als `decision_pending`; bei auslaufendem Vertrag nennt `message.args.demands` die Forderungen für ein bis vier Jahre. Eine Verlängerung (`renew`) gilt mindestens zur Forderung im Augenblick des Ablaufs | | `live.step` | `minutes` (1–150, sonst 1) | spielt so viele Spielminuten des Live-Spiels und hält wieder an; ist der Spieltag vorbei, kommt die Antwort des Anstoßes | | `live.substitute` | `outPlayerId`, `inPlayerId` | Wechsel wie im Spielfeld-Bildschirm des Originals (öffnen, tauschen, schließen; ab Minute 3); Fehler `substitution_refused` | | `live.tactics` | `values` (8) | Taktik wie im Taktik-Bildschirm während des Spiels; Fehler `invalid_tactic` | diff --git a/docs/new_ui/integration/NATIVE_ENGINE_COVERAGE.md b/docs/new_ui/integration/NATIVE_ENGINE_COVERAGE.md index 4723de0..d9ae1d9 100644 --- a/docs/new_ui/integration/NATIVE_ENGINE_COVERAGE.md +++ b/docs/new_ui/integration/NATIVE_ENGINE_COVERAGE.md @@ -5,8 +5,8 @@ Dies ist eine Routenübersicht des nativen Engine-Einstiegs auf `0.3`, keine Fertigstellungsquote des gesamten Spiels. HTML-/Demo-Presenter sind getrennt von echten Karrierewerten. Stand einschließlich Transfermarkt, Erfolgsverlauf, Nachrichtenpostfach, Bilanz, Hallenansichten, Einstellungen/Automatik und Managerverwaltung. -Von 32 Desktoprouten sind 30 an Sessiondaten bzw. tatsächliche Aktionen -angebunden. Anstoß bleibt auf ausdrücklichen Wunsch gesperrt. Eine weitere +Von 32 Desktoprouten sind 31 an Sessiondaten bzw. tatsächliche Aktionen +angebunden, seit dem 14.11.2026 einschließlich Anstoß. Eine weitere Route besitzt ihre Präsentation, ist im echten Einstieg aber noch nicht freigeschaltet. Rollen-, Termin- und Angebotssperren können auch eine angebundene Route vorübergehend deaktivieren; insbesondere hat der Nationaltrainer weniger @@ -34,6 +34,7 @@ Vereinsmenüs. | Stadion | Acht Blöcke, acht Ausstattungen, Außenansicht, tatsächliche Angebote/Bauzustände und Statistik | Standardbau; optionaler Beschleunigungsdialog noch offen; Parkplatz aktuell binär | | Manager | Tatsächlicher Hub, aktuelle Vereinszuordnung, bestätigter atomarer Beitritt, Ein-Mensch-Aufgeben und Archividentität | Vier Menschen; Nationalbeitritt, Mehrspieler-KI-Übergabe und Vereinssuche gesperrt; [Details](../desktop/manager/ENGINE.md) | | Speichern und Laden | Echte OBS-Dateibibliothek, Metadaten, Ersetzen/Umbenennen/Löschen und Import/Export | Gleiche Welt-ID und Datenrevision; Demo-JSON bleibt separat | +| Anstoß, Live-Ticker, Nach dem Spiel (14.11.2026) | Ein Probelauf (`session.advance` mit `dryRun`) klärt Rückfragen vor dem Anstoß. Mit eigenem Spiel läuft der Spieltag live: `session.advance` mit `live`, danach je Takt ein `live.step`; „Aufstellung & Wechsel“ sendet `live.substitute`. Nach dem Abpfiff ersetzt die Aufzeichnung der Engine die unterwegs zusammengesetzten Meldungen; Ergebnisse, Spielbericht, Übersicht und Tabelle stammen aus derselben Aufzeichnung. Ohne eigenes Spiel geht es direkt zum nächsten Termin | Taktikänderungen während des Spiels (`live.tactics`) noch nicht angebunden; Elf des Tages nicht verfügbar; ein auslaufender Vertrag wird mit Forderung abgefragt (verlängern zur Forderung oder freigeben); keine Auslosungsansicht beim Saisonwechsel einer laufenden Karriere; Verlassen des Tickers spielt das Spiel zu Ende | Die konkreten verbleibenden Besitzer-/Transportlücken und vorhandenen Dispatcher beschreibt [Nächste Sessionanbindungen](NEXT_ENGINE_BINDINGS.md). diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 546dcb2..a269f04 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -8678,6 +8678,11 @@ cli::Json ModernSession::read_live(const cli::Json& request) const { // a live kickoff standing still: the minute and the live matches' scores so far (the // full recording with every event follows after the final whistle, kind "fixture") if (!live_->paused || !live_->groups) return fail("live_running"); + // the world's own spelling of a club name where the data set has one + const auto club_label = [this](int team) { + if (team >= 0 && size_t(team) < g_.world_club_name.size() && !g_.world_club_name[size_t(team)].empty()) return g_.world_club_name[size_t(team)]; + return ui::original_to_utf8(g_.club_name(team)); + }; cli::Json::Array matches; for (const MatchGroup& grp : *live_->groups) for (int m = 0; m < grp.matches(); ++m) { @@ -8711,8 +8716,8 @@ cli::Json ModernSession::read_live(const cli::Json& request) const { {"player", person(player)}, {"other", person(assistant)}}); } matches.push_back(O{{"events", std::move(events)}, - {"home", O{{"id", modern::ui_team_id(g_, home)}, {"name", ui::original_to_utf8(g_.club_name(home))}}}, - {"away", O{{"id", modern::ui_team_id(g_, away)}, {"name", ui::original_to_utf8(g_.club_name(away))}}}, + {"home", O{{"id", modern::ui_team_id(g_, home)}, {"name", club_label(home)}}}, + {"away", O{{"id", modern::ui_team_id(g_, away)}, {"name", club_label(away)}}}, {"homeManagerId", hm >= 0 ? cli::Json(modern::ui_manager_id(g_, hm)) : cli::Json(nullptr)}, {"awayManagerId", am >= 0 ? cli::Json(modern::ui_manager_id(g_, am)) : cli::Json(nullptr)}, // the crowd and the weather the kickoff set (descriptor +0x30 temperature, @@ -9835,7 +9840,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision const auto demands = modern::contract_demands(state, m, row, false, random); const uint32_t demand = demands[size_t(it->second.term)]; if (demand == 0 || demand == UINT32_MAX) return 0; - return modern::contract_offer(state, m, row, it->second.term, it->second.salary, demand, false, true, random, nullptr) ? 1 : 0; + return modern::contract_offer(state, m, row, it->second.term, std::max(it->second.salary, demand), demand, false, true, random, nullptr) ? 1 : 0; } catch (const std::exception&) { return -2; } }); turn_driver_.sportschau.awards = [r, inner = run->previous_sportschau.awards](const GameState& state, const SportschauAwardsView& v) { @@ -9942,7 +9947,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision const auto demands = modern::contract_demands(state, m, row, false, random); const uint32_t demand = demands[size_t(it->second.term)]; if (demand == 0 || demand == UINT32_MAX) return 0; - return modern::contract_offer(state, m, row, it->second.term, it->second.salary, demand, false, true, random, nullptr) ? 1 : 0; + return modern::contract_offer(state, m, row, it->second.term, std::max(it->second.salary, demand), demand, false, true, random, nullptr) ? 1 : 0; } catch (const std::exception&) { return -2; } @@ -9987,6 +9992,14 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision return refuse(r.kind == TurnDeskKind::WaitingAtDesk ? "decision_pending" : "advance_failed", "Weiter nicht möglich: " + reason); } + if (const cli::Json* dry = ui_field(*payload, "dryRun"); dry && std::holds_alternative(dry->value) && std::get(dry->value)) { + // a rehearsal: everything goes back, the interface only learns that no question is open + restore(); + g_.contract_screen = previous_hook; + cli::Json rehearsal = modern::ui_command_result(request_id, previous, previous, {}, "Probelauf ohne offene Rückfrage."); + std::get(rehearsal.value)["outcome"] = "rehearsed"; + return rehearsal; + } modern::journal_advance(g_, saved_state); modern::ensure_ui_identities(g_); revision = previous + 1; diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 2c32141..ddbc983 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -901,7 +901,7 @@ void App::script() { const auto type = command.value("type", std::string()); if (type == "engine-wait") { const auto until = SDL_GetTicks64() + command.value("timeout_ms", uint64_t(300000)); - while ((engine_busy_ || engine_creation_busy_ || engine_files_busy_) && SDL_GetTicks64() < until) { pump_events(); frame(); SDL_Delay(10); } + while ((engine_busy_ || engine_creation_busy_ || engine_files_busy_ || engine_live_busy_) && SDL_GetTicks64() < until) { pump_events(); live_tick(); frame(); SDL_Delay(10); } if (engine_busy_ || engine_creation_busy_ || engine_files_busy_) throw editor::Error("Engine-Vorgang hat das QA-Zeitlimit überschritten."); } else if(type=="window-resize-probe"){ // QA-only synthetic event: no OS window or mouse coordinate is changed. diff --git a/src/modern/ui/demo_live.cpp b/src/modern/ui/demo_live.cpp index af8b649..7d76bf3 100644 --- a/src/modern/ui/demo_live.cpp +++ b/src/modern/ui/demo_live.cpp @@ -355,9 +355,18 @@ bool LivePlayback::open(const Json &fixture, const std::string &owner_id) { *this = std::move(next); return true; } void LivePlayback::close() { fixture_ = nullptr; sequence_ = 0; speed_ = 0; elapsed_ = 0; owner_.clear(); } -bool LivePlayback::finished() const { return available() && sequence_ + 1 == fixture_.at("frames").size(); } +bool LivePlayback::finished() const { return available() && !running() && sequence_ + 1 == fixture_.at("frames").size(); } +bool LivePlayback::running() const { return available() && fixture_.value("live_running", false); } +bool LivePlayback::follow(const Json &fixture) { + if (!valid_live_fixture(fixture)) return false; + const auto keep = owner_; + fixture_ = fixture; sequence_ = fixture_.at("frames").size() - 1; elapsed_ = 0; + if (!owner(keep)) owner_ = fixture_.at("owners").front().at("id"); + if (finished()) speed_ = 0; + return true; +} bool LivePlayback::next() { - if (!available() || finished()) return false; + if (!available() || finished() || sequence_ + 1 >= fixture_.at("frames").size()) return false; ++sequence_; elapsed_ = 0; if (finished()) speed_ = 0; return true; } bool LivePlayback::speed(int value) { diff --git a/src/modern/ui/demo_live.hpp b/src/modern/ui/demo_live.hpp index 6882c3e..9ae4c96 100644 --- a/src/modern/ui/demo_live.hpp +++ b/src/modern/ui/demo_live.hpp @@ -34,6 +34,10 @@ public: const std::string &owner() const { return owner_; } bool available() const { return fixture_.is_object(); } bool finished() const; + // A kickoff of the engine that is still being played minute by minute. + bool running() const; + // Replaces the fixture by its continuation and shows its newest frame. + bool follow(const Json &fixture); private: Json fixture_; diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 92887a2..1a6359e 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -10,12 +10,32 @@ void App::engine_start(std::string label, std::function job, bool // 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_); + // A rehearsal first: a question of the run (a contract running out) is asked before the + // kickoff, never after a match the manager has watched and steered. + Json rehearsal = engine_advance_payload_, live = engine_advance_payload_; + rehearsal["dryRun"] = true; live["live"] = true; + const auto probe = engine_advance_command(engine_data_, editor::new_id("request:ui-"), rehearsal); + const auto command = engine_advance_command(engine_data_, editor::new_id("request:ui-"), live); 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; + const Json desk = engine_data_; + engine_start("Anstoß …", [link, probe, command, desk] { + auto response = link->command(probe); + if (response.value("messageType", "") != "command_result") { + response["advanceRefused"] = true; + return EngineReply{link, link->snapshot(), response, nullptr}; + } + response = link->command(command); + if (response.value("messageType", "") != "command_result") { + response["advanceRefused"] = true; + return EngineReply{link, link->snapshot(), response, nullptr}; + } + const auto state = link->read_live({{"kind", "fixture"}}); + if (state.value("ok", false) && state.value("live", false)) { + // the kickoff stands after its first minute; the desk snapshot stays the one before it + response["liveState"] = state; + return EngineReply{link, desk, response, nullptr}; + } + response["liveRecording"] = state; return EngineReply{link, link->snapshot(), response, nullptr}; }, true); } @@ -67,6 +87,7 @@ void App::engine_accept(EngineReply result) { engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert."; if(engine_exit_after_save_){engine_exit_after_save_=false;closed_=true;} } else if(engine_response_.value("messageType","")=="created"){engine_dirty_=true;engine_notice_="Neue Partie · Noch nicht gespeichert.";} + else if(engine_response_.value("messageType","")=="live_finished"){engine_dirty_=true;engine_notice_="Abpfiff · Änderungen noch nicht gespeichert.";} 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(); @@ -96,6 +117,12 @@ void App::engine_accept(EngineReply result) { if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "contract_expiry") engine_expiry_ask(args); } + if (engine_response_.contains("liveState")) { + const Json state = engine_response_.at("liveState"); + engine_response_.erase("liveState"); + engine_advance_payload_ = Json::object(); + engine_live_begin(state, engine_response_.value("newRevision", std::string())); + } if (engine_response_.contains("liveRecording")) { const Json recording = engine_response_.at("liveRecording"); engine_response_.erase("liveRecording"); diff --git a/src/modern/ui/engine_live.cpp b/src/modern/ui/engine_live.cpp index 42efb2a..61d1bd6 100644 --- a/src/modern/ui/engine_live.cpp +++ b/src/modern/ui/engine_live.cpp @@ -69,7 +69,8 @@ bool valid_engine_live_fixture(const Json &v) { 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; + // a kickoff still under way has no final frame yet + if (v.value("live_running", false) ? phase == "finished" : (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; @@ -172,7 +173,8 @@ Json engine_live_fixture(const Json &recording, const Json &bundle) { 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")}}); + {"gf", row.at("goalsFor")}, {"ga", row.at("goalsAgainst")}, {"points", row.at("points")}, + {"won", row.value("won", Json())}, {"drawn", row.value("drawn", Json())}, {"lost", row.value("lost", Json())}}); } tables[table.value("competitionId", std::string("table"))] = std::move(converted); } @@ -194,4 +196,162 @@ Json engine_live_fixture(const Json &recording, const Json &bundle) { return out; } catch (const std::exception &) { return failure("invalid_live_fixture"); } } + +Json engine_live_command(const Json &bundle, const std::string &revision, const std::string &request_id, + const std::string &kind, const Json &payload) { + const auto &meta = bundle.at("desktop").at("meta"); + return {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")}, {"requestId", request_id}, + {"careerId", meta.at("careerId")}, {"expectedRevision", revision}, + {"owner", {{"managerId", meta.at("scope").at("managerId")}}}, + {"kind", kind}, {"payload", payload.is_object() ? payload : Json::object()}}; +} + +Json engine_live_roster(const Json &bundle) { + Json rows = Json::array(); + try { + const auto &players = bundle.at("squad").at("data").at("players"); + std::map by_id; + std::vector listed, order; + for (const auto &p : players) { + const std::string id = p.at("player").at("id"); + by_id[id] = &p; listed.push_back(id); + } + 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(); } + return rows; +} + +// The standing kickoff as the ticker's fixture: the frames so far plus one for this minute. +// Event texts are composed here from the engine's facts (kind, player, minute); the full +// recording with the engine's own wording replaces this fixture after the final whistle. +Json engine_live_progress(const Json &previous, const Json &state, const Json &bundle, const Json &roster) { + try { + if (!state.is_object() || !state.value("ok", false) || !state.value("live", false)) return failure("live_unavailable"); + const auto &meta = bundle.at("desktop").at("meta"); + const std::string desk_team = meta.at("scope").at("teamId"), desk_manager = meta.at("scope").at("managerId"); + const std::string role = desk_team.starts_with("nt:") || meta.at("scope").value("role", "club") == "national" ? "national" : "club"; + const int64_t minute = std::clamp(state.at("minute").get(), 0, 120); + Json out = previous.is_object() && previous.value("live_running", false) ? previous : Json(); + if (!out.is_object()) { + out = {{"ok", true}, {"schema", "openbmh-live-fixture@1"}, {"source", "engine-recording"}, {"live_running", true}, + {"fixture_id", "live:running:" + meta.at("date").get()}, {"source_revision", 0}, + {"date", meta.at("date")}, {"world", meta.value("worldId", std::string())}, {"role", role}, {"surface", "outdoor"}, + {"duration", 90}, {"field_count", 11}, {"owners", Json::array()}, {"matches", Json::array()}, + {"frames", Json::array()}, {"notice", "Der Spieltag läuft"}}; + std::set portraits; + for (const auto &m : state.at("matches")) { + const std::string id = "live:" + m.at("home").at("id").get(); + Json owners = Json::array(); + for (auto side : {"home", "away"}) { + const auto &manager = m.at(std::string(side) + "ManagerId"); + if (!manager.is_string() || out.at("owners").size() >= 4) continue; + const bool own = manager == desk_manager; + int portrait = int(out.at("owners").size()); + Json team = m.at(side); team["role"] = role; + std::string name = own ? bundle.at("desktop").at("data").at("manager").value("name", std::string("Manager")) : std::string("Manager"); + out["owners"].push_back({{"id", manager}, {"portrait", portrait}, {"name", name}, {"team", team}, {"match_id", id}, + {"view", {{"ok", true}, {"engine", true}, {"rows", own ? roster : Json::array()}, {"field_count", 11}}}}); + owners.push_back(manager); + } + Json home = m.at("home"), away = m.at("away"); + home["role"] = role; away["role"] = role; + out["matches"].push_back({{"id", id}, {"home", home}, {"away", away}, {"owners", owners}, {"competition", "Spieltag"}, + {"attendance", m.value("attendance", Json())}, {"weather", m.value("weather", Json())}}); + } + if (out.at("owners").empty() || out.at("matches").empty()) return failure("live_no_human_match"); + } + // the desk manager's roster follows substitutions made during the match + for (auto &owner : out.at("owners")) if (owner.at("id") == desk_manager) owner["view"]["rows"] = roster; + if (minute > 90) out["duration"] = 120; + + Json events = Json::array(), scores = Json::array(); + const size_t sequence = out.at("frames").size() + (out.at("frames").empty() ? 1 : 0); + // earlier events keep the frame they first appeared in + std::map known; + if (!out.at("frames").empty()) + for (const auto &e : out.at("frames").back().at("events")) known[e.at("id")] = e; + for (const auto &m : state.at("matches")) { + const std::string id = "live:" + m.at("home").at("id").get(); + int goals[2] = {0, 0}, chances[2] = {0, 0}, yellow[2] = {0, 0}, red[2] = {0, 0}; + size_t index = 0; + for (const auto &e : m.at("events")) { + const std::string kind = e.value("kind", std::string()); + const size_t side = e.value("side", std::string("home")) == "away" ? 1 : 0; + const std::string team = m.at(side ? "away" : "home").at("name"); + const std::string player = e.at("player").is_object() ? e.at("player").value("name", std::string()) : std::string(); + const std::string other = e.contains("other") && e.at("other").is_object() ? e.at("other").value("name", std::string()) : std::string(); + std::string headline, body, shown = kind; + if (kind == "goal") { + ++goals[side]; ++chances[side]; + headline = "Tor für " + team; + body = (player.empty() ? std::string("Treffer") : player + " trifft") + " zum " + std::to_string(goals[0]) + ":" + std::to_string(goals[1]) + "." + + (other.empty() ? "" : " Vorlage: " + other + "."); + } else if (kind == "miss") { + ++chances[side]; shown = "chance"; + headline = "Chance für " + team; body = player.empty() ? "Die Chance bleibt ungenutzt." : player + " vergibt."; + } else if (kind == "yellow") { + ++yellow[side]; headline = "Gelbe Karte"; body = (player.empty() ? "Ein Spieler" : player) + " (" + team + ") sieht Gelb."; + } else if (kind == "second_yellow" || kind == "red") { + ++red[side]; shown = "red"; + headline = kind == "red" ? "Rote Karte" : "Gelb-Rot"; body = (player.empty() ? "Ein Spieler" : player) + " (" + team + ") muss vom Platz."; + } else if (kind == "injury") { + headline = "Verletzung"; body = (player.empty() ? "Ein Spieler" : player) + " (" + team + ") muss behandelt werden."; + } else continue; + const std::string event_id = id + ":event:" + std::to_string(index++); + const auto at = known.find(event_id); + events.push_back(at != known.end() ? at->second + : Json{{"id", event_id}, {"sequence", sequence}, {"match_id", id}, + {"minute", std::clamp(e.value("minute", int64_t(minute)), 0, minute)}, {"kind", shown}, + {"headline", headline}, {"body", body}, {"score", {goals[0], goals[1]}}, + {"side", side ? "away" : "home"}, {"player", e.at("player")}, {"other", e.value("other", Json())}}); + } + Json score = m.value("score", Json::array({goals[0], goals[1]})); + Json standings = Json::array(); + if (role == "club" && state.contains("standings")) + for (const auto &table : state.at("standings")) { + if (!table.is_object() || !table.contains("rows")) continue; + Json rows = Json::array(); bool has = false; + for (const auto &row : table.at("rows")) { + Json team = row.at("team"); team["role"] = "club"; + has = has || team.at("id") == m.at("home").at("id"); + rows.push_back({{"team", team}, {"position", row.at("rank")}, {"played", row.at("played")}, {"gf", row.at("goalsFor")}, + {"ga", row.at("goalsAgainst")}, {"points", row.at("points")}, {"won", row.value("won", Json())}, + {"drawn", row.value("drawn", Json())}, {"lost", row.value("lost", Json())}}); + } + if (has) { standings = std::move(rows); break; } + } + scores.push_back({{"match_id", id}, {"score", score}, {"chances", {chances[0], chances[1]}}, {"yellow", {yellow[0], yellow[1]}}, + {"red", {red[0], red[1]}}, {"players", {std::max(0, 11 - red[0]), std::max(0, 11 - red[1])}}, + {"standings", standings}}); + } + // events are shown newest last, in minute order across the matches + std::stable_sort(events.begin(), events.end(), [](const Json &a, const Json &b) { return a.at("minute").get() < b.at("minute").get(); }); + if (out.at("frames").empty()) { + Json zero = Json::array(); + for (const auto &s : scores) zero.push_back({{"match_id", s.at("match_id")}, {"score", {0, 0}}, {"chances", {0, 0}}, {"yellow", {0, 0}}, + {"red", {0, 0}}, {"players", {11, 11}}, {"standings", s.at("standings")}}); + out["frames"].push_back({{"sequence", 0}, {"minute", 0}, {"phase", "first_half"}, {"matches", zero}, {"events", Json::array()}}); + } + const int64_t last_minute = out.at("frames").back().at("minute"); + out["frames"].push_back({{"sequence", out.at("frames").size()}, {"minute", std::max(minute, last_minute)}, + {"phase", minute <= 45 ? "first_half" : minute <= 90 ? "second_half" : "extra_time"}, + {"matches", scores}, {"events", events}}); + if (out.at("frames").size() > 1900) return failure("invalid_live_fixture"); + 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 index 8890dc9..8b40020 100644 --- a/src/modern/ui/engine_live.hpp +++ b/src/modern/ui/engine_live.hpp @@ -11,4 +11,12 @@ Json engine_advance_command(const Json &bundle, const std::string &request_id, c // 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 &); +// A command of a kickoff under way (live.step, live.finish, live.substitute, live.tactics); +// `revision` is the revision of the last live answer. +Json engine_live_command(const Json &bundle, const std::string &revision, const std::string &request_id, + const std::string &kind, const Json &payload); +// The desk manager's squad in line-up order, as the ticker's team tab lists it. +Json engine_live_roster(const Json &bundle); +// One more frame for the standing kickoff (`state` is the paused read_live answer). +Json engine_live_progress(const Json &previous, const Json &state, const Json &bundle, const Json &roster); } // namespace bmh::modern_ui diff --git a/src/modern/ui/engine_screens.inc b/src/modern/ui/engine_screens.inc index 8ee873e..7b0419c 100644 --- a/src/modern/ui/engine_screens.inc +++ b/src/modern/ui/engine_screens.inc @@ -172,7 +172,9 @@ void App::engine_render() { 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"); + setting_menu_markup_ = true; element("canvas")->SetInnerRML(out); ++document_generation_; + setting_menu_markup_ = false; live_detail_pending_ = live_ticker_pending_ = false; scale_chalk_shadow(); if (!engine_player_.empty()) { diff --git a/src/modern/ui/live_controls.inc b/src/modern/ui/live_controls.inc index 10ecbc8..1eea92a 100644 --- a/src/modern/ui/live_controls.inc +++ b/src/modern/ui/live_controls.inc @@ -26,13 +26,147 @@ bool App::live_open() { } 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, "")) { + // after a kickoff that was followed live the ticker stays on the final whistle + const bool at_end = engine_live_at_end_ && scene_ == "live"; + engine_live_at_end_ = false; + if (!fixture.value("ok", false) || !(at_end ? live_.follow(fixture) : live_.open(fixture, ""))) { engine_notice_ = "Spieltag gespielt · Der Ticker kann diese Aufzeichnung nicht zeigen (" + fixture.value("error", std::string("invalid_live_fixture")) + ")."; + if (scene_ == "live") { scene_ = live_return_scene_; live_.close(); } return false; } + if (at_end) { + live_.speed(0); live_feedback_ = "Abpfiff."; live_reset_ticker_ = live_reset_detail_ = true; + live_selected_match_ = live_.fixture().at("matches").front().at("id"); + for (const auto &owner : live_.fixture().at("owners")) if (owner.at("id") == live_.owner()) live_selected_match_ = owner.at("match_id"); + live_dialog_.clear(); live_dialog_draft_ = Json(); postmatch_data_ = Json::object(); postmatch_scrolls_ = Json::object(); postmatch_playing_ = false; + focus_after_render_ = "live-review"; + return true; + } + engine_live_enter(); + live_.speed(2); + return true; +} +// The kickoff stands after its first minute: the ticker opens on it and plays on by live.step. +void App::engine_live_begin(const Json &state, const std::string &revision) { + engine_live_roster_ = engine_live_roster(engine_data_); + engine_live_revision_ = revision; engine_live_running_ = true; engine_live_busy_ = false; + engine_live_at_end_ = false; engine_live_elapsed_ = 0; engine_live_queue_ = Json(); engine_live_swap_ = Json(); + engine_live_tactics_ = Json::array(); engine_live_tactics_sent_ = Json(); + try { + for (const auto &control : engine_data_.at("tactics").at("data").at("controls")) + engine_live_tactics_.push_back({{"label", control.at("label").value("text", std::string("Taktik"))}, + {"min", control.at("range").at("min")}, {"max", control.at("range").at("max")}, + {"value", control.at("value")}}); + } catch (const std::exception &) { engine_live_tactics_ = Json::array(); } + if (engine_live_tactics_.size() != 8) engine_live_tactics_ = Json::array(); + const auto fixture = engine_live_progress(Json(), state, engine_data_, engine_live_roster_); + if (!fixture.value("ok", false) || !live_.open(fixture, "")) { + // nothing the ticker can show: the kickoff is simply played to its end + engine_notice_ = "Der Spieltag wird ohne Ticker zu Ende gespielt."; + engine_live_send("live.finish", Json::object()); + return; + } + engine_live_enter(); + live_.speed(2); +} +void App::engine_live_send(const std::string &kind, const Json &payload) { + if (!engine_live_running_ || !engine_link_) return; + if (engine_live_busy_) { engine_live_queue_ = {{"kind", kind}, {"payload", payload}}; return; } + const auto command = engine_live_command(engine_data_, engine_live_revision_, editor::new_id("request:ui-"), kind, payload); + auto link = engine_link_; + engine_live_busy_ = true; + engine_live_job_ = std::async(std::launch::async, [link, command, kind] { + Json result = {{"kind", kind}}; + try { + result["response"] = link->command(command); + result["live"] = link->read_live({{"kind", "fixture"}}); + } catch (const std::exception &e) { result["failure"] = e.what(); } + return result; + }); +} +void App::engine_live_poll() { + if (!engine_live_busy_ || engine_live_job_.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) return; + engine_live_busy_ = false; + Json result; + try { result = engine_live_job_.get(); } catch (const std::exception &e) { result = {{"failure", e.what()}}; } + const std::string kind = result.value("kind", std::string()); + const Json response = result.value("response", Json::object()), state = result.value("live", Json::object()); + const bool accepted = response.value("messageType", "") == "command_result"; + if (accepted) engine_live_revision_ = response.value("newRevision", engine_live_revision_); + if (kind == "live.substitute") { + if (accepted && engine_live_swap_.is_array() && engine_live_swap_.size() == 2) { + // the engine swapped the two rows of the line-up; the team tab follows + size_t a = engine_live_roster_.size(), b = engine_live_roster_.size(); + for (size_t i = 0; i < engine_live_roster_.size(); ++i) { + if (engine_live_roster_[i].at("id") == engine_live_swap_[0]) a = i; + if (engine_live_roster_[i].at("id") == engine_live_swap_[1]) b = i; + } + if (a < engine_live_roster_.size() && b < engine_live_roster_.size()) { + std::swap(engine_live_roster_[a], engine_live_roster_[b]); + engine_live_roster_[a]["slot"] = a; engine_live_roster_[b]["slot"] = b; + } + live_feedback_ = "Wechsel ausgeführt."; + } else if (!accepted) { + const Json refusal = response.value("message", Json()); + std::string reason = refusal.is_object() ? refusal.value("text", std::string()) : std::string(); + if (reason.empty()) reason = response.value("code", std::string("substitution_refused")); + live_feedback_ = "Wechsel nicht möglich: " + reason; + } + engine_live_swap_ = Json(); + } + if (kind == "live.tactics") { + if (accepted && engine_live_tactics_sent_.is_array() && engine_live_tactics_sent_.size() == engine_live_tactics_.size()) { + for (size_t i = 0; i < engine_live_tactics_.size(); ++i) engine_live_tactics_[i]["value"] = engine_live_tactics_sent_[i]; + live_feedback_ = "Taktik geändert."; + } else if (!accepted) { + const Json refusal = response.value("message", Json()); + std::string reason = refusal.is_object() ? refusal.value("text", std::string()) : std::string(); + if (reason.empty()) reason = response.value("code", std::string("invalid_tactic")); + live_feedback_ = "Taktik nicht geändert: " + reason; + } + engine_live_tactics_sent_ = Json(); + } + const bool standing = + state.is_object() && state.value("ok", false) && state.value("live", false); + if (standing) { + if (accepted || kind != "live.step") { + const auto fixture = engine_live_progress(live_.fixture(), state, engine_data_, engine_live_roster_); + if (fixture.value("ok", false)) live_.follow(fixture); + } else { + live_.speed(0); + live_feedback_ = "Der Spieltag steht: " + response.value("code", std::string("live_step_refused")); + } + if (engine_live_queue_.is_object()) { + const Json next = engine_live_queue_; engine_live_queue_ = Json(); + engine_live_send(next.at("kind"), next.at("payload")); + } + refresh(); + return; + } + // the run is over: its recording replaces the frames composed on the way, the desk is read anew + engine_live_running_ = false; engine_live_queue_ = Json(); + auto link = engine_link_; + if (accepted) { + engine_live_at_end_ = true; + engine_start("Abpfiff …", [link, state] { + Json finished = {{"messageType", "live_finished"}, {"liveRecording", state}}; + return EngineReply{link, link->snapshot(), finished, nullptr}; + }, true); + } else { + // the engine took the kickoff back (a question it could not ask in time): back to the desk + scene_ = live_return_scene_; live_.close(); + engine_start("Der Spieltag wurde zurückgenommen …", [link, response] { + Json refused = response; refused["advanceRefused"] = true; + return EngineReply{link, link->snapshot(), refused, nullptr}; + }, false); + } + refresh(); +} +void App::engine_live_enter() { try { live_.owner(engine_data_.at("desktop").at("meta").at("scope").at("managerId").get()); } catch (const std::exception &) {} + const auto &fixture = live_.fixture(); 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(); @@ -45,11 +179,18 @@ bool App::engine_live_open(const Json &recording) { 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(); + live_last_tick_ = SDL_GetTicks64(); focus_after_render_ = "live-pause"; - return true; } void App::live_close() { + if (engine_mode_ && engine_live_running_) { + // a kickoff under way cannot be left standing: it is played to its final whistle + live_dialog_.clear(); live_dialog_draft_ = Json(); live_.speed(0); + live_feedback_ = "Das Spiel wird zu Ende gespielt …"; + engine_live_send("live.finish", Json::object()); + refresh(); + return; + } live_review_=false;postmatch_playing_=false; live_.speed(0); live_dialog_.clear(); live_dialog_draft_ = Json(); live_resume_speed_ = 0; live_speed_dragging_ = false; @@ -76,6 +217,7 @@ void App::live_set_speed(int value) { dirty_ = true; } void App::live_tick() { + if (engine_live_busy_) engine_live_poll(); if (scene_ != "live" || !live_.available()) return; const auto now = SDL_GetTicks64(), elapsed = now - live_last_tick_; live_last_tick_ = now; if(live_review_){postmatch_tick(now);return;} @@ -87,12 +229,32 @@ void App::live_tick() { 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; } + if (engine_live_running_) { + // one engine minute per beat; the beat follows the speed control + if (engine_live_busy_ || !live_.speed()) return; + static constexpr std::array beats{0, 1600, 900, 450, 150}; + engine_live_elapsed_ += std::min(elapsed, 2000); + if (engine_live_elapsed_ >= beats[size_t(live_.speed())]) { engine_live_elapsed_ = 0; engine_live_send("live.step", {{"minutes", 1}}); } + return; + } if (live_.elapse(elapsed)) needs_render_ = true; } void App::live_dialog_close(bool apply_draft) { if (live_dialog_.empty()) return; - if (apply_draft) { + if (apply_draft && engine_live_running_) { + if (live_dialog_ == "lineup" && !live_out_.empty() && !live_in_.empty()) { + engine_live_swap_ = Json::array({live_out_, live_in_}); + live_feedback_ = "Wechsel wird ausgeführt …"; + engine_live_send("live.substitute", {{"outPlayerId", live_out_}, {"inPlayerId", live_in_}}); + } + if (live_dialog_ == "tactics" && live_dialog_draft_.is_object() && live_dialog_draft_.contains("values")) { + engine_live_tactics_sent_ = live_dialog_draft_.at("values"); + live_feedback_ = "Taktik wird geändert …"; + engine_live_send("live.tactics", {{"values", engine_live_tactics_sent_}}); + } + } else if (apply_draft) { auto proposed = live_dialog_draft_; + if (live_dialog_ == "lineup") { const auto owner = live_owner(); const auto error = edit_demo_lineup(proposed, {{"kind", "swap"}, {"a", live_out_}, {"b", live_in_}}, @@ -143,6 +305,7 @@ bool App::live_action(const std::string &action, Rml::Element *target) { } live_reset_ticker_ = true; } else if (action == "live-next") { + if (engine_live_running_) { engine_live_elapsed_ = 0; engine_live_send("live.step", {{"minutes", 1}}); return true; } live_.next(); live_last_tick_ = SDL_GetTicks64(); } else if (action == "live-pause") { live_set_speed(live_.speed() ? 0 : 1); return true; @@ -151,8 +314,14 @@ bool App::live_action(const std::string &action, Rml::Element *target) { } 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() || live_.fixture().at("source") == "engine-recording") return true; + if (live_.finished() || (live_.fixture().at("source") == "engine-recording" && !live_.running())) return true; + if (live_.running() && action == "live-intervene-tactics" && engine_live_tactics_.size() != 8) return true; const auto owner = live_owner(); live_dialog_draft_ = live_owner_state(owner); + if (live_.running() && action == "live-intervene-tactics") { + Json values = Json::array(); + for (const auto &control : engine_live_tactics_) values.push_back(control.at("value")); + live_dialog_draft_ = {{"values", values}}; + } live_dialog_ = action == "live-intervene-lineup" ? "lineup" : "tactics"; live_resume_speed_ = live_.speed(); live_.speed(0); live_last_tick_ = SDL_GetTicks64(); live_out_.clear(); live_in_.clear(); @@ -166,6 +335,15 @@ bool App::live_action(const std::string &action, Rml::Element *target) { try { const int index = std::stoi(id); if (index < 0 || index > 7) return true; + if (engine_live_running_) { + // the next value of the engine's own range, wrapping to its lowest + const auto &control = engine_live_tactics_.at(size_t(index)); + int value = live_dialog_draft_.at("values").at(size_t(index)).get() + 1; + if (value > control.at("max").get()) value = control.at("min").get(); + live_dialog_draft_["values"][size_t(index)] = value; + if (target) focus_after_render_ = target->GetId(); + refresh(); return true; + } const auto error = edit_demo_tactics(live_dialog_draft_["tactics"], {{"kind", "cycle"}, {"index", index}}); if (!error.empty()) return true; } catch (const std::exception &) { return true; } diff --git a/src/modern/ui/live_screens.inc b/src/modern/ui/live_screens.inc index 01cb038..160bce8 100644 --- a/src/modern/ui/live_screens.inc +++ b/src/modern/ui/live_screens.inc @@ -99,6 +99,13 @@ std::string App::live_detail(const Json &owner, const Json &frame) { } return out + ""; } + if (live_tab_ == "tactics" && live_.running() && engine_live_tactics_.size() == 8) { + std::string out = "

" + live_text("Taktik in diesem Spiel") + "

"; + for (size_t i = 0; i < engine_live_tactics_.size(); ++i) + out += "
" + live_text(engine_live_tactics_[i].at("label").get()) + + live_text("Wert " + std::to_string(engine_live_tactics_[i].at("value").get())) + "
"; + return out + btn("live-intervene-tactics", "Taktik ändern", "", "id=\"live-tactics-edit\"") + "
"; + } 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") { @@ -127,20 +134,21 @@ std::string App::live_detail(const Json &owner, const Json &frame) { std::string App::live_dialog_markup(const Json &owner) { if (live_dialog_.empty()) return ""; const auto rows = live_owner_rows(owner); - std::string body = "

" + live_text(live_dialog_ == "lineup" ? "Aufstellung & Wechsel · Demo" : "Taktik · Demo") + "

" + live_text("Nur lokale Vorschau für " + owner.at("name").get() + " · " + owner.at("team").at("name").get() + ". Keine Änderung an der Partie; der feste Spielverlauf bleibt unverändert.") + "

"; + std::string body = "

" + live_text(live_.running() ? (live_dialog_ == "lineup" ? "Aufstellung & Wechsel" : "Taktik") : live_dialog_ == "lineup" ? "Aufstellung & Wechsel · Demo" : "Taktik · Demo") + "

" + live_text(live_.running() ? owner.at("team").at("name").get() + " · Das Spiel steht, bis du entschieden hast." : "Nur lokale Vorschau für " + owner.at("name").get() + " · " + owner.at("team").at("name").get() + ". Keine Änderung an der Partie; der feste Spielverlauf bleibt unverändert.") + "

"; if (live_dialog_ == "lineup") { std::vector> active, bench; for (size_t i = 0; i < rows.size(); ++i) (i < size_t(live_.fixture().at("field_count").get()) ? active : bench).emplace_back(rows[i].at("id"), rows[i].at("name")); body += ""; - if (active.empty() || bench.empty()) body += "

" + live_text("Für diese Demokaderbasis ist kein Wechselpaar verfügbar.") + "

"; + if (active.empty() || bench.empty()) body += "

" + live_text(live_.running() ? "Kein Wechselpaar verfügbar." : "Für diese Demokaderbasis ist kein Wechselpaar verfügbar.") + "

"; } else { const std::array names{"Defensiv / offensiv", "Pass-/Schussbild unten", "Pass-/Schussbild Mitte", "Pass-/Schussbild links", "Flache / hohe Bälle", "Flügelbild links", "Flügelbild rechts", "Einsatz"}; - const auto &values = live_dialog_draft_.at("tactics").at("values"); + const bool engine_board = live_.running() && engine_live_tactics_.size() == 8; + const auto &values = engine_board ? live_dialog_draft_.at("values") : live_dialog_draft_.at("tactics").at("values"); for (size_t i = 0; i < names.size(); ++i) - body += "
" + live_text(names[i]) + btn("live-tactic-cycle", "Wert " + std::to_string(values[i].get()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "
"; + body += "
" + live_text(engine_board ? engine_live_tactics_[i].at("label").get() : std::string(names[i])) + btn("live-tactic-cycle", "Wert " + std::to_string(values[i].get()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "
"; } body += "
" + btn("live-dialog-cancel", "Abbrechen", "", "id=\"live-dialog-cancel\"") + - btn("live-dialog-apply", "Demovorschau anzeigen", "", "id=\"live-dialog-apply\" " + std::string(live_dialog_ == "lineup" && (live_out_.empty() || live_in_.empty()) ? "disabled" : "")) + "
"; + btn("live-dialog-apply", live_.running() ? (live_dialog_ == "lineup" ? "Wechsel ausführen" : "Taktik übernehmen") : "Demovorschau anzeigen", "", "id=\"live-dialog-apply\" " + std::string(live_dialog_ == "lineup" && (live_out_.empty() || live_in_.empty()) ? "disabled" : "")) + ""; return "
" + body + "
"; } std::string App::live_ticker_events(const Json &frame, size_t &shown) { @@ -198,10 +206,10 @@ std::string App::render_live() { out += "
" "" + esc(std::to_string(shown) + (live_.fixture().at("source") == "engine-recording" ? " Meldungen" : " Meldungen · feste Aufzeichnung")) + "" + "" + esc(phase_text) + "
"; + out += "
" + live_detail(owner, frame) + "
" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() || (recorded && !live_.running()) ? "disabled" : "")) + "
"; out += "
" + live_text("+") + "" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "
"; - 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() ? "Zur Auswertung" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "
"; + out += "
" + btn("live-back", live_.running() ? "Zu Ende spielen" : 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() ? "Zur Auswertung" : live_.running() ? "Nächste Minute" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "
"; return out + live_dialog_markup(owner) + ""; } void App::live_after_render() { diff --git a/src/modern/ui/live_state.inc b/src/modern/ui/live_state.inc index f03e2fd..8b1ee0d 100644 --- a/src/modern/ui/live_state.inc +++ b/src/modern/ui/live_state.inc @@ -30,6 +30,18 @@ Json engine_advance_payload_ = Json::object(); std::string engine_expiry_player_; void engine_kickoff(); + // A kickoff of the engine that is played minute by minute while the ticker is open. + bool engine_live_running_ = false, engine_live_busy_ = false, engine_live_at_end_ = false; + std::future engine_live_job_; + std::string engine_live_revision_; + uint64_t engine_live_elapsed_ = 0; + Json engine_live_roster_ = Json::array(), engine_live_swap_, engine_live_queue_; + // The tactics board during a live kickoff: the engine's controls with the values in force. + Json engine_live_tactics_ = Json::array(), engine_live_tactics_sent_; + void engine_live_begin(const Json &state, const std::string &revision); + void engine_live_send(const std::string &kind, const Json &payload); + void engine_live_poll(); + void engine_live_enter(); void engine_expiry_ask(const Json &args); void live_close(); bool live_action(const std::string &, Rml::Element *); diff --git a/src/modern/ui/postmatch_screens.inc b/src/modern/ui/postmatch_screens.inc index 2b86ad3..d454a19 100644 --- a/src/modern/ui/postmatch_screens.inc +++ b/src/modern/ui/postmatch_screens.inc @@ -415,8 +415,10 @@ std::string App::render_postmatch() { : "") + "\">" + live_text(postmatch_count(r.at("position"))) + postmatch_team(r.at("team"), false, 43) + - live_text(postmatch_count(r.at("played"))) + live_text("—") + - live_text("—") + live_text("—") + + live_text(postmatch_count(r.at("played"))) + + live_text(postmatch_count(r.value("won", Json()))) + + live_text(postmatch_count(r.value("drawn", Json()))) + + live_text(postmatch_count(r.value("lost", Json()))) + live_text(postmatch_count(r.at("gf")) + ":" + postmatch_count(r.at("ga"))) + live_text((diff > 0 ? "+" : "") + std::to_string(diff)) +