Bind squad and lineup views to confirmed engine player swaps (by Codex)

This commit is contained in:
Codex committed 2026-10-28 09:01:14 +01:00
1 parent 94dc5ecbc4
commit 7d3b3f1101
15 files changed
+340 -36

No files matched your search

+84
View File
@@ -84,4 +84,88 @@ Json engine_camp_command(const Json &bundle, const std::string &id,
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
{"kind", "camp.book"}, {"payload", {{"campId", id}, {"focus", focus}}}};
}
namespace {
const Json &lineup_read(const Json &bundle, const char *kind) {
const auto &read = bundle.at(kind), &meta = bundle.at("desktop").at("meta");
require(read.value("messageType", "") == "snapshot" && read.at("data").value("kind", "") == kind,
"Kader oder Aufstellung sind in diesem Kontext nicht verfügbar.");
for (const auto *key : {"contractVersion", "careerId", "worldId", "worldRevision", "stateRevision", "scope"})
require(read.at("meta").at(key) == meta.at(key), "Kader und Aufstellung haben unterschiedliche Kontexte.");
return read.at("data");
}
Json metric_value(const Json &row, const char *key) {
const auto &metrics = row.at("metrics");
if (!metrics.contains(key) || !metrics.at(key).is_object()) return nullptr;
const auto &metric = metrics.at(key);
if (metric.contains("availability") && metric.at("availability").value("status", "") != "available") return nullptr;
const auto value = metric.value("value", Json());
return value.is_number_integer() ? value : Json();
}
}
Json engine_lineup_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &squad = lineup_read(bundle, "squad"), &lineup = lineup_read(bundle, "lineup");
const auto &team = bundle.at("desktop").at("meta").at("scope").at("teamId");
require(squad.at("team").at("id") == team && lineup.at("teamId") == team,
"Aufstellung gehört einer anderen Mannschaft.");
require(lineup.at("order").is_array() && lineup.at("rows").is_array() && lineup.at("positions").is_array(),
"Ungültige Aufstellungsdaten.");
std::map<std::string, Json> members, roles, positions;
for (const auto &row : squad.at("players")) {
const auto id = row.at("player").at("id").get<std::string>();
require(!id.empty() && members.emplace(id, row).second, "Doppelte Spieler-ID im Kader.");
}
for (const auto &row : lineup.at("rows"))
require(roles.emplace(row.at("playerId").get<std::string>(), row.at("role")).second, "Doppelte Aufstellungszeile.");
for (const auto &point : lineup.at("positions")) {
const auto id = point.at("playerId").get<std::string>();
require(members.contains(id) && positions.emplace(id, point).second, "Unbekannte oder doppelte Spielfeldposition.");
}
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.");
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>();
require(members.contains(id) && roles.contains(id) && ids.insert(id).second, "Aufstellung enthält fremde oder doppelte Spieler.");
const auto &raw = members.at(id), &person = raw.at("player");
Json row = {{"id", id}, {"name", person.at("name")}, {"slot", rows.size()},
{"position", person.at("positions").empty() ? Json() : person.at("positions")[0]},
{"nation", person.at("nationIds").empty() ? Json() : person.at("nationIds")[0]},
{"role", roles.at(id)}, {"availability", raw.at("availability")}, {"age", raw.at("age")}};
for (const auto *key : {"condition", "technique", "form", "strength"}) row[key] = metric_value(raw, key);
for (const auto *key : {"corner", "free_kick", "tackling", "passing", "shooting", "speed", "teamplay"})
row[key] = raw.at("skills").value(key, Json());
for (const auto *key : {"motivation", "goals", "assists", "games", "grade"}) row[key] = nullptr;
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" : "—";
rows.push_back(std::move(row));
if (points.size() < lineup.at("positions").size()) {
if (!positions.contains(id)) points.push_back(nullptr);
else {
const auto &point = positions.at(id); const int x = point.at("depth"), y = point.at("lane");
points.push_back(x >= 0 && x <= depth_max && y >= 0 && y <= lane_max ? Json::array({x, y}) : Json());
}
}
}
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()},
{"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) {
const auto projection = engine_lineup_projection(bundle);
const auto &meta = bundle.at("desktop").at("meta");
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
require(!request_id.empty() && commands.is_array() && std::find(commands.begin(), commands.end(), Json("lineup.commit")) != commands.end(),
"Aufstellungsänderungen sind in diesem Kontext gesperrt.");
require(order.is_array() && order.size() == projection.at("board").at("order").size(), "Der vollständige Kader wird benötigt.");
std::set<std::string> expected, proposed;
for (const auto &id : projection.at("board").at("order")) expected.insert(id.get<std::string>());
for (const auto &id : order) require(id.is_string() && proposed.insert(id.get<std::string>()).second, "Doppelte oder ungültige Spieler-ID.");
require(proposed == expected, "Die Aufstellung enthält fremde oder fehlende Spieler.");
return {{"messageType", "command"}, {"requestId", request_id}, {"careerId", meta.at("careerId")},
{"expectedRevision", meta.at("stateRevision")}, {"owner", {{"managerId", meta.at("scope").at("managerId")}}},
{"kind", "lineup.commit"}, {"payload", {{"order", order}}}};
}
} // namespace bmh::modern_ui