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
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user