Connect Almanac UI to revision-bound career history (by Codex)
This commit is contained in:
1 parent
4b6c18f654
commit
959154c3c0
18 files changed
+405
-44
No files matched your search
@@ -74,6 +74,11 @@ std::string almanac_competition_label(const Json &record) {
|
||||
(almanac_text(almanac_field(competition, "type"), "") == "league"
|
||||
? "Spieltag" : "Runde");
|
||||
}
|
||||
bool almanac_phases_known(const Json &result) {
|
||||
if(!almanac_flag(result,"penalties_played"))return true;
|
||||
const auto &score=almanac_field(result,"penalties");
|
||||
return score.is_array()&&score.size()==2&&score[0].is_number_integer()&&score[1].is_number_integer()&&score[0]!=score[1];
|
||||
}
|
||||
std::string almanac_event_kind(const std::string &kind) {
|
||||
if (kind == "goal") return "Tor";
|
||||
if (kind == "miss") return "Fehlschuss";
|
||||
@@ -90,7 +95,7 @@ std::string almanac_event_kind(const std::string &kind) {
|
||||
std::string App::render_almanac() {
|
||||
const auto query = [&](const Json &request) -> Json {
|
||||
try {
|
||||
return source_ ? source_->read_almanac(request)
|
||||
return engine_mode_ ? engine_almanac_read(request) : source_ ? source_->read_almanac(request)
|
||||
: Json{{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
} catch (const std::exception &) {
|
||||
return {{"ok", false}, {"error", "almanac_unavailable"}};
|
||||
@@ -106,8 +111,7 @@ std::string App::render_almanac() {
|
||||
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 reference = engine_mode_ ? engine_data_.at("desktop").at("meta").at("date") : snap().state.at("date");
|
||||
const auto date = almanac_date_parts(reference);
|
||||
if (almanac_year_ == 0 ||
|
||||
std::find(years.begin(), years.end(), almanac_year_) == years.end()) {
|
||||
@@ -140,11 +144,12 @@ std::string App::render_almanac() {
|
||||
: 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");
|
||||
auto key = almanac_field(team, "crest");
|
||||
if (engine_mode_ && key.is_null()) if (const auto *club = world_->find("clubs", almanac_text(almanac_field(team,"id"),""))) key=club->value("crest",Json());
|
||||
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)
|
||||
? picture(renderer_.crest(key.get<std::string>(), theme_ == "silver"),size,size)
|
||||
: "<span class=\"alm-no-crest\">—</span>") + "</div>";
|
||||
};
|
||||
const auto team_label = [&](const Json &team, bool home) {
|
||||
@@ -176,7 +181,8 @@ std::string App::render_almanac() {
|
||||
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 bool known=almanac_phases_known(result);
|
||||
const bool penalties = known && almanac_flag(result, "penalties_played"), extra = known && 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";
|
||||
@@ -186,7 +192,7 @@ std::string App::render_almanac() {
|
||||
"<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>"
|
||||
(!known ? "unklar" : 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 " +
|
||||
@@ -260,11 +266,13 @@ std::string App::render_almanac() {
|
||||
} 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") +
|
||||
const bool known=almanac_phases_known(result);
|
||||
const auto phase = !known ? std::string("Endstand") : 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"));
|
||||
if (!known) phases="Spielphasen nicht eindeutig überliefert.";
|
||||
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");
|
||||
@@ -390,3 +398,16 @@ std::string App::render_almanac() {
|
||||
output += btn("alm-year-cancel", "", "alm-picker-shield", "id=\"alm-year-shield\" aria-label=\"Jahresauswahl schließen\"");
|
||||
return output + "</div>";
|
||||
}
|
||||
|
||||
bool App::almanac_layout_update() {
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in new issue
Block a user