// SPDX-License-Identifier: GPL-3.0-only std::string App::engine_widget_crest(const Json &team, double size) { const auto *club = world_->find("clubs", team.at("id").get()); if (club) return crest(club, size); return picture(renderer_.crest(team.value("crestAssetId", std::string()), theme_ == "silver"), size, size); } std::string App::engine_widget(const std::string &id, const Json &o) { if (id == "news") return engine_news_value_.is_object() ? render_news_widget(o) : std::string(); if (id != "warnings" && id != "competition" && id != "own-summary" && id != "opponent-summary" && id != "results" && id != "own-curve") return {}; const auto data = engine_widgets_projection(engine_data_); if (id == "results") { // the last recorded matches, newest on the right; nothing to show before the first one const auto &rows = data.at("recent"); if (!rows.is_array() || rows.empty()) return widget_heading("Letzte Spiele", false) + "
Noch kein Spiel gespielt.
"; const int w = o.at("w"); const bool wide = o.at("h") == 224; int won = 0, drawn = 0, lost = 0; std::string out = widget_heading(rows.size() == 1 ? "Letztes Spiel" : "Die letzten " + std::to_string(rows.size()) + " Spiele", false) + "
"; for (const auto &row : rows) { const auto form = row.value("form", std::string("U")); ++(form == "S" ? won : form == "N" ? lost : drawn); out += "
" + esc(form) + "" + esc(row.value("score", std::string())) + "
"; } const auto count = [](int n, const char *one, const char *many) { return std::to_string(n) + " " + (n == 1 ? one : many); }; return out + "
" + (wide ? std::string() : "

" + count(won, "Sieg", "Siege") + " · " + std::to_string(drawn) + " Unentschieden · " + count(lost, "Niederlage", "Niederlagen") + "

"); } if (id == "own-curve") { const auto &places = data.at("rankCurve"); if (!places.is_array() || places.size() < 2) return widget_heading("Tabellenplatz", false) + "
Die Kurve beginnt nach dem zweiten Spieltag.
"; // widget_curve draws from the widget values; lend it the engine's series const Json kept = widget_data_; widget_data_ = {{"own_curve", places}}; const auto curve = widget_curve(id, o, o.at("w"), o.at("h")); widget_data_ = kept; return widget_heading("Tabellenplatz", false) + curve; } if (id == "warnings") return widget_warnings(data.at("warnings"), o); if (id == "own-summary" || id == "opponent-summary") { const auto &row = data.at(id == "own-summary" ? "own" : "opponent"); if (!row.is_object()) return widget_heading("Platz & Stärke", false) + "
Noch kein Gegner bestätigt.
"; const auto *club = world_->find("clubs", row.at("teamId").get()); const auto number = [&](const char *key) { return row.at(key).is_null() ? std::string("—") : std::to_string(row.at(key).get()); }; std::string name = club ? world_->name(*club) : "Nationalteam"; if (!club) { const auto &desk = engine_data_.at("desktop").at("data"); if (desk.at("team").at("id") == row.at("teamId")) name = engine_text(desk.at("team").at("name")); else if (data.at("fixture").is_object()) for (const auto *side : {"home", "away"}) if (data.at("fixture").at(side).at("id") == row.at("teamId")) name = engine_text(data.at("fixture").at(side).at("name")); } return widget_heading(name, false) + "
Tabellenplatz" + number("rank") + "
Teamstärke" + number("strength") + "
"; } const auto &next = data.at("fixture"); if (!next.is_object()) return widget_heading("Nächste Begegnung", false) + "
Keine bestätigte " "Begegnung.
"; const auto &home = next.at("home"), &away = next.at("away"); const auto team = [&](const Json &v) { return "
" + engine_widget_crest(v, o.at("w").get() <= 472 ? 68 : 80) + "" + esc(engine_text(v.at("name"))) + "
"; }; return widget_heading("Nächste Begegnung", false) + "
" + team(home) + "
" + esc(engine_text(next.at("competition"))) + "–" + (home.at("id") == data.at("own").at("teamId") ? std::string("Heimspiel") : std::string("Auswärtsspiel")) + "
" + team(away) + "
"; }