Render authoritative indoor surfaces and substitution pairs in native lineups (by Codex)
This commit is contained in:
1 parent
179843700a
commit
d30e83c0a5
9 files changed
+206
-18
No files matched your search
@@ -106,6 +106,7 @@ Json metric_value(const Json &row, const char *key) {
|
||||
const auto value = metric.value("value", Json());
|
||||
return value.is_number_integer() ? value : Json();
|
||||
}
|
||||
#include "modern/ui/engine_lineup_context.inc"
|
||||
}
|
||||
Json engine_lineup_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
@@ -128,6 +129,7 @@ Json engine_lineup_projection(const Json &bundle) {
|
||||
}
|
||||
const auto depth_max = lineup.at("depthMax").get<int>(), lane_max = lineup.at("laneMax").get<int>();
|
||||
require(depth_max > 0 && lane_max > 0, "Ungültige Spielfeldkoordinaten.");
|
||||
const auto surface = lineup_surface_context(lineup, positions);
|
||||
Json rows = Json::array(), points = Json::array(); std::set<std::string> ids;
|
||||
for (const auto &value : lineup.at("order")) {
|
||||
const auto id = value.get<std::string>();
|
||||
@@ -144,6 +146,8 @@ Json engine_lineup_projection(const Json &bundle) {
|
||||
const auto role = roles.at(id).get<std::string>();
|
||||
require(role == "starter" || role == "bench" || role == "reserve", "Unbekannter Kaderstatus.");
|
||||
row["status"] = role == "starter" ? "Startelf" : role == "bench" ? "Ersatzbank" : "—";
|
||||
row["partner"] = nullptr; row["pair_number"] = nullptr; row["pair_member"] = nullptr;
|
||||
if (surface.at("members").contains(id)) row.update(surface.at("members").at(id));
|
||||
rows.push_back(std::move(row));
|
||||
if (points.size() < lineup.at("positions").size()) {
|
||||
if (!positions.contains(id)) points.push_back(nullptr);
|
||||
@@ -155,6 +159,7 @@ Json engine_lineup_projection(const Json &bundle) {
|
||||
}
|
||||
require(ids.size() == members.size() && ids.size() == roles.size(), "Aufstellung enthält nicht den vollständigen Kader.");
|
||||
return {{"ok", true}, {"rows", rows}, {"field_count", points.size()},
|
||||
{"surface", surface.at("surface")}, {"duration", surface.at("duration")}, {"pairs", surface.at("pairs")},
|
||||
{"board", {{"order", lineup.at("order")}, {"points", points}, {"depth_max", depth_max}, {"lane_max", lane_max}}}};
|
||||
}
|
||||
Json engine_lineup_command(const Json &bundle, const Json &order, const std::string &request_id) {
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Presentation and selection only. The existing session validates each swap.
|
||||
std::string App::engine_lineup_controls() {
|
||||
return "<div class=\"lineup-orders\" style=\"position:relative;width:100%;height:100%;\"><h2>Aufstellung</h2>"
|
||||
"<p class=\"lineup-order-name\">Zwei Spieler zum Tauschen anklicken.</p>"
|
||||
"<p class=\"lineup-hint\">Der Tausch wird erst nach Bestätigung übernommen. "
|
||||
"Formationen, Anweisungen und Schützen sind hier noch nicht angebunden.</p>"
|
||||
const auto data = engine_lineup_projection(engine_data_);
|
||||
std::string pairs;
|
||||
if (data.at("surface") == "indoor") {
|
||||
pairs = "<div id=\"lineup-engine-pairs\" class=\"lineup-engine-pairs\"><strong>Halle · 40 Minuten</strong><p>Das Aufgebot bleibt vollständig. Markierte Partner wechseln gemeinsam.</p>";
|
||||
for (const auto &pair : data.at("pairs")) {
|
||||
std::string names;
|
||||
for (const auto &id : pair.at("playerIds")) {
|
||||
for (const auto &row : data.at("rows")) if (row.at("id") == id) {
|
||||
if (!names.empty()) names += " / ";
|
||||
names += row.at("name").get<std::string>();
|
||||
}
|
||||
}
|
||||
pairs += "<div class=\"lineup-engine-pair\"><span>P" + std::to_string(pair.at("number").get<int>()) + "</span><span>" + esc(names) + "</span></div>";
|
||||
}
|
||||
if (data.at("pairs").empty()) pairs += "<p>Keine Wechselpaare bestätigt.</p>";
|
||||
pairs += "</div>";
|
||||
}
|
||||
return "<div class=\"lineup-engine-controls\" style=\"position:relative;width:100%;height:100%;\"><h2>Aufstellung</h2>"
|
||||
"<p class=\"lineup-engine-instruction\">Zwei Spieler zum Tauschen anklicken.</p>"
|
||||
"<p class=\"lineup-engine-hint\">Der Tausch wird erst nach Bestätigung übernommen. "
|
||||
"Formationen, Anweisungen und Schützen sind hier noch nicht angebunden.</p>" + pairs +
|
||||
"<p class=\"small muted\" style=\"position:absolute;left:0;right:0;bottom:0;\">" +
|
||||
esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</p></div>";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The transport context is independent of the saved eleven-player order.
|
||||
Json lineup_surface_context(const Json &lineup,
|
||||
const std::map<std::string, Json> &positions) {
|
||||
const auto surface = lineup.value("surface", std::string("unknown"));
|
||||
require(surface == "unknown" || surface == "outdoor" || surface == "indoor",
|
||||
"Unbekannte Spielfeldoberfläche.");
|
||||
Json result = {{"surface", surface},
|
||||
{"duration", nullptr},
|
||||
{"pairs", Json::array()},
|
||||
{"members", Json::object()}};
|
||||
if (surface == "unknown") {
|
||||
require(!lineup.contains("pairs") && !lineup.contains("durationMinutes"),
|
||||
"Unvollständiger Spielfeldkontext.");
|
||||
return result;
|
||||
}
|
||||
require(lineup.at("starterCount").is_number_integer() &&
|
||||
lineup.at("starterCount") == 11 &&
|
||||
lineup.at("durationMinutes").is_number_integer() &&
|
||||
lineup.at("durationMinutes") == (surface == "indoor" ? 40 : 90) &&
|
||||
lineup.at("pairs").is_array() && lineup.at("pairs").size() <= 5,
|
||||
"Ungültiger Hallen-/Rasenkontext.");
|
||||
result["duration"] = lineup.at("durationMinutes");
|
||||
std::map<std::string, int> source_rows, display_rows;
|
||||
int index = 0;
|
||||
for (const auto &id : lineup.at("order"))
|
||||
display_rows.emplace(id.get<std::string>(), index++);
|
||||
std::set<int> occupied_rows;
|
||||
for (const auto &row : lineup.at("rows")) {
|
||||
require(row.at("row").is_number_integer() && row.at("row") >= 0 &&
|
||||
row.at("row") < 256 &&
|
||||
occupied_rows.insert(row.at("row").get<int>()).second,
|
||||
"Ungültige ursprüngliche Kaderzeile.");
|
||||
source_rows.emplace(row.at("playerId").get<std::string>(), row.at("row"));
|
||||
}
|
||||
std::set<std::string> paired;
|
||||
for (const auto &pair : lineup.at("pairs")) {
|
||||
const auto &ids = pair.at("playerIds"), &rows = pair.at("rows");
|
||||
require(ids.is_array() && ids.size() == 2 && rows.is_array() &&
|
||||
rows.size() == 2,
|
||||
"Unvollständiges Wechselpaar.");
|
||||
std::array<std::string, 2> members;
|
||||
Json numbers = Json::array();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
require(ids[size_t(i)].is_string() && rows[size_t(i)].is_number_integer(),
|
||||
"Ungültiges Wechselpaar.");
|
||||
members[size_t(i)] = ids[size_t(i)].get<std::string>();
|
||||
const auto &id = members[size_t(i)];
|
||||
require(positions.contains(id) && source_rows.contains(id) &&
|
||||
display_rows.contains(id) && rows[size_t(i)] >= 0 &&
|
||||
rows[size_t(i)] < 11 &&
|
||||
source_rows.at(id) == rows[size_t(i)] &&
|
||||
paired.insert(id).second,
|
||||
"Wechselpaar enthält fremde oder doppelte Spieler.");
|
||||
numbers.push_back(display_rows.at(id) + 1);
|
||||
}
|
||||
require(positions.at(members[0]).at("partnerId") == members[1] &&
|
||||
positions.at(members[1]).at("partnerId") == members[0],
|
||||
"Wechselpaar ist nicht gegenseitig bestätigt.");
|
||||
// Outdoor boards may retain valid partner bytes; they are not indoor
|
||||
// groups.
|
||||
if (surface != "indoor")
|
||||
continue;
|
||||
const int group = int(result.at("pairs").size()) + 1;
|
||||
result["pairs"].push_back(
|
||||
{{"playerIds", ids}, {"numbers", numbers}, {"number", group}});
|
||||
for (int i = 0; i < 2; ++i)
|
||||
result["members"][members[size_t(i)]] = {
|
||||
{"partner", members[size_t(1 - i)]},
|
||||
{"pair_number", group},
|
||||
{"pair_member", i}};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ std::string App::render_lineup() {
|
||||
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<int>() : demo_career_field_count(s.state);
|
||||
const bool indoor = !engine_mode_ && field_count == 6;
|
||||
const bool indoor = engine_mode_ ? projection.at("surface") == "indoor" : field_count == 6;
|
||||
if (lineup_slot(l, lineup_selected_) < 0)
|
||||
lineup_selected_.clear();
|
||||
lineup_data_ = lineup_data_ == 1 ? 1 : 0;
|
||||
@@ -208,7 +208,10 @@ std::string App::render_lineup() {
|
||||
out += "<span class=\"lineup-cell lineup-col-0\"><span>" +
|
||||
(slot < field_count ? std::to_string(slot + 1) : "–") +
|
||||
"</span></span>";
|
||||
out += btn("lineup-player", esc(row.at("name").get<std::string>()),
|
||||
auto name = esc(row.at("name").get<std::string>());
|
||||
if (engine_mode_ && row.at("pair_number").is_number_integer())
|
||||
name = "<span class=\"lineup-pair-name\">" + name + "</span><span class=\"lineup-pair-chip\">P" + std::to_string(row.at("pair_number").get<int>()) + "</span>";
|
||||
out += btn("lineup-player", name,
|
||||
"lineup-cell lineup-col-1 lineup-name",
|
||||
player_attrs(row, "lineup-name-"));
|
||||
std::vector<std::string> fields;
|
||||
@@ -295,10 +298,10 @@ std::string App::render_lineup() {
|
||||
out +=
|
||||
"<nav class=\"lineup-surface-controls\" "
|
||||
"aria-label=\"Spielfeldvariante\">" +
|
||||
btn("lineup-surface", "Rasen · 11", indoor ? "" : "selected",
|
||||
btn("lineup-surface", engine_mode_ ? "Rasen · 90 Min." : "Rasen · 11", indoor ? "" : "selected",
|
||||
"id=\"lineup-surface-outdoor\" data-id=\"outdoor\" aria-pressed=\"" +
|
||||
(indoor ? std::string("false") : "true") + "\" " + (engine_mode_ ? "disabled" : "")) +
|
||||
btn("lineup-surface", "Halle · 6", indoor ? "selected" : "",
|
||||
btn("lineup-surface", engine_mode_ ? "Halle · 40 Min." : "Halle · 6", indoor ? "selected" : "",
|
||||
"id=\"lineup-surface-indoor\" data-id=\"indoor\" aria-pressed=\"" +
|
||||
(indoor ? std::string("true") : "false") + "\" " +
|
||||
(engine_mode_ || s.state.at("career").value("role", "club") == "national"
|
||||
@@ -322,27 +325,43 @@ std::string App::render_lineup() {
|
||||
lineup_art_width_dp, lineup_art_height_dp) +
|
||||
"</div>";
|
||||
}
|
||||
for (size_t i = 0; i < std::min(size_t(field_count), rows.size()); ++i) {
|
||||
const auto marker_position = [&](size_t 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<std::string>();
|
||||
const auto x =
|
||||
const bool paired = engine_mode_ && row.at("pair_number").is_number_integer();
|
||||
const auto pair_offset = paired ? (row.at("pair_member") == 0 ? -0.30 : 0.30) * lineup_player_size_dp : 0.;
|
||||
const auto x = pair_offset +
|
||||
(8 + point[0].get<int>() / 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<int>() / double(l.value("lane_max", 8)) * 80) * lineup_art_height_dp / 100.0 -
|
||||
lineup_player_anchor_y_dp;
|
||||
return std::pair<double, double>{x, y};
|
||||
};
|
||||
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<std::string>();
|
||||
const bool paired = engine_mode_ && row.at("pair_number").is_number_integer();
|
||||
const auto [x, y] = marker_position(i);
|
||||
out +=
|
||||
btn("lineup-player",
|
||||
img(selected ? "lineup.player.selected" : "lineup.player.normal",
|
||||
lineup_player_size_dp, lineup_player_size_dp) +
|
||||
"<span class=\"lineup-jersey\">" + std::to_string(i + 1) +
|
||||
"</span>",
|
||||
"lineup-player",
|
||||
paired ? "lineup-player lineup-paired" : "lineup-player",
|
||||
player_attrs(row, "lineup-player-") +
|
||||
attr("style", rect(x, y, lineup_player_size_dp,
|
||||
lineup_player_size_dp)));
|
||||
}
|
||||
if (engine_mode_ && indoor) for (const auto &pair : projection.at("pairs")) {
|
||||
const auto &ids = pair.at("playerIds");
|
||||
const int a = lineup_slot(l, ids[0]), b = lineup_slot(l, ids[1]);
|
||||
if (a < 0 || b < 0 || a >= field_count || b >= field_count || l.at("points")[size_t(a)].is_null() || l.at("points")[size_t(b)].is_null()) continue;
|
||||
const auto [ax, ay] = marker_position(size_t(a));
|
||||
const auto [bx, by] = marker_position(size_t(b));
|
||||
out += "<span class=\"lineup-pair-tag\" id=\"lineup-pair-group-" + std::to_string(pair.at("number").get<int>()) + "\" style=\"" + rect((ax + bx + lineup_player_size_dp) / 2 - 24, std::min(ay, by) - 24, 48, 22) + "\"><span>P" + std::to_string(pair.at("number").get<int>()) + "</span></span>";
|
||||
}
|
||||
out += "<div id=\"lineup-ghost\" class=\"lineup-ghost\">" +
|
||||
img("lineup.player.ghost", lineup_player_size_dp,
|
||||
lineup_player_size_dp) +
|
||||
@@ -546,9 +565,8 @@ std::string App::render_lineup() {
|
||||
: 0;
|
||||
out += "<footer class=\"lineup-team-actions\">" + data_btn() + view_btn() +
|
||||
"<span>" +
|
||||
std::to_string(std::min(size_t(field_count), rows.size())) +
|
||||
" Spieler auf dem Feld · " + std::to_string(bench) +
|
||||
(indoor ? " Wechselspieler · " : " Ersatzbank · ") +
|
||||
(engine_mode_ && indoor ? "Hallenaufgebot: " + std::to_string(std::min(size_t(field_count), rows.size())) + " · " + std::to_string(projection.at("pairs").size()) + " Wechselpaare · " : std::to_string(std::min(size_t(field_count), rows.size())) + " Spieler auf dem Feld · ") + std::to_string(bench) +
|
||||
(indoor && !engine_mode_ ? " Wechselspieler · " : " Ersatzbank · ") +
|
||||
std::to_string(reserves) + " Reserve</span></footer>";
|
||||
}
|
||||
out += "</div>";
|
||||
|
||||
Reference in new issue
Block a user