// SPDX-License-Identifier: GPL-3.0-only // Read-only presentation of canonical DemoSource opening_flow. No extra App // API. Timer, phase changes, persistence, keyboard handling and completion // belong to the controller. No participants or pairings are invented by the // renderer. std::string App::render_opening() { const auto state = engine_mode_?engine_opening_state_:snap().state; const auto &flow = state.at("opening_flow"); const auto phase = flow.at("phase").get(); const bool playing = flow.value("playing", false) && !opening_io_blocked_; std::set own; for (const auto &m : state.at("managers")) own.insert(m.value("club", "")); std::vector order; std::set seen; for (const auto &id : flow.at("order")) { if (!id.is_string()) continue; const auto key = id.get(); if (const auto *c = world_->find("clubs", key); c && seen.insert(key).second) order.push_back(c); } const int total = int(order.size()), pairs = total / 2; const int revealed = std::clamp(flow.value("revealed", 0), 0, total); const auto date = state.value( "date", world_->manifest().value("start_date", std::string())); std::string season = "–"; if (date.size() >= 4 && std::all_of(date.begin(), date.begin() + 4, [](char c) { return c >= '0' && c <= '9'; })) { const int year = std::stoi(date.substr(0, 4)); const int following = (year + 1) % 100; season = std::to_string(year) + "/" + (following < 10 ? "0" : "") + std::to_string(following); } const auto owned = [&](const Json *c) { return c && own.contains(c->value("id", "")); }; const auto heading = [&](const std::string &title, const std::string &subtitle, const std::string &detail) { return "

" + esc(title) + "

" + esc(subtitle) + "

" "" + esc(detail) + "
"; }; const auto note = [&](const std::string &text) { if(engine_mode_)return std::string(); return "" + esc(text) + ""; }; const auto pair = [&](int index, int known, int logo_size, const std::string &extra) { if (index < 0 || index >= pairs) return std::string(); const auto *home = order[size_t(index * 2)], *away = order[size_t(index * 2 + 1)]; const auto side = [&](const Json *c, bool home_side, bool visible) { const auto name = visible ? world_->name(*c) : home_side ? "Heim" : "Noch nicht gezogen"; const auto text = "" + esc(name) + ""; const auto logo = visible ? "" + crest(c, logo_size) + "" : ""; return "" + (home_side ? text + logo : logo + text) + ""; }; return "
value("id", "")) + "\" data-away=\"" + esc(away->value("id", "")) + "\">" "" + std::to_string(index + 1) + "" + side(home, true, known > 0) + "–" + side(away, false, known > 1) + "
"; }; const bool entrants_page = phase == "uefa" || phase == "champions" || phase == "winners"; std::string body, titlebar; if (entrants_page) { const int page = phase == "uefa" ? 0 : phase == "champions" ? 1 : 2; const std::array titles = {"UEFA-Cup", "Champions League", "Europapokal der Pokalsieger"}; std::vector entrants; std::set entered; const auto &ids = flow.at("entrants").at(phase); for (const auto &id : ids) { if (!id.is_string()) continue; const auto key = id.get(); if (const auto *c = world_->find("clubs", key); c && entered.insert(key).second) entrants.push_back(c); } const bool german = !entrants.empty() && std::all_of(entrants.begin(), entrants.end(), [](const auto *c) { return c->value("nation", "") == "nation:de"; }); titlebar = german ? "Deutsche Teams" : "Teilnehmende Teams"; body = "
" + heading(titles[size_t(page)], titlebar + " · Saison " + season, std::to_string(page + 1) + " / 3") + "
"; if (entrants.empty()) { body += "

Keine " "Teilnehmer eingetragen

" "

"+std::string(engine_mode_?"Für diesen Wettbewerb sind derzeit keine deutschen Vereine gemeldet.":"Für diesen Wettbewerb sind in dieser Demo-Welt keine Vereine vorgesehen.")+"

"; } else { const bool single = entrants.size() == 1; const auto card = [&](const Json *c) { return "
value("id", "")) + "\">" + "
" + crest(c, single ? 620 : 360) + "
" "

" + esc(world_->name(*c)) + "

" + (owned(c) ? "

Dein Verein

" : "") + "
"; }; body += "
"; if (single) { body += card(entrants.front()); } else { const size_t rows = std::max(size_t(2), (entrants.size() + 1) / 2); for (size_t row = 0; row < rows; ++row) { body += "
"; for (size_t column = 0; column < 2; ++column) { const size_t index = row * 2 + column; body += index < entrants.size() ? card(entrants[index]) : "
"; } body += "
"; } } body += "
"; } body += "
"; } else if (phase == "draw") { titlebar = "DFB-Pokal"; body = "
" + heading("1. Runde", "DFB-Pokal · Saison " + season, std::to_string(revealed) + " / " + std::to_string(total) + " Mannschaften") + "
"; // a data set may carry a newer picture of the draw auto art = renderer_.image("art.cup-draw-v2.png", false, 1800); if (art.token.empty()) art = renderer_.image("art.cup-draw-v1.png", false, 1800); if (!art.token.empty() && art.width > 0 && art.height > 0) { const double ratio = double(art.width) / art.height; const double width = std::min(2608.0, 846.0 * ratio), height = width / ratio; body += "
" + picture(art, width, height, false) + "
"; } else { body += "

Die Illustration der " "Auslosung ist nicht verfügbar.

"; } body += "
" "
"; if (pairs) { const int current = std::min(pairs - 1, std::max(0, (revealed - 1) / 2)); const int known = std::clamp(revealed - current * 2, 0, 2); body += pair(current, known, 66, "current") + "
"; const int first = std::max(0, current - 3); for (int i = first; i < current; ++i) body += "
" + pair(i, 2, 42, "recent") + "
"; body += "
"; } else { body += "

Für diese Welt ist keine " "vollständige Paarung vorhanden.

"; } body += "
"; } else { titlebar = "DFB-Pokal"; body = "
" + heading("DFB-Pokal", "1. Runde · Saison " + season, std::to_string(pairs) + (pairs == 1 ? " Paarung" : " Paarungen")) + "
"; if (!pairs) { body += "

Für diese Welt " "sind keine vollständigen Paarungen vorhanden.

"; } else { const int columns = pairs > 1 ? 2 : 1, per_column = (pairs + columns - 1) / columns; for (int column = 0; column < columns; ++column) { const int first = column * per_column, last = std::min(pairs, first + per_column); body += "
"; for (int i = first; i < last; ++i) body += "
" + pair(i, 2, 36, "compact") + "
"; body += "
"; } } body += "
"; } return window(titlebar, body, false); }