// SPDX-License-Identifier: GPL-3.0-only // The line-up as a page of the notebook (the real game): the squad as a table at the left, // grouped into starting eleven, bench and the rest; at the right the pitch seen from behind // the own goal with the eleven as shirts, or the whole squad as shirts. Two players are // clicked to swap them; any other cell of a row opens the player's card. std::string App::render_lineup_page() { const auto projection = engine_lineup_projection(engine_data_); if (!projection.value("ok", false)) return "
Die Aufstellung ist derzeit nicht verfügbar.
"; const auto &l = projection.at("board"); const auto &rows = projection.at("rows"); const int field_count = projection.at("field_count").get(); const bool indoor = projection.at("surface") == "indoor"; if (lineup_slot(l, lineup_selected_) < 0) lineup_selected_.clear(); lineup_data_ = lineup_data_ == 1 ? 1 : 0; 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"))); }; const auto last_name = [](const std::string &name) { const auto at = name.rfind(' '); return at == std::string::npos ? name : name.substr(at + 1); }; const auto flag = [&](const Json &nation) -> std::string { if (!nation.is_string()) return "—"; auto code = nation.get(); if (code.starts_with("nation:")) code = code.substr(7); const auto svg = code == "de" ? lineup_svg("", "0 0 40 24") : ui_nation_flag_svg(code); if (!svg.empty()) return "" + picture(renderer_.diagram("lineup-flag-" + code, svg, 80), 45, 27) + ""; std::transform(code.begin(), code.end(), code.begin(), [](unsigned char c) { return char(std::toupper(c)); }); return code.size() == 2 ? esc(code) : std::string("—"); }; // --- the table --- struct Column { const char *label, *key; double width; const char *align; }; const std::vector columns = lineup_data_ == 0 ? std::vector{{"Nr.", "", 40, "r"}, {"Name", "", 0, ""}, {"Pos.", "position", 60, "c"}, {"Ko", "condition", 42, "c"}, {"Te", "technique", 42, "c"}, {"Fo", "form", 42, "c"}, {"Stärke", "strength", 60, "c"}, {"Status", "status", 104, "c"}, {"Land", "nation", 50, "c"}, {"Sp.", "games", 42, "c"}, {"Tore", "goals", 46, "c"}, {"Vorl.", "assists", 46, "c"}} : std::vector{{"Nr.", "", 40, "r"}, {"Name", "", 0, ""}, {"Alter", "age", 54, "c"}, {"Eck.", "corner", 58, "c"}, {"Frei.", "free_kick", 58, "c"}, {"Zwei.", "tackling", 58, "c"}, {"Pass", "passing", 58, "c"}, {"Schuss", "shooting", 58, "c"}, {"Schn.", "speed", 58, "c"}, {"Team", "teamplay", 58, "c"}, {"Spiele", "games", 56, "c"}, {"Note", "grade", 52, "c"}}; std::string out = "
"; for (const auto &column : columns) out += pg_th(column.label, column.width, column.align); out += "
"; int group = -1; for (const auto &row : rows) { const auto slot = row.at("slot").get(); const auto id = row.at("id").get(); const int part = slot < field_count ? 0 : row.value("role", std::string()) == "bench" ? 1 : 2; if (part != group) { group = part; out += "
" + pg_td(pg_upper(part == 0 ? (indoor ? "Aufgebot" : "Startelf") : part == 1 ? "Ersatzbank" : "Übriger Kader"), 0) + "
"; } out += "
"; size_t field = 0; for (const auto &column : columns) { const std::string key = column.key; if (std::string(column.label) == "Nr.") { out += pg_td(slot < field_count ? std::to_string(slot + 1) : std::string("–"), column.width, "r"); continue; } if (std::string(column.label) == "Name") { auto name = esc(row.at("name").get()); if (row.at("pair_number").is_number_integer()) name += "P" + std::to_string(row.at("pair_number").get()); // the player's photo heads his name out += pg_td("" + img("asset:player/" + (id.starts_with("player:") ? id.substr(7) : id) + "/photo", 46, 46 * 4.0 / 3.0, true, true, 128) + "" + btn("lineup-player", "" + name + "", "pg-link", player_attrs(row, "lineup-name-")), 0, "", true); continue; } std::string value; if (key == "position") value = pg_pos(lineup_position(row.at("position"))); else if (key == "nation") value = flag(row.at("nation")); else if (key == "status") { const auto text = row.at("status").get(); const bool out_of_action = text.find("erletz") != std::string::npos || text.find("esperr") != std::string::npos; value = out_of_action ? "" + esc(text) + "" : "" + esc(text) + ""; } else if (key == "strength") value = "" + esc(lineup_value(row.at(key))) + ""; else if (lineup_data_ == 1 && key != "age" && key != "games" && key != "grade" && row.at(key).is_number_integer() && row.at(key).get() >= 0 && row.at(key).get() <= 3) value = pg_dots(row.at(key).get(), 3); else value = "" + esc(lineup_value(row.at(key))) + ""; out += btn("player-detail", value, std::string("pg-td lp-cell ") + column.align, attr("id", "lineup-detail-" + id + "-" + std::to_string(field++)) + attr("data-id", id) + attr("aria-label", row.at("name").get() + ", Spielerinformationen") + " style=\"width:" + pg(column.width) + ";\""); } out += "
"; } if (rows.empty()) out += "
Für diesen Verein sind keine Spieler überliefert.
"; out += "
"; // --- the pitch or the squad as shirts --- std::string shirt_colour; if (const auto *club = world_->find("clubs", engine_data_.at("desktop").at("meta").at("scope").at("teamId").get()); club && !club->value("crest", "").empty()) shirt_colour = renderer_.crest_colour(club->value("crest", "")); if (shirt_colour.empty()) shirt_colour = "#b2622d"; const double shirt_size = 100; const auto shirt = [&](const Json &row, size_t index, const std::string &style) { const auto &condition = row.contains("condition") ? row.at("condition") : Json(); const bool selected = lineup_selected_ == row.at("id").get(); const std::string level = condition.is_number_integer() ? (condition.get() >= 85 ? "a" : condition.get() >= 70 ? "b" : "c") : "n"; return btn("lineup-player", "" + picture(renderer_.diagram("lineup-shirt-" + shirt_colour + (selected ? "-s-" : "-n-") + level, lineup_shirt(shirt_colour, selected, condition), 160), shirt_size, shirt_size) + "" + (index < size_t(field_count) ? std::to_string(index + 1) : std::string()) + "" + esc(last_name(row.at("name").get())) + "", std::string("lp-shirt") + (selected ? " sel" : ""), player_attrs(row, "lineup-player-") + (style.empty() ? std::string() : " style=\"" + style + "\"")); }; const double side_width = 900, pitch_height = 1512 - 27 - (indoor ? 420 : 250); out += "
"; if (lineup_pitch_) { std::string stripes; for (int band = 0; band < 8; ++band) stripes += ""; const auto field = "" + stripes + ""; out += "
" + picture(renderer_.diagram(std::string("lineup-page-field") + (indoor ? "-indoor" : ""), field, 900), side_width, pitch_height, true); const double depth_max = l.value("depth_max", 18), lane_max = l.value("lane_max", 8); 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; // the own goal is at the bottom: depth runs up the pitch, the lanes from left to right const bool paired = row.at("pair_number").is_number_integer(); const double x = (14 + point[1].get() / lane_max * 72) / 100 * side_width + (paired ? (row.at("pair_member") == 0 ? -0.62 : 0.62) * shirt_size : 0); const double y = (87 - point[0].get() / depth_max * 76) / 100 * pitch_height; out += shirt(row, i, "position:absolute;left:" + scalar(x - 110) + "dp;top:" + scalar(y - 70) + "dp;"); } out += "
"; } else { out += "
"; for (int part = 0; part < 3; ++part) { std::string shirts; for (size_t i = 0; i < rows.size(); ++i) { const int slot = rows[i].at("slot").get(); if ((slot < field_count ? 0 : rows[i].value("role", std::string()) == "bench" ? 1 : 2) == part) shirts += shirt(rows[i], size_t(slot), ""); } if (!shirts.empty()) out += pg_kicker(part == 0 ? (indoor ? "Aufgebot" : "Startelf") : part == 1 ? "Ersatzbank" : "Reserve") + "
" + shirts + "
"; } out += "
"; } const bool takers = lineup_side_ == "takers" && projection.at("set_pieces").is_object(); if (takers) { // who takes the set pieces: one of the three is chosen, the next click on a player names him out += "
Standardschützen" + pg_button("lineup-piece-auto", "Alle dem Co-Trainer", "", "id=\"lineup-piece-auto\"") + "
"; for (const auto &[key, label] : std::array, 3>{{{"freeKick", "Freistoß"}, {"penalty", "Elfmeter"}, {"corner", "Eckball"}}}) { const auto &taker = projection.at("set_pieces").at(key); std::string name = "Co-Trainer"; if (taker.is_string()) for (const auto &row : rows) if (row.at("id") == taker) name = last_name(row.at("name").get()); const bool chosen = lineup_piece_ == key; out += btn("lineup-piece", "" + pg_upper(label) + "" + esc(name) + "", std::string("pg-card lp-piece") + (chosen ? " sel" : ""), attr("id", std::string("lineup-piece-") + key) + attr("data-id", key) + attr("aria-pressed", chosen ? "true" : "false")); } out += "
Eine der drei Karten wählen, dann den Schützen in der Liste oder auf dem Feld anklicken. Möglich ist, wer aufgestellt ist oder auf der Bank sitzt.
"; } else { out += "
Aufstellung" "ab 85ab 70" "darunter
Zwei Spieler zum Tauschen anklicken." "Der Tausch wird erst nach Bestätigung übernommen."; if (indoor) { out += "
" + pg_kicker("Halle · Wechselpaare", "width:100%;"); for (const auto &pair : projection.at("pairs")) { std::string names; for (const auto &id : pair.at("playerIds")) for (const auto &row : rows) if (row.at("id") == id) names += (names.empty() ? "" : " / ") + last_name(row.at("name").get()); out += "P" + std::to_string(pair.at("number").get()) + " · " + esc(names) + ""; } if (projection.at("pairs").empty()) out += "Keine Wechselpaare bestätigt."; out += "
"; } out += "
"; } // --- the foot --- const auto pair_of = [&](const char *action, const char *id, const std::string &first, const std::string &second, bool second_on) { std::string seg = "
"; for (int i = 0; i < 2; ++i) { const bool on = (i == 1) == second_on; seg += btn(action, "" + (i ? second : first) + "", std::string(i ? "" : "first ") + (on ? "on" : ""), on ? std::string("style=\"pointer-events:none;\" aria-pressed=\"true\"") : "id=\"" + std::string(id) + "\" aria-pressed=\"false\""); } return seg + "
"; }; std::string status = engine_busy_ ? engine_operation_ : engine_notice_; if (!lineup_selected_.empty()) for (const auto &row : rows) if (row.at("id") == lineup_selected_) status = row.at("name").get() + " markiert · zweiten Spieler wählen."; if (lineup_side_ == "takers" && projection.at("set_pieces").is_object() && !engine_busy_) status = "Schützen: Karte wählen, dann Spieler anklicken."; if (status.empty()) status = "Kein Spieler markiert."; out += ""; return out + engine_player_profile(projection); }