Add read-only Almanac desktop and match history views (by Codex)
This commit is contained in:
1 parent
af60e499a2
commit
d42c855843
29 files changed
+2009
-35
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 gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.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 STATIC view.cpp ticket_popover.cpp)
|
||||
@@ -14,7 +14,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)
|
||||
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)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
file(GLOB modern_icons CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/icons/*.svg")
|
||||
@@ -47,6 +47,12 @@ if(MSVC)
|
||||
target_compile_options(modern_planning_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME modern_planning_tests COMMAND modern_planning_tests)
|
||||
add_executable(modern_almanac_ui_tests ../../../tests/modern_almanac_ui_tests.cpp)
|
||||
target_link_libraries(modern_almanac_ui_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
target_compile_options(modern_almanac_ui_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME modern_almanac_ui_tests COMMAND modern_almanac_ui_tests)
|
||||
add_executable(modern_reports_tests ../../../tests/modern_reports_tests.cpp)
|
||||
target_link_libraries(modern_reports_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::almanac_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("alm-")) return false;
|
||||
if (menu_ != "almanac" || !source_) return true;
|
||||
const auto id = target ? target->GetAttribute<Rml::String>("data-id", "") : "";
|
||||
if (action == "alm-year-cancel" || (action == "alm-back" && report_picker_ == "year")) {
|
||||
close_report_picker(true);
|
||||
return true;
|
||||
}
|
||||
if (action == "alm-back") {
|
||||
if (!almanac_match_.empty()) {
|
||||
focus_after_render_ = "alm-match-" + almanac_match_;
|
||||
almanac_match_.clear();
|
||||
} else if (!almanac_day_.empty()) {
|
||||
focus_after_render_ = "alm-day-" + almanac_day_;
|
||||
almanac_day_.clear();
|
||||
} else {
|
||||
menu_.clear();
|
||||
focus_after_render_ = "object-app-almanac";
|
||||
}
|
||||
} else if (action == "alm-day") {
|
||||
const auto result = source_->read_almanac({{"kind", "day"}, {"date", id}});
|
||||
if (!result.value("ok", false) || result.at("matches").empty()) return true;
|
||||
almanac_day_ = id;
|
||||
almanac_match_.clear();
|
||||
focus_after_render_ = "alm-heading";
|
||||
} else if (action == "alm-match") {
|
||||
const auto result = source_->read_almanac({{"kind", "match"}, {"id", id}});
|
||||
if (!result.value("ok", false) || result.at("match").at("date") != almanac_day_) return true;
|
||||
almanac_match_ = id;
|
||||
almanac_tab_ = "lineups";
|
||||
focus_after_render_ = "alm-heading";
|
||||
} else if (action == "alm-tab") {
|
||||
if (almanac_match_.empty() || (id != "lineups" && id != "events")) return true;
|
||||
almanac_tab_ = id;
|
||||
focus_after_render_ = "alm-tab-" + id;
|
||||
} else return false;
|
||||
close_report_picker(false);
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
const Json &almanac_field(const Json &object, const char *key) {
|
||||
static const Json absent;
|
||||
if (object.is_object()) {
|
||||
const auto found = object.find(key);
|
||||
if (found != object.end())
|
||||
return *found;
|
||||
}
|
||||
return absent;
|
||||
}
|
||||
std::string almanac_text(const Json &value, const std::string &fallback = "—") {
|
||||
return value.is_string() && !value.get_ref<const std::string &>().empty()
|
||||
? value.get<std::string>() : fallback;
|
||||
}
|
||||
std::string almanac_name(const Json &person) {
|
||||
return almanac_text(almanac_field(person, "name"));
|
||||
}
|
||||
bool almanac_flag(const Json &object, const char *key) {
|
||||
const auto &value = almanac_field(object, key);
|
||||
return value.is_boolean() && value.get<bool>();
|
||||
}
|
||||
std::string almanac_number(const Json &value) {
|
||||
return value.is_number_integer() ? number(value.get<int64_t>()) : "—";
|
||||
}
|
||||
std::string almanac_score(const Json &value) {
|
||||
return value.is_array() && value.size() == 2 &&
|
||||
value[0].is_number_integer() && value[1].is_number_integer()
|
||||
? std::to_string(value[0].get<int>()) + " : " +
|
||||
std::to_string(value[1].get<int>()) : "—";
|
||||
}
|
||||
std::optional<std::array<int, 3>> almanac_date_parts(const Json &value) {
|
||||
if (!value.is_string())
|
||||
return {};
|
||||
const auto text = value.get<std::string>();
|
||||
if (text.size() != 10 || text[4] != '-' || text[7] != '-')
|
||||
return {};
|
||||
for (size_t i = 0; i < text.size(); ++i)
|
||||
if (i != 4 && i != 7 && (text[i] < '0' || text[i] > '9'))
|
||||
return {};
|
||||
const std::array<int, 3> date = {std::stoi(text.substr(0, 4)),
|
||||
std::stoi(text.substr(5, 2)),
|
||||
std::stoi(text.substr(8, 2))};
|
||||
if (!std::chrono::year_month_day{std::chrono::year{date[0]},
|
||||
std::chrono::month{unsigned(date[1])},
|
||||
std::chrono::day{unsigned(date[2])}}.ok())
|
||||
return {};
|
||||
return date;
|
||||
}
|
||||
const std::array<const char *, 12> almanac_months = {
|
||||
"Januar", "Februar", "März", "April", "Mai", "Juni",
|
||||
"Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
std::string almanac_date_label(const Json &value) {
|
||||
const auto date = almanac_date_parts(value);
|
||||
return date ? std::to_string((*date)[2]) + ". " +
|
||||
almanac_months[size_t((*date)[1] - 1)] + " " +
|
||||
std::to_string((*date)[0]) : "—";
|
||||
}
|
||||
std::string almanac_iso(int year, int month, int day) {
|
||||
std::ostringstream out;
|
||||
out << std::setfill('0') << std::setw(4) << year << '-' << std::setw(2)
|
||||
<< month << '-' << std::setw(2) << day;
|
||||
return out.str();
|
||||
}
|
||||
std::string almanac_position(const Json &player) {
|
||||
const auto value = almanac_text(almanac_field(player, "position"));
|
||||
return value == "gk" ? "TW" : value == "def" ? "ABW"
|
||||
: value == "mid" ? "MIT" : value == "fwd" ? "STU" : value;
|
||||
}
|
||||
std::string almanac_competition_label(const Json &record) {
|
||||
const auto &competition = almanac_field(record, "competition");
|
||||
return almanac_name(competition) + " · " +
|
||||
almanac_number(almanac_field(record, "round")) + ". " +
|
||||
(almanac_text(almanac_field(competition, "type"), "") == "league"
|
||||
? "Spieltag" : "Runde");
|
||||
}
|
||||
std::string almanac_event_kind(const std::string &kind) {
|
||||
if (kind == "goal") return "Tor";
|
||||
if (kind == "miss") return "Fehlschuss";
|
||||
if (kind == "yellow") return "Gelbe Karte";
|
||||
if (kind == "second_yellow") return "Gelb-Rote Karte";
|
||||
if (kind == "red") return "Rote Karte";
|
||||
if (kind == "injury") return "Verletzung";
|
||||
if (kind == "substitution") return "Wechsel";
|
||||
if (kind == "shootout") return "Elfmeterschießen";
|
||||
return "Ereignis";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string App::render_almanac() {
|
||||
const auto query = [&](const Json &request) -> Json {
|
||||
try {
|
||||
return source_ ? source_->read_almanac(request)
|
||||
: Json{{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
} catch (const std::exception &) {
|
||||
return {{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
}
|
||||
};
|
||||
const auto index = query({{"kind", "index"}});
|
||||
const bool available = almanac_flag(index, "ok");
|
||||
std::vector<int> years;
|
||||
const auto &year_values = almanac_field(index, "years");
|
||||
if (available && year_values.is_array())
|
||||
for (const auto &value : year_values)
|
||||
if (value.is_number_integer() && value >= 1 && value <= 9999)
|
||||
years.push_back(value.get<int>());
|
||||
std::sort(years.begin(), years.end());
|
||||
years.erase(std::unique(years.begin(), years.end()), years.end());
|
||||
const auto snapshot = snap();
|
||||
const auto &reference = almanac_field(snapshot.state, "date");
|
||||
const auto date = almanac_date_parts(reference);
|
||||
if (almanac_year_ == 0 ||
|
||||
std::find(years.begin(), years.end(), almanac_year_) == years.end()) {
|
||||
almanac_year_ = years.empty() ? (date ? (*date)[0] : 0) : years.back();
|
||||
almanac_day_.clear();
|
||||
almanac_match_.clear();
|
||||
almanac_tab_ = "lineups";
|
||||
}
|
||||
if (almanac_tab_ != "lineups" && almanac_tab_ != "events")
|
||||
almanac_tab_ = "lineups";
|
||||
if (!almanac_day_.empty()) {
|
||||
const auto selected = almanac_date_parts(almanac_day_);
|
||||
if (!selected || (*selected)[0] != almanac_year_) {
|
||||
almanac_day_.clear();
|
||||
almanac_match_.clear();
|
||||
}
|
||||
}
|
||||
Json record;
|
||||
if (!almanac_match_.empty()) {
|
||||
const auto response = query({{"kind", "match"}, {"id", almanac_match_}});
|
||||
if (almanac_flag(response, "ok") && almanac_field(response, "match").is_object())
|
||||
record = response.at("match");
|
||||
else {
|
||||
almanac_match_.clear();
|
||||
almanac_tab_ = "lineups";
|
||||
}
|
||||
}
|
||||
const bool detail = record.is_object(), day_view = !almanac_day_.empty();
|
||||
const auto title = detail ? almanac_competition_label(record)
|
||||
: day_view ? almanac_date_label(almanac_day_)
|
||||
: "Spielarchiv" + (almanac_year_ ? " · " + std::to_string(almanac_year_) : "");
|
||||
const auto crest_image = [&](const Json &team, double size) {
|
||||
const auto &key = almanac_field(team, "crest");
|
||||
return "<div class=\"alm-crest\" style=\"width:" + scalar(size) +
|
||||
"dp;height:" + scalar(size) + "dp;\">" +
|
||||
(key.is_string() && !key.get_ref<const std::string &>().empty()
|
||||
? img(key.get<std::string>(), size, size, true)
|
||||
: "<span class=\"alm-no-crest\">—</span>") + "</div>";
|
||||
};
|
||||
const auto team_label = [&](const Json &team, bool home) {
|
||||
const auto label = "<span class=\"alm-team-name\" title=\"" +
|
||||
esc(almanac_name(team)) + "\">" + esc(almanac_name(team)) + "</span>";
|
||||
return "<div class=\"alm-team " + std::string(home ? "alm-team-home" : "alm-team-away") +
|
||||
"\">" + (home ? label + crest_image(team, 42)
|
||||
: crest_image(team, 42) + label) + "</div>";
|
||||
};
|
||||
std::string output = "<div class=\"almanac\"><nav class=\"alm-toolbar\" aria-label=\"Archivnavigation\">" +
|
||||
btn("alm-back", "<span>‹ " + std::string(detail ? "Tagespaarungen" : day_view ? "Jahreskalender" : "Desktop") +
|
||||
"</span>", "alm-control alm-back", "id=\"alm-back\"") +
|
||||
"<h2 id=\"alm-heading\" class=\"alm-heading\" tabindex=\"-1\" style=\"tab-index:auto;\">" + esc(title) + "</h2>";
|
||||
if (!detail && !day_view)
|
||||
output += report_picker("year", 2192, 420);
|
||||
else
|
||||
output += "<div class=\"alm-year-context\"><span>" +
|
||||
std::to_string(almanac_year_) + "</span></div>";
|
||||
output += "</nav><div id=\"almanac-underlay\" class=\"alm-underlay\">";
|
||||
|
||||
Json day_response;
|
||||
if (!detail && day_view) {
|
||||
day_response = query({{"kind", "day"}, {"date", almanac_day_}});
|
||||
output += "<div id=\"alm-day-list\" class=\"alm-day-list\">"
|
||||
"<div class=\"alm-list-head\"><div class=\"alm-row-home\"><span>Heim</span></div>"
|
||||
"<div class=\"alm-row-score\"><span>Ergebnis</span></div><div class=\"alm-row-away\"><span>Auswärts</span></div></div>";
|
||||
const auto &matches = almanac_field(day_response, "matches");
|
||||
if (matches.is_array())
|
||||
for (size_t i = 0; i < matches.size(); ++i) {
|
||||
const auto &match = matches[i], &result = almanac_field(match, "result");
|
||||
const auto id = almanac_text(almanac_field(match, "id"), "");
|
||||
const bool penalties = almanac_flag(result, "penalties_played"), extra = almanac_flag(result, "extra_played");
|
||||
const auto description = almanac_name(almanac_field(match, "home")) + " " +
|
||||
almanac_score(almanac_field(result, "final")) + " " +
|
||||
almanac_name(almanac_field(match, "away")) + " · Spielbericht öffnen";
|
||||
output += btn("alm-match",
|
||||
"<div class=\"alm-match-main\"><div class=\"alm-row-home\">" +
|
||||
team_label(almanac_field(match, "home"), true) + "</div>"
|
||||
"<div class=\"alm-row-score alm-list-score\"><span class=\"alm-list-score-value\">" +
|
||||
esc(almanac_score(almanac_field(result, penalties ? "penalties" : "final"))) +
|
||||
"</span><span class=\"alm-list-score-phase\">" +
|
||||
(penalties ? "i. E." : extra ? "n. V." : "") + "</span></div>"
|
||||
"<div class=\"alm-row-away\">" + team_label(almanac_field(match, "away"), false) +
|
||||
"</div></div><div class=\"alm-match-meta\"><span>" +
|
||||
esc(almanac_competition_label(match) + " · Saison " +
|
||||
almanac_text(almanac_field(match, "season"))) + "</span></div>",
|
||||
"alm-match-row " + std::string(i % 2 == 0 ? "striped" : ""),
|
||||
"id=\"alm-match-" + esc(id) + "\" data-id=\"" + esc(id) +
|
||||
"\" aria-label=\"" + esc(description) + "\"");
|
||||
}
|
||||
if (!matches.is_array() || matches.empty())
|
||||
output += "<p class=\"alm-empty\">Keine gespielten Partien an diesem Tag.</p>";
|
||||
output += "</div>";
|
||||
} else if (!detail) {
|
||||
output += "<div class=\"alm-calendar\">";
|
||||
Json days = Json::array();
|
||||
if (available && almanac_year_) {
|
||||
const auto calendar = query({{"kind", "calendar"}, {"year", almanac_year_}});
|
||||
if (almanac_flag(calendar, "ok") && almanac_field(calendar, "days").is_array())
|
||||
days = calendar.at("days");
|
||||
}
|
||||
constexpr double month_width = 635, month_height = 1550.0 / 3;
|
||||
if (almanac_year_ >= 1 && almanac_year_ <= 9999)
|
||||
for (int month = 1; month <= 12; ++month) {
|
||||
const int column = (month - 1) % 4, row = (month - 1) / 4;
|
||||
const auto first = std::chrono::year{almanac_year_} / std::chrono::month{unsigned(month)} / 1;
|
||||
const int offset = int(std::chrono::weekday{std::chrono::sys_days{first}}.iso_encoding()) - 1;
|
||||
const int count = int(unsigned(std::chrono::year_month_day{
|
||||
std::chrono::sys_days{std::chrono::year{almanac_year_} /
|
||||
std::chrono::month{unsigned(month)} / std::chrono::last}}.day()));
|
||||
constexpr double grid_width = 599;
|
||||
const double grid_height = month_height - 86, cell_height = grid_height / 7;
|
||||
constexpr double cell_width = (grid_width - 65) / 6;
|
||||
output += "<section class=\"alm-month\" style=\"" +
|
||||
rect(column * 659, row * (month_height + 24), month_width, month_height) +
|
||||
"\"><h3>" + almanac_months[size_t(month - 1)] + "</h3>"
|
||||
"<div class=\"alm-month-grid\" style=\"width:599dp;height:" + scalar(grid_height) + "dp;\">";
|
||||
const std::array<const char *, 7> weekdays = {"MO", "DI", "MI", "DO", "FR", "SA", "SO"};
|
||||
for (int weekday = 0; weekday < 7; ++weekday) {
|
||||
output += "<div class=\"alm-weekday " + std::string(weekday == 6 ? "sunday" : "") +
|
||||
"\" style=\"" + rect(0, weekday * cell_height, 65, cell_height) +
|
||||
"\"><span>" + weekdays[size_t(weekday)] + "</span></div>";
|
||||
for (int week = 0; week < 6; ++week) {
|
||||
const int day = week * 7 + weekday - offset + 1;
|
||||
if (day < 1 || day > count)
|
||||
continue;
|
||||
const auto iso = almanac_iso(almanac_year_, month, day);
|
||||
const auto found = std::find_if(days.begin(), days.end(), [&](const auto &entry) {
|
||||
return almanac_field(entry, "date") == iso;
|
||||
});
|
||||
const bool played = found != days.end() &&
|
||||
almanac_field(*found, "count").is_number_integer() &&
|
||||
found->at("count").get<int>() > 0;
|
||||
const auto style = rect(65 + week * cell_width, weekday * cell_height, cell_width, cell_height);
|
||||
const auto text = "<span class=\"alm-day-text\">" + std::to_string(day) + "</span>";
|
||||
if (played)
|
||||
output += btn("alm-day", text, "alm-day played",
|
||||
"id=\"alm-day-" + iso + "\" data-id=\"" + iso + "\" style=\"" + style +
|
||||
"\" aria-label=\"" + esc(almanac_date_label(iso) + ", " +
|
||||
almanac_number(found->at("count")) + " gespielte Partien") + "\"");
|
||||
else {
|
||||
const bool future = reference.is_string() && iso > reference.get<std::string>();
|
||||
output += "<div class=\"alm-day " + std::string(future ? "future" : "") +
|
||||
"\" style=\"" + style + "\">" + text + "</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
output += "</div></section>";
|
||||
}
|
||||
else
|
||||
output += "<p class=\"alm-empty\">Keine gespielten Partien im Archiv.</p>";
|
||||
output += "</div>";
|
||||
} else {
|
||||
const auto &result = almanac_field(record, "result"), &weather = almanac_field(record, "weather");
|
||||
const bool extra = almanac_flag(result, "extra_played"), penalties = almanac_flag(result, "penalties_played");
|
||||
const auto phase = std::string(extra ? "Nach Verlängerung" : "Nach regulärer Spielzeit") +
|
||||
(penalties ? " · Entscheidung i. E." : "");
|
||||
std::string phases = "Reguläre Zeit: " + almanac_score(almanac_field(result, "regulation"));
|
||||
if (extra) phases += " · Verlängerung: " + almanac_score(almanac_field(result, "extra"));
|
||||
if (penalties) phases += " · i. E.: " + almanac_score(almanac_field(result, "penalties"));
|
||||
output += "<section class=\"alm-summary\"><div class=\"alm-summary-teams\">";
|
||||
const auto summary_team = [&](const char *side, const std::string &css) {
|
||||
const auto &team = almanac_field(record, side), &manager = almanac_field(team, "manager");
|
||||
const auto manager_name = manager.is_null() ? std::string("Computer") : almanac_name(manager);
|
||||
return "<div class=\"alm-summary-team " + css + "\">" + crest_image(team, 80) +
|
||||
"<span class=\"alm-summary-team-name\" title=\"" + esc(almanac_name(team)) + "\">" +
|
||||
esc(almanac_name(team)) + "</span><span class=\"alm-summary-manager\">Manager: " +
|
||||
esc(manager_name) + "</span></div>";
|
||||
};
|
||||
output += summary_team("home", "home") +
|
||||
"<div class=\"alm-summary-result\"><span class=\"alm-summary-score\">" +
|
||||
esc(almanac_score(almanac_field(result, "final"))) +
|
||||
"</span><span class=\"alm-summary-phase\">" + esc(phase) +
|
||||
"</span><span class=\"alm-summary-phases\">" + esc(phases) + "</span></div>" +
|
||||
summary_team("away", "away") + "</div><div class=\"alm-match-facts\">";
|
||||
const std::vector<std::pair<std::string, std::string>> facts = {
|
||||
{"Schiedsrichter", almanac_text(almanac_field(record, "referee"))},
|
||||
{"Zuschauer", almanac_number(almanac_field(record, "attendance"))},
|
||||
{"Temperatur", almanac_number(almanac_field(weather, "temperature")) +
|
||||
(almanac_field(weather, "temperature").is_number_integer() ? " °C" : "")},
|
||||
{"Regen", almanac_number(almanac_field(weather, "rain")) +
|
||||
(almanac_field(weather, "rain").is_number_integer() ? " / 7" : "")}};
|
||||
for (const auto &[label, value] : facts)
|
||||
output += "<div class=\"alm-match-fact\"><span class=\"alm-fact-label\">" + esc(label) +
|
||||
"</span><span class=\"alm-fact-value\">" + esc(value) + "</span></div>";
|
||||
output += "</div></section><nav class=\"alm-tabs\" role=\"tablist\" aria-label=\"Spielbericht\">";
|
||||
for (const auto &[key, label] :
|
||||
std::array<std::pair<std::string, std::string>, 2>{{{"lineups", "Aufstellungen"}, {"events", "Ereignisse"}}})
|
||||
output += btn("alm-tab", "<span>" + label + "</span>",
|
||||
"alm-tab " + std::string(almanac_tab_ == key ? "selected" : ""),
|
||||
"id=\"alm-tab-" + key + "\" data-id=\"" + key +
|
||||
"\" role=\"tab\" aria-selected=\"" + (almanac_tab_ == key ? "true" : "false") +
|
||||
"\" aria-controls=\"alm-detail-content\"");
|
||||
output += "</nav><div id=\"alm-detail-content\" class=\"alm-detail-content\" role=\"tabpanel\" "
|
||||
"aria-labelledby=\"alm-tab-" + almanac_tab_ + "\">";
|
||||
if (almanac_tab_ == "lineups") {
|
||||
output += "<div class=\"alm-lineups\">";
|
||||
for (const auto *side : {"home", "away"}) {
|
||||
const auto &team = almanac_field(record, side), &lineup = almanac_field(almanac_field(record, "lineups"), side);
|
||||
// Both roster headings read left-to-right. Pairing rows alone mirror the home label.
|
||||
output += "<section class=\"alm-lineup\"><header>" + team_label(team, false) + "</header>";
|
||||
if (!lineup.is_object())
|
||||
output += "<p class=\"alm-empty\">Keine Aufstellung überliefert.</p>";
|
||||
else
|
||||
for (const auto *part : {"starters", "bench"}) {
|
||||
output += "<h3>" + std::string(std::string_view(part) == "starters" ? "Startelf" : "Bank") + "</h3>";
|
||||
const auto &players = almanac_field(lineup, part);
|
||||
if (players.is_array())
|
||||
for (size_t i = 0; i < players.size(); ++i) {
|
||||
const auto &player = players[i];
|
||||
output += "<div class=\"alm-player\"><span class=\"alm-player-number\">" +
|
||||
std::to_string(i + (std::string_view(part) == "starters" ? 1 : 12)) +
|
||||
"</span><span class=\"alm-position\">" + esc(almanac_position(player)) +
|
||||
"</span><span class=\"alm-player-name\" title=\"" + esc(almanac_name(player)) +
|
||||
"\">" + esc(almanac_name(player)) + "</span></div>";
|
||||
}
|
||||
}
|
||||
output += "</section>";
|
||||
}
|
||||
output += "</div>";
|
||||
} else {
|
||||
std::vector<Json> events;
|
||||
const auto &source_events = almanac_field(record, "events");
|
||||
if (source_events.is_array())
|
||||
for (const auto &event : source_events) events.push_back(event);
|
||||
std::stable_sort(events.begin(), events.end(), [](const Json &a, const Json &b) {
|
||||
const auto &am = almanac_field(a, "minute"), &bm = almanac_field(b, "minute");
|
||||
return (am.is_number_integer() ? am.get<int>() : 0) <
|
||||
(bm.is_number_integer() ? bm.get<int>() : 0);
|
||||
});
|
||||
output += "<div class=\"alm-events\" role=\"list\">";
|
||||
int kick = 0;
|
||||
const std::array<const char *, 4> goal_types = {"Spiel", "Elfmeter/Freistoß", "Nachschuss", "Ecke"};
|
||||
for (size_t i = 0; i < events.size(); ++i) {
|
||||
const auto &event = events[i];
|
||||
const auto kind = almanac_text(almanac_field(event, "kind"), "");
|
||||
const auto side = almanac_text(almanac_field(event, "side"), "");
|
||||
const auto player = almanac_name(almanac_field(event, "player"));
|
||||
const auto other = almanac_name(almanac_field(event, "other"));
|
||||
const auto &value = almanac_field(event, "detail");
|
||||
const int detail_value = value.is_number_integer() ? value.get<int>() : -1;
|
||||
std::string description = player;
|
||||
if (kind == "shootout")
|
||||
description = std::string(detail_value == 1 ? "Treffer" : detail_value == 0 ? "Fehlversuch" : "—") + " · " + player;
|
||||
else if (kind == "substitution")
|
||||
description = "Ein: " + player + " · Aus: " + other;
|
||||
else if (kind == "goal" || kind == "miss")
|
||||
description = player + " · " + (kind == "miss" ? "Zuspiel" : "Vorlage") + ": " + other +
|
||||
" · " + (detail_value >= 0 && detail_value < 4 ? goal_types[size_t(detail_value)] : "—");
|
||||
const auto minute = kind == "shootout" ? "i. E. · " + std::to_string(++kick)
|
||||
: almanac_number(almanac_field(event, "minute")) + "′";
|
||||
const auto team = side == "home" || side == "away"
|
||||
? almanac_name(almanac_field(record, side.c_str())) : "—";
|
||||
output += "<div class=\"alm-event " + esc(kind) + (i % 2 == 0 ? " striped" : "") +
|
||||
"\" role=\"listitem\"><span class=\"alm-event-minute\">" + esc(minute) +
|
||||
"</span><span class=\"alm-event-team\" title=\"" + esc(team) + "\">" + esc(team) +
|
||||
"</span><div class=\"alm-event-description\"><span class=\"alm-event-kind\">" +
|
||||
almanac_event_kind(kind) + "</span><span class=\"alm-event-text\">" + esc(description) + "</span></div></div>";
|
||||
}
|
||||
if (events.empty())
|
||||
output += "<p class=\"alm-empty\">Keine Ereignisse überliefert.</p>";
|
||||
output += "</div>";
|
||||
}
|
||||
output += "</div>";
|
||||
}
|
||||
std::string footer;
|
||||
if (detail)
|
||||
footer = almanac_date_label(almanac_field(record, "date")) + " · Saison " +
|
||||
almanac_text(almanac_field(record, "season"));
|
||||
else if (day_view) {
|
||||
const auto &matches = almanac_field(day_response, "matches");
|
||||
footer = std::to_string(matches.is_array() ? matches.size() : 0) + " gespielte Partien";
|
||||
} else if (!available)
|
||||
footer = "Almanach derzeit nicht verfügbar.";
|
||||
else if (years.empty())
|
||||
footer = "Keine gespielten Partien im Archiv";
|
||||
else
|
||||
footer = almanac_number(almanac_field(index, "match_count")) + " Partien · " +
|
||||
std::to_string(years.front()) + "–" + std::to_string(years.back());
|
||||
output += "<footer class=\"alm-footer\"><div class=\"alm-key\"><span class=\"alm-key-marker\"></span>"
|
||||
"<span>Gespielte Partien</span></div><span class=\"alm-footer-info\">" + esc(footer) + "</span></footer></div>";
|
||||
if (report_picker_ == "year")
|
||||
output += btn("alm-year-cancel", "", "alm-picker-shield", "id=\"alm-year-shield\" aria-label=\"Jahresauswahl schließen\"");
|
||||
return output + "</div>";
|
||||
}
|
||||
@@ -187,6 +187,32 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
}
|
||||
} else if (report_detail_kind_.empty() && planning_dialog_.empty() && popup_.empty() && report_picker_event(event))
|
||||
return;
|
||||
if (menu_ == "almanac" && popup_.empty() && report_picker_.empty()) {
|
||||
const auto key = type == "keydown" ? Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0)) : Rml::Input::KI_UNKNOWN;
|
||||
if (key == Rml::Input::KI_ESCAPE || (type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
|
||||
almanac_action("alm-back", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB && context_->GetFocusElement() &&
|
||||
context_->GetFocusElement()->GetId() == "alm-heading") {
|
||||
auto *next = event.GetParameter<int>("shift_key", 0) ? element("alm-back")
|
||||
: !almanac_match_.empty() ? element("alm-tab-lineups")
|
||||
: doc_->QuerySelector("#alm-day-list .alm-match-row");
|
||||
if (!next) next = element("alm-back");
|
||||
if (next) next->Focus(true);
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
if (type == "keydown" && !almanac_match_.empty() && event.GetTargetElement()->GetId().starts_with("alm-tab-") &&
|
||||
(key == Rml::Input::KI_LEFT || key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_HOME || key == Rml::Input::KI_END)) {
|
||||
almanac_tab_ = key == Rml::Input::KI_HOME ? "lineups" : key == Rml::Input::KI_END ? "events" : almanac_tab_ == "lineups" ? "events" : "lineups";
|
||||
focus_after_render_ = "alm-tab-" + almanac_tab_;
|
||||
refresh();
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (menu_ == "friendlies" && planning_dialog_.empty() && popup_.empty() &&
|
||||
snap().state.at("calendar").at("friendly_stage") == 1 &&
|
||||
((type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) ||
|
||||
@@ -362,7 +388,8 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
controls[size_t(next)]->Focus(true);
|
||||
if (controls[size_t(next)]->GetId().starts_with("report-detail-player-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("report-club-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("friendly-opponent-"))
|
||||
controls[size_t(next)]->GetId().starts_with("friendly-opponent-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("alm-match-"))
|
||||
controls[size_t(next)]->ScrollIntoView(
|
||||
Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
event.StopImmediatePropagation();
|
||||
@@ -402,7 +429,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (planning_action(action, target) || indoor_action(action, target)) return;
|
||||
if (almanac_action(action, target) || planning_action(action, target) || indoor_action(action, target)) return;
|
||||
if (report_detail_action(action, target)) {
|
||||
close_report_picker(false);
|
||||
return;
|
||||
@@ -589,8 +616,8 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto file =
|
||||
user_dir() / "layouts" / editor::path(selections_["view"] + ".json");
|
||||
auto next = Json::parse(editor::read_file(file));
|
||||
if (!valid_desktop(next))
|
||||
throw editor::Error("Ungültige Desktopansicht.");
|
||||
if (!migrate_desktop(next))
|
||||
throw editor::Error("Ungültige Desktopansicht oder kein freier Platz für den Almanach.");
|
||||
undo_.push_back(desktop_);
|
||||
desktop_ = std::move(next);
|
||||
menu_.clear();
|
||||
@@ -1013,7 +1040,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
static const std::set<std::string> available = {
|
||||
"tables", "strengths", "camp", "settings",
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor"};
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac"};
|
||||
if (!available.contains(route)) {
|
||||
message("Diese native Ansicht wird im nächsten Menüpaket übertragen.");
|
||||
return;
|
||||
@@ -1393,6 +1420,10 @@ void App::script() {
|
||||
{"menu", menu_},
|
||||
{"report_picker", report_picker_},
|
||||
{"planning_dialog", planning_dialog_},
|
||||
{"source_revision", source_ ? Json(snap().revision) : Json()},
|
||||
{"game_dirty", source_ && source_->dirty()},
|
||||
{"desktop_dirty", desktop_ != saved_desktop_},
|
||||
{"almanac_view", {{"year", almanac_year_}, {"date", almanac_day_}, {"id", almanac_match_}, {"tab", almanac_tab_}}},
|
||||
{"report_detail", {{"kind", report_detail_kind_},
|
||||
{"club", report_detail_club_},
|
||||
{"player", report_detail_player_}}},
|
||||
|
||||
@@ -0,0 +1,435 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
bool keys(const Json &v, std::initializer_list<const char *> required,
|
||||
std::initializer_list<const char *> optional = {}) {
|
||||
if (!v.is_object()) return false;
|
||||
std::set<std::string> allowed;
|
||||
for (auto *key : required) {
|
||||
if (!v.contains(key)) return false;
|
||||
allowed.emplace(key);
|
||||
}
|
||||
for (auto *key : optional) allowed.emplace(key);
|
||||
for (const auto &entry : v.items())
|
||||
if (!allowed.contains(entry.key())) return false;
|
||||
return true;
|
||||
}
|
||||
bool integer(const Json &v, int lo, int hi) {
|
||||
if (v.is_number_unsigned())
|
||||
return hi >= 0 && v.get<uint64_t>() <= uint64_t(hi) &&
|
||||
(lo <= 0 || v.get<uint64_t>() >= uint64_t(lo));
|
||||
return v.is_number_integer() && v.get<int64_t>() >= lo && v.get<int64_t>() <= hi;
|
||||
}
|
||||
bool text(const Json &v, bool nonempty = true) {
|
||||
return v.is_string() && (!nonempty || !v.get_ref<const std::string &>().empty());
|
||||
}
|
||||
bool date(const std::string &iso) {
|
||||
if (iso.size() != 10 || iso[4] != '-' || iso[7] != '-') return false;
|
||||
for (size_t i = 0; i < iso.size(); ++i)
|
||||
if (i != 4 && i != 7 && (iso[i] < '0' || iso[i] > '9')) return false;
|
||||
const auto y = std::stoi(iso.substr(0, 4)), m = std::stoi(iso.substr(5, 2)),
|
||||
d = std::stoi(iso.substr(8, 2));
|
||||
return y >= 1 && std::chrono::year_month_day{std::chrono::year{y},
|
||||
std::chrono::month{unsigned(m)}, std::chrono::day{unsigned(d)}}.ok();
|
||||
}
|
||||
std::string iso(int year, int month, int day) {
|
||||
std::ostringstream out;
|
||||
out.imbue(std::locale::classic());
|
||||
out << std::setfill('0') << std::setw(4) << year << '-' << std::setw(2)
|
||||
<< month << '-' << std::setw(2) << day;
|
||||
return out.str();
|
||||
}
|
||||
std::string season(int year) {
|
||||
std::ostringstream out;
|
||||
out.imbue(std::locale::classic());
|
||||
out << std::setfill('0') << std::setw(4) << year << '/' << std::setw(2)
|
||||
<< (year + 1) % 100;
|
||||
return out.str();
|
||||
}
|
||||
bool person(const Json &p, bool position = false) {
|
||||
return keys(p, {"id", "name"}, position
|
||||
? std::initializer_list<const char *>{"position"}
|
||||
: std::initializer_list<const char *>{}) && text(p.at("id")) &&
|
||||
text(p.at("name"), false) && (!p.contains("position") || text(p.at("position")));
|
||||
}
|
||||
bool score(const Json &v) {
|
||||
return v.is_array() && v.size() == 2 && integer(v[0], 0, 99) && integer(v[1], 0, 99);
|
||||
}
|
||||
std::string position(const Json &p) {
|
||||
const auto found = p.find("positions");
|
||||
if (found == p.end() || !found->is_array()) return "";
|
||||
if (std::find(found->begin(), found->end(), "gk") != found->end()) return "gk";
|
||||
for (const auto &v : *found)
|
||||
if (text(v)) return v.get<std::string>();
|
||||
return "";
|
||||
}
|
||||
Json snapshot_player(const Catalog &world, const Json &p) {
|
||||
Json result = {{"id", p.at("id")}, {"name", world.name(p)}};
|
||||
const auto role = position(p);
|
||||
if (!role.empty()) result["position"] = role;
|
||||
return result;
|
||||
}
|
||||
Json lineup(const Catalog &world, const std::string &club) {
|
||||
const auto players = world.squad(club);
|
||||
const Json *keeper = nullptr;
|
||||
std::vector<const Json *> outfield;
|
||||
for (auto *p : players) {
|
||||
if (position(*p) == "gk") {
|
||||
if (!keeper) keeper = p;
|
||||
} else outfield.push_back(p);
|
||||
}
|
||||
// A partial squad is missing information, never an invented starting XI.
|
||||
if (!keeper || outfield.size() < 10) return nullptr;
|
||||
Json starters = Json::array({snapshot_player(world, *keeper)}), bench = Json::array();
|
||||
std::set<std::string> selected{keeper->at("id").get<std::string>()};
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
starters.push_back(snapshot_player(world, *outfield[i]));
|
||||
selected.emplace(outfield[i]->at("id").get<std::string>());
|
||||
}
|
||||
for (auto *p : players)
|
||||
if (!selected.contains(p->at("id").get<std::string>()))
|
||||
bench.push_back(snapshot_player(world, *p));
|
||||
return {{"starters", starters}, {"bench", bench}};
|
||||
}
|
||||
Json actor(const Json &team, int index, bool bench = false) {
|
||||
if (team.is_null()) return nullptr;
|
||||
const auto &players = team.at(bench ? "bench" : "starters");
|
||||
if (index < 0 || size_t(index) >= players.size()) return nullptr;
|
||||
const auto &p = players.at(size_t(index));
|
||||
return {{"id", p.at("id")}, {"name", p.at("name")}};
|
||||
}
|
||||
Json club_snapshot(const Catalog &world, const Json &club, int manager_index = -1) {
|
||||
Json manager = nullptr;
|
||||
if (manager_index >= 0)
|
||||
manager = {{"id", "demo:almanac:manager:" + std::to_string(manager_index)},
|
||||
{"name", "Demo-Manager " + std::to_string(manager_index + 1)}};
|
||||
Json crest = nullptr;
|
||||
if (club.contains("crest") && text(club.at("crest"))) crest = club.at("crest");
|
||||
return {{"id", club.at("id")}, {"name", world.name(club)},
|
||||
{"crest", crest}, {"manager", manager}};
|
||||
}
|
||||
Json competition(const Catalog &world, const Json &home, const Json &away, bool cup) {
|
||||
if (!cup && home.value("competition", "") == away.value("competition", "")) {
|
||||
const auto *league = world.find("competitions", home.value("competition", ""));
|
||||
if (league && league->value("type", "") == "league")
|
||||
return {{"id", league->at("id")}, {"name", world.name(*league)}, {"type", "league"}};
|
||||
}
|
||||
if (cup)
|
||||
for (const auto &c : world.rows("competitions"))
|
||||
if (c.value("type", "") == "cup")
|
||||
return {{"id", c.at("id")}, {"name", world.name(c)}, {"type", "cup"}};
|
||||
return {{"id", cup ? "demo:competition:cup" : "demo:competition:friendly"},
|
||||
{"name", cup ? "Demo-Pokal" : "Demo-Freundschaftsspiel"},
|
||||
{"type", cup ? "cup" : "friendly"}};
|
||||
}
|
||||
Json make_match(const Catalog &world, const Json &home, const Json &away,
|
||||
int year, int ordinal) {
|
||||
const std::array<std::pair<int, int>, 6> scores{{{3, 1}, {0, 0}, {2, 0},
|
||||
{2, 1}, {2, 2}, {1, 2}}};
|
||||
const auto [hg, ag] = scores[size_t(ordinal)];
|
||||
const bool extra = ordinal == 3 || ordinal == 4, shootout = ordinal == 4;
|
||||
const auto day = ordinal < 3 ? iso(year, 8, 3) : ordinal == 3 ? iso(year, 12, 14)
|
||||
: ordinal == 4 ? iso(year + 1, 2, 20) : iso(year + 1, 5, 18);
|
||||
Json rosters = {{"home", lineup(world, home.at("id"))},
|
||||
{"away", lineup(world, away.at("id"))}};
|
||||
// Historical recording can be incomplete even when the current world has a squad.
|
||||
if (ordinal == 5) rosters["away"] = nullptr;
|
||||
Json events = Json::array();
|
||||
const auto event = [&](const char *kind, int minute, const char *side, int index,
|
||||
int detail = 0, Json other = nullptr, bool bench = false) {
|
||||
events.push_back({{"kind", kind}, {"minute", minute}, {"side", side},
|
||||
{"player", actor(rosters.at(side), index, bench)}, {"other", std::move(other)},
|
||||
{"detail", detail}});
|
||||
};
|
||||
if (ordinal == 0) {
|
||||
event("miss", 6, "home", 1, 0);
|
||||
event("goal", 9, "home", 1, 0, actor(rosters.at("home"), 3));
|
||||
event("goal", 18, "away", 1, 1);
|
||||
event("yellow", 23, "home", 2);
|
||||
event("miss", 25, "away", 3, 1);
|
||||
event("miss", 41, "home", 4, 2);
|
||||
event("injury", 49, "home", 5);
|
||||
if (!rosters.at("home").is_null() && !rosters["home"]["bench"].empty())
|
||||
event("substitution", 50, "home", 0, 0, actor(rosters.at("home"), 5), true);
|
||||
else if (rosters.at("home").is_null())
|
||||
event("substitution", 50, "home", -1);
|
||||
event("goal", 61, "home", 2, 2);
|
||||
event("red", 67, "away", 4);
|
||||
event("second_yellow", 72, "home", 2);
|
||||
event("miss", 79, "away", 6, 3);
|
||||
event("goal", 82, "home", 3, 3);
|
||||
} else if (ordinal == 1) {
|
||||
event("miss", 27, "home", 1, 1);
|
||||
event("yellow", 54, "away", 3);
|
||||
} else if (ordinal == 2) {
|
||||
event("goal", 29, "home", 2, 1);
|
||||
event("goal", 76, "home", 3, 0);
|
||||
} else if (extra) {
|
||||
event("goal", 19, "home", 1, 0);
|
||||
event("goal", 58, "away", 1, 3);
|
||||
event("goal", 103, "home", 2, 2);
|
||||
if (shootout) {
|
||||
event("goal", 117, "away", 2, 1);
|
||||
const std::array<int, 5> h{1, 1, 0, 1, 1}, a{1, 1, 0, 1, 0};
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
event("shootout", 121, "home", i + 1, h[size_t(i)]);
|
||||
event("shootout", 121, "away", i + 1, a[size_t(i)]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event("goal", 12, "away", 1, 0);
|
||||
event("goal", 43, "home", 1, 3);
|
||||
event("goal", 88, "away", 2, 2);
|
||||
}
|
||||
return {{"id", "demo:almanac:" + std::to_string(year) + ":" + std::to_string(ordinal)},
|
||||
{"date", day}, {"season", season(year)},
|
||||
{"competition", competition(world, home, away, extra)},
|
||||
{"round", ordinal + 1}, {"home", club_snapshot(world, home, ordinal == 0 ? 0 : -1)},
|
||||
{"away", club_snapshot(world, away, ordinal == 0 ? 1 : -1)},
|
||||
{"result", {{"regulation", extra ? Json::array({1, 1}) : Json::array({hg, ag})},
|
||||
{"extra", extra ? Json::array({hg - 1, ag - 1}) : Json(nullptr)},
|
||||
{"penalties", shootout ? Json::array({4, 3}) : Json(nullptr)},
|
||||
{"final", {hg, ag}}, {"extra_played", extra}, {"penalties_played", shootout}}},
|
||||
{"referee", ordinal == 5 ? Json(nullptr) : Json("Demo-Schiedsrichter " + std::to_string(ordinal % 3 + 1))},
|
||||
{"attendance", ordinal == 5 ? Json(nullptr) : Json(ordinal == 1 ? 0 : 14500 + ordinal * 3275)},
|
||||
{"weather", {{"temperature", ordinal == 5 ? Json(nullptr) : Json(ordinal == 1 ? 0 : ordinal == 4 ? 3 : 16 + ordinal)},
|
||||
{"rain", ordinal == 5 ? Json(nullptr) : Json(ordinal == 1 ? 0 : ordinal % 8)}}},
|
||||
{"lineups", rosters}, {"events", events}};
|
||||
}
|
||||
bool valid_club(const Json &club) {
|
||||
return keys(club, {"id", "name", "crest", "manager"}) && text(club.at("id")) &&
|
||||
text(club.at("name"), false) && (club.at("crest").is_null() || text(club.at("crest"))) &&
|
||||
(club.at("manager").is_null() || person(club.at("manager")));
|
||||
}
|
||||
struct Roster {
|
||||
bool known = false;
|
||||
std::map<std::string, std::string> names;
|
||||
std::set<std::string> active, bench, yellow, dismissed;
|
||||
};
|
||||
bool valid_roster(const Json &value, Roster &out) {
|
||||
if (value.is_null()) return true;
|
||||
if (!keys(value, {"starters", "bench"}) || !value.at("starters").is_array() ||
|
||||
value.at("starters").size() != 11 || !value.at("bench").is_array()) return false;
|
||||
out.known = true;
|
||||
int keepers = 0, unknown_positions = 0;
|
||||
for (const auto *key : {"starters", "bench"})
|
||||
for (const auto &p : value.at(key)) {
|
||||
if (!person(p, true)) return false;
|
||||
const auto id = p.at("id").get<std::string>();
|
||||
if (!out.names.emplace(id, p.at("name").get<std::string>()).second) return false;
|
||||
if (std::string(key) == "starters") {
|
||||
out.active.insert(id);
|
||||
if (!p.contains("position")) ++unknown_positions;
|
||||
if (p.value("position", "") == "gk") ++keepers;
|
||||
} else out.bench.insert(id);
|
||||
}
|
||||
return keepers == 1 || (keepers == 0 && unknown_positions > 0);
|
||||
}
|
||||
bool valid_match(const Json &m) {
|
||||
if (!keys(m, {"id", "date", "season", "competition", "round", "home", "away",
|
||||
"result", "referee", "attendance", "weather", "lineups", "events"}) ||
|
||||
!text(m.at("id")) || !text(m.at("date")) || !date(m.at("date").get<std::string>()) ||
|
||||
!text(m.at("season")) || !integer(m.at("round"), 1, 999) ||
|
||||
!valid_club(m.at("home")) || !valid_club(m.at("away")) ||
|
||||
m.at("home").at("id") == m.at("away").at("id")) return false;
|
||||
const auto when = m.at("date").get<std::string>();
|
||||
const int year = std::stoi(when.substr(0, 4)) - (when.substr(5, 2) < "07" ? 1 : 0);
|
||||
if (year < 1 || m.at("season") != season(year)) return false;
|
||||
const auto &c = m.at("competition"), &r = m.at("result"), &w = m.at("weather");
|
||||
if (!keys(c, {"id", "name", "type"}) || !text(c.at("id")) || !text(c.at("name"), false) ||
|
||||
!text(c.at("type")) ||
|
||||
!keys(r, {"regulation", "extra", "penalties", "final", "extra_played", "penalties_played"}) ||
|
||||
!score(r.at("final")) || !r.at("extra_played").is_boolean() ||
|
||||
!r.at("penalties_played").is_boolean() ||
|
||||
!(r.at("regulation").is_null() || score(r.at("regulation"))) ||
|
||||
!(r.at("extra").is_null() || score(r.at("extra"))) ||
|
||||
!(r.at("penalties").is_null() || score(r.at("penalties"))) ||
|
||||
!(m.at("referee").is_null() || text(m.at("referee"))) ||
|
||||
!(m.at("attendance").is_null() || integer(m.at("attendance"), 0, 1000000)) ||
|
||||
!keys(w, {"temperature", "rain"}) ||
|
||||
!(w.at("temperature").is_null() || integer(w.at("temperature"), -100, 100)) ||
|
||||
!(w.at("rain").is_null() || integer(w.at("rain"), 0, 7))) return false;
|
||||
const bool extra = r.at("extra_played"), penalties = r.at("penalties_played");
|
||||
if ((!extra && !r.at("extra").is_null()) ||
|
||||
(!extra && !r.at("regulation").is_null() && r.at("regulation") != r.at("final")) ||
|
||||
(extra && !r.at("regulation").is_null() && r.at("regulation")[0] != r.at("regulation")[1]) ||
|
||||
(penalties != !r.at("penalties").is_null()) ||
|
||||
(penalties && (r.at("final")[0] != r.at("final")[1] ||
|
||||
r.at("penalties")[0] == r.at("penalties")[1]))) return false;
|
||||
if (!keys(m.at("lineups"), {"home", "away"}) || !m.at("events").is_array()) return false;
|
||||
std::array<Roster, 2> rosters;
|
||||
if (!valid_roster(m.at("lineups").at("home"), rosters[0]) ||
|
||||
!valid_roster(m.at("lineups").at("away"), rosters[1])) return false;
|
||||
for (const auto &[id, name] : rosters[0].names) {
|
||||
(void)name;
|
||||
if (rosters[1].names.contains(id)) return false;
|
||||
}
|
||||
std::array<int, 2> goals{}, regular{}, added{}, kicks{}, taken{};
|
||||
int last_minute = 0, kick_count = 0, first_kicker = -1;
|
||||
bool decided = false;
|
||||
for (const auto &e : m.at("events")) {
|
||||
if (!keys(e, {"kind", "minute", "side", "player", "other", "detail"}) ||
|
||||
!text(e.at("kind")) || !integer(e.at("minute"), 1, 121) ||
|
||||
!(e.at("side") == "home" || e.at("side") == "away") ||
|
||||
!(e.at("player").is_null() || person(e.at("player"))) ||
|
||||
!(e.at("other").is_null() || person(e.at("other")))) return false;
|
||||
const auto kind = e.at("kind").get<std::string>();
|
||||
const bool kick = kind == "shootout", chance = kind == "goal" || kind == "miss";
|
||||
if (!(chance || kick || kind == "yellow" || kind == "second_yellow" || kind == "red" ||
|
||||
kind == "injury" || kind == "substitution") ||
|
||||
!integer(e.at("detail"), 0, kick ? 1 : chance ? 3 : 0)) return false;
|
||||
const int minute = e.at("minute"), side = e.at("side") == "home" ? 0 : 1;
|
||||
if (minute < last_minute || (kick ? (!penalties || minute != 121) : minute > (extra ? 120 : 90)))
|
||||
return false;
|
||||
last_minute = minute;
|
||||
auto &roster = rosters[size_t(side)];
|
||||
for (const auto *key : {"player", "other"}) {
|
||||
const auto &p = e.at(key);
|
||||
if (!p.is_null() && roster.known) {
|
||||
const auto found = roster.names.find(p.at("id").get<std::string>());
|
||||
if (found == roster.names.end() || found->second != p.at("name").get<std::string>())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const auto player = e.at("player").is_null() ? "" : e.at("player").at("id").get<std::string>();
|
||||
const auto other = e.at("other").is_null() ? "" : e.at("other").at("id").get<std::string>();
|
||||
if (!other.empty() && !chance && kind != "substitution") return false;
|
||||
if (roster.known) {
|
||||
if (kind == "substitution") {
|
||||
if (!player.empty() && other.empty() &&
|
||||
roster.active.size() >= 11 - roster.dismissed.size()) return false;
|
||||
if (!player.empty() && !roster.bench.erase(player)) return false;
|
||||
if (!other.empty() && !roster.active.erase(other)) return false;
|
||||
if (!player.empty()) roster.active.insert(player);
|
||||
} else if ((!player.empty() && !roster.active.contains(player)) ||
|
||||
(!other.empty() && (!roster.active.contains(other) || player == other))) return false;
|
||||
if (kind == "yellow" && !player.empty()) {
|
||||
if (!roster.yellow.insert(player).second) return false;
|
||||
} else if ((kind == "red" || kind == "second_yellow") && !player.empty()) {
|
||||
if (kind == "second_yellow" && !roster.yellow.contains(player)) return false;
|
||||
roster.active.erase(player);
|
||||
roster.dismissed.insert(player);
|
||||
}
|
||||
}
|
||||
if (kind == "goal") {
|
||||
++goals[size_t(side)];
|
||||
if (minute <= 90) ++regular[size_t(side)];
|
||||
else ++added[size_t(side)];
|
||||
} else if (kick) {
|
||||
if (first_kicker < 0) first_kicker = side;
|
||||
if (decided || side != (first_kicker + kick_count) % 2) return false;
|
||||
++kick_count;
|
||||
++taken[size_t(side)];
|
||||
kicks[size_t(side)] += e.at("detail").get<int>();
|
||||
if (taken[0] <= 5 && taken[1] <= 5)
|
||||
decided = kicks[0] > kicks[1] + 5 - taken[1] || kicks[1] > kicks[0] + 5 - taken[0];
|
||||
else if (taken[0] == taken[1]) decided = kicks[0] != kicks[1];
|
||||
}
|
||||
}
|
||||
for (int side = 0; side < 2; ++side) {
|
||||
if (r.at("final")[size_t(side)] != goals[size_t(side)] ||
|
||||
(!r.at("regulation").is_null() && r.at("regulation")[size_t(side)] != regular[size_t(side)]) ||
|
||||
(!r.at("extra").is_null() && r.at("extra")[size_t(side)] != added[size_t(side)]) ||
|
||||
(penalties && r.at("penalties")[size_t(side)] != kicks[size_t(side)])) return false;
|
||||
}
|
||||
return penalties ? decided : kick_count == 0;
|
||||
}
|
||||
Json error(const char *message) { return {{"ok", false}, {"error", message}}; }
|
||||
} // namespace
|
||||
|
||||
Json make_demo_almanac(const Catalog &world) {
|
||||
Json archive = {{"schema", "openbmh-ui-demo-almanac@1"}, {"matches", Json::array()}};
|
||||
const auto clubs = world.clubs();
|
||||
if (clubs.size() < 2) return archive;
|
||||
const auto start = world.manifest().value("start_date", Json("2026-07-01"));
|
||||
if (!text(start) || !date(start.get<std::string>())) return archive;
|
||||
const auto when = start.get<std::string>();
|
||||
const int current = std::stoi(when.substr(0, 4)) - (when.substr(5, 2) < "07" ? 1 : 0);
|
||||
if (current < 3) return archive;
|
||||
for (int year = current - 2; year < current; ++year)
|
||||
for (int ordinal = 0; ordinal < 6; ++ordinal) {
|
||||
const size_t pair = ordinal < 3 ? size_t(ordinal) * 2 : 0;
|
||||
const auto *home = clubs[pair % clubs.size()], *away = clubs[(pair + 1) % clubs.size()];
|
||||
archive["matches"].push_back(make_match(world, *home, *away, year, ordinal));
|
||||
}
|
||||
return archive;
|
||||
}
|
||||
bool valid_demo_almanac(const Json &archive) {
|
||||
try {
|
||||
if (!keys(archive, {"schema", "matches"}) ||
|
||||
archive.at("schema") != "openbmh-ui-demo-almanac@1" || !archive.at("matches").is_array())
|
||||
return false;
|
||||
std::set<std::string> ids;
|
||||
for (const auto &m : archive.at("matches"))
|
||||
if (!valid_match(m) || !ids.insert(m.at("id").get<std::string>()).second) return false;
|
||||
return true;
|
||||
} catch (const Json::exception &) { return false; }
|
||||
}
|
||||
Json query_demo_almanac(const Json &archive, const Json &request, const std::string &as_of) {
|
||||
if (!date(as_of)) return error("invalid_almanac_cutoff");
|
||||
if (!valid_demo_almanac(archive)) return error("invalid_demo_almanac");
|
||||
try {
|
||||
if (!request.is_object() || !request.contains("kind") || !text(request.at("kind")))
|
||||
return error("invalid_almanac_request");
|
||||
const auto kind = request.at("kind").get<std::string>();
|
||||
const bool index = kind == "index", calendar = kind == "calendar", day = kind == "day", match = kind == "match";
|
||||
if (!(index || calendar || day || match) ||
|
||||
!(index ? keys(request, {"kind"}) : calendar ? keys(request, {"kind", "year"})
|
||||
: day ? keys(request, {"kind", "date"}) : keys(request, {"kind", "id"})) ||
|
||||
(calendar && !integer(request.at("year"), 1, 9999)) ||
|
||||
(day && (!text(request.at("date")) || !date(request.at("date").get<std::string>()))) ||
|
||||
(match && !text(request.at("id")))) return error("invalid_almanac_request");
|
||||
std::vector<const Json *> visible;
|
||||
for (const auto &m : archive.at("matches"))
|
||||
if (m.at("date").get<std::string>() <= as_of) visible.push_back(&m);
|
||||
std::stable_sort(visible.begin(), visible.end(), [](const auto *a, const auto *b) {
|
||||
return a->at("date").template get<std::string>() < b->at("date").template get<std::string>();
|
||||
});
|
||||
if (index) {
|
||||
std::set<int> years;
|
||||
for (const auto *m : visible) years.insert(std::stoi(m->at("date").template get<std::string>().substr(0, 4)));
|
||||
Json listed = Json::array();
|
||||
for (int year : years) listed.push_back(year);
|
||||
return {{"ok", true}, {"years", listed}, {"match_count", visible.size()},
|
||||
{"first_date", visible.empty() ? Json(nullptr) : visible.front()->at("date")},
|
||||
{"last_date", visible.empty() ? Json(nullptr) : visible.back()->at("date")}};
|
||||
}
|
||||
if (calendar) {
|
||||
const int year = request.at("year");
|
||||
std::map<std::string, Json> days;
|
||||
for (const auto *m : visible) {
|
||||
const auto when = m->at("date").template get<std::string>();
|
||||
if (std::stoi(when.substr(0, 4)) != year) continue;
|
||||
auto [it, inserted] = days.try_emplace(when, Json{{"date", when}, {"count", 0}, {"highlights", Json::array()}});
|
||||
(void)inserted;
|
||||
it->second["count"] = it->second.at("count").get<int>() + 1;
|
||||
const auto &r = m->at("result");
|
||||
if (r.at("extra_played") == true || r.at("penalties_played") == true ||
|
||||
r.at("final")[0].get<int>() + r.at("final")[1].get<int>() >= 4)
|
||||
it->second["highlights"].push_back(m->at("id"));
|
||||
}
|
||||
Json listed = Json::array();
|
||||
for (const auto &[when, item] : days) { (void)when; listed.push_back(item); }
|
||||
return {{"ok", true}, {"year", year}, {"days", listed}};
|
||||
}
|
||||
if (day) {
|
||||
Json matches = Json::array();
|
||||
for (const auto *m : visible)
|
||||
if (m->at("date") == request.at("date")) matches.push_back(*m);
|
||||
return {{"ok", true}, {"date", request.at("date")}, {"matches", matches}};
|
||||
}
|
||||
for (const auto *m : visible)
|
||||
if (m->at("id") == request.at("id")) return {{"ok", true}, {"match", *m}};
|
||||
return error("almanac_match_not_found");
|
||||
} catch (const Json::exception &) { return error("invalid_almanac_request"); }
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Immutable presentation archive. It is deliberately separate from Snapshot and
|
||||
// UI checkpoints; neither generation nor queries touch an engine, OBS or RNG.
|
||||
// Two completed seasons precede the season of manifest.start_date (2026-07-01
|
||||
// when absent). Missing catalogues yield a valid empty archive.
|
||||
Json make_demo_almanac(const Catalog &);
|
||||
bool valid_demo_almanac(const Json &);
|
||||
// Requests: {kind:"index"}, {kind:"calendar",year:2025},
|
||||
// {kind:"day",date:"2025-08-03"}, {kind:"match",id:"..."}.
|
||||
// Responses always contain ok. Errors contain error; successful index responses
|
||||
// have years (ascending), match_count, first_date/last_date (nullable). Calendar
|
||||
// has year and days [{date,count,highlights:[match IDs]}], day has date/matches,
|
||||
// and match has match. Only records dated <= as_of are ever returned.
|
||||
// regulation contains 90-minute goals; extra contains only additional goals
|
||||
// during extra time. Their sum is final; final excludes shootout goals.
|
||||
// An engine adapter may derive regulation from complete goal events <= minute
|
||||
// 90. AlmanacMatch itself only stores the end score and separate shootout; this
|
||||
// demo does not claim that its explicit phase fields came from the backend.
|
||||
// In particular, backend decided==2 alone does not establish extra-time
|
||||
// participation, and F10 player identities do not carry archived positions.
|
||||
Json query_demo_almanac(const Json &archive, const Json &request,
|
||||
const std::string &as_of);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -74,7 +74,7 @@ const std::vector<std::string> &desktop_routes() {
|
||||
"camp", "training", "transfer", "tactics", "settings",
|
||||
"scorers", "advertising", "stadium", "statistics", "environment",
|
||||
"fairplay", "highscore", "contracts", "balance", "newplayer",
|
||||
"news"};
|
||||
"news", "almanac"};
|
||||
return value;
|
||||
}
|
||||
const std::vector<WidgetDefinition> &widget_definitions() {
|
||||
@@ -170,6 +170,21 @@ bool valid_desktop(const Json &layout) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool migrate_desktop(Json &layout) {
|
||||
try {
|
||||
if (layout.at("objects").contains("app-almanac"))
|
||||
return valid_desktop(layout);
|
||||
auto next = layout;
|
||||
next["objects"]["app-almanac"] = object(0, 0, 1, 1, false, true);
|
||||
if (!valid_desktop(next) ||
|
||||
!find_space(next, "app-almanac", left, top, false))
|
||||
return false;
|
||||
layout = std::move(next);
|
||||
return true;
|
||||
} catch (const Json::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool place_desktop_object(Json &layout, const std::string &id, int x, int y,
|
||||
bool nearest) {
|
||||
if (!valid_desktop(layout) || !layout["objects"].contains(id))
|
||||
|
||||
@@ -13,6 +13,8 @@ const std::vector<std::string> &desktop_routes();
|
||||
// untouched.
|
||||
Json default_desktop();
|
||||
bool valid_desktop(const Json &);
|
||||
// Add new applications to a valid older view without moving existing objects.
|
||||
bool migrate_desktop(Json &);
|
||||
bool place_desktop_object(Json &, const std::string &, int x, int y,
|
||||
bool nearest = true);
|
||||
bool resize_desktop_widget(Json &, const std::string &, int columns, int rows);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
@@ -48,7 +49,7 @@ bool preferences(const Json &value) {
|
||||
}
|
||||
} // namespace
|
||||
DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
: catalog_(std::move(catalog)) {
|
||||
: catalog_(std::move(catalog)), almanac_(make_demo_almanac(*catalog_)) {
|
||||
std::string club;
|
||||
for (const auto *c : catalog_->clubs()) {
|
||||
if (!catalog_->manageable(c->value("id", "")))
|
||||
@@ -86,6 +87,9 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
saved_ = state_;
|
||||
}
|
||||
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
|
||||
Json DemoSource::read_almanac(const Json &request) const {
|
||||
return query_demo_almanac(almanac_, request, state_.at("date"));
|
||||
}
|
||||
ActionResult DemoSource::apply(const Action &action) {
|
||||
if (action.revision != revision_)
|
||||
return {false, revision_, "stale_revision"};
|
||||
@@ -243,8 +247,8 @@ Json DemoSource::load(const fs::path &file) {
|
||||
if (!v.is_number_integer() || v < 0 || v > 15)
|
||||
throw editor::Error("invalid_focus");
|
||||
auto next = data;
|
||||
const auto desktop = next.value("desktop", Json::object());
|
||||
if (!valid_desktop(desktop))
|
||||
auto desktop = next.value("desktop", Json::object());
|
||||
if (!migrate_desktop(desktop))
|
||||
throw editor::Error("invalid_demo_desktop");
|
||||
next.erase("desktop");
|
||||
state_ = std::move(next);
|
||||
|
||||
@@ -24,18 +24,25 @@ public:
|
||||
virtual ~DataSource() = default;
|
||||
virtual Snapshot snapshot() const = 0;
|
||||
virtual ActionResult apply(const Action &) = 0;
|
||||
// Read-side history projections can be backed by lazy engine-season decoding.
|
||||
// Browsing does not change the game revision or copy the archive into a save.
|
||||
virtual Json read_almanac(const Json &) const {
|
||||
return {{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
}
|
||||
};
|
||||
class DemoSource final : public DataSource {
|
||||
public:
|
||||
explicit DemoSource(std::shared_ptr<const Catalog>);
|
||||
Snapshot snapshot() const override;
|
||||
ActionResult apply(const Action &) override;
|
||||
Json read_almanac(const Json &) const override;
|
||||
void save(const fs::path &, const Json &desktop);
|
||||
Json load(const fs::path &);
|
||||
bool dirty() const { return state_ != saved_; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<const Catalog> catalog_;
|
||||
const Json almanac_;
|
||||
Json state_, saved_;
|
||||
uint64_t revision_ = 0;
|
||||
};
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
namespace {
|
||||
bool report_picker_menu(const std::string &menu) {
|
||||
return menu == "tables" || menu == "strengths" || menu == "league" ||
|
||||
menu == "other" || menu == "calendar" || menu == "friendlies";
|
||||
menu == "other" || menu == "calendar" || menu == "friendlies" || menu == "almanac";
|
||||
}
|
||||
bool report_picker_kind(const std::string &kind) {
|
||||
return kind == "country" || kind == "league" || kind == "filter" ||
|
||||
kind == "competition";
|
||||
kind == "competition" || kind == "year";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -15,6 +15,15 @@ App::report_picker_items(const std::string &kind) const {
|
||||
std::vector<std::pair<std::string, std::string>> items;
|
||||
if (!world_ || !report_picker_kind(kind))
|
||||
return items;
|
||||
if (kind == "year") {
|
||||
if (!source_) return items;
|
||||
const auto index = source_->read_almanac({{"kind", "index"}});
|
||||
if (!index.value("ok", false)) return items;
|
||||
for (const auto &year : index.at("years"))
|
||||
items.emplace_back(std::to_string(year.get<int>()), std::to_string(year.get<int>()));
|
||||
std::reverse(items.begin(), items.end());
|
||||
return items;
|
||||
}
|
||||
if (kind == "filter" || kind == "competition") {
|
||||
const std::vector<std::string> captions =
|
||||
kind == "filter"
|
||||
@@ -56,6 +65,7 @@ App::report_picker_items(const std::string &kind) const {
|
||||
std::string App::report_picker_value(const std::string &kind) const {
|
||||
if (!world_ || !report_picker_kind(kind))
|
||||
return {};
|
||||
if (kind == "year") return std::to_string(almanac_year_);
|
||||
const auto reports = snap().state.at("reports");
|
||||
if (kind == "filter" || kind == "competition")
|
||||
return std::to_string(reports.at(kind).get<int>());
|
||||
@@ -78,10 +88,11 @@ std::string App::report_picker(const std::string &kind, double left,
|
||||
for (const auto &[value, label] : items)
|
||||
if (value == selected)
|
||||
caption = label;
|
||||
if (kind == "year") caption = "Jahr " + std::to_string(almanac_year_);
|
||||
const bool open = report_picker_ == kind;
|
||||
const std::string menu_label = kind == "country" ? "Land"
|
||||
: kind == "league" ? "Liga"
|
||||
: kind == "filter" ? "Spiele" : "Wettbewerb";
|
||||
: kind == "filter" ? "Spiele" : kind == "year" ? "Kalenderjahr" : "Wettbewerb";
|
||||
std::string out =
|
||||
"<div class=\"report-picker-wrapper\" data-report-picker=\"" + kind +
|
||||
"\" style=\"left:" + scalar(left) + "dp;width:" + scalar(width) + "dp;\">" +
|
||||
@@ -103,8 +114,8 @@ std::string App::report_picker(const std::string &kind, double left,
|
||||
"<span class=\"report-picker-check-slot\" aria-hidden=\"true\">" +
|
||||
std::string(checked ? "<span class=\"report-picker-check\"></span>" : "") +
|
||||
"</span>";
|
||||
out += btn("report-choice", marker + "<span class=\"report-picker-option-label\">" +
|
||||
esc(items[i].second) + "</span>",
|
||||
const auto option_label = "<span class=\"report-picker-option-label\">" + esc(items[i].second) + "</span>";
|
||||
out += btn("report-choice", kind == "year" ? option_label + marker : marker + option_label,
|
||||
"report-picker-option",
|
||||
"id=\"report-option-" + kind + "-" + std::to_string(i) +
|
||||
"\" data-kind=\"" + kind + "\" data-value=\"" +
|
||||
@@ -130,6 +141,10 @@ void App::close_report_picker(bool focus) {
|
||||
context_->Update();
|
||||
if (focus && trigger)
|
||||
trigger->Focus(keyboard_navigation_);
|
||||
if (kind == "year") {
|
||||
if (focus) focus_after_render_ = "report-picker-year";
|
||||
refresh();
|
||||
}
|
||||
dirty_ = true;
|
||||
}
|
||||
|
||||
@@ -171,7 +186,12 @@ bool App::report_picker_action(const std::string &action, Rml::Element *target)
|
||||
? Json(std::stoi(value)) : Json(value);
|
||||
close_report_picker(false);
|
||||
// Commit even an unchanged country: the Gold resets its first league.
|
||||
if (menu_ == "friendlies")
|
||||
if (kind == "year" && menu_ == "almanac") {
|
||||
almanac_year_ = std::stoi(value);
|
||||
almanac_day_.clear();
|
||||
almanac_match_.clear();
|
||||
almanac_tab_ = "lineups";
|
||||
} else if (menu_ == "friendlies")
|
||||
apply("calendar", {{"kind", "friendly-" + kind}, {"value", selection}});
|
||||
else if (menu_ == "calendar") {
|
||||
const auto leagues = kind == "country" ? world_->leagues(value) : std::vector<const Json *>{};
|
||||
@@ -211,6 +231,7 @@ bool App::report_picker_event(Rml::Event &event) {
|
||||
return true;
|
||||
}
|
||||
if (type == "mousedown") {
|
||||
if (report_picker_ == "year") return false; // Dedicated backdrop dismisses this toolbar popup.
|
||||
auto *wrapper = ancestor("data-report-picker");
|
||||
if (!wrapper || wrapper->GetAttribute<Rml::String>("data-report-picker", "") !=
|
||||
report_picker_)
|
||||
@@ -229,13 +250,14 @@ bool App::report_picker_event(Rml::Event &event) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB) {
|
||||
if (key == Rml::Input::KI_TAB && report_picker_ != "year") {
|
||||
keyboard_navigation_ = true;
|
||||
close_report_picker(true);
|
||||
return false;
|
||||
}
|
||||
if (key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
|
||||
key == Rml::Input::KI_HOME || key == Rml::Input::KI_END) {
|
||||
key == Rml::Input::KI_HOME || key == Rml::Input::KI_END ||
|
||||
(key == Rml::Input::KI_TAB && report_picker_ == "year")) {
|
||||
const auto items = report_picker_items(report_picker_);
|
||||
if (items.empty())
|
||||
return false;
|
||||
@@ -250,7 +272,7 @@ bool App::report_picker_event(Rml::Event &event) {
|
||||
const int count = int(items.size());
|
||||
const int next = key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END ? count - 1
|
||||
: (current + (key == Rml::Input::KI_UP ? -1 : 1) + count) % count;
|
||||
: (current + ((key == Rml::Input::KI_UP || (key == Rml::Input::KI_TAB && event.GetParameter<int>("shift_key", 0))) ? -1 : 1) + count) % count;
|
||||
if (auto *node = element("report-option-" + report_picker_ + "-" +
|
||||
std::to_string(next))) {
|
||||
keyboard_navigation_ = true;
|
||||
|
||||
@@ -208,13 +208,13 @@ std::string App::render_desktop() {
|
||||
"</div>";
|
||||
else {
|
||||
const auto route = id.substr(4);
|
||||
const std::array<std::string, 31> colors = {
|
||||
const std::array<std::string, 32> colors = {
|
||||
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
|
||||
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
|
||||
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
|
||||
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
|
||||
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
|
||||
"#ac5e63"};
|
||||
"#ac5e63", "#806c98"};
|
||||
const auto i = std::find(routes.begin(), routes.end(), route);
|
||||
const auto color = colors[size_t(i - routes.begin())];
|
||||
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
|
||||
@@ -875,6 +875,8 @@ std::string App::render_menu(const std::string &key) {
|
||||
std::string body;
|
||||
if (key == "tables" || key == "strengths" || key == "league" || key == "other")
|
||||
body = render_reports(key);
|
||||
else if (key == "almanac")
|
||||
body = render_almanac();
|
||||
else if (key == "postpone")
|
||||
body = render_postpone();
|
||||
else if (key == "friendlies")
|
||||
|
||||
+39
-8
@@ -59,15 +59,15 @@ std::string btn(const std::string &action, const std::string &label,
|
||||
const std::string &css = {}, const std::string &attrs = {}) {
|
||||
return button_markup(action, label, css, attrs);
|
||||
}
|
||||
const std::array<std::string, 31> routes = {
|
||||
const std::array<std::string, 32> routes = {
|
||||
"tables", "league", "strengths", "lineup", "achievements",
|
||||
"other", "friendlies", "postpone", "calendar", "indoor",
|
||||
"load", "save", "kickoff", "toto", "bank",
|
||||
"camp", "training", "transfer", "tactics", "settings",
|
||||
"scorers", "advertising", "stadium", "statistics", "environment",
|
||||
"fairplay", "highscore", "contracts", "balance", "newplayer",
|
||||
"news"};
|
||||
const std::array<std::string, 31> titles = {"Tabellen",
|
||||
"news", "almanac"};
|
||||
const std::array<std::string, 32> titles = {"Tabellen",
|
||||
"Ligaspiele",
|
||||
"Stärken",
|
||||
"Aufstellung",
|
||||
@@ -97,7 +97,7 @@ const std::array<std::string, 31> titles = {"Tabellen",
|
||||
"Verträge",
|
||||
"Bilanz",
|
||||
"Neuer Spieler",
|
||||
"Nachrichten"};
|
||||
"Nachrichten", "Almanach"};
|
||||
std::string title(const std::string &route) {
|
||||
const auto i = std::find(routes.begin(), routes.end(), route);
|
||||
if (i != routes.end())
|
||||
@@ -212,6 +212,8 @@ public:
|
||||
}
|
||||
}
|
||||
raster = editor::images::decode(svg, ".svg", pixels);
|
||||
} else if (key == "button.almanac" && !gui_.contains(key)) {
|
||||
raster = editor::images::decode(editor::read_file(assets_ / "icons" / "almanac.svg"), ".svg", pixels);
|
||||
} else if (gui_.contains(key))
|
||||
raster = gui_.decode(key, pixels);
|
||||
else if (key == "background")
|
||||
@@ -308,10 +310,13 @@ class App final : public Rml::EventListener {
|
||||
std::optional<float> training_scroll_;
|
||||
std::optional<float> report_scroll_;
|
||||
float fixture_half_width_ = -1.f;
|
||||
float almanac_list_width_ = -1.f;
|
||||
std::string last_report_state_, report_picker_, report_detail_kind_,
|
||||
report_detail_club_, report_detail_player_, report_detail_return_focus_,
|
||||
report_option_to_scroll_;
|
||||
std::string planning_dialog_, planning_notice_, planning_return_focus_;
|
||||
int almanac_year_ = 0;
|
||||
std::string almanac_day_, almanac_match_, almanac_tab_ = "lineups";
|
||||
float device_ratio_ = 1.f;
|
||||
Json desktop_ = Json::object(), saved_desktop_ = Json::object(),
|
||||
options_ = Json::object();
|
||||
@@ -521,6 +526,10 @@ class App final : public Rml::EventListener {
|
||||
renderer_.world(next);
|
||||
world_ = std::move(next);
|
||||
source_ = std::move(demo);
|
||||
almanac_year_ = 0;
|
||||
almanac_day_.clear();
|
||||
almanac_match_.clear();
|
||||
almanac_tab_ = "lineups";
|
||||
desktop_ = Json::object();
|
||||
ticket_ =
|
||||
std::make_unique<TicketPopover>(*context_, *doc_, *source_, [this] {
|
||||
@@ -626,6 +635,8 @@ class App final : public Rml::EventListener {
|
||||
std::string render_planning_dialog();
|
||||
std::string planning_progress(bool, bool);
|
||||
bool planning_action(const std::string &, Rml::Element *);
|
||||
std::string render_almanac();
|
||||
bool almanac_action(const std::string &, Rml::Element *);
|
||||
std::string render_indoor();
|
||||
bool indoor_action(const std::string &, Rml::Element *);
|
||||
std::string training_balls(const std::string &, int, int, bool,
|
||||
@@ -688,6 +699,7 @@ class App final : public Rml::EventListener {
|
||||
}
|
||||
void render() {
|
||||
fixture_half_width_ = -1.f;
|
||||
almanac_list_width_ = -1.f;
|
||||
// A window-close save prompt can leave a menu while its local dialog is
|
||||
// open. Never keep that menu's modal/input gate in the destination view.
|
||||
if (menu_ != last_rendered_menu_) {
|
||||
@@ -757,7 +769,8 @@ class App final : public Rml::EventListener {
|
||||
if (auto *node = element(focus_after_render_))
|
||||
node->Focus(keyboard_navigation_);
|
||||
if (focus_after_render_.starts_with("report-option-") ||
|
||||
focus_after_render_.starts_with("friendly-opponent-"))
|
||||
focus_after_render_.starts_with("friendly-opponent-") ||
|
||||
focus_after_render_.starts_with("alm-match-"))
|
||||
report_option_to_scroll_ = focus_after_render_;
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
@@ -793,12 +806,28 @@ class App final : public Rml::EventListener {
|
||||
button->Focus();
|
||||
}
|
||||
bool center_fixture_columns() {
|
||||
bool changed = false;
|
||||
// History can contain every competition on one date. Keep its whole-row
|
||||
// buttons on the same centre even when the long list gains a scrollbar.
|
||||
if (auto *history = element("alm-day-list")) {
|
||||
if (auto *content = doc_->QuerySelector(".window .content")) {
|
||||
const float width = content->GetBox().GetSize(Rml::BoxArea::Content).x;
|
||||
if (std::abs(width - almanac_list_width_) >= .001f) {
|
||||
almanac_list_width_ = width;
|
||||
history->SetProperty("width", scalar(width) + "px");
|
||||
Rml::ElementList rows;
|
||||
history->QuerySelectorAll(rows, ".alm-list-head,.alm-match-row");
|
||||
for (auto *row : rows) row->SetProperty("width", scalar(width) + "px");
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto *list = element("report-list");
|
||||
if (!list || !list->IsClassSet("match-list"))
|
||||
return false;
|
||||
return changed;
|
||||
auto *score = list->QuerySelector(".report-cell.score");
|
||||
if (!score)
|
||||
return false;
|
||||
return changed;
|
||||
const auto &box = list->GetBox();
|
||||
// Rml rounds borders to physical pixels. Use the actual full inner width,
|
||||
// independently of the scrollport, so fractional density cannot move scores.
|
||||
@@ -807,7 +836,7 @@ class App final : public Rml::EventListener {
|
||||
box.GetEdge(Rml::BoxArea::Border, Rml::BoxEdge::Right);
|
||||
const float half = std::max(0.f, (inner - score->GetBox().GetSize(Rml::BoxArea::Border).x) / 2.f);
|
||||
if (std::abs(half - fixture_half_width_) < .001f)
|
||||
return false;
|
||||
return changed;
|
||||
fixture_half_width_ = half;
|
||||
Rml::ElementList sides;
|
||||
list->QuerySelectorAll(sides, ".report-cell.first,.report-cell:last-child");
|
||||
@@ -1088,6 +1117,8 @@ public:
|
||||
#include "modern/ui/indoor_screen.inc"
|
||||
#include "modern/ui/planning_screens.inc"
|
||||
#include "modern/ui/planning_controls.inc"
|
||||
#include "modern/ui/almanac_screens.inc"
|
||||
#include "modern/ui/almanac_controls.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user