Add a read-only native live-ticker demo with finite fixtures (by Codex)
This commit is contained in:
1 parent
0a54b8338e
commit
8e3d9f83e0
17 files changed
+1601
-10
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.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_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.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_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_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)
|
||||
@@ -38,7 +38,7 @@ endif()
|
||||
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
FetchContent_GetProperties(rmlui)
|
||||
file(MAKE_DIRECTORY "${modern_assets}")
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.rcss)
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss live.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
@@ -124,7 +124,7 @@ foreach(component environment advertising toto lineup transfer stadium)
|
||||
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
|
||||
endforeach()
|
||||
|
||||
foreach(component statistics news settings desktop files entry opening career)
|
||||
foreach(component statistics news settings desktop files entry opening career live)
|
||||
add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp)
|
||||
target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -148,6 +148,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (live_event(event)) return;
|
||||
if (career_event(event)) return;
|
||||
if (entry_event(event)) return;
|
||||
if (opening_event(event)) return;
|
||||
@@ -465,6 +466,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if(front_action(action,target))return;
|
||||
if (live_action(action, target)) return;
|
||||
if (career_action(action,target)) return;
|
||||
if (entry_action(action, target)) return;
|
||||
if (opening_action(action, target)) return;
|
||||
@@ -924,6 +926,13 @@ void App::script() {
|
||||
context_->ProcessMouseMove(point.x + (end.x - point.x) * i / 12,
|
||||
point.y + (end.y - point.y) * i / 12, 0);
|
||||
context_->ProcessMouseButtonUp(0, 0);
|
||||
} else if (type == "wheel") {
|
||||
const auto point = locate(command);
|
||||
const float delta = command.at("delta").get<float>();
|
||||
if (!std::isfinite(delta) || std::abs(delta) > 1000)
|
||||
throw editor::Error("UI-Skript: ungültiger Mausradweg.");
|
||||
context_->ProcessMouseMove(point.x, point.y, 0);
|
||||
context_->ProcessMouseWheel(delta, 0);
|
||||
} else if (type == "text")
|
||||
context_->ProcessTextInput(command.value("value", std::string()));
|
||||
else if (type == "key") {
|
||||
@@ -934,6 +943,7 @@ void App::script() {
|
||||
{"LEFT", Rml::Input::KI_LEFT}, {"RIGHT", Rml::Input::KI_RIGHT},
|
||||
{"UP", Rml::Input::KI_UP}, {"DOWN", Rml::Input::KI_DOWN},
|
||||
{"A", Rml::Input::KI_A}, {"Z", Rml::Input::KI_Z}, {"V", Rml::Input::KI_V},
|
||||
{"P", Rml::Input::KI_P},
|
||||
{"BACKSPACE", Rml::Input::KI_BACK}, {"DELETE", Rml::Input::KI_DELETE}, {"F4", Rml::Input::KI_F4}, {"F10", Rml::Input::KI_F10}, {"CONTEXT", Rml::Input::KI_APPS},
|
||||
{"0", Rml::Input::KI_0}, {"1", Rml::Input::KI_1}, {"2", Rml::Input::KI_2}, {"3", Rml::Input::KI_3},
|
||||
{"4", Rml::Input::KI_4}, {"5", Rml::Input::KI_5}, {"6", Rml::Input::KI_6}, {"7", Rml::Input::KI_7},
|
||||
@@ -955,6 +965,7 @@ void App::script() {
|
||||
pump_events();
|
||||
front_poll();
|
||||
opening_tick();
|
||||
live_tick();
|
||||
frame();
|
||||
SDL_Delay(5);
|
||||
}
|
||||
@@ -969,6 +980,7 @@ void App::script() {
|
||||
editor::path(command.at("path").get<std::string>()),
|
||||
Json{{"scene", scene_},
|
||||
{"menu", menu_},
|
||||
{"live_view", live_snapshot()},
|
||||
{"report_picker", report_picker_},
|
||||
{"planning_dialog", planning_dialog_},
|
||||
{"bank_view", bank_view_}, {"bank_property", bank_property_}, {"bank_stock", bank_stock_},
|
||||
@@ -1000,7 +1012,7 @@ void App::script() {
|
||||
.dump(2));
|
||||
else if(type=="metrics"){
|
||||
context_->Update();Json rows=Json::array();
|
||||
for(const auto &selector:command.at("selectors")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,selector.get<std::string>());for(auto *node:nodes){auto at=node->GetAbsoluteOffset(Rml::BoxArea::Border),size=node->GetBox().GetSize(Rml::BoxArea::Border);rows.push_back({{"selector",selector},{"id",node->GetId()},{"x",at.x},{"y",at.y},{"width",size.x},{"height",size.y},{"scroll_top",node->GetScrollTop()},{"scroll_height",node->GetScrollHeight()},{"client_height",node->GetClientHeight()},{"visible",node->IsVisible(true)}});}}
|
||||
for(const auto &selector:command.at("selectors")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,selector.get<std::string>());for(auto *node:nodes){auto at=node->GetAbsoluteOffset(Rml::BoxArea::Border),size=node->GetBox().GetSize(Rml::BoxArea::Border);rows.push_back({{"selector",selector},{"id",node->GetId()},{"x",at.x},{"y",at.y},{"width",size.x},{"height",size.y},{"scroll_top",node->GetScrollTop()},{"scroll_height",node->GetScrollHeight()},{"client_height",node->GetClientHeight()},{"font_size",node->GetComputedValues().font_size()},{"rml",node->GetInnerRML()},{"visible",node->IsVisible(true)}});}}
|
||||
editor::write_atomic(editor::path(command.at("path").get<std::string>()),rows.dump(2));
|
||||
}
|
||||
else if (type == "dom")
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
Json failure(const char *error) { return {{"ok", false}, {"error", error}}; }
|
||||
std::string fingerprint(const std::string &text) {
|
||||
// Stable recording identity, independent of std::hash or active right pane.
|
||||
uint64_t hash = 14695981039346656037ULL;
|
||||
for (unsigned char c : text) { hash ^= c; hash *= 1099511628211ULL; }
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
std::string value(16, '0');
|
||||
for (int i = 15; i >= 0; --i) { value[size_t(i)] = hex[hash & 15]; hash >>= 4; }
|
||||
return value;
|
||||
}
|
||||
Json team(const Catalog &world, const std::string &id) {
|
||||
const auto *row = world.find("clubs", id);
|
||||
return {{"id", id}, {"name", row ? world.name(*row) : "Demo-Gegner"},
|
||||
{"role", "club"}, {"catalogue", row != nullptr}};
|
||||
}
|
||||
Json owner_view(const Catalog &world, const Json &state, const Json &manager,
|
||||
bool national, bool indoor) {
|
||||
const auto club = manager.value("club", "");
|
||||
Json view = state;
|
||||
const auto active_club = demo_career_manager(state).value("club", "");
|
||||
if (club != active_club) {
|
||||
const auto views = state.value("career_views", Json::object());
|
||||
if (views.contains(club)) restore_demo_career_view(view, views.at(club));
|
||||
else {
|
||||
view["lineup"] = demo_lineup(world, club);
|
||||
view["tactics"] = demo_tactics();
|
||||
view.erase("indoor_lineup");
|
||||
}
|
||||
}
|
||||
view["career"]["active_portrait"] = manager.at("portrait");
|
||||
view["career"]["surface"] = indoor ? "indoor" : "outdoor";
|
||||
if (!migrate_demo_lineup(view, world, club))
|
||||
return {{"ok", false}, {"error", "live_owner_lineup_unavailable"}};
|
||||
auto projection = demo_lineup_rows(view, world, club);
|
||||
if (!projection.value("ok", false)) return projection;
|
||||
auto rows = projection.at("rows");
|
||||
// These are catalogue attributes, never fixture-generated fitness/strength.
|
||||
for (auto &row : rows) {
|
||||
row["caps"] = nullptr;
|
||||
row["international_goals"] = nullptr;
|
||||
if (const auto *player = world.find("players", row.at("id"))) {
|
||||
const auto attributes = player->value("attributes", Json::object());
|
||||
for (const auto *key : {"caps", "international_goals"})
|
||||
if (attributes.contains(key) && attributes.at(key).is_number_integer() &&
|
||||
attributes.at(key) >= 0) row[key] = attributes.at(key);
|
||||
}
|
||||
}
|
||||
Json edit_state = {{"lineup", view.at("lineup")},
|
||||
{"tactics", view.value("tactics", demo_tactics())},
|
||||
{"career", {{"surface", indoor ? "indoor" : "outdoor"}}},
|
||||
{"date", state.at("date")}};
|
||||
if (view.contains("indoor_lineup")) edit_state["indoor_lineup"] = view.at("indoor_lineup");
|
||||
return {{"ok", true}, {"rows", rows}, {"board", demo_lineup_visible(view)},
|
||||
{"tactics", view.value("tactics", demo_tactics())},
|
||||
{"edit_state", edit_state},
|
||||
{"club_basis", club}, {"national_demo_basis", national},
|
||||
{"field_count", indoor ? 6 : 11}, {"on_field_limit", indoor ? 6 : 11},
|
||||
{"rotation_rows", indoor ? Json(std::min(size_t(11), rows.size())) : Json()},
|
||||
{"roster_size", rows.size()}, {"roster_limit", nullptr}};
|
||||
}
|
||||
// Every outcome, statistic and minute below is authored fixture data. There is
|
||||
// no event generation, chance/goal rule, random draw or match clock simulation.
|
||||
struct Moment {
|
||||
int outdoor, indoor;
|
||||
const char *phase, *kind, *headline, *body;
|
||||
std::array<int, 2> score, chances, yellow, red;
|
||||
std::array<int, 2> points, goals_for, goals_against;
|
||||
};
|
||||
constexpr std::array<Moment, 9> recording{{
|
||||
{0, 0, "first_half", "kickoff", "Anpfiff!", "Der Ball rollt. Beide Mannschaften beginnen mit ihrer Aufstellung.", {0,0}, {0,0}, {0,0}, {0,0}, {22,19}, {20,18}, {10,12}},
|
||||
{12, 6, "first_half", "goal", "Die Heimelf geht in Führung", "Die Gastgeber nutzen ihre Gelegenheit und gehen mit 1:0 in Führung.", {1,0}, {2,1}, {0,0}, {0,0}, {24,18}, {21,18}, {10,13}},
|
||||
{23, 11, "first_half", "yellow", "Gelbe Karte für die Gäste", "Die Gäste werden verwarnt. Es bleibt beim knappen Rückstand.", {1,0}, {3,2}, {0,1}, {0,0}, {24,18}, {21,18}, {10,13}},
|
||||
{45, 20, "interval", "interval", "Halbzeit", "Mit einer knappen Führung der Gastgeber geht es in die Pause.", {1,0}, {4,3}, {0,1}, {0,0}, {24,18}, {21,18}, {10,13}},
|
||||
{46, 21, "second_half", "restart", "Die zweite Hälfte beginnt", "Die Mannschaften sind zurück. Die Heimelf beginnt mit einem Tor Vorsprung.", {1,0}, {4,3}, {0,1}, {0,0}, {24,18}, {21,18}, {10,13}},
|
||||
{62, 28, "second_half", "goal", "Ausgleich für die Gäste", "Die Gäste treffen zum 1:1. Damit ist die Begegnung wieder offen.", {1,1}, {5,4}, {0,1}, {0,0}, {22,19}, {21,19}, {11,13}},
|
||||
{70, 32, "second_half", "chance", "Eine weitere Torchance", "Die Heimelf kommt zum Abschluss. Der Spielstand bleibt unverändert.", {1,1}, {6,5}, {0,1}, {0,0}, {22,19}, {21,19}, {11,13}},
|
||||
{78, 36, "second_half", "goal", "Die Heimelf trifft erneut", "Die Gastgeber erzielen das 2:1 und liegen wieder vorn.", {2,1}, {7,5}, {0,1}, {0,0}, {24,18}, {22,19}, {11,14}},
|
||||
{90, 40, "finished", "fulltime", "Abpfiff", "Die Partie endet mit einem 2:1 für die Heimmannschaft.", {2,1}, {8,6}, {0,1}, {0,0}, {24,18}, {22,19}, {11,14}}
|
||||
}};
|
||||
Json standings(const Catalog &world, const Json &match, const Moment &moment) {
|
||||
// One declared snapshot per catalogue competition, independent of the owner
|
||||
// or watched match. Both passes are authored table ordering, not a computed
|
||||
// league ranking; all pairs in this recording share the same fixed outcomes.
|
||||
Json rows = Json::array();
|
||||
const auto *home = world.find("clubs", match.at("home").at("id"));
|
||||
if (!home) return rows;
|
||||
const auto pool = world.clubs(home->value("competition", ""));
|
||||
for (size_t side = 0; side < 2; ++side)
|
||||
for (size_t slot = side; slot < std::min(size_t(18), pool.size()); slot += 2)
|
||||
rows.push_back({{"position", rows.size() + 1}, {"team", team(world, pool[slot]->at("id"))},
|
||||
{"played", 8}, {"gf", moment.goals_for[side]},
|
||||
{"ga", moment.goals_against[side]}, {"points", moment.points[side]}});
|
||||
return rows;
|
||||
}
|
||||
bool uint_value(const Json &v, uint64_t maximum) {
|
||||
return (v.is_number_unsigned() && v.get<uint64_t>() <= maximum) ||
|
||||
(v.is_number_integer() && v.get<int64_t>() >= 0 &&
|
||||
uint64_t(v.get<int64_t>()) <= maximum);
|
||||
}
|
||||
bool string_value(const Json &v, size_t maximum = 240) {
|
||||
if (!v.is_string()) return false;
|
||||
const auto &value = v.get_ref<const std::string &>();
|
||||
return !value.empty() && value.size() <= maximum &&
|
||||
std::none_of(value.begin(), value.end(), [](unsigned char c) { return c < 32 || c == 127; });
|
||||
}
|
||||
bool team_value(const Json &v, const Json &role) {
|
||||
return v.is_object() && string_value(v.at("id")) && string_value(v.at("name")) && v.at("role") == role;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Json make_demo_live(const Catalog &world, const Json &state, uint64_t revision) {
|
||||
try {
|
||||
if (!state.is_object() || state.value("schema", "") != "openbmh-ui-demo@1")
|
||||
return failure("live_demo_state_required");
|
||||
const auto context = demo_career_context(state, world);
|
||||
if (context.value("ended", false)) return failure("live_career_ended");
|
||||
const auto role = context.value("role", ""), surface = context.value("surface", "");
|
||||
if ((role != "club" && role != "national") ||
|
||||
(surface != "outdoor" && surface != "indoor") ||
|
||||
(role == "national" && surface != "outdoor")) return failure("invalid_live_scope");
|
||||
const bool national = role == "national", indoor = surface == "indoor";
|
||||
const auto humans = context.at("active_managers");
|
||||
if (!humans.is_array() || humans.empty() || humans.size() > 4)
|
||||
return failure("invalid_live_owners");
|
||||
Json owners = Json::array(), matches = Json::array();
|
||||
std::set<int> portraits;
|
||||
for (const auto &manager : humans) {
|
||||
if (national && manager.at("portrait") != context.at("current_manager").at("portrait")) continue;
|
||||
const int portrait = manager.at("portrait");
|
||||
if (portrait < 0 || portrait > 11 || !portraits.insert(portrait).second ||
|
||||
!world.manageable(manager.value("club", ""))) return failure("invalid_live_owners");
|
||||
const auto managed = national ? context.at("current_team") : team(world, manager.at("club"));
|
||||
const auto view = owner_view(world, state, manager, national, indoor);
|
||||
if (!view.value("ok", false)) return failure("live_owner_lineup_unavailable");
|
||||
owners.push_back({{"id", "manager:" + std::to_string(portrait)}, {"portrait", portrait},
|
||||
{"name", manager.at("name")}, {"team", managed}, {"view", view}});
|
||||
}
|
||||
for (auto &owner : owners) {
|
||||
const std::string id = owner.at("team").at("id");
|
||||
auto existing = std::find_if(matches.begin(), matches.end(), [&](const auto &match) {
|
||||
return match.at("home").at("id") == id || match.at("away").at("id") == id;
|
||||
});
|
||||
if (existing != matches.end()) { owner["match_id"] = existing->at("id"); existing->at("owners").push_back(owner.at("id")); continue; }
|
||||
Json home = owner.at("team"), away;
|
||||
if (national) {
|
||||
away = {{"id", "fixture:national-opponent"}, {"name", "Demo-Nationalteam"}, {"role", "national"}, {"catalogue", false}};
|
||||
for (const auto &nation : world.rows("nations")) if (nation.value("id", "") != "nation:de") {
|
||||
away = {{"id", "national:" + nation.at("id").get<std::string>()}, {"name", world.name(nation)}, {"role", "national"}, {"nation", nation.at("id")}, {"catalogue", true}}; break;
|
||||
}
|
||||
} else {
|
||||
const auto *club = world.find("clubs", id);
|
||||
const auto pool = world.clubs(club ? club->value("competition", "") : "");
|
||||
auto at = std::find_if(pool.begin(), pool.end(), [&](const auto *c) { return c->value("id", "") == id; });
|
||||
if (at == pool.end()) return failure("live_team_unavailable");
|
||||
const size_t index = size_t(at - pool.begin()), partner = index % 2 ? index - 1 : index + 1;
|
||||
if (partner < pool.size()) {
|
||||
away = team(world, pool[partner]->at("id"));
|
||||
if (index % 2) std::swap(home, away);
|
||||
} else away = team(world, "fixture:opponent:" + id);
|
||||
}
|
||||
const auto match_id = "ui-match:" + fingerprint(Json::array({world.manifest().value("id", ""), state.at("date"), role, surface, home.at("id"), away.at("id")}).dump());
|
||||
owner["match_id"] = match_id;
|
||||
matches.push_back({{"id", match_id}, {"home", home}, {"away", away},
|
||||
{"owners", Json::array({owner.at("id")})},
|
||||
{"competition", national ? "Länderspiel · Demo" : indoor ? "Hallenpartie · Demo" : "Spieltag · Demo"}});
|
||||
}
|
||||
Json frames = Json::array(), events = Json::array();
|
||||
for (size_t sequence = 0; sequence < recording.size(); ++sequence) {
|
||||
const auto &moment = recording[sequence];
|
||||
Json scores = Json::array();
|
||||
for (const auto &match : matches) {
|
||||
const auto event_id = match.at("id").get<std::string>() + ":event:" + std::to_string(sequence);
|
||||
events.push_back({{"id", event_id}, {"sequence", sequence}, {"match_id", match.at("id")},
|
||||
{"minute", indoor ? moment.indoor : moment.outdoor}, {"kind", moment.kind},
|
||||
{"headline", moment.headline}, {"body", moment.body}, {"score", moment.score},
|
||||
{"side", std::string(moment.kind) == "yellow" || sequence == 5 ? "away" : "home"}});
|
||||
scores.push_back({{"match_id", match.at("id")}, {"score", moment.score},
|
||||
{"chances", moment.chances}, {"yellow", moment.yellow}, {"red", moment.red},
|
||||
{"players", indoor ? Json::array({6,6}) : Json::array({11,11})},
|
||||
{"standings", national ? Json::array() : standings(world, match, moment)}});
|
||||
}
|
||||
frames.push_back({{"sequence", sequence}, {"minute", indoor ? moment.indoor : moment.outdoor},
|
||||
{"phase", moment.phase}, {"matches", scores}, {"events", events}});
|
||||
}
|
||||
const auto identity = Json{{"world", world.manifest().value("id", "")}, {"date", state.at("date")},
|
||||
{"role", role}, {"surface", surface}, {"matches", matches}};
|
||||
return {{"ok", true}, {"schema", "openbmh-live-fixture@1"}, {"source", "ui-demo-fixture"},
|
||||
{"fixture_id", "ui-live:" + fingerprint(identity.dump())}, {"source_revision", revision},
|
||||
{"world", world.manifest().value("id", "")}, {"date", state.at("date")},
|
||||
{"role", role}, {"surface", surface}, {"duration", indoor ? 40 : 90},
|
||||
{"field_count", indoor ? 6 : 11}, {"owners", owners}, {"matches", matches},
|
||||
{"frames", frames}, {"notice", "UI-Demo · vorgegebene Ergebnisse, keine Spielsimulation"}};
|
||||
} catch (const std::exception &) { return failure("invalid_live_demo"); }
|
||||
}
|
||||
|
||||
bool valid_live_fixture(const Json &v) {
|
||||
try {
|
||||
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() ||
|
||||
v.at("owners").empty() || v.at("owners").size() > 4 || !v.at("matches").is_array() ||
|
||||
v.at("matches").empty() || v.at("matches").size() > 4 || !v.at("frames").is_array() ||
|
||||
v.at("frames").size() < 2 || v.at("frames").size() > 2000) return false;
|
||||
const bool indoor = v.at("surface") == "indoor", national = v.at("role") == "national";
|
||||
if ((!national && v.at("role") != "club") || (!indoor && v.at("surface") != "outdoor") ||
|
||||
(national && (indoor || v.at("owners").size() != 1)) ||
|
||||
v.at("duration") != (indoor ? 40 : 90) || v.at("field_count") != (indoor ? 6 : 11)) return false;
|
||||
std::set<std::string> owner_ids, match_ids, teams, assigned_owners;
|
||||
std::set<int> portraits;
|
||||
for (const auto &owner : v.at("owners")) {
|
||||
if (!string_value(owner.at("id")) || !owner_ids.insert(owner.at("id")).second ||
|
||||
!uint_value(owner.at("portrait"), 11) || !portraits.insert(owner.at("portrait").get<int>()).second ||
|
||||
!string_value(owner.at("name")) || !team_value(owner.at("team"), v.at("role"))) return false;
|
||||
const auto &view = owner.at("view");
|
||||
if (!view.value("ok", false) || !view.at("rows").is_array() || view.at("rows").size() > 2000 ||
|
||||
view.at("field_count") != v.at("field_count") || view.at("on_field_limit") != v.at("field_count") ||
|
||||
view.at("roster_size") != view.at("rows").size() || !view.at("roster_limit").is_null() ||
|
||||
!view.at("board").at("order").is_array() || !view.at("board").at("points").is_array() ||
|
||||
view.at("board").at("points").size() != 11 || !view.at("edit_state").is_object() ||
|
||||
!view.at("edit_state").at("lineup").is_object() || !valid_demo_tactics(view.at("tactics")) ||
|
||||
view.at("national_demo_basis") != national) return false;
|
||||
if ((indoor && view.at("rotation_rows") != std::min(size_t(11), view.at("rows").size())) ||
|
||||
(!indoor && !view.at("rotation_rows").is_null())) return false;
|
||||
std::set<std::string> players;
|
||||
size_t slot = 0;
|
||||
for (const auto &row : view.at("rows")) {
|
||||
if (!string_value(row.at("id")) || !players.insert(row.at("id")).second || !string_value(row.at("name")) ||
|
||||
row.at("slot") != slot++ || !row.contains("strength") || !row.contains("condition")) return false;
|
||||
for (auto field : {"caps", "international_goals"})
|
||||
if (!row.at(field).is_null() && !uint_value(row.at(field), 1000000)) return false;
|
||||
}
|
||||
}
|
||||
for (const auto &match : v.at("matches")) {
|
||||
if (!string_value(match.at("id")) || !match_ids.insert(match.at("id")).second ||
|
||||
!match.at("owners").is_array() || match.at("owners").empty()) return false;
|
||||
for (auto side : {"home", "away"})
|
||||
if (!team_value(match.at(side), v.at("role")) ||
|
||||
!teams.insert(match.at(side).at("id")).second) return false;
|
||||
std::set<std::string> assigned;
|
||||
for (const auto &owner_id : match.at("owners")) {
|
||||
if (!owner_id.is_string() || !owner_ids.contains(owner_id) || !assigned.insert(owner_id).second || !assigned_owners.insert(owner_id).second) return false;
|
||||
const auto owner = std::find_if(v.at("owners").begin(), v.at("owners").end(), [&](const auto &o) { return o.at("id") == owner_id; });
|
||||
if (owner->at("match_id") != match.at("id") ||
|
||||
(owner->at("team").at("id") != match.at("home").at("id") && owner->at("team").at("id") != match.at("away").at("id"))) return false;
|
||||
}
|
||||
}
|
||||
if (assigned_owners != owner_ids) return false;
|
||||
for (const auto &owner : v.at("owners")) if (!match_ids.contains(owner.at("match_id"))) return false;
|
||||
int minute = -1; size_t sequence = 0;
|
||||
std::map<std::string, Json> history;
|
||||
for (const auto &frame : v.at("frames")) {
|
||||
if (!uint_value(frame.at("sequence"), v.at("frames").size() - 1) || frame.at("sequence") != sequence++ || !uint_value(frame.at("minute"), indoor ? 40 : 90) ||
|
||||
frame.at("minute").get<int>() < 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;
|
||||
const auto phase = frame.value("phase", "");
|
||||
if (phase != "first_half" && phase != "interval" && phase != "second_half" && phase != "finished") return false;
|
||||
if (phase == "finished" && sequence != v.at("frames").size()) return false;
|
||||
minute = frame.at("minute"); std::set<std::string> scored, event_ids;
|
||||
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 || !uint_value(m.at(key)[0], 1000) || !uint_value(m.at(key)[1], 1000)) return false;
|
||||
if (!m.at("standings").is_array() || m.at("standings").size() > 128 || (national && !m.at("standings").empty())) return false;
|
||||
for (const auto &row : m.at("standings")) {
|
||||
if (!team_value(row.at("team"), v.at("role"))) return false;
|
||||
for (auto key : {"position", "played", "gf", "ga", "points"}) if (!uint_value(row.at(key), 1000000)) return false;
|
||||
}
|
||||
}
|
||||
const auto previous_history = history;
|
||||
for (const auto &event : frame.at("events")) {
|
||||
if (!string_value(event.at("id")) || !event_ids.insert(event.at("id")).second ||
|
||||
!match_ids.contains(event.at("match_id")) || !uint_value(event.at("sequence"), sequence - 1) ||
|
||||
!uint_value(event.at("minute"), uint64_t(minute)) || !string_value(event.at("headline")) ||
|
||||
!string_value(event.at("body"), 2200) || !string_value(event.at("kind"), 40) ||
|
||||
(event.at("side") != "home" && event.at("side") != "away") || !event.at("score").is_array() ||
|
||||
event.at("score").size() != 2 || !uint_value(event.at("score")[0], 1000) || !uint_value(event.at("score")[1], 1000)) return false;
|
||||
const std::string id = event.at("id");
|
||||
if (history.contains(id) && history.at(id) != event) return false;
|
||||
history[id] = event;
|
||||
}
|
||||
for (const auto &[id, event] : previous_history) { (void)event; if (!event_ids.contains(id)) return false; }
|
||||
}
|
||||
return v.at("frames").front().at("minute") == 0 && minute == (indoor ? 40 : 90) &&
|
||||
v.at("frames").back().at("phase") == "finished";
|
||||
} catch (const std::exception &) { return false; }
|
||||
}
|
||||
Json live_fixture_frame(const Json &v, size_t sequence) {
|
||||
if (!valid_live_fixture(v)) return failure("invalid_live_fixture");
|
||||
if (sequence >= v.at("frames").size()) return failure("invalid_live_sequence");
|
||||
auto frame = v.at("frames")[sequence];
|
||||
frame["ok"] = true; frame["source"] = v.at("source"); frame["fixture_id"] = v.at("fixture_id");
|
||||
frame["source_revision"] = v.at("source_revision"); return frame;
|
||||
}
|
||||
Json query_demo_live(const Catalog &world, const Json &state, uint64_t revision, const Json &q) {
|
||||
try {
|
||||
if (!q.is_object()) return failure("invalid_live_query");
|
||||
for (const auto &[key, value] : q.items()) { (void)value;
|
||||
if (key != "kind" && key != "revision" && key != "sequence" && key != "fixture_id") return failure("invalid_live_query");
|
||||
}
|
||||
if (q.contains("revision") && (!uint_value(q.at("revision"), UINT64_MAX) || q.at("revision") != revision)) return failure("stale_live_revision");
|
||||
const auto kind = q.value("kind", "fixture");
|
||||
if (kind != "fixture" && kind != "frame") return failure("invalid_live_query");
|
||||
auto fixture = make_demo_live(world, state, revision);
|
||||
if (!fixture.value("ok", false)) return fixture;
|
||||
if (q.contains("fixture_id") && q.at("fixture_id") != fixture.at("fixture_id")) return failure("stale_live_fixture");
|
||||
if (kind == "fixture") return q.contains("sequence") ? failure("invalid_live_query") : fixture;
|
||||
if (!q.contains("sequence") || !uint_value(q.at("sequence"), fixture.at("frames").size() - 1)) return failure("invalid_live_sequence");
|
||||
return live_fixture_frame(fixture, q.at("sequence").get<size_t>());
|
||||
} catch (const std::exception &) { return failure("invalid_live_query"); }
|
||||
}
|
||||
|
||||
bool LivePlayback::open(const Json &fixture, const std::string &owner_id) {
|
||||
if (!valid_live_fixture(fixture)) return false;
|
||||
LivePlayback next; next.fixture_ = fixture;
|
||||
next.owner_ = fixture.at("owners").front().at("id");
|
||||
if (!owner_id.empty() && !next.owner(owner_id)) return false;
|
||||
*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::next() {
|
||||
if (!available() || finished()) return false;
|
||||
++sequence_; elapsed_ = 0; if (finished()) speed_ = 0; return true;
|
||||
}
|
||||
bool LivePlayback::speed(int value) {
|
||||
if (!available() || value < 0 || value > 4 || (finished() && value)) return false;
|
||||
speed_ = value; elapsed_ = 0; return true;
|
||||
}
|
||||
bool LivePlayback::elapse(uint64_t milliseconds) {
|
||||
if (!available() || !speed_ || finished()) return false;
|
||||
constexpr std::array<uint64_t, 5> intervals{0, 2400, 1400, 800, 400};
|
||||
const auto interval = intervals[size_t(speed_)];
|
||||
// A delayed/hidden window never skips an arbitrary backlog of recorded scenes.
|
||||
elapsed_ = std::min(interval, elapsed_ + std::min(milliseconds, interval));
|
||||
return elapsed_ >= interval && next();
|
||||
}
|
||||
bool LivePlayback::owner(const std::string &id) {
|
||||
if (!available()) return false;
|
||||
for (const auto &o : fixture_.at("owners")) if (o.at("id") == id) { owner_ = id; return true; }
|
||||
return false;
|
||||
}
|
||||
bool LivePlayback::cycle_owner(int direction) {
|
||||
if (!available() || (direction != -1 && direction != 1)) return false;
|
||||
const auto &owners = fixture_.at("owners");
|
||||
for (size_t i = 0; i < owners.size(); ++i) if (owners[i].at("id") == owner_)
|
||||
return owner(owners[(i + owners.size() + direction) % owners.size()].at("id"));
|
||||
return false;
|
||||
}
|
||||
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()},
|
||||
{"fixture_id", available() ? fixture_.at("fixture_id") : Json()},
|
||||
{"source_revision", available() ? fixture_.at("source_revision") : Json()},
|
||||
{"sequence", sequence_}, {"speed", speed_}, {"owner", owner_}, {"finished", finished()}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// A finite, authored presentation recording. No simulation, game state, RNG,
|
||||
// calendar progression or source mutation is involved in constructing/reading it.
|
||||
// Only catalogue identities and explicit owner presentation boards are reused.
|
||||
Json make_demo_live(const Catalog &, const Json &state, uint64_t revision);
|
||||
// Requests: {kind:"fixture",revision?:uint64}; or
|
||||
// {kind:"frame",sequence:uint,fixture_id?:string,revision?:uint64}.
|
||||
Json query_demo_live(const Catalog &, const Json &state, uint64_t revision,
|
||||
const Json &request);
|
||||
bool valid_live_fixture(const Json &);
|
||||
Json live_fixture_frame(const Json &, size_t sequence);
|
||||
|
||||
// Playback belongs to the view, never to DataSource or a saved career. Elapsed
|
||||
// time only reveals the next prerecorded snapshot; it cannot execute an action.
|
||||
class LivePlayback {
|
||||
public:
|
||||
bool open(const Json &fixture, const std::string &owner = {});
|
||||
void close();
|
||||
bool next();
|
||||
bool speed(int value); // 0 = pause, 1..4 = recording playback speed
|
||||
bool elapse(uint64_t milliseconds);
|
||||
bool owner(const std::string &id);
|
||||
bool cycle_owner(int direction);
|
||||
Json frame() const;
|
||||
Json status() const;
|
||||
const Json &fixture() const { return fixture_; }
|
||||
size_t sequence() const { return sequence_; }
|
||||
int speed() const { return speed_; }
|
||||
const std::string &owner() const { return owner_; }
|
||||
bool available() const { return fixture_.is_object(); }
|
||||
bool finished() const;
|
||||
|
||||
private:
|
||||
Json fixture_;
|
||||
size_t sequence_ = 0;
|
||||
int speed_ = 0;
|
||||
uint64_t elapsed_ = 0;
|
||||
std::string owner_;
|
||||
};
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,208 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::live_open() {
|
||||
if (!source_) { message("Für diese Ansicht steht keine Live-Datenquelle bereit."); return false; }
|
||||
const auto snapshot = snap();
|
||||
if (!live_.available() || live_source_ != source_.get() || live_world_ != snapshot.world ||
|
||||
live_.fixture().at("source_revision") != snapshot.revision) {
|
||||
const auto fixture = source_->read_live({{"kind", "fixture"}, {"revision", snapshot.revision}});
|
||||
const auto owner_id = "manager:" + std::to_string(demo_career_manager(snapshot.state).value("portrait", 0));
|
||||
if (!fixture.value("ok", false) || !live_.open(fixture, owner_id)) {
|
||||
message("Live-Ticker nicht verfügbar: " + fixture.value("error", "invalid_live_fixture")); return false;
|
||||
}
|
||||
live_source_ = source_.get(); live_world_ = snapshot.world;
|
||||
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");
|
||||
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;
|
||||
live_last_tick_ = SDL_GetTicks64(); scene_ = "live"; menu_.clear();
|
||||
focus_after_render_ = live_.finished() ? "live-review" : "live-next";
|
||||
refresh(); return true;
|
||||
}
|
||||
void App::live_close() {
|
||||
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();
|
||||
}
|
||||
void App::live_set_speed(int value) {
|
||||
if (!live_.speed(value)) return;
|
||||
live_feedback_.clear();
|
||||
live_last_tick_ = SDL_GetTicks64();
|
||||
if (auto *node = dynamic_cast<Rml::ElementFormControl *>(element("live-speed"))) {
|
||||
// Native vertical sliders increase downward; the user's logical speed is
|
||||
// deliberately inverted so the bottom position always means zero/pause.
|
||||
node->SetValue(std::to_string(4 - value)); node->SetAttribute("aria-valuenow", value);
|
||||
node->SetAttribute("aria-valuetext", value ? "Wiedergabe Stufe " + std::to_string(value) : "Pause");
|
||||
}
|
||||
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";
|
||||
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<int>()) + "′ · keine Spielwertänderung"));
|
||||
dirty_ = true;
|
||||
}
|
||||
void App::live_tick() {
|
||||
if (scene_ != "live" || !live_.available()) return;
|
||||
const auto now = SDL_GetTicks64(), elapsed = now - live_last_tick_; live_last_tick_ = now;
|
||||
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<uint64_t>()) {
|
||||
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;
|
||||
}
|
||||
if (live_.elapse(elapsed)) needs_render_ = true;
|
||||
}
|
||||
void App::live_dialog_close(bool apply_draft) {
|
||||
if (live_dialog_.empty()) return;
|
||||
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_}},
|
||||
*live_world_, owner.at("view").at("club_basis"));
|
||||
if (!error.empty()) { live_feedback_ = "Die Demovorschau konnte nicht geändert werden: " + error; refresh(); return; }
|
||||
}
|
||||
live_drafts_[live_.owner()] = std::move(proposed);
|
||||
live_feedback_ = "Lokale Demovorschau geändert. Spielverlauf und Quelle bleiben unverändert.";
|
||||
}
|
||||
const auto was = live_dialog_; live_dialog_.clear(); live_dialog_draft_ = Json();
|
||||
live_out_.clear(); live_in_.clear(); live_speed_dragging_ = false;
|
||||
const int resume = live_resume_speed_; live_resume_speed_ = 0;
|
||||
if (resume && !live_.finished()) live_.speed(resume);
|
||||
live_last_tick_ = SDL_GetTicks64(); focus_after_render_ = was == "lineup" ? "live-lineup-edit" : "live-tactics-edit";
|
||||
refresh();
|
||||
}
|
||||
bool App::live_action(const std::string &action, Rml::Element *target) {
|
||||
if (action == "open:kickoff") { live_open(); return true; }
|
||||
if (!action.starts_with("live-")) return false;
|
||||
if (scene_ != "live" || !live_.available()) return true;
|
||||
const auto id = target ? target->GetAttribute<Rml::String>("data-id", "") : "";
|
||||
if (!live_dialog_.empty() && action != "live-dialog-cancel" && action != "live-dialog-apply" && action != "live-tactic-cycle") return true;
|
||||
if (action == "live-back") { live_close(); return true; }
|
||||
if (action == "live-owner-prev" || action == "live-owner-next") {
|
||||
live_.cycle_owner(action == "live-owner-prev" ? -1 : 1); live_reset_detail_ = true;
|
||||
} else if (action == "live-tab") {
|
||||
if (id != "team" && id != "tactics" && id != "opponent" && id != "table" && id != "stats") return true;
|
||||
live_tab_ = id; live_reset_detail_ = true;
|
||||
} else if (action == "live-filter") {
|
||||
if (id != "all" && id != "highlights" && id != "goal" && id != "yellow") return true;
|
||||
live_filter_ = id; live_reset_ticker_ = true;
|
||||
} else if (action == "live-coverage") {
|
||||
if (id != "all" && id != "single" && id != "conference") return true;
|
||||
live_coverage_ = id; live_reset_ticker_ = true;
|
||||
} else if (action == "live-match") {
|
||||
for (const auto &match : live_.fixture().at("matches")) if (match.at("id") == id) {
|
||||
live_selected_match_ = id; live_reset_ticker_ = true; break;
|
||||
}
|
||||
} else if (action == "live-match-prev" || action == "live-match-next") {
|
||||
const auto &matches = live_.fixture().at("matches");
|
||||
for (size_t i = 0; i < matches.size(); ++i) if (matches[i].at("id") == live_selected_match_) {
|
||||
live_selected_match_ = matches[(i + matches.size() + (action == "live-match-prev" ? -1 : 1)) % matches.size()].at("id"); break;
|
||||
}
|
||||
live_reset_ticker_ = true;
|
||||
} else if (action == "live-next") {
|
||||
live_.next(); live_last_tick_ = SDL_GetTicks64();
|
||||
} else if (action == "live-pause") {
|
||||
live_set_speed(live_.speed() ? 0 : 1);
|
||||
} else if (action == "live-review" && live_.finished()) {
|
||||
live_review_ = true;
|
||||
} else if (action == "live-review-back") {
|
||||
live_review_ = false;
|
||||
} else if (action == "live-intervene-lineup" || action == "live-intervene-tactics") {
|
||||
if (live_.finished()) 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();
|
||||
live_out_.clear(); live_in_.clear();
|
||||
const auto rows = live_owner_rows(owner); const size_t count = live_.fixture().at("field_count");
|
||||
if (!rows.empty()) live_out_ = rows[0].at("id");
|
||||
if (rows.size() > count) live_in_ = rows[count].at("id");
|
||||
focus_after_render_ = "live-dialog-cancel";
|
||||
} else if (action == "live-dialog-cancel" || action == "live-dialog-apply") {
|
||||
live_dialog_close(action == "live-dialog-apply"); return true;
|
||||
} else if (action == "live-tactic-cycle" && live_dialog_ == "tactics") {
|
||||
try {
|
||||
const int index = std::stoi(id);
|
||||
if (index < 0 || index > 7) 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; }
|
||||
} else return true;
|
||||
if (target && focus_after_render_.empty()) focus_after_render_ = target->GetId();
|
||||
refresh(); return true;
|
||||
}
|
||||
bool App::live_event(Rml::Event &event) {
|
||||
if (scene_ != "live" || !live_.available() || !popup_.empty()) return false;
|
||||
const auto type = event.GetType(); auto *target = event.GetTargetElement();
|
||||
bool speed_control = false;
|
||||
for (auto *node = target; node && node != doc_; node = node->GetParentNode()) if (node->GetId() == "live-speed") speed_control = true;
|
||||
if (type == "mousedown" && speed_control) live_speed_dragging_ = true;
|
||||
if (type == "mouseup" && live_speed_dragging_) {
|
||||
live_speed_dragging_ = false; live_last_tick_ = SDL_GetTicks64();
|
||||
focus_after_render_ = "live-speed"; needs_render_ = true;
|
||||
}
|
||||
if ((type == "change" || type == "input") && speed_control) {
|
||||
if (setting_menu_markup_) return true;
|
||||
if (auto *input = dynamic_cast<Rml::ElementFormControl *>(element("live-speed"))) {
|
||||
try { live_set_speed(4 - std::stoi(input->GetValue())); } catch (const std::exception &) {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ((type == "change" || type == "input") && !live_dialog_.empty()) {
|
||||
if (setting_menu_markup_) return true;
|
||||
if (target->GetId() == "live-player-out") live_out_ = field("live-player-out");
|
||||
if (target->GetId() == "live-player-in") live_in_ = field("live-player-in");
|
||||
return true;
|
||||
}
|
||||
if (type == "mouseup" && event.GetParameter<int>("button", 0) == 1) {
|
||||
if (!live_dialog_.empty()) live_dialog_close(false); else live_close();
|
||||
event.StopImmediatePropagation(); return true;
|
||||
}
|
||||
if (type == "keydown") {
|
||||
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (key == Rml::Input::KI_ESCAPE) {
|
||||
if (!live_dialog_.empty()) live_dialog_close(false); else live_close();
|
||||
event.StopImmediatePropagation(); return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, live_dialog_.empty() ? "#live-stage button,#live-stage input" : "#live-dialog button,#live-dialog select");
|
||||
Rml::ElementList visible; for (auto *node : controls) if (node->IsVisible(true) && !node->HasAttribute("disabled")) visible.push_back(node);
|
||||
if (!visible.empty()) {
|
||||
auto at = std::find(visible.begin(), visible.end(), context_->GetFocusElement());
|
||||
int index = at == visible.end() ? -1 : int(at - visible.begin());
|
||||
const bool reverse = event.GetParameter<int>("shift_key", 0) != 0;
|
||||
index = (index + int(visible.size()) + (reverse ? -1 : 1)) % int(visible.size()); visible[size_t(index)]->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation(); return true;
|
||||
}
|
||||
if (live_dialog_.empty() && key == Rml::Input::KI_P && !live_.finished()) {
|
||||
live_set_speed(live_.speed() ? 0 : 1); event.StopImmediatePropagation(); return true;
|
||||
}
|
||||
if (speed_control && (key == Rml::Input::KI_HOME || key == Rml::Input::KI_END || key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN)) {
|
||||
live_set_speed(key == Rml::Input::KI_HOME ? 0 : key == Rml::Input::KI_END ? 4 : std::clamp(live_.speed() + (key == Rml::Input::KI_UP ? 1 : -1), 0, 4));
|
||||
event.StopImmediatePropagation(); return true;
|
||||
}
|
||||
}
|
||||
if (type == "click" && live_dialog_.empty()) for (auto *node = target; node && node != doc_; node = node->GetParentNode()) if (node->HasAttribute("data-live-match")) {
|
||||
live_selected_match_ = node->GetAttribute<Rml::String>("data-live-match", "");
|
||||
if (live_coverage_ == "single") live_reset_ticker_ = true;
|
||||
refresh(); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Json App::live_snapshot() const {
|
||||
auto status = live_.status(); status["tab"] = live_tab_; status["coverage"] = live_coverage_;
|
||||
status["selected_match"] = live_selected_match_; status["filter"] = live_filter_;
|
||||
status["review"] = live_review_; status["dialog"] = live_dialog_;
|
||||
status["drafts"] = live_drafts_; status["dialog_draft"] = live_dialog_draft_;
|
||||
status["ticker_scroll"] = element("live-ticker") ? element("live-ticker")->GetScrollTop() : live_ticker_scroll_;
|
||||
status["frame"] = live_.frame();
|
||||
if (live_.available()) { status["owners"] = live_.fixture().at("owners"); status["matches"] = live_.fixture().at("matches"); }
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
std::string live_text(const std::string &value, const std::string &css = {}) {
|
||||
return "<span" + (css.empty() ? std::string() : " class=\"" + css + "\"") + ">" + esc(value) + "</span>";
|
||||
}
|
||||
std::string live_score_text(const Json &score) {
|
||||
return std::to_string(score[0].get<int>()) + " : " + std::to_string(score[1].get<int>());
|
||||
}
|
||||
const Json &live_match_by_id(const Json &rows, const Json &id) {
|
||||
for (const auto &row : rows) if (row.at("id") == id) return row;
|
||||
throw editor::Error("live_match_unavailable");
|
||||
}
|
||||
const Json &live_score_by_id(const Json &frame, const Json &id) {
|
||||
for (const auto &row : frame.at("matches")) if (row.at("match_id") == id) return row;
|
||||
throw editor::Error("live_score_unavailable");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Json App::live_owner() const {
|
||||
for (const auto &owner : live_.fixture().at("owners")) if (owner.at("id") == live_.owner()) return owner;
|
||||
return Json();
|
||||
}
|
||||
Json App::live_owner_state(const Json &owner) const {
|
||||
const auto id = owner.at("id").get<std::string>();
|
||||
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 (!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"));
|
||||
if (!projection.value("ok", false)) return Json::array();
|
||||
auto rows = projection.at("rows");
|
||||
for (auto &row : rows) {
|
||||
row["caps"] = nullptr; row["international_goals"] = nullptr;
|
||||
for (const auto &base : owner.at("view").at("rows")) if (base.at("id") == row.at("id")) {
|
||||
row["caps"] = base.at("caps"); row["international_goals"] = base.at("international_goals");
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
std::string App::live_badge(const Json &team, double size) {
|
||||
std::string art;
|
||||
if (team.value("role", "club") == "national") {
|
||||
auto nation = team.value("nation", team.value("id", "") == "national-de" ? "nation:de" : "");
|
||||
if (nation.starts_with("nation:")) nation = nation.substr(7);
|
||||
const auto flag = ui_nation_flag_svg(nation);
|
||||
if (!flag.empty()) art = picture(renderer_.diagram("live-flag-" + nation, flag, int(size * 2)), size, size * .7);
|
||||
} else if (live_world_) {
|
||||
if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty()) art = crest(club, size);
|
||||
}
|
||||
if (art.empty()) art = glyph(team.value("role", "club") == "national" ? "world" : "shirt", size);
|
||||
return "<div class=\"live-badge\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;\">" + art + "</div>";
|
||||
}
|
||||
std::string App::live_roster(const Json &owner) {
|
||||
const bool national = live_.fixture().at("role") == "national";
|
||||
const int field_count = live_.fixture().at("field_count");
|
||||
std::string out = "<div class=\"live-roster\"><div class=\"live-roster-row heading\">" +
|
||||
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") + "</div>";
|
||||
const auto rows = live_owner_rows(owner);
|
||||
if (national) out += "<p class=\"live-roster-note\">" + live_text("Demokader auf Vereinsbasis · keine Nationalkaderberufung") + "</p>";
|
||||
for (size_t i = 0; i < rows.size(); ++i) {
|
||||
if (int(i) == field_count) out += "<p class=\"live-roster-note\">" + live_text(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : "Reserven · Demovorschau") + "</p>";
|
||||
if (field_count == 6 && i == 11) out += "<p class=\"live-roster-note\">" + live_text("Weitere Kaderreserven") + "</p>";
|
||||
const auto &row = rows[i];
|
||||
out += "<div class=\"live-roster-row\" data-live-player=\"" + esc(row.at("id").get<std::string>()) + "\">" +
|
||||
live_text(std::to_string(i + 1), "live-roster-number") + live_text(row.at("name"), "live-roster-name") +
|
||||
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") + "</div>";
|
||||
}
|
||||
if (rows.empty()) out += "<p class=\"live-note\">" + live_text("Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "</p>";
|
||||
return out + "</div>";
|
||||
}
|
||||
std::string App::live_detail(const Json &owner, const Json &frame) {
|
||||
const auto &fixture = live_.fixture();
|
||||
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);
|
||||
if (live_tab_ == "table") {
|
||||
if (fixture.at("role") == "national") return "<p class=\"live-note\">" + live_text("Dieses Demo-Länderspiel gehört zu keiner Liga. Der Spielstand steht links; eine Vereins-Live-Tabelle wird nicht eingeblendet.") + "</p>";
|
||||
std::string out = "<p class=\"live-note\">" + live_text("Vorgegebene Demo-Tabelle · keine echte Saisonwertung") + "</p><div class=\"live-table\" role=\"table\" aria-label=\"Demo-Live-Tabelle\"><div class=\"live-table-row heading\">" +
|
||||
live_text("Pl.", "live-table-pos") + "<div class=\"live-table-team\">" + live_text("Verein") + "</div>" + 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") + "</div>";
|
||||
for (const auto &row : score.at("standings")) {
|
||||
const bool own = row.at("team").at("id") == owner.at("team").at("id");
|
||||
const int difference = row.at("gf").get<int>() - row.at("ga").get<int>();
|
||||
out += "<div class=\"live-table-row " + std::string(own ? "own" : "") + "\" data-live-table-team=\"" + esc(row.at("team").at("id").get<std::string>()) + "\"" + (own ? " aria-current=\"true\"" : "") + ">" +
|
||||
live_text(std::to_string(row.at("position").get<int>()), "live-table-pos") +
|
||||
"<div class=\"live-table-team\">" + live_badge(row.at("team"), 48) + live_text(row.at("team").at("name")) + "</div>" +
|
||||
live_text(std::to_string(row.at("played").get<int>()), "live-table-number") +
|
||||
live_text(std::to_string(row.at("gf").get<int>()) + ":" + std::to_string(row.at("ga").get<int>()), "live-table-number live-table-goals") +
|
||||
live_text((difference > 0 ? "+" : "") + std::to_string(difference), "live-table-number") +
|
||||
live_text(std::to_string(row.at("points").get<int>()), "live-table-number") + "</div>";
|
||||
}
|
||||
return out + "</div>";
|
||||
}
|
||||
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");
|
||||
for (int i = 0; i < count; ++i) points.push_back(board.at("points")[size_t(i)]);
|
||||
return "<div class=\"live-context\"><h3>" + live_text("Aktuelle Demoaufstellung") + "</h3><p>" + live_text(std::to_string(count) + " Spieler auf dem Feld · unabhängige Manageransicht") + "</p><div class=\"live-pitch\">" +
|
||||
picture(renderer_.diagram("live-formation", lineup_mini(points, theme_), 1200), 1140, 684) + "</div>" +
|
||||
btn("live-intervene-tactics", "Taktik als Demo bearbeiten", "", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) +
|
||||
"<p>" + live_text("Die Vorschau verändert weder diese feste Ereignisfolge noch Spiel- oder Saisonwerte.") + "</p></div>";
|
||||
}
|
||||
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 = "<div class=\"live-context\"><h3>" + live_text(opponent.at("name")) + "</h3><p>" + live_text("Gegner dieser vorgegebenen Demopartie. Es werden keine unbekannten Gegneranweisungen behauptet.") + "</p></div>";
|
||||
}
|
||||
const std::array<std::pair<const char *, const char *>, 5> fields{{{"Tore", "score"}, {"Chancen", "chances"}, {"Gelbe Karten", "yellow"}, {"Rote Karten", "red"}, {"Spieler auf dem Feld", "players"}}};
|
||||
for (const auto &[label, key] : fields) {
|
||||
const auto &pair = score.at(key); const int a = pair[0], b = pair[1];
|
||||
const double percent = a + b ? 100.0 * a / (a + b) : 50;
|
||||
out += "<div class=\"live-stat\"><div class=\"live-stat-label\">" + live_text(std::to_string(a)) + live_text(label, "stat-title") + live_text(std::to_string(b)) +
|
||||
"</div><div class=\"live-stat-bar\"><div class=\"home\" style=\"width:" + scalar(percent) + "%;\"></div><div class=\"away\"></div></div></div>";
|
||||
}
|
||||
return out + "<p class=\"live-note\">" + live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>() + " · vorgegebene Demowerte") + "</p>";
|
||||
}
|
||||
std::string App::live_dialog_markup(const Json &owner) {
|
||||
if (live_dialog_.empty()) return "";
|
||||
const auto rows = live_owner_rows(owner);
|
||||
std::string body = "<h2 id=\"live-dialog-heading\">" + live_text(live_dialog_ == "lineup" ? "Aufstellung & Wechsel · Demo" : "Taktik · Demo") + "</h2><p>" + live_text("Nur lokale Vorschau für " + owner.at("name").get<std::string>() + " · " + owner.at("team").at("name").get<std::string>() + ". Keine Änderung an der Partie; der feste Spielverlauf bleibt unverändert.") + "</p>";
|
||||
if (live_dialog_ == "lineup") {
|
||||
std::vector<std::pair<std::string, std::string>> active, bench;
|
||||
for (size_t i = 0; i < rows.size(); ++i) (i < size_t(live_.fixture().at("field_count").get<int>()) ? active : bench).emplace_back(rows[i].at("id"), rows[i].at("name"));
|
||||
body += "<label for=\"live-player-out\">" + live_text("Vom Feld") + select("live-player-out", active, live_out_) + "</label><label for=\"live-player-in\">" + live_text("Von der Ersatzbank") + select("live-player-in", bench, live_in_) + "</label>";
|
||||
if (active.empty() || bench.empty()) body += "<p>" + live_text("Für diese Demokaderbasis ist kein Wechselpaar verfügbar.") + "</p>";
|
||||
} else {
|
||||
const std::array<const char *, 8> 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");
|
||||
for (size_t i = 0; i < names.size(); ++i)
|
||||
body += "<div class=\"live-tactic-row\">" + live_text(names[i]) + btn("live-tactic-cycle", "Wert " + std::to_string(values[i].get<int>()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "</div>";
|
||||
}
|
||||
body += "<div class=\"live-dialog-actions\">" + 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" : "")) + "</div>";
|
||||
return "<div class=\"live-dialog-layer\"><div id=\"live-dialog\" class=\"live-dialog\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"live-dialog-heading\">" + body + "</div></div>";
|
||||
}
|
||||
std::string App::render_live() {
|
||||
if (!live_.available()) return "";
|
||||
if (auto *node = element("live-ticker")) live_ticker_scroll_ = live_reset_ticker_ ? 0 : node->GetScrollTop();
|
||||
if (auto *node = element("live-detail-body")) live_detail_scroll_ = live_reset_detail_ ? 0 : node->GetScrollTop();
|
||||
live_reset_detail_ = live_reset_ticker_ = false;
|
||||
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<std::string>();
|
||||
const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? "Aufzeichnung läuft" : "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", "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\"><path d=\"" + std::string(right ? "M7 4l6 6-6 6" : "M13 4l-6 6 6 6") + "\" fill=\"none\" stroke=\"" + color + "\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", 72), 36, 36); };
|
||||
std::string out = "<section id=\"live-stage\" class=\"live-stage\" data-source=\"ui-demo-fixture\" data-fixture-id=\"" + esc(fixture.at("fixture_id").get<std::string>()) + "\"><header class=\"live-header\"><div>" + live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow") +
|
||||
"<h1>" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : "Gemeinsamer Spieltag") + "</h1></div>" + live_text("UI-Demo · vorgegebene Ergebnisse", "live-demo-tag") + "</header>";
|
||||
const auto scoreline = [&](const Json &match) {
|
||||
const auto &value = live_score_by_id(frame, match.at("id"));
|
||||
return "<div class=\"live-scoreline\">" + 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") + "</div>";
|
||||
};
|
||||
if (live_review_) {
|
||||
out += "<section class=\"live-review live-panel\"><h2>" + live_text("Die Demoaufzeichnung ist abgeschlossen.") + "</h2><p class=\"live-note\">" + live_text("Diese Ergebnisse und Berichte sind vorgegeben. Datum, Tabellen, Konten und Saisonfortschritt der Quelle wurden nicht verändert.") + "</p>";
|
||||
for (const auto &match : fixture.at("matches")) out += "<article class=\"live-review-card\" data-live-result=\"" + esc(match.at("id").get<std::string>()) + "\">" + scoreline(match) + "<p>" + live_text("1:0 · Führung der Heimelf | Halbzeit 1:0 | 1:1 · Ausgleich | 2:1 · Endstand nach " + std::to_string(fixture.at("duration").get<int>()) + " Minuten") + "</p></article>";
|
||||
out += "</section><footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", "Zum Desktop", "", "id=\"live-back\"") + "</div>" + live_text("Kein Saisonfortschritt · keine Spielwertänderung", "live-bottom-note") + btn("live-review-back", "Zum Ticker", "", "id=\"live-review-back\"") + "</footer></section>";
|
||||
return out;
|
||||
}
|
||||
out += "<div id=\"live-underlay\" class=\"live-body\"><div class=\"live-left\"><section class=\"live-panel live-overview\"><nav class=\"live-coverage\">";
|
||||
for (const auto &[id, text] : std::array<std::pair<const char *, const char *>, 3>{{{"all", "Alle Spiele"}, {"single", "Einzelspiel"}, {"conference", "Konferenz"}}})
|
||||
out += btn("live-coverage", text, live_coverage_ == id ? "selected" : "", "id=\"live-coverage-" + std::string(id) + "\" data-id=\"" + id + "\"");
|
||||
if (live_coverage_ == "single" && fixture.at("matches").size() > 1) out += btn("live-match-prev", arrow(false), "live-match-arrow", "id=\"live-match-prev\" aria-label=\"Vorherige Tickerpartie\"") + btn("live-match-next", arrow(true), "live-match-arrow", "id=\"live-match-next\" aria-label=\"Nächste Tickerpartie\"");
|
||||
out += live_text(std::to_string(minute) + ":00", "live-clock") + "</nav><div class=\"live-cards " + std::string(fixture.at("matches").size() == 1 || live_coverage_ == "single" ? "single" : "") + "\">";
|
||||
for (const auto &match : fixture.at("matches")) {
|
||||
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<std::string>(); }
|
||||
out += "<button data-action=\"live-match\" class=\"live-game " + std::string(match.at("id") == live_selected_match_ ? "active" : "") + "\" data-live-match=\"" + esc(match.at("id").get<std::string>()) + "\" data-id=\"" + esc(match.at("id").get<std::string>()) + "\">" + live_text(names, "live-owners") + scoreline(match) + live_text(std::to_string(minute) + "′ · " + (match.at("owners").size() > 1 ? "Zwei menschliche Manager" : "Eine menschliche Mannschaft"), "live-card-caption") + "</button>";
|
||||
}
|
||||
out += "</div></section><section class=\"live-panel live-ticker\"><header class=\"live-panel-heading\"><h2>" + live_text("Gemeinsamer Live-Ticker") + "</h2>" + live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small") + "</header><nav class=\"live-filters\">";
|
||||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 4>{{{"all", "Alles"}, {"highlights", "Highlights"}, {"goal", "Tore"}, {"yellow", "Karten"}}}) out += btn("live-filter", label, live_filter_ == id ? "selected" : "", "id=\"live-filter-" + std::string(id) + "\" data-id=\"" + id + "\"");
|
||||
out += "</nav><div id=\"live-ticker\" class=\"live-event-list\" tabindex=\"0\" aria-label=\"Gemeinsamer Ereignisverlauf\">";
|
||||
size_t shown = 0;
|
||||
for (auto i = frame.at("events").rbegin(); i != frame.at("events").rend(); ++i) {
|
||||
const auto &event = *i; const auto kind = event.value("kind", "");
|
||||
if (live_coverage_ == "single" && event.at("match_id") != live_selected_match_) continue;
|
||||
if (live_filter_ == "goal" && kind != "goal") continue;
|
||||
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red") continue;
|
||||
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "red") continue;
|
||||
const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id"));
|
||||
out += "<article class=\"live-event " + std::string(kind == "goal" ? "is-goal" : "") + "\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\">" + live_text(std::to_string(event.at("minute").get<int>()) + "′", "live-event-time") + live_badge(match.at(event.at("side").get<std::string>()), 54) +
|
||||
"<div class=\"live-event-copy\">" + live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>(), "live-event-owners") + "<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" + live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
|
||||
++shown;
|
||||
}
|
||||
if (!shown) out += "<p class=\"live-note\">" + live_text("Für diesen Filter liegt noch keine Demomeldung vor.") + "</p>";
|
||||
out += "</div><footer class=\"live-ticker-footer\">" + live_text(std::to_string(shown) + " Meldungen · feste Aufzeichnung", "live-small") + "<span id=\"live-phase-status\" class=\"live-small\">" + esc(phase_text) + "</span></footer></section></div><aside id=\"live-detail\" class=\"live-detail live-panel\"><header class=\"live-panel-heading\"><div class=\"live-detail-heading\"><h2>" + live_text(owner.at("team").at("name")) + "</h2><p>" + live_text(owner.at("name")) + "</p></div><nav class=\"live-team-switch\" aria-label=\"Managerdetails wechseln\">" +
|
||||
btn("live-owner-prev", arrow(false), "", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + btn("live-owner-next", arrow(true), "", "id=\"live-owner-next\" aria-label=\"Nächster Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + "</nav></header><nav class=\"live-tabs\">";
|
||||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", "Gegner"}, {"table", "Live-Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
|
||||
out += "</nav><div id=\"live-detail-body\" class=\"live-detail-body\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"live-detail-footer\">" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() ? "disabled" : "")) + "</footer></aside></div>";
|
||||
out += "<div class=\"live-speed\">" + live_text("+") + "<input id=\"live-speed\" type=\"range\" orientation=\"vertical\" min=\"0\" max=\"4\" step=\"1\" value=\"" + std::to_string(4 - live_.speed()) + "\" aria-label=\"Wiedergabegeschwindigkeit; unten Pause\" aria-valuenow=\"" + std::to_string(live_.speed()) + "\" " + (live_.finished() ? "disabled" : "") + "/><span id=\"live-speed-value\" class=\"live-speed-value\">" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "</span></div>";
|
||||
out += "<footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "</div><span id=\"live-playback-status\" class=\"live-bottom-note\">" + esc(live_feedback_.empty() ? std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung" : live_feedback_) + "</span>" +
|
||||
btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "</footer>";
|
||||
return out + live_dialog_markup(owner) + "</section>";
|
||||
}
|
||||
void App::live_after_render() {
|
||||
if (scene_ != "live" || !live_restore_scroll_) return;
|
||||
live_restore_scroll_ = false;
|
||||
if (auto *node = element("live-ticker")) node->SetScrollTop(live_ticker_scroll_);
|
||||
if (auto *node = element("live-detail-body")) node->SetScrollTop(live_detail_scroll_);
|
||||
if (!live_dialog_.empty()) {
|
||||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#live-underlay button,#live-speed,.live-bottom button");
|
||||
for (auto *node : controls) { node->SetProperty("pointer-events", "none"); node->SetAttribute("tabindex", "-1"); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
LivePlayback live_;
|
||||
Json live_drafts_ = Json::object(), live_dialog_draft_;
|
||||
std::string live_tab_ = "team", live_coverage_ = "all", live_filter_ = "all",
|
||||
live_selected_match_, live_dialog_, live_feedback_, live_out_, live_in_;
|
||||
uint64_t live_last_tick_ = 0;
|
||||
const DataSource *live_source_ = nullptr;
|
||||
std::shared_ptr<const Catalog> live_world_;
|
||||
int live_resume_speed_ = 0;
|
||||
bool live_speed_dragging_ = false, live_review_ = false,
|
||||
live_reset_detail_ = false, live_reset_ticker_ = false,
|
||||
live_restore_scroll_ = false;
|
||||
float live_ticker_scroll_ = 0, live_detail_scroll_ = 0;
|
||||
std::string render_live();
|
||||
std::string live_roster(const Json &owner);
|
||||
std::string live_detail(const Json &owner, const Json &frame);
|
||||
std::string live_dialog_markup(const Json &owner);
|
||||
std::string live_badge(const Json &, double);
|
||||
Json live_owner() const;
|
||||
Json live_owner_rows(const Json &) const;
|
||||
Json live_owner_state(const Json &) const;
|
||||
bool live_open();
|
||||
void live_close();
|
||||
bool live_action(const std::string &, Rml::Element *);
|
||||
bool live_event(Rml::Event &);
|
||||
void live_tick();
|
||||
void live_after_render();
|
||||
void live_set_speed(int);
|
||||
void live_dialog_close(bool);
|
||||
Json live_snapshot() const;
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
@@ -241,6 +242,9 @@ Json DemoSource::read_almanac(const Json &request) const {
|
||||
Json DemoSource::read_statistics(const Json &request) const {
|
||||
return demo_statistics(*catalog_, state_, request);
|
||||
}
|
||||
Json DemoSource::read_live(const Json &request) const {
|
||||
return query_demo_live(*catalog_, state_, revision_, request);
|
||||
}
|
||||
ActionResult DemoSource::apply(const Action &action) {
|
||||
if (action.revision != revision_)
|
||||
return {false, revision_, "stale_revision"};
|
||||
|
||||
@@ -37,6 +37,10 @@ public:
|
||||
virtual Json read_statistics(const Json &) const {
|
||||
return {{"ok", false}, {"error", "statistics_unavailable"}};
|
||||
}
|
||||
// Explicit authoritative adapter required; reading never starts a match.
|
||||
virtual Json read_live(const Json &) const {
|
||||
return {{"ok", false}, {"error", "live_unavailable"}};
|
||||
}
|
||||
};
|
||||
class DemoSource final : public DataSource {
|
||||
public:
|
||||
@@ -47,6 +51,7 @@ public:
|
||||
ActionResult apply(const Action &) override;
|
||||
Json read_almanac(const Json &) const override;
|
||||
Json read_statistics(const Json &) const override;
|
||||
Json read_live(const Json &) const override;
|
||||
void save(const fs::path &, const Json &desktop);
|
||||
Json load(const fs::path &);
|
||||
// UI continuation may retain the previous explicit-save clean baseline.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/demo_career_reports.hpp"
|
||||
@@ -449,6 +450,7 @@ class App final : public Rml::EventListener {
|
||||
#include "modern/ui/widgets_state.inc"
|
||||
#include "modern/ui/files_state.inc"
|
||||
#include "modern/ui/front_state.inc"
|
||||
#include "modern/ui/live_state.inc"
|
||||
std::map<std::string, std::string> selections_;
|
||||
Rml::Element *element(const std::string &id) const {
|
||||
return doc_->GetElementById(id);
|
||||
@@ -615,6 +617,9 @@ class App final : public Rml::EventListener {
|
||||
}
|
||||
void publish_world(std::shared_ptr<const Catalog> next,
|
||||
std::unique_ptr<DemoSource> demo) {
|
||||
live_.close(); live_drafts_ = Json::object(); live_dialog_.clear();
|
||||
live_dialog_draft_ = Json(); live_world_.reset(); live_source_ = nullptr;
|
||||
live_last_tick_ = 0; live_speed_dragging_ = false; live_review_ = false;
|
||||
reset_settings();
|
||||
reset_files();
|
||||
ticket_.reset();
|
||||
@@ -936,6 +941,8 @@ class App final : public Rml::EventListener {
|
||||
markup = render_desktop()+"<div class=\"fill\" style=\"z-index:100;\">"+render_career()+"</div>";
|
||||
else if (scene_ == "opening")
|
||||
markup = main_menu()+"<div class=\"fill\" style=\"z-index:100;\">"+render_opening()+"</div>";
|
||||
else if (scene_ == "live")
|
||||
markup = render_live();
|
||||
else if (source_)
|
||||
markup = render_desktop();
|
||||
if (!menu_.empty())
|
||||
@@ -1123,6 +1130,7 @@ class App final : public Rml::EventListener {
|
||||
if (menu_ == "settings") settings_after_render();
|
||||
files_after_render();
|
||||
front_after_render();
|
||||
live_after_render();
|
||||
if(menu_=="widgets" && widget_restore_scroll_){if(auto *gallery=element("widget-gallery"))gallery->SetScrollTop(widget_gallery_scroll_);widget_restore_scroll_=false;}
|
||||
if (!report_option_to_scroll_.empty()) {
|
||||
if (auto *node = element(report_option_to_scroll_))
|
||||
@@ -1385,6 +1393,7 @@ public:
|
||||
while (!closed_) {
|
||||
front_poll();
|
||||
opening_tick();
|
||||
live_tick();
|
||||
if (needs_render_ || dirty_)
|
||||
frame();
|
||||
SDL_Event event;
|
||||
@@ -1455,6 +1464,8 @@ public:
|
||||
#include "modern/ui/news_controls.inc"
|
||||
#include "modern/ui/settings_screens.inc"
|
||||
#include "modern/ui/settings_controls.inc"
|
||||
#include "modern/ui/live_screens.inc"
|
||||
#include "modern/ui/live_controls.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user