The four instructions of a starter can be set in the line-up
The read lineup states the instructions of every starter (board bytes +2..+5) and lineup.setOrder sets one through set_player_order_source. Anweis. in the line-up shows them for the chosen starter with the original's four arrows; each is moved in steps of 1 or 5. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
3330dfb69c
commit
a2790751a6
8 files changed
+101
-8
No files matched your search
@@ -21,6 +21,7 @@ Json engine_training_command(const Json &bundle, const Json &draft,
|
||||
const std::string &request_id);
|
||||
Json engine_bank_projection(const Json &bundle);
|
||||
Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id);
|
||||
Json engine_order_command(const Json &bundle, const std::string &player, int aspect, int value, const std::string &request_id);
|
||||
Json engine_set_piece_command(const Json &bundle, const Json &payload, const std::string &request_id);
|
||||
Json engine_credit_projection(const Json &bundle, const Json &read);
|
||||
Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id);
|
||||
|
||||
@@ -131,7 +131,14 @@ 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;
|
||||
Json rows = Json::array(), points = Json::array(), orders = Json::object(); std::set<std::string> ids;
|
||||
// the four instructions of every starter, where the backend states them
|
||||
for (const auto &[id, point] : positions)
|
||||
if (point.contains("orders") && point.at("orders").is_array() && point.at("orders").size() == 4) {
|
||||
Json four = Json::array();
|
||||
for (const auto &value : point.at("orders")) { require(value.is_number_integer() && value.get<int>() >= 0 && value.get<int>() <= 255, "Ungültige Anweisung."); four.push_back(value.get<int>()); }
|
||||
orders[id] = four;
|
||||
}
|
||||
for (const auto &value : lineup.at("order")) {
|
||||
const auto id = value.get<std::string>();
|
||||
require(members.contains(id) && roles.contains(id) && ids.insert(id).second, "Aufstellung enthält fremde oder doppelte Spieler.");
|
||||
@@ -173,11 +180,16 @@ Json engine_lineup_projection(const Json &bundle) {
|
||||
set_pieces[key] = taker;
|
||||
}
|
||||
}
|
||||
return {{"ok", true}, {"rows", rows}, {"field_count", points.size()}, {"set_pieces", set_pieces},
|
||||
return {{"ok", true}, {"rows", rows}, {"field_count", points.size()}, {"set_pieces", set_pieces}, {"orders", orders},
|
||||
{"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}}}};
|
||||
}
|
||||
namespace { Json sports_command(const Json &bundle, const char *kind, const Json &payload, const std::string &id); }
|
||||
Json engine_order_command(const Json &bundle, const std::string &player, int aspect, int value, const std::string &request_id) {
|
||||
const auto projection = engine_lineup_projection(bundle);
|
||||
require(projection.at("orders").contains(player) && aspect >= 0 && aspect <= 3 && value >= 2 && value <= 40, "Ungültige Anweisung.");
|
||||
return sports_command(bundle, "lineup.setOrder", {{"playerId", player}, {"aspect", aspect}, {"value", value}}, request_id);
|
||||
}
|
||||
Json engine_set_piece_command(const Json &bundle, const Json &payload, const std::string &request_id) {
|
||||
const auto projection = engine_lineup_projection(bundle);
|
||||
require(projection.at("set_pieces").is_object(), "Schützen sind in diesem Kontext nicht verfügbar.");
|
||||
|
||||
@@ -67,8 +67,8 @@ bool App::engine_lineup_action(const std::string &action, const std::string &id,
|
||||
}
|
||||
// "Schütze": the side panel names the takers of the set pieces; a click on a player then names him
|
||||
if (action == "lineup-side") {
|
||||
lineup_side_ = id == "takers" && lineup_side_ != "takers" ? "takers" : "formations";
|
||||
lineup_selected_.clear(); focus_after_render_ = "lineup-side-takers"; refresh(); return true;
|
||||
lineup_side_ = (id == "takers" || id == "orders") && lineup_side_ != id ? id : "formations";
|
||||
lineup_selected_.clear(); focus_after_render_ = "lineup-side-" + id; refresh(); return true;
|
||||
}
|
||||
if (action == "lineup-piece") {
|
||||
if (id == "freeKick" || id == "penalty" || id == "corner") lineup_piece_ = id;
|
||||
@@ -87,8 +87,31 @@ bool App::engine_lineup_action(const std::string &action, const std::string &id,
|
||||
} catch (const std::exception &e) { message(e.what()); }
|
||||
};
|
||||
if (action == "lineup-piece-auto") { send_takers({{"auto", true}}, "lineup-piece-auto"); return true; }
|
||||
// "Anweis.": the four instructions of the chosen starter, each moved by a step
|
||||
if (action == "lineup-order") {
|
||||
if (!engine_fresh_ || engine_busy_ || lineup_selected_.empty() || !target) return true;
|
||||
try {
|
||||
const auto orders = engine_lineup_projection(engine_data_).at("orders");
|
||||
const int aspect = target->GetAttribute<int>("data-id", -1), step = target->GetAttribute<int>("data-step", 0);
|
||||
if (!orders.contains(lineup_selected_) || aspect < 0 || aspect > 3 || !step) return true;
|
||||
const int value = std::clamp(orders.at(lineup_selected_)[size_t(aspect)].get<int>() + step, 2, 40);
|
||||
const auto command = engine_order_command(engine_data_, lineup_selected_, aspect, value, editor::new_id("request:ui-"));
|
||||
focus_after_render_ = target->GetId();
|
||||
auto link = engine_link_;
|
||||
engine_start("Anweisung wird übernommen …", [link, command] {
|
||||
auto response = link->command(command);
|
||||
return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
}, true);
|
||||
} catch (const std::exception &e) { message(e.what()); }
|
||||
return true;
|
||||
}
|
||||
if (action != "lineup-player" && action != "player-detail") return action.starts_with("lineup-");
|
||||
const auto projection = engine_lineup_projection(engine_data_);
|
||||
if (action == "lineup-player" && lineup_side_ == "orders") {
|
||||
// a click chooses whose instructions are shown; nobody is swapped here
|
||||
lineup_selected_ = lineup_selected_ == id ? "" : id;
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
if (action == "lineup-player" && lineup_side_ == "takers" && projection.at("set_pieces").is_object()) {
|
||||
send_takers({{"piece", lineup_piece_}, {"playerId", id}}, target->GetId());
|
||||
return true;
|
||||
|
||||
@@ -128,7 +128,31 @@ std::string App::render_lineup_page() {
|
||||
out += "</div>";
|
||||
}
|
||||
const bool takers = lineup_side_ == "takers" && projection.at("set_pieces").is_object();
|
||||
if (takers) {
|
||||
const bool ordering = lineup_side_ == "orders" && projection.at("orders").is_object() && !projection.at("orders").empty();
|
||||
if (ordering) {
|
||||
// the four instructions of the chosen starter: how far he goes forward and back, how wide he plays, how much he covers
|
||||
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\">Anweisungen</strong><span class=\"pg-mut\">";
|
||||
std::string who;
|
||||
for (const auto &row : rows) if (row.at("id") == lineup_selected_) who = row.at("name").get<std::string>();
|
||||
const bool starter = !lineup_selected_.empty() && projection.at("orders").contains(lineup_selected_);
|
||||
out += esc(starter ? who : lineup_selected_.empty() ? std::string("Einen Feldspieler anklicken.") : who + " ist nicht aufgestellt.") + "</span></div>";
|
||||
if (starter) {
|
||||
static constexpr std::array<const char *, 4> paths{"M8 34L34 8M14 8H34V28", "M8 34L34 8M8 14V34H28", "M4 22H40M13 13L4 22L13 31M31 13L40 22L31 31", "M22 4V40M13 13L22 4L31 13M13 31L22 40L31 31"};
|
||||
static constexpr std::array<const char *, 4> spoken{"nach vorn", "nach hinten", "in die Breite", "in die Tiefe"};
|
||||
const std::string ink = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f";
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const int value = projection.at("orders").at(lineup_selected_)[size_t(i)].get<int>();
|
||||
const auto step = [&](int by, const char *label) {
|
||||
return pg_button("lineup-order", label, "round lp-step", attr("id", "lineup-order-" + std::to_string(i) + (by < 0 ? "-less" : "-more") + (std::abs(by) > 1 ? "-far" : "")) + attr("data-id", std::to_string(i)) + attr("data-step", std::to_string(by)) +
|
||||
attr("aria-label", std::string("Anweisung ") + spoken[size_t(i)] + (by < 0 ? " verringern" : " erhöhen")) + ((by < 0 && value <= 2) || (by > 0 && value >= 40) ? " disabled=\"disabled\"" : ""));
|
||||
};
|
||||
out += "<div class=\"pg-row lp-order\"><span class=\"lp-order-icon\" title=\"" + std::string(spoken[size_t(i)]) + "\">" +
|
||||
picture(renderer_.diagram("lineup-order-" + std::to_string(i) + "-" + theme_, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 44 44\"><path d=\"" + std::string(paths[size_t(i)]) + "\" fill=\"none\" stroke=\"" + ink + "\" stroke-width=\"3\"/></svg>", 96), 50, 50) +
|
||||
"</span>" + step(-5, "«") + step(-1, "−") + pg_bar((value - 2) * 100.0 / 38, i < 2 ? "accent" : "sage") + "<strong class=\"lp-order-value\">" + std::to_string(value) + "</strong>" + step(1, "+") + step(5, "»") + "</div>";
|
||||
}
|
||||
}
|
||||
out += "</div></div></div>";
|
||||
} else if (takers) {
|
||||
// who takes the set pieces: one of the three is chosen, the next click on a player names him
|
||||
out += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:6px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-h\">Standardschützen</strong>" +
|
||||
pg_button("lineup-piece-auto", "Alle dem Co-Trainer", "", "id=\"lineup-piece-auto\"") + "</div><div class=\"pg-row\" style=\"align-items:stretch;" + pg_css("gap:8px;") + "\">";
|
||||
@@ -173,11 +197,12 @@ std::string App::render_lineup_page() {
|
||||
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 (lineup_side_ == "takers" && projection.at("set_pieces").is_object() && !engine_busy_) status = "Schützen: Karte wählen, dann Spieler anklicken.";
|
||||
if (ordering && !engine_busy_) status = lineup_selected_.empty() ? "Anweisungen: einen Feldspieler anklicken." : "Anweisungen in Schritten von 1 oder 5 ändern.";
|
||||
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(std::string(side) == "formations" ? "first" : "") + (std::string(side) == "takers" && takers ? " on" : ""),
|
||||
attr("id", "lineup-side-" + std::string(side)) + attr("data-id", side) + (std::string(side) == "takers" && projection.at("set_pieces").is_object() ? attr("aria-pressed", takers ? "true" : "false") : std::string(" disabled title=\"Im Spiel nicht verfügbar\"")));
|
||||
out += btn("lineup-side", "<span>" + std::string(label) + "</span>", std::string(std::string(side) == "formations" ? "first" : "") + ((std::string(side) == "takers" && takers) || (std::string(side) == "orders" && ordering) ? " on" : ""),
|
||||
attr("id", "lineup-side-" + std::string(side)) + attr("data-id", side) + ((std::string(side) == "takers" && projection.at("set_pieces").is_object()) || (std::string(side) == "orders" && projection.at("orders").is_object() && !projection.at("orders").empty()) ? attr("aria-pressed", (std::string(side) == "takers" ? takers : ordering) ? "true" : "false") : std::string(" 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);
|
||||
}
|
||||
Reference in new issue
Block a user