Line-up and training as pages; the friendlies' opponents as tiles

The line-up of the real game is the squad as a grouped table and the eleven as
shirts on a pitch seen from behind the own goal, or the whole squad as shirts.
Training keeps the game's own arrangement and pictures in the page's size and
inks. The opponents of a friendly are tiles in four columns with both crests.
The demo keeps the older line-up sheet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 18:42:07 +01:00
1 parent 9faf0acf81
commit c7d23185ec
7 files changed
+268 -109

No files matched your search

+164
View File
@@ -0,0 +1,164 @@
// 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 "<div class=\"pg-page\"><div class=\"pg-empty\">Die Aufstellung ist derzeit nicht verfügbar.</div></div>";
const auto &l = projection.at("board");
const auto &rows = projection.at("rows");
const int field_count = projection.at("field_count").get<int>();
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<std::string>();
return attr("id", prefix + id) + attr("data-id", id) + attr("data-squad-player", id) + attr("data-slot", std::to_string(row.at("slot").get<size_t>())) +
attr("aria-pressed", lineup_selected_ == id ? "true" : "false") + attr("aria-label", row.at("name").get<std::string>() + ", " + 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<std::string>();
if (code.starts_with("nation:")) code = code.substr(7);
const auto svg = code == "de" ? lineup_svg("<path fill=\"#111111\" d=\"M0 0H40V8H0Z\"/><path fill=\"#bc302e\" d=\"M0 8H40V16H0Z\"/><path fill=\"#edc758\" d=\"M0 16H40V24H0Z\"/>", "0 0 40 24") : ui_nation_flag_svg(code);
if (!svg.empty()) return "<span class=\"lp-flag\">" + picture(renderer_.diagram("lineup-flag-" + code, svg, 80), 45, 27) + "</span>";
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<Column> columns = lineup_data_ == 0
? std::vector<Column>{{"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<Column>{{"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 = "<div id=\"lineup-underlay\" class=\"pg-page" + std::string(indoor ? " indoor-lineup" : "") + "\"><div class=\"pg-body\"><div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:0px;padding:6px 10px;") +
"\"><div class=\"pg-t\" role=\"table\"><div class=\"pg-thead\" role=\"row\">";
for (const auto &column : columns) out += pg_th(column.label, column.width, column.align);
out += "</div><div id=\"lineup-roster-scroll\" class=\"pg-tbody\" tabindex=\"0\" aria-label=\"Kaderliste, scrollbar\">";
int group = -1;
for (const auto &row : rows) {
const auto slot = row.at("slot").get<int>();
const auto id = row.at("id").get<std::string>();
const int part = slot < field_count ? 0 : row.value("role", std::string()) == "bench" ? 1 : 2;
if (part != group) {
group = part;
out += "<div class=\"pg-tr grp\">" + pg_td(pg_upper(part == 0 ? (indoor ? "Aufgebot" : "Startelf") : part == 1 ? "Ersatzbank" : "Übriger Kader"), 0) + "</div>";
}
out += "<div class=\"pg-tr " + std::string(lineup_selected_ == id ? "sel" : "") + "\" role=\"row\" style=\"height:" + pg(30) + ";\">";
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<std::string>());
if (row.at("pair_number").is_number_integer()) name += "</span><span class=\"pg-tag sage\" style=\"margin-left:" + pg(6) + ";\">P" + std::to_string(row.at("pair_number").get<int>());
out += pg_td(btn("lineup-player", "<span>" + name + "</span>", "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<std::string>();
const bool out_of_action = text.find("erletz") != std::string::npos || text.find("esperr") != std::string::npos;
value = out_of_action ? "<span class=\"pg-tag accent\">" + esc(text) + "</span>" : "<span>" + esc(text) + "</span>";
} else if (key == "strength") value = "<strong>" + esc(lineup_value(row.at(key))) + "</strong>";
else if (lineup_data_ == 1 && key != "age" && key != "games" && key != "grade" && row.at(key).is_number_integer() && row.at(key).get<int>() >= 0 && row.at(key).get<int>() <= 3)
value = pg_dots(row.at(key).get<int>(), 3);
else value = "<span>" + esc(lineup_value(row.at(key))) + "</span>";
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<std::string>() + ", Spielerinformationen") + " style=\"width:" + pg(column.width) + ";\"");
}
out += "</div>";
}
if (rows.empty()) out += "<div class=\"pg-empty\">Für diesen Verein sind keine Spieler überliefert.</div>";
out += "</div></div></div>";
// --- 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<std::string>()); 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<std::string>();
const std::string level = condition.is_number_integer() ? (condition.get<int>() >= 85 ? "a" : condition.get<int>() >= 70 ? "b" : "c") : "n";
return btn("lineup-player", "<span class=\"lp-shirt-art\">" + picture(renderer_.diagram("lineup-shirt-" + shirt_colour + (selected ? "-s-" : "-n-") + level, lineup_shirt(shirt_colour, selected, condition), 160), shirt_size, shirt_size) +
"<span class=\"lp-num\">" + (index < size_t(field_count) ? std::to_string(index + 1) : std::string()) + "</span></span><span class=\"lp-name\">" + esc(last_name(row.at("name").get<std::string>())) + "</span>",
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 += "<div class=\"pg-col\" style=\"width:" + scalar(side_width) + "dp;\">";
if (lineup_pitch_) {
std::string stripes;
for (int band = 0; band < 8; ++band)
stripes += "<rect y=\"" + scalar(band * 16.25) + "\" width=\"100\" height=\"16.25\" fill=\"" + (indoor ? (band % 2 ? "#d2ad7a" : "#c79d68") : (band % 2 ? "#b6cf97" : "#a9c489")) + "\"/>";
const auto field = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 130\" preserveAspectRatio=\"none\">" + stripes +
"<g fill=\"none\" stroke=\"#fdfbf4\" stroke-width=\".7\"><rect x=\"5\" y=\"5\" width=\"90\" height=\"120\" rx=\"1\"/><path d=\"M5 65h90M30 5v17h40V5M30 125v-17h40v17M41 5v6h18V5M41 125v-6h18v6\"/><ellipse cx=\"50\" cy=\"65\" rx=\"11\" ry=\"9\"/></g></svg>";
out += "<div id=\"lineup-pitch\" class=\"lp-pitch\" role=\"group\" aria-label=\"Spielfeld, Spieler auswählen\" style=\"height:" + scalar(pitch_height) + "dp;\">" +
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<int>() / 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<int>() / depth_max * 76) / 100 * pitch_height;
out += shirt(row, i, "position:absolute;left:" + scalar(x - 110) + "dp;top:" + scalar(y - 70) + "dp;");
}
out += "</div>";
} else {
out += "<div class=\"pg-panel pg-col lp-team\" style=\"height:" + scalar(pitch_height) + "dp;\">";
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<int>();
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") + "<div class=\"lp-team-row\">" + shirts + "</div>";
}
out += "</div>";
}
out += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-h\">Aufstellung</strong><span class=\"pg-legend\">"
"<span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot a\"></span><span>ab 85</span></span><span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot b\"></span><span>ab 70</span></span>"
"<span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot c\"></span><span>darunter</span></span></span></div><span style=\"display:block;\">Zwei Spieler zum Tauschen anklicken.</span>"
"<span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">Der Tausch wird erst nach Bestätigung übernommen.</span>";
if (indoor) {
out += "<div id=\"lineup-engine-pairs\" class=\"lp-pairs\">" + 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<std::string>());
out += "<span class=\"pg-nowrap lp-pair\"><strong>P" + std::to_string(pair.at("number").get<int>()) + "</strong> · " + esc(names) + "</span>";
}
if (projection.at("pairs").empty()) out += "<span class=\"pg-mut\" style=\"display:block;\">Keine Wechselpaare bestätigt.</span>";
out += "</div>";
}
out += "</div></div></div>";
// --- 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 = "<div class=\"pg-seg\">";
for (int i = 0; i < 2; ++i) {
const bool on = (i == 1) == second_on;
seg += btn(action, "<span>" + (i ? second : first) + "</span>", 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 + "</div>";
};
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<std::string>() + " markiert · zweiten Spieler wählen.";
if (status.empty()) status = "Kein Spieler markiert.";
out += "<nav class=\"pg-foot\">" + pair_of("lineup-data", "lineup-data", "Daten A", "Daten B", lineup_data_ == 1) + pair_of("lineup-view", "lineup-view", "Spielfeld", "Team", !lineup_pitch_) + "<div class=\"pg-seg\">";
for (const auto &[side, label] : std::array<std::pair<const char *, const char *>, 3>{{{"formations", "Aufst."}, {"orders", "Anweis."}, {"takers", "Schütze"}}})
out += btn("lineup-side", "<span>" + std::string(label) + "</span>", std::string(side) == "formations" ? "first" : "", attr("id", "lineup-side-" + std::string(side)) + attr("data-id", side) + " disabled title=\"Im Spiel nicht verfügbar\"");
out += "</div><span class=\"pg-tag sage\">" + std::string(indoor ? "Halle · 40 Min." : "Rasen · 90 Min.") + "</span><span class=\"pg-sp\"></span>" + pg_status(status) + "</nav></div>";
return out + engine_player_profile(projection);
}