98 lines
6.4 KiB
C++
98 lines
6.4 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "modern/ui/demo_widgets.hpp"
|
|
#include "modern/ui/desktop.hpp"
|
|
#include "modern/ui/demo_career.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <chrono>
|
|
namespace bmh::modern_ui {
|
|
const Json &widget_catalogue() {
|
|
static const Json catalogue = Json::parse(R"widgets([
|
|
{"id":"calendar","label":"Kalender","group":"Spieltag","description":"Spieldatum und nächster Termin","spans":{"s":[2,2],"m":[2,3],"l":[3,3]},"size":"m","route":"calendar"},
|
|
{"id":"account","label":"Konto & Eintritt","group":"Verein","description":"Guthaben, Sparbuch und Eintrittspreis","spans":{"wide":[4,1],"s":[2,2],"m":[4,2],"l":[4,3]},"size":"m","route":"bank"},
|
|
{"id":"competition","label":"Wettbewerb & Gegner","group":"Spieltag","description":"Das nächste Spiel auf einen Blick","spans":{"s":[2,2],"m":[4,2],"l":[4,3]},"size":"m","route":"league"},
|
|
{"id":"portrait","label":"Managerporträt","group":"Verein","description":"Dein gewähltes Managerporträt","spans":{"s":[2,2],"m":[3,3]},"size":"s","route":"newplayer"},
|
|
{"id":"crest","label":"Vereinswappen","group":"Verein","description":"Das Wappen deines Vereins","spans":{"s":[2,2],"m":[3,3]},"size":"s","route":"achievements"},
|
|
{"id":"opponent-crest","label":"Gegnerwappen","group":"Spieltag","description":"Der nächste Gegner","spans":{"s":[2,2],"m":[3,3]},"size":"s","route":"league"},
|
|
{"id":"warnings","label":"Warnlampen","group":"Verein","description":"Vereinsstatus, kompakt mit acht Lampen","spans":{"wide":[4,1],"s":[2,2],"m":[4,2],"l":[4,3]},"size":"m"},
|
|
{"id":"fans","label":"Fan-Stimmung","group":"Verein","description":"Die aktuelle Stimmung der Fans","spans":{"s":[2,1],"m":[4,1]},"size":"s","route":"environment"},
|
|
{"id":"own-curve","label":"Tabellenplatz · eigener Verein","group":"Statistik","description":"Deine Platzierungen im Saisonverlauf","spans":{"s":[2,2],"square":[3,3],"m":[4,2],"l":[4,4]},"size":"m","route":"tables"},
|
|
{"id":"opponent-curve","label":"Tabellenplatz · Gegner","group":"Statistik","description":"Der Saisonverlauf deines nächsten Gegners","spans":{"s":[2,2],"square":[3,3],"m":[4,2],"l":[4,4]},"size":"m","route":"tables"},
|
|
{"id":"comparison-curve","label":"Tabellenplätze · Vergleich","group":"Statistik","description":"Dein Verein und dein Gegner in einer gemeinsamen Grafik","spans":{"square":[3,3],"m":[4,2],"l":[4,4]},"size":"square","route":"tables"},
|
|
{"id":"results","label":"Letzte sechs Spiele","group":"Statistik","description":"Ergebnisse und Formkurve","spans":{"wide":[4,1],"s":[2,2],"m":[4,2],"l":[4,4]},"size":"m","route":"league"},
|
|
{"id":"duels","label":"Direkter Vergleich","group":"Statistik","description":"Die letzten Begegnungen mit dem Gegner","spans":{"s":[2,2],"m":[4,2]},"size":"s","route":"statistics"},
|
|
{"id":"own-summary","label":"Platz & Stärke · eigener Verein","group":"Statistik","description":"Deine Mannschaft im Überblick","spans":{"s":[2,1],"m":[4,1]},"size":"s","route":"strengths"},
|
|
{"id":"opponent-summary","label":"Platz & Stärke · Gegner","group":"Statistik","description":"Die nächste Mannschaft im Überblick","spans":{"s":[2,1],"m":[4,1]},"size":"s","route":"strengths"},
|
|
{"id":"news","label":"Nachrichten","group":"Verein","description":"Postfach, Schlagzeilen und ungelesene Meldungen","spans":{"s":[2,2],"m":[4,2],"l":[4,4]},"size":"s","route":"news"},
|
|
{"id":"trash","label":"Papierkorb","group":"Desktop","description":"Widgets zum Entfernen hier ablegen","spans":{"s":[1,1],"m":[2,2]},"size":"s"}
|
|
])widgets");
|
|
return catalogue;
|
|
}
|
|
Json demo_desktop_widgets(const Catalog &world, const Json &state) {
|
|
const auto own = demo_career_manager(state).value("club", "");
|
|
const auto *club = world.find("clubs", own);
|
|
const auto clubs = world.clubs(club ? club->value("competition", "") : "");
|
|
std::string opponent = own;
|
|
for (const auto *c : clubs)
|
|
if (c->at("id") != own) {
|
|
opponent = c->at("id").get<std::string>();
|
|
break;
|
|
}
|
|
const auto date = state.at("date").get<std::string>();
|
|
const int year = std::stoi(date.substr(0, 4)),
|
|
month = std::stoi(date.substr(5, 2)),
|
|
day = std::stoi(date.substr(8, 2));
|
|
const auto ymd = std::chrono::year_month_day{
|
|
std::chrono::year{year}, std::chrono::month{unsigned(month)},
|
|
std::chrono::day{unsigned(day)}};
|
|
if (!ymd.ok())
|
|
throw editor::Error("invalid_widget_date");
|
|
const std::array<const char *, 12> months{
|
|
"Januar", "Februar", "März", "April", "Mai", "Juni",
|
|
"Juli", "August", "September", "Oktober", "November", "Dezember"};
|
|
const std::array<const char *, 7> weekdays{
|
|
"Sonntag", "Montag", "Dienstag", "Mittwoch",
|
|
"Donnerstag", "Freitag", "Samstag"};
|
|
const auto week =
|
|
std::chrono::weekday{std::chrono::sys_days{ymd}}.c_encoding();
|
|
const int season = year - (month < 7 ? 1 : 0);
|
|
Json result = {{"own", own},
|
|
{"opponent", opponent},
|
|
{"month", std::string(months[size_t(month - 1)]) + " " +
|
|
std::to_string(year)},
|
|
{"weekday", weekdays[week]},
|
|
{"day", day},
|
|
{"season", std::to_string(season) + "/" +
|
|
std::to_string(season + 1).substr(2)},
|
|
{"matchday", state.value("matchday", 0)},
|
|
{"fans", state.value("fans", 67)},
|
|
{"own_curve", {9, 11, 8, 8, 6, 9, 7, 5, 7, 6, 4, 5}},
|
|
{"opponent_curve", {4, 5, 2, 3, 6, 4, 3, 5, 3, 2, 3, 2}},
|
|
{"form", {"S", "S", "U", "N", "S", "U"}},
|
|
{"scores", {"2:0", "3:1", "1:1", "0:2", "2:1", "0:0"}},
|
|
{"own_rank", 5},
|
|
{"opponent_rank", 2},
|
|
{"own_strength", 78},
|
|
{"opponent_strength", 83}};
|
|
std::array<bool, 10> flags{};
|
|
for (const auto &n : state.at("finance").at("stocks"))
|
|
if (n > 0)
|
|
flags[0] = true;
|
|
flags[1] = state.at("cash") < 100000;
|
|
for (const auto &n : state.at("advertising").at("contracts"))
|
|
if (n.at("sponsor") == -1)
|
|
flags[2] = true;
|
|
const auto count = state.at("lineup").at("order").size();
|
|
flags[5] = count < 11;
|
|
flags[6] = count < 16;
|
|
flags[7] = state.at("tactics").at("values")[7] > 8;
|
|
for (const auto &[id, c] : state.at("contracts").at("players").items())
|
|
if (c.at("months") < 4)
|
|
flags[8] = true;
|
|
result["warnings"] = desktop_warning_definitions();
|
|
for (size_t i = 0; i < flags.size(); ++i)
|
|
result["warnings"][i]["attention"] = flags[i];
|
|
return result;
|
|
}
|
|
} // namespace bmh::modern_ui
|