// SPDX-License-Identifier: GPL-3.0-only namespace { const std::array rankings_categories{ "Tore", "Vorlagen", "Gelbe Karten", "Rote Karten"}; std::string rankings_cell_text(const std::string &value) { return "" + esc(value) + ""; } std::string rankings_league(const Catalog &world, const Json &state, const std::string &club) { const auto *own = world.find("clubs", club); const auto requested = state.value("reports", Json::object()).value( "league", own ? own->value("competition", "") : ""); const auto *league = world.find("competitions", requested); if (league && league->value("type", "") == "league") return requested; const auto leagues = world.leagues(); return leagues.empty() ? "" : leagues.front()->value("id", ""); } std::string rankings_season(const Json &state, const Catalog &world) { const auto date = state.value("date", world.manifest().value("start_date", "")); if (date.size() < 7 || date.find_first_not_of("0123456789", 0) < 4) return "—"; try { int year = std::stoi(date.substr(0, 4)); if (std::stoi(date.substr(5, 2)) < 7) --year; return std::to_string(year) + "/" + std::to_string(year + 1).substr(2); } catch (...) { return "—"; } } std::string rankings_icon(int kind, const std::string &color) { const std::string shape = kind == 0 ? "" : ""; return "" + shape + ""; } } // namespace void App::rankings_remember_scroll() { if (!rankings_view_.is_object()) return; if (auto *list = element("rankings-list")) { const auto key = list->GetAttribute("data-scroll-key", ""); if (!key.empty()) rankings_view_["scrolls"][key] = list->GetScrollTop(); } } void App::rankings_restore_scroll() { if ((menu_ != "scorers" && menu_ != "fairplay") || !rankings_view_.value("restore_scroll", false)) return; rankings_view_["restore_scroll"] = false; if (auto *list = element("rankings-list")) { const auto key = list->GetAttribute("data-scroll-key", ""); const auto values = rankings_view_.value("scrolls", Json::object()); if (auto it = values.find(key); it != values.end() && it->is_number()) list->SetScrollTop(it->get()); } } std::string App::render_scorers() { rankings_remember_scroll(); const auto snapshot = engine_mode_?Snapshot{}:snap(); const auto club = engine_mode_?engine_data_.at("desktop").at("meta").at("scope").at("teamId").get():manager(snapshot).value("club", ""); if (!rankings_view_.is_object()) rankings_view_ = Json::object(); if (!engine_mode_ && !rankings_view_.contains("league")) rankings_view_["league"] = rankings_league(*world_, snapshot.state, club); const auto league_id = engine_mode_?engine_rankings_value_.at("leagueId").get():rankings_view_.value("league", std::string()); const int scope = engine_mode_?engine_rankings_state_.at("scope").get():std::clamp(rankings_view_.value("scope", 0), 0, 1), kind = std::clamp(rankings_view_.value("tab", 0), 0, 3); rankings_view_["scope"] = scope; rankings_view_["tab"] = kind; const auto *league = world_->find("competitions", league_id), *own = world_->find("clubs", club); const auto title = engine_mode_?(scope?engine_rankings_value_.at("team").at("name").get():engine_rankings_value_.at("league").at("name").get()):scope ? (own ? world_->name(*own) : "—") : (league ? world_->name(*league) : "—"); const auto nation = scope ? (own ? own->value("nation", "") : "") : (league ? league->value("nation", "") : ""); const auto rows = engine_mode_?engine_rankings_value_.at("categories").at(size_t(kind)):demo_scorer_rows(*world_, league_id, club, scope, kind); const auto key = "scorers:" + league_id + ":" + std::to_string(scope) + ":" + std::to_string(kind); const auto player_button = [&](const Json &r, bool leader) { const auto id = r.at("player").get(); const double size = leader ? 126 : 88; const auto image = "" + img(r.at("photo").get(), size, size, true, true, 256) + ""; return btn("player-detail", image + "" + esc(r.at("name").get()) + "", "rankings-player-button", "id=\"rankings-player-" + esc(id) + "\" data-id=\"" + esc(id) + "\" data-club=\"" + esc(r.at("club").get()) + "\" title=\"" + esc(r.at("name").get()) + "\""); }; const auto club_button = [&](const Json &r, bool leader) { const auto id = r.at("club").get(); return btn("club-detail", engine_mode_?""+crest(world_->find("clubs",id),leader?34:42)+""+esc(r.at("club_name").get())+"":label(world_->find("clubs", id), leader ? 34 : 42), "rankings-club-button " + std::string(id == club ? "current" : ""), "id=\"rankings-club-" + esc(r.at("player").get()) + "\" data-id=\"" + esc(id) + "\""); }; std::string out = "

" + esc(title) + "

" + esc(world_->nation_name(nation)) + " · Saison " + esc(engine_mode_?engine_rankings_value_.at("season").get():rankings_season(snapshot.state, *world_)) + "
"+(engine_mode_?"":"

Spielwerte fiktiv

")+"
"; for (size_t i = 0; i < std::min(size_t(3), rows.size()); ++i) { const auto &r = rows[i]; out += "
" + r.at("rank").dump() + ".
" + player_button(r, true) + club_button(r, true) + "
" + r.at("value").dump() + "" + rankings_categories[size_t(kind)] + "
"; } out += "
" + rankings_cell_text("Spieler") + "
" + rankings_cell_text("Verein") + "
" + rankings_cell_text(rankings_categories[size_t(kind)]) + "
"; for (size_t i = 3; i < rows.size(); ++i) { const auto &r = rows[i]; out += "
" + r.at("rank").dump() + "." + player_button(r, false) + "
" + club_button(r, false) + "
" + rankings_cell_text(r.at("value").dump()) + "
"; } if (rows.empty()) out += "
"+rankings_cell_text("Keine Einträge in dieser Kategorie.")+"
"; out += "
" + render_report_detail(); } std::string App::render_fairplay() { rankings_remember_scroll(); const auto rows = engine_mode_?engine_fairplay_value_.at("rows"):demo_fairplay_rows(*world_); std::string out = "

Strafpunkte · weniger ist besser

Gelb · 1 PunktRot · 4 Punkte
" + rankings_cell_text("Pl. / Verein") + "
" + rankings_cell_text("Gelb") + "
" + rankings_cell_text("Rot") + "
" + rankings_cell_text("Punkte") + "
"; for (size_t i = 0; i < rows.size(); ++i) { const auto &r = rows[i]; out += "
" + r.at("rank").dump() + "." + report_club_button(r.at("club").get()) + "
" + rankings_cell_text(r.at("yellow").dump()) + "
" + rankings_cell_text(r.at("red").dump()) + "
" + rankings_cell_text(r.at("points").dump()) + "
"; } if (rows.empty()) out += "

" + rankings_cell_text("Keine Vereine in der deutschen Ligavorschau.") + "

"; rankings_view_["restore_scroll"] = true; return out + "
" + render_report_detail(); }