// SPDX-License-Identifier: GPL-3.0-only namespace { // Shared with lineup_controls.inc: proportional outer pitch and its border-free // art box. constexpr double lineup_roster_height_dp = 1216.0; constexpr double lineup_pitch_top_dp = 1256.0; constexpr double lineup_pitch_height_dp = 608.0; constexpr double lineup_pitch_width_dp = lineup_pitch_height_dp * 196.0 / 117.0; constexpr double lineup_pitch_border_dp = 2.0; constexpr double lineup_art_width_dp = lineup_pitch_width_dp - 2.0 * lineup_pitch_border_dp; constexpr double lineup_art_height_dp = lineup_pitch_height_dp - 2.0 * lineup_pitch_border_dp; constexpr double lineup_player_size_dp = 126.0 * lineup_pitch_width_dp / 1920.0; constexpr double lineup_player_anchor_x_dp = lineup_player_size_dp * 0.5; constexpr double lineup_player_anchor_y_dp = lineup_player_size_dp * 0.61; constexpr double lineup_controls_width_dp = 2612.0 - lineup_pitch_width_dp - 40.0; constexpr double lineup_formation_width_dp = (lineup_controls_width_dp - 18.0) / 2.0; constexpr double lineup_tools_width_dp = lineup_controls_width_dp - 16.0; constexpr double lineup_order_width_dp = (lineup_tools_width_dp - 40.0) / 2.0; constexpr double lineup_taker_width_dp = (lineup_tools_width_dp - 36.0) / 3.0; constexpr int lineup_pitch_raster_px = 2048; // Current demo follows the Classic German/Modern24-slot markers:11 start,6 // bench. This is not a universal match rule; a future session adapter supplies // its DTO status. See game/lineup.cpp DispatchLiveOverview and // ui/lineup_tests.cpp fixture markers. constexpr size_t lineup_start_limit = 11; constexpr size_t lineup_bench_limit = 6; std::string lineup_status(size_t slot, bool indoor = false) { if (indoor) return slot < 6 ? "Hallen-Sechs" : slot < 11 ? "Wechselpaar" : "Reserve"; return slot < lineup_start_limit ? "Startelf" : slot < lineup_start_limit + lineup_bench_limit ? "Ersatzbank" : "—"; } std::string lineup_managed(const Snapshot &s) { return demo_career_manager(s.state).value("club", ""); } std::string lineup_position(const Json &v) { if (!v.is_string()) return "—"; const auto code = v.get(); return code == "gk" ? "TW" : code == "def" ? "ABW" : code == "mid" ? "MIT" : code == "fwd" ? "STU" : code.empty() ? "—" : code; } std::string lineup_value(const Json &v) { if (!v.is_number()) return "—"; if (v.is_number_integer()) return number(v.get()); if (!std::isfinite(v.get())) return "—"; std::ostringstream out; out << std::setprecision(5) << v.get(); auto text = out.str(); std::replace(text.begin(), text.end(), '.', ','); return text; } int lineup_slot(const Json &l, const std::string &id) { if (!l.is_object() || !l.contains("order") || !l.at("order").is_array()) return -1; const auto &a = l.at("order"); const auto p = std::find(a.begin(), a.end(), id); return p == a.end() ? -1 : int(p - a.begin()); } std::string lineup_svg(const std::string &body, const std::string &box = "0 0 120 72") { return "" + body + ""; } std::string lineup_mini(const Json &points, const std::string &theme, size_t limit = 11) { const auto line = theme == "silver" ? "#536f66" : "#c3e8cb"; std::string body = ""; if (points.is_array()) for (size_t i = 0; i < std::min(limit, points.size()); ++i) { const auto &p = points[i]; const int depth = p[0].get(), lane = p[1].get(); const auto color = theme == "silver" ? (depth < 7 ? "#85600c" : depth < 13 ? "#a46914" : "#b44931") : (depth < 7 ? "#ffdc69" : depth < 13 ? "#ecac4b" : "#f07852"); body += ""; } return lineup_svg(body); } std::string lineup_field(bool indoor = false) { std::string body; for (int x = 0; x < 196; x += 15) body += ""; body += "" "" ""; return lineup_svg(body, "0 0 196 117"); } std::string lineup_zone(const Json &l, const std::string &id) { const int row = lineup_slot(l, id); if (row < 0 || row >= 11) return ""; const auto &point = l.at("points")[size_t(row)], &orders = l.at("orders").at(id); const double forward = orders[0].get(), width = orders[1].get(), coverage = orders[2].get(); const double x = (8 + point[0].get() / 18.0 * 84) * 1.96, y = (10 + point[1].get() / 8.0 * 80) * 1.17; double x0 = x - (width / 2 + 46 - forward), x1 = x + width / 2 + forward + 8; std::string body = ""; for (int n = 0; n <= int(coverage / 2); ++n) { if (n) { const int bend = (n == 8 ? 3 : 0) + (n == 6 ? 2 : 0) + (n == 3 ? 1 : 0); if (x0 < x1 - (1 + bend) * 2 - 20) { x0 += 1 + bend; x1 -= 1 + bend; } } const double lo = std::max(3.0, x0), hi = std::min(192.0, x1); if (hi > lo) for (const auto yy : {std::max(2.0, y - n - 1), std::min(114.0, y + n + 1)}) body += ""; } return lineup_svg(body + "", "0 0 196 117"); } } // namespace std::string App::render_lineup() { const auto s = engine_mode_ ? Snapshot{0, world_, Json()} : snap(); if (!s.world) return "

Die Aufstellung ist derzeit nicht " "verfügbar.

"; const auto projection = engine_mode_ ? engine_lineup_projection(engine_data_) : demo_lineup_rows(s.state, *s.world, lineup_managed(s)); if (!projection.value("ok", false)) return "

Die Aufstellung ist derzeit nicht " "verfügbar.

"; const auto &l = engine_mode_ ? projection.at("board") : demo_lineup_visible(s.state); const auto &rows = projection.at("rows"); const int field_count = engine_mode_ ? projection.at("field_count").get() : demo_career_field_count(s.state); const bool indoor = !engine_mode_ && field_count == 6; if (lineup_slot(l, lineup_selected_) < 0) lineup_selected_.clear(); lineup_data_ = lineup_data_ == 1 ? 1 : 0; lineup_page_ = lineup_page_ == 1 ? 1 : 0; if (lineup_side_ != "orders" && lineup_side_ != "takers") lineup_side_ = "formations"; const auto attr = [](const std::string &key, const std::string &value) { return " " + key + "=\"" + esc(value) + "\""; }; const auto player_attrs = [&](const Json &row, const std::string &prefix) { const auto id = row.at("id").get(); return attr("id", prefix + id) + attr("data-id", id) + attr("data-squad-player", id) + attr("data-slot", std::to_string(row.at("slot").get())) + attr("aria-pressed", lineup_selected_ == id ? "true" : "false") + attr("aria-label", row.at("name").get() + ", " + lineup_position(row.at("position"))); }; std::string out = "
"; const std::array, 2> headings{ {{{"Nr.", "Name", "Pos.", "Ko", "Te", "Fo", "Stärke", "Status", "Land", "Mot.", "Tore", "Ass."}}, {{"Nr.", "Name", "Alter", "Eck.", "Frei.", "Zwei.", "Pass", "Schuss", "Schn.", "Team", "Spiele", "Note"}}}}; for (int c = 0; c < 12; ++c) out += "" + headings[size_t(lineup_data_)][size_t(c)] + ""; out += "
"; for (const auto &row : rows) { const auto slot = row.at("slot").get(); const auto id = row.at("id").get(); out += "
"; out += "" + (slot < field_count ? std::to_string(slot + 1) : "–") + ""; out += btn("lineup-player", esc(row.at("name").get()), "lineup-cell lineup-col-1 lineup-name", player_attrs(row, "lineup-name-")); std::vector fields; if (!lineup_data_) fields = {lineup_position(row.at("position")), lineup_value(row.at("condition")), lineup_value(row.at("technique")), lineup_value(row.at("form")), lineup_value(row.at("strength")), engine_mode_ ? row.at("status").get() : lineup_status(size_t(slot), indoor), row.at("nation").is_string() ? row.at("nation").get() : "—", lineup_value(row.at("motivation")), lineup_value(row.at("goals")), lineup_value(row.at("assists"))}; else for (const auto *key : {"age", "corner", "free_kick", "tackling", "passing", "shooting", "speed", "teamplay", "games", "grade"}) fields.push_back(lineup_value(row.at(key))); for (size_t f = 0; f < fields.size(); ++f) { std::string value = esc(fields[f]); if (!lineup_data_ && f == 6 && row.at("nation").is_string()) { auto code = row.at("nation").get(); if (code.starts_with("nation:")) code = code.substr(7); if (code == "de") value = picture( renderer_.diagram( "lineup-flag-de", lineup_svg("", "0 0 40 24"), 80), 40, 24); else { const auto flag = ui_nation_flag_svg(code); if (!flag.empty()) value = picture(renderer_.diagram("lineup-flag-" + code, flag, 80), 40, 24); else { // Legacy placeholders are identifiers, not useful country labels. const bool country_code = code.size() == 2 && std::all_of(code.begin(), code.end(), [](unsigned char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }); if (country_code) { std::transform( code.begin(), code.end(), code.begin(), [](unsigned char c) { return char(std::toupper(c)); }); value = esc(code); } else value = "—"; } } } if (!lineup_data_ && f == 5) value = "" + value + ""; out += btn("player-detail", value, "lineup-cell lineup-col-" + std::to_string(f + 2) + " lineup-detail", attr("id", "lineup-detail-" + id + "-" + std::to_string(f)) + attr("data-id", id) + attr("aria-label", row.at("name").get() + ", Spielerinformationen")); } out += "
"; } if (rows.empty()) out += "

Für diesen Verein sind keine Spieler " "überliefert.

"; out += "
"; const auto data_btn = [&]() { return btn("lineup-data", lineup_data_ ? "Daten A" : "Daten B", "lineup-tab", "id=\"lineup-data\""); }; const auto view_btn = [&]() { return btn("lineup-view", lineup_pitch_ ? "Team" : "Spielfeld", "lineup-tab", "id=\"lineup-view\""); }; out += ""; if (lineup_pitch_) { out += "
" + picture(renderer_.diagram("lineup-field", lineup_field(indoor), lineup_pitch_raster_px), lineup_art_width_dp, lineup_art_height_dp) + "
"; if (!engine_mode_ && lineup_side_ == "orders" && !lineup_selected_.empty()) { const auto zone = lineup_zone(l, lineup_selected_); if (!zone.empty()) out += "
" + picture(renderer_.diagram("lineup-zone", zone, lineup_pitch_raster_px), lineup_art_width_dp, lineup_art_height_dp) + "
"; } for (size_t i = 0; i < std::min(size_t(field_count), rows.size()); ++i) { const auto &row = rows[i], &point = l.at("points")[i]; if (point.is_null()) continue; const bool selected = lineup_selected_ == row.at("id").get(); const auto x = (8 + point[0].get() / double(l.value("depth_max", 18)) * 84) * lineup_art_width_dp / 100.0 - lineup_player_anchor_x_dp; const auto y = (10 + point[1].get() / double(l.value("lane_max", 8)) * 80) * lineup_art_height_dp / 100.0 - lineup_player_anchor_y_dp; out += btn("lineup-player", img(selected ? "lineup.player.selected" : "lineup.player.normal", lineup_player_size_dp, lineup_player_size_dp) + "" + std::to_string(i + 1) + "", "lineup-player", player_attrs(row, "lineup-player-") + attr("style", rect(x, y, lineup_player_size_dp, lineup_player_size_dp))); } out += "
" + img("lineup.player.ghost", lineup_player_size_dp, lineup_player_size_dp) + "
"; } else { const auto bench = engine_mode_ ? size_t(std::count_if(rows.begin(), rows.end(), [](const auto &r) { return r.at("role") == "bench"; })) : std::min(indoor ? size_t(5) : lineup_bench_limit, rows.size() > size_t(field_count) ? rows.size() - size_t(field_count) : 0); const auto reserves = engine_mode_ ? size_t(std::count_if(rows.begin(), rows.end(), [](const auto &r) { return r.at("role") == "reserve"; })) : rows.size() > size_t(field_count) + bench ? rows.size() - size_t(field_count) - bench : 0; out += ""; } out += "
"; return out + (engine_mode_ ? engine_player_profile(projection) : render_report_detail()); }