Add read-only game and league regulations to editor 0.5.2 (by Codex)
OBW Editor / editor (linux-x64, ubuntu-24.04) (push) Canceled after 0s
OBW Editor / editor (macos-arm64, macos-14) (push) Canceled after 0s
OBW Editor / editor (windows-x64, windows-2022) (push) Canceled after 0s
OBW Editor / release (push) Canceled after 0s

This commit is contained in:
Codex committed 2026-10-23 06:28:12 +02:00
1 parent 221478b629
commit 9f1928bd9e
27 files changed
+993 -22

No files matched your search

+8 -2
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
include(FetchContent)
set(OPENBMH_EDITOR_VERSION "0.5.1")
set(OPENBMH_EDITOR_VERSION "0.5.2")
file(WRITE "${CMAKE_BINARY_DIR}/editor-version.json" "{\"version\": \"${OPENBMH_EDITOR_VERSION}\"}\n")
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
FetchContent_Declare(editor_json GIT_REPOSITORY https://github.com/nlohmann/json.git
@@ -44,7 +44,7 @@ foreach(component editor_json editor_http editor_images editor_svg editor_xml)
endforeach()
file(APPEND "${CMAKE_BINARY_DIR}/editor-dependencies.json" "}\n")
add_library(bmh_editor_core STATIC archive.cpp world.cpp session.cpp comparison.cpp images.cpp options.cpp mcp.cpp)
add_library(bmh_editor_core STATIC archive.cpp world.cpp session.cpp comparison.cpp regulations.cpp images.cpp options.cpp mcp.cpp)
target_compile_definitions(bmh_editor_core PUBLIC OPENBMH_EDITOR_VERSION="${OPENBMH_EDITOR_VERSION}")
target_include_directories(bmh_editor_core PUBLIC .. ${editor_http_SOURCE_DIR})
target_link_libraries(bmh_editor_core PUBLIC nlohmann_json::nlohmann_json bmh_content
@@ -91,5 +91,11 @@ if(MSVC)
target_compile_options(editor_comparison_tests PRIVATE /utf-8)
endif()
add_test(NAME editor_comparison_tests COMMAND editor_comparison_tests)
add_executable(editor_regulations_tests ../../tests/editor_regulations_tests.cpp)
target_link_libraries(editor_regulations_tests PRIVATE bmh_editor_core)
if(MSVC)
target_compile_options(editor_regulations_tests PRIVATE /utf-8)
endif()
add_test(NAME editor_regulations_tests COMMAND editor_regulations_tests)
add_test(NAME editor_version COMMAND openbmh_editor --version)
set_tests_properties(editor_version PROPERTIES PASS_REGULAR_EXPRESSION "OpenBMH Editor ${OPENBMH_EDITOR_VERSION}")
+13
View File
@@ -53,6 +53,7 @@ const std::map<std::string, std::string> commands{{"editor_info", "info"},
{"editor_new", "new"},
{"editor_list", "list"},
{"editor_compare", "compare"},
{"editor_regulations", "regulations"},
{"editor_get", "get"},
{"editor_apply", "apply"},
{"editor_validate", "validate"},
@@ -168,6 +169,18 @@ Json McpServer::tools() {
{"offset", field("integer")},
{"limit", field("integer")}},
{}, true);
add("editor_regulations",
"Read-only declared game/league rules, promotion, relegation and qualification selectors. "
"Also identifies inherited classic-season-entrants@1 and Classic ladder policies, without "
"replacing them with current football regulations. Missing rules remain unspecified. "
"Preserves source definitions and returns all game rule records. Never simulates a season or edits "
"data.",
{{"language", {{"type", "string"}, {"enum", {"de", "en"}}}},
{"search", field("string")},
{"nation", id},
{"competition", id},
{"expected_revision", revision}},
{}, true);
add("editor_get", "Read a complete row, including preserved extensions and sources.",
{{"table", table}, {"id", id}}, {"table", "id"}, true);
add("editor_apply",
+86
View File
@@ -89,6 +89,92 @@ std::string tr(const std::string &language, const std::string &key) {
using Pair = std::pair<std::string, std::string>;
static const std::map<std::string, Pair> words{
{"data_areas", {"Datenbereiche", "World data"}},
{"regulations", {"Regelwerk", "Regulations"}},
{"regulations_title", {"Spiel- & Ligaregeln", "Game & league rules"}},
{"subtitle_regulations",
{"Aufstieg, Abstieg und internationale Qualifikation",
"Promotion, relegation and international qualification"}},
{"regulation_readonly", {"Nur Anzeige", "Read only"}},
{"regulation_competitions", {"Ligen & Wettbewerbe", "Leagues & competitions"}},
{"regulation_game", {"Spielregeln", "Game rules"}},
{"regulation_movement_title", {"Auf- & Abstieg", "Promotion & relegation"}},
{"regulation_qualification_title",
{"Internationale Qualifikation & Teilnehmer", "International qualification & entrants"}},
{"regulation_promotion", {"Aufstieg", "Promotion"}},
{"regulation_relegation", {"Abstieg", "Relegation"}},
{"regulation_playoff", {"Relegationsspiele", "Playoffs"}},
{"regulation_playoff_winner", {"Sieger der Classic-Relegation", "Classic playoff winner"}},
{"regulation_classic_playoffs",
{"Bei parallelen unteren Ligen steigen die Meister direkt auf. Weitere Aufsteiger bestimmt die "
"Classic-Relegation. Ohne deren Ergebnis werden nur die Meister ausgetauscht.",
"For parallel lower leagues, champions go up directly. Additional promotion follows the Classic "
"playoffs. Without a playoff result, only champions are exchanged."}},
{"regulation_movement", {"Ligenwechsel", "League movement"}},
{"regulation_rank", {"Platz", "Rank"}},
{"regulation_to", {"in", "to"}},
{"regulation_closed", {"Kein regulärer Auf- oder Abstieg.", "No regular promotion or relegation."}},
{"regulation_unspecified", {"Nicht im OBW festgelegt.", "Not specified in the OBW."}},
{"regulation_amateur_pool",
{"Nachrückerpool der untersten Spielklasse", "Lowest-tier newcomer pool"}},
{"regulation_declared", {"Im OBW festgelegt", "Declared in the OBW"}},
{"regulation_classic", {"Classic-Verfahrensregel", "Classic adapter policy"}},
{"regulation_classic_movement_note",
{"Reguläre Plätze. Lizenzentzüge können die Saisonentscheidung ändern. Die Zuordnung zu parallelen "
"Ligen erfolgt beim Saisonwechsel.",
"Regular places. License withdrawals can change the season outcome. Allocation to parallel leagues "
"occurs at season rollover."}},
{"regulation_classic_intro",
{"Übernommenes Classic-Verfahren, keine heutigen UEFA-Regeln.",
"Inherited Classic policy; current UEFA regulations do not apply."}},
{"regulation_classic_champion",
{"Meister qualifiziert für die Champions League. Titelverteidiger werden zusätzlich berücksichtigt; "
"ist dieser bereits Meister, rückt der Zweite nach.",
"Champion qualifies for the Champions League. The holder also qualifies; if already champion, the "
"runner-up receives the extra place."}},
{"regulation_classic_cup",
{"Nationaler Pokalsieger qualifiziert für den Pokalsieger-Wettbewerb, bei bestehender Qualifikation "
"der Finalist. Ausländische Pokalvertreter werden im Classic-Verfahren bestimmt.",
"Domestic cup winner qualifies for the Cup Winners’ Cup; the finalist replaces an already "
"qualified winner. Foreign cup entrants follow the Classic selection policy."}},
{"regulation_classic_uefa",
{"reguläre Plätze nach Tabellenrang; bereits qualifizierte Teams werden übersprungen.",
"regular places by league rank; already qualified teams are skipped."}},
{"regulation_classic_holders",
{"Titelverteidiger von UEFA- und Pokalsieger-Cup sowie Doppelqualifikationen können zusätzliche "
"Plätze und Nachrücker auslösen.",
"UEFA/Cup Winners’ Cup holders and overlapping qualifications may produce extra places or "
"replacements."}},
{"regulation_runtime",
{"Teilnehmer werden durch das hinterlegte Classic-Verfahren bestimmt.",
"Entrants are resolved by the stored Classic policy."}},
{"regulation_winner", {"Sieger", "Winner"}},
{"regulation_runner_up", {"Finalist / Zweiter", "Runner-up"}},
{"regulation_next_unqualified", {"Nächstes noch nicht qualifiziertes Team", "Next unqualified team"}},
{"regulation_holder", {"Titelverteidiger", "Title holder"}},
{"regulation_coefficient",
{"Qualifikation nach Koeffizientenrang", "Qualification by coefficient rank"}},
{"regulation_fallback", {"Nachrücken", "Replacement"}},
{"regulation_stage", {"Phase", "Stage"}},
{"regulation_stages", {"Wettbewerbsphasen & Spielregeln", "Competition stages & match rules"}},
{"regulation_show_source", {"OBW-Details anzeigen", "Show OBW details"}},
{"regulation_hide_source", {"OBW-Details ausblenden", "Hide OBW details"}},
{"regulation_preserved",
{"Unveränderte Angaben aus world/rules.json. Diese Ansicht ist schreibgeschützt.",
"Unmodified values from world/rules.json. This view is read only."}},
{"regulation_type_league", {"Liga", "League"}},
{"regulation_type_cup", {"Pokal", "Cup"}},
{"regulation_type_national_team", {"Nationalmannschaften", "National teams"}},
{"regulation_type_club_international",
{"Internationaler Vereinswettbewerb", "International club competition"}},
{"regulation_type_friendly", {"Freundschaftsspiel", "Friendly"}},
{"regulation_type_indoor", {"Hallenturnier", "Indoor tournament"}},
{"rule_type_attribute_set", {"Spielwerte & Wertebereiche", "Attributes & ranges"}},
{"rule_type_fixture_tables", {"Spielplanverfahren", "Fixture generation"}},
{"rule_type_legacy_ladder", {"Classic-Ligenpyramide", "Classic league pyramid"}},
{"rule_type_training_camps", {"Trainingslager", "Training camps"}},
{"rule_type_credit_rates", {"Kreditregeln", "Credit rules"}},
{"rule_type_classic_runtime", {"Classic-Verfahren", "Classic runtime policies"}},
{"rule_type_classic_data_regions", {"Übernommene Classic-Regeldaten", "Preserved Classic rule data"}},
{"comparison", {"Wertevergleich", "Comparison"}},
{"comparison_title", {"Stärken & Gehälter", "Ratings & salaries"}},
{"subtitle_comparison",
+250
View File
@@ -0,0 +1,250 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "editor/regulations.hpp"
#include "editor/world.hpp"
#include <algorithm>
namespace bmh::editor {
namespace {
Json object(const Json &value, const char *key) {
const auto found = value.find(key);
return found != value.end() && found->is_object() ? *found : Json::object();
}
Json array(const Json &value, const char *key) {
const auto found = value.find(key);
return found != value.end() && found->is_array() ? *found : Json::array();
}
std::optional<int> number(const Json &value) {
if (!value.is_number_integer() || value.get<double>() < 0 || value.get<double>() > 100000)
return {};
return value.get<int>();
}
int count_teams(const Json &comp) {
if (comp.value("members", Json()).is_array() && !comp["members"].empty())
return int(comp["members"].size());
for (const auto &stage : array(comp, "stages"))
if (auto value = number(stage.value("teams", Json())))
return *value;
return 0;
}
} // namespace
Json regulation_view(const World &world, const Json &args) {
const auto language = str(args, "language", "de"), search = folded(str(args, "search")),
nation = str(args, "nation"), chosen = str(args, "competition");
if (language != "de" && language != "en")
throw Error("invalid_change");
std::map<std::string, const Json *> competitions;
std::map<int, const Json *> indexed;
for (const auto &comp : world.rows("competitions")) {
competitions[str(comp, "id")] = &comp;
const auto legacy = object(comp, "x-legacy");
if (const auto index = number(legacy.value("league_index", Json()));
index && str(comp, "type") == "league")
indexed[*index] = &comp;
}
const Json *ladder = nullptr;
bool classic = false;
for (const auto &rule : world.rows("rules")) {
if (str(rule, "type") == "legacy_ladder")
ladder = &rule;
if (str(rule, "type") == "classic_runtime" &&
str(rule, "qualifications") == "classic-season-entrants@1")
classic = true;
}
auto target = [&](const std::string &id) {
return Json{{"id", id},
{"name", competitions.contains(id) ? world.title(*competitions.at(id), language) : id}};
};
std::map<std::string, Json> movement, qualification;
std::set<std::string> movement_known;
// Explicit OBW movement always takes precedence over compatibility policy.
for (const auto &[id, comp] : competitions) {
movement[id] = Json::array();
qualification[id] = Json::array();
if (comp->contains("movement") && (*comp)["movement"].is_array()) {
movement_known.insert(id);
for (const auto &definition : (*comp)["movement"]) {
const auto to = str(definition, "to");
const auto role = str(definition, "role");
std::string kind = role == "challenger" || role == "defender" || role == "incumbent"
? "playoff"
: "movement";
if (kind == "movement" && competitions.contains(to)) {
auto from_tier = number(comp->value("tier", Json()));
auto to_tier = number(competitions.at(to)->value("tier", Json()));
if (from_tier && to_tier && str(*competitions.at(to), "type") == "league")
kind = *to_tier < *from_tier ? "promotion"
: *to_tier > *from_tier ? "relegation"
: "movement";
}
movement[id].push_back({{"kind", kind},
{"ranks", definition.value("ranks", Json())},
{"targets", Json::array({target(to)})},
{"source", "declared"},
{"definition", definition}});
}
}
}
if (classic && ladder) {
auto span = [&](const char *first_key, const char *count_key, int group) {
std::vector<const Json *> result;
const auto first = ladder->value(first_key, Json()), count = ladder->value(count_key, Json());
if (!first.is_array() || !count.is_array() || size_t(group) >= first.size() ||
size_t(group) >= count.size())
return result;
const auto start = number(first[group]), length = number(count[group]);
if (!start || !length || *length < 1 || *length > 24)
return result;
for (int i = *start; i < *start + *length; ++i) {
if (!indexed.contains(i))
return std::vector<const Json *>{};
result.push_back(indexed.at(i));
}
return result;
};
// The versioned Classic ladder has four domestic movement groups.
// Its final group draws newcomers; below[3] is not a foreign league
// destination. License withdrawals can change the actual season result.
for (int group = 0; group < 4; ++group) {
const auto upper = span("first_league", "league_count", group);
const auto lower = group < 3 ? span("below", "below_count", group) : std::vector<const Json *>{};
if (upper.empty() || (group < 3 && lower.empty()))
continue;
int down_total = 0;
bool complete = true;
for (const auto *comp : upper) {
const auto down = number(object(*comp, "x-legacy").value("relegation_places", Json()));
if (!down || *down > count_teams(*comp)) {
complete = false;
break;
}
down_total += *down;
}
if (!complete)
continue;
Json destinations = Json::array(), origins = Json::array();
for (const auto *comp : lower)
destinations.push_back(target(str(*comp, "id")));
for (const auto *comp : upper)
origins.push_back(target(str(*comp, "id")));
for (const auto *comp : upper) {
const auto id = str(*comp, "id");
if (comp->contains("movement"))
continue;
movement_known.insert(id);
const int down = *number(object(*comp, "x-legacy")["relegation_places"]);
if (down)
movement[id].push_back({{"kind", "relegation"},
{"places", down},
{"ranks", {count_teams(*comp) - down + 1, count_teams(*comp)}},
{"targets", destinations},
{"newcomer_pool", group == 3},
{"pool_size", ladder->value("newcomer_count", Json())},
{"conditional_playoffs", lower.size() > 1},
{"source", "classic-ladder@1"}});
}
if (!lower.empty())
for (const auto *comp : lower) {
const auto id = str(*comp, "id");
if (comp->contains("movement"))
continue;
const bool playoffs = lower.size() > 1;
const int up = playoffs ? 1 : down_total;
if (up > count_teams(*comp) || down_total % int(lower.size()) != 0)
continue;
movement_known.insert(id);
if (up)
movement[id].push_back({{"kind", "promotion"},
{"places", up},
{"ranks", {1, up}},
{"targets", origins},
{"source", "classic-ladder@1"}});
if (playoffs)
movement[id].push_back({{"kind", "playoff"},
{"ranks", nullptr},
{"selector", "classic-playoff-winner"},
{"conditional_playoffs", true},
{"targets", origins},
{"source", "classic-ladder@1"}});
}
}
}
auto slots = [&](const std::string &to, const std::string &stage, const Json &definitions) {
if (!definitions.is_array())
return;
for (const auto &definition : definitions) {
const auto from = str(definition, "from"), holder = str(definition, "holder");
// Fixed team lists are already participants, not a qualification
// rule. Keep the untouched stages available separately below.
if (from.empty() && holder.empty() && !definition.contains("winner") &&
!definition.contains("resolver"))
continue;
const auto destination = str(definition, "to", to);
const Json rule{
{"from", target(from)},
{"to", target(destination)},
{"stage", str(definition, "stage", stage)},
{"definition", definition},
{"source", str(definition, "resolver").empty() ? "declared" : str(definition, "resolver")}};
qualification[destination].push_back(rule);
if (competitions.contains(from) && from != destination)
qualification[from].push_back(rule);
}
};
for (const auto &[id, comp] : competitions) {
slots(id, "", comp->value("slots", Json::array()));
for (const auto &stage : array(*comp, "stages"))
slots(id, str(stage, "id"), stage.value("slots", Json::array()));
}
Json items = Json::array();
for (const auto &[id, comp] : competitions) {
const auto label = world.title(*comp, language);
if ((!chosen.empty() && id != chosen) || (!nation.empty() && str(*comp, "nation") != nation) ||
(!search.empty() && folded(label).find(search) == std::string::npos &&
folded(id).find(search) == std::string::npos))
continue;
Json policy;
if (classic) {
const auto index = number(object(*comp, "x-legacy").value("league_index", Json()));
const bool declared =
std::any_of(qualification[id].begin(), qualification[id].end(),
[](const auto &rule) { return str(rule, "source") != "classic-entry@1"; });
// Registry for classic-season-entrants@1, the named format policy
// consumed by the existing Classic adapter. These quotas are not
// the historical x-legacy.europe_places prediction/colouring field.
if (!declared && index && (*index == 0 || (*index >= 5 && *index <= 8)))
policy = {{"id", "classic-season-entrants@1"},
{"uefa_base_places", *index == 8 ? 3 : 4},
{"champion", true},
{"cup_winner_or_finalist", true},
{"titleholder_adjustments", true}};
else if (!declared &&
str(object(*comp, "classic"), "qualification") == "classic-season-entrants@1")
policy = {{"id", "classic-season-entrants@1"}, {"runtime_participants", true}};
if (index && *index >= 5)
movement_known.insert(id); // Closed foreign Classic leagues.
}
items.push_back({{"id", id},
{"name", label},
{"nation", str(*comp, "nation")},
{"type", str(*comp, "type")},
{"tier", comp->value("tier", Json())},
{"teams", count_teams(*comp)},
{"movement_defined", movement_known.contains(id)},
{"movement", movement[id]},
{"qualification", qualification[id]},
{"classic_qualification", policy},
{"stages", array(*comp, "stages")},
{"record", *comp}});
}
std::stable_sort(items.begin(), items.end(), [](const auto &a, const auto &b) {
const auto av = folded(str(a, "name")), bv = folded(str(b, "name"));
return av == bv ? str(a, "id") < str(b, "id") : av < bv;
});
return {{"read_only", true},
{"items", items},
{"rules", world.rows("rules")},
{"classic_policy", classic},
{"date", world.manifest.value("start_date", Json())}};
}
} // namespace bmh::editor
+10
View File
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "editor/types.hpp"
namespace bmh::editor {
class World;
// Presentation of declared rules and versioned Classic policy, never a season
// simulation or an editable replacement for world/rules.json.
Json regulation_view(const World &, const Json &args);
} // namespace bmh::editor
+6
View File
@@ -3,6 +3,7 @@
#include "content/digest.hpp"
#include "editor/comparison.hpp"
#include "editor/images.hpp"
#include "editor/regulations.hpp"
#include <algorithm>
#include <limits>
@@ -459,6 +460,11 @@ Json Session::execute(const std::string &command, const Json &args) {
}
if (command == "rules")
return w.rows("rules");
if (command == "regulations") {
auto result = regulation_view(w, args);
result["revision"] = revision_;
return result;
}
if (command == "validate")
return {{"diagnostics", w.validate()}, {"revision", revision_}};
if (command == "history") {
+206 -5
View File
@@ -147,6 +147,8 @@ class EditorUi final : public Rml::EventListener {
bool comparison_descending_ = false;
Json comparison_;
std::map<std::string, std::vector<std::string>> comparison_columns_;
bool regulations_game_ = false, regulations_source_ = false;
std::string regulation_id_, game_rule_id_;
int offset_ = 0;
size_t total_ = 0;
struct Field {
@@ -212,6 +214,7 @@ class EditorUi final : public Rml::EventListener {
{"players", "M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0M4 22v-3c0-8 16-8 16 0v3"},
{"roster", "M3 3h18v18H3zM9 3v18M3 9h18M3 15h18"},
{"comparison", "M4 20h17M7 17v-5M12 17V7M17 17V3"},
{"regulations", "M5 3h14v18H5zM8 7h8M8 11h8M8 15h5"},
{"stadiums", "M3 8c0-7 18-7 18 0v8c0 7-18 7-18 0zM3 8c0 7 18 7 18 0M8 "
"13v7M16 13v7"},
{"staff", "M5 22V3h13l-4 5 4 5H5"},
@@ -403,14 +406,17 @@ class EditorUi final : public Rml::EventListener {
button("save", t("save"), "primary", info_.value("loaded", false) ? "" : "disabled") +
button("options", t("options"), "quiet"));
std::string nav;
for (const std::string name : {"overview", "nations", "competitions", "clubs", "players", "roster",
"comparison", "stadiums", "staff", "assets", "review", "changes"})
for (const std::string name :
{"overview", "nations", "competitions", "clubs", "players", "roster", "comparison",
"regulations", "stadiums", "staff", "assets", "review", "changes"})
nav += "<button class=\"nav " + std::string(name == page_ ? "selected" : "") +
"\" data-action=\"navigate\" data-value=\"" + name + "\">" + icon(name) + "<span>" +
escaped(t(name)) + "</span></button>";
html("navigation", nav);
label("page-kicker", "OpenBMH / " + t(page_));
label("page-title", t(page_ == "comparison" ? "comparison_title" : page_));
label("page-title", t(page_ == "comparison" ? "comparison_title"
: page_ == "regulations" ? "regulations_title"
: page_));
label("page-subtitle", page_ == "roster" ? t("roster_hint")
: page_ == "review" ? t("review_hint")
: t("subtitle_" + page_));
@@ -988,6 +994,188 @@ class EditorUi final : public Rml::EventListener {
size_t(offset_) + listed_.size() < total_ ? "" : "disabled") +
"</div>");
}
std::string regulation_ranks(const Json &ranks) const {
if (!ranks.is_array() || ranks.empty())
return t("regulation_unspecified");
std::string result = t("regulation_rank") + " " + text(ranks.front());
if (ranks.size() == 2 && ranks.front() != ranks.back())
result += "–" + text(ranks.back());
else if (ranks.size() > 2)
result = t("regulation_rank") + " " + ranks.dump();
return result;
}
std::string regulation_selector(const Json &definition) const {
if (definition.contains("ranks"))
return regulation_ranks(definition["ranks"]);
for (auto key : {"winner", "runner_up", "next_unqualified"})
if (definition.value(key, Json()) == true)
return t("regulation_" + std::string(key));
if (definition.contains("holder"))
return t("regulation_holder") + " · " + ref(definition, "holder");
if (str(definition, "from") == "coefficient")
return t("regulation_coefficient");
if (definition.contains("resolver"))
return t("regulation_runtime");
return t("regulation_unspecified");
}
std::string regulation_type(const Json &row, const std::string &prefix) const {
const auto type = str(row, "type"), key = prefix + type;
const auto translated = t(key);
return translated == key ? type : translated;
}
void regulations() {
html("page-actions", "<span class=\"badge\">" + escaped(t("regulation_readonly")) + "</span>");
html("pagination", "");
html("toolbar",
button("regulations-tab", t("regulation_competitions"), regulations_game_ ? "" : "primary",
"data-value=\"competitions\"") +
button("regulations-tab", t("regulation_game"), regulations_game_ ? "primary" : "",
"data-value=\"game\"") +
"<input id=\"search\" type=\"text\" value=\"" + escaped(search_) + "\" placeholder=\"" +
escaped(t("search")) + "\"/>" +
(regulations_game_ ? ""
: "<select id=\"filter-nation\">" +
choices("nations", nation_, t("all_nations")) + "</select>"));
if (!info_.value("loaded", false)) {
html("page-content", "<div class=\"empty\">" + escaped(t("welcome_hint")) + "</div>");
return;
}
const auto view = session_.execute(
"regulations", {{"language", options_.language}, {"search", search_}, {"nation", nation_}});
Json rows = regulations_game_ ? view["rules"] : view["items"];
if (regulations_game_ && !search_.empty()) {
Json filtered = Json::array();
for (const auto &row : rows)
if (folded(str(row, "id") + " " + str(row, "type")).find(folded(search_)) !=
std::string::npos)
filtered.push_back(row);
rows = std::move(filtered);
}
auto &chosen = regulations_game_ ? game_rule_id_ : regulation_id_;
const Json *selected = nullptr;
for (const auto &row : rows)
if (str(row, "id") == chosen)
selected = &row;
if (!selected && !rows.empty()) {
selected = &rows.front();
chosen = str(*selected, "id");
}
std::string body = "<div class=\"regulation-layout\"><div class=\"list-panel regulation-list\"><div "
"class=\"table-scroll\">";
for (const auto &row : rows) {
const auto id = str(row, "id");
body += "<button class=\"regulation-choice " + std::string(id == chosen ? "primary" : "quiet") +
"\" data-action=\"regulation-select\" data-value=\"" + escaped(id) + "\">" +
escaped(regulations_game_ ? regulation_type(row, "rule_type_") : str(row, "name")) +
"<small>" + escaped(regulations_game_ ? id : ref(row, "nation")) + "</small></button>";
}
body += "</div></div><div class=\"list-panel regulation-detail\"><div class=\"regulation-scroll\">";
auto section = [&](const std::string &key, const std::string &content) {
return "<div class=\"regulation-section\"><h2>" + escaped(t(key)) + "</h2>" + content + "</div>";
};
auto paragraph = [&](const std::string &value) { return "<p>" + escaped(value) + "</p>"; };
auto source = [&](const Json &value) {
return "<div class=\"source-json\">" + escaped(value.dump(2)) + "</div>";
};
if (!selected)
body += "<div class=\"empty\">" + escaped(t("empty")) + "</div>";
else if (regulations_game_) {
body += "<h2>" + escaped(regulation_type(*selected, "rule_type_")) + "</h2><small>" +
escaped(chosen) + "</small>" + paragraph(t("regulation_preserved")) + source(*selected);
} else {
const auto &row = *selected;
body += "<h2>" + escaped(str(row, "name")) + "</h2><small>" + escaped(chosen) + "</small>" +
paragraph(ref(row, "nation") + " · " + regulation_type(row, "regulation_type_") + " · " +
std::to_string(row.value("teams", 0)) + " " + t("teams"));
std::string movement;
for (const auto &entry : row["movement"]) {
std::string destinations;
for (const auto &target : entry["targets"]) {
if (!destinations.empty())
destinations += " / ";
destinations += str(target, "name");
}
if (entry.value("newcomer_pool", false))
destinations = t("regulation_amateur_pool");
movement +=
"<div class=\"regulation-clause\"><strong>" +
escaped(t("regulation_" + str(entry, "kind"))) + "</strong>" +
paragraph((str(entry, "selector") == "classic-playoff-winner"
? t("regulation_playoff_winner")
: regulation_ranks(entry.value("ranks", Json()))) +
" · " + t("regulation_to") + " " + destinations) +
"<small>" +
escaped(t(str(entry, "source") == "declared" ? "regulation_declared"
: "regulation_classic")) +
"</small>" +
(entry.value("conditional_playoffs", false) ? paragraph(t("regulation_classic_playoffs"))
: "") +
(regulations_source_ ? source(entry) : "") + "</div>";
}
if (movement.empty())
movement = paragraph(
t(row.value("movement_defined", false) ? "regulation_closed" : "regulation_unspecified"));
if (std::any_of(row["movement"].begin(), row["movement"].end(),
[](const auto &entry) { return str(entry, "source") == "classic-ladder@1"; }))
movement += "<small>" + escaped(t("regulation_classic_movement_note")) + "</small>";
body += section("regulation_movement_title", movement);
std::string qualification;
const auto policy = row["classic_qualification"];
if (!policy.is_null()) {
qualification = "<div class=\"regulation-clause\"><span class=\"badge\">" +
escaped(t("regulation_classic")) + "</span>" +
paragraph(t("regulation_classic_intro"));
if (policy.value("runtime_participants", false))
qualification += paragraph(t("regulation_runtime"));
else
qualification +=
paragraph(t("regulation_classic_champion")) + paragraph(t("regulation_classic_cup")) +
paragraph("UEFA-Cup · " + std::to_string(policy.value("uefa_base_places", 0)) + " " +
t("regulation_classic_uefa")) +
paragraph(t("regulation_classic_holders"));
qualification += "<small>classic-season-entrants@1</small></div>";
}
for (const auto &entry : row["qualification"]) {
const auto &definition = entry["definition"];
if (!policy.is_null() && str(entry, "source") == "classic-entry@1")
continue;
auto from = str(entry["from"], "name");
auto to = str(entry["to"], "name");
qualification += "<div class=\"regulation-clause\"><strong>" +
escaped((from.empty() ? "" : from + " · " + t("regulation_to") + " ") + to) +
"</strong>" + paragraph(regulation_selector(definition));
if (definition.contains("fallback"))
qualification +=
paragraph(t("regulation_fallback") + ": " + ref(definition["fallback"], "from") +
" · " + regulation_selector(definition["fallback"]));
if (!str(entry, "stage").empty())
qualification +=
"<small>" + escaped(t("regulation_stage") + ": " + str(entry, "stage")) + "</small>";
qualification += (regulations_source_ ? source(definition) : "") + "</div>";
}
if (qualification.empty())
qualification = paragraph(t("regulation_unspecified"));
body += section("regulation_qualification_title", qualification);
std::string stages;
for (auto stage : row["stages"]) {
// Participants can be large; the source toggle exposes them.
if (!regulations_source_) {
stage.erase("slots");
stage.erase("fixtures");
}
stages += source(stage);
}
if (stages.empty())
stages = paragraph(t("regulation_unspecified"));
body +=
section("regulation_stages", stages) +
button("regulation-source",
t(regulations_source_ ? "regulation_hide_source" : "regulation_show_source"), "quiet");
if (regulations_source_)
body += source(row["record"]);
}
html("page-content", body + "</div></div></div>");
}
void changes() {
html("toolbar", "");
html("pagination", "");
@@ -1029,6 +1217,8 @@ class EditorUi final : public Rml::EventListener {
changes();
else if (page_ == "comparison")
comparison();
else if (page_ == "regulations")
regulations();
else
records();
if (page_ == "comparison" && doc_->GetElementById("comparison-x")) {
@@ -1300,14 +1490,25 @@ class EditorUi final : public Rml::EventListener {
selected_id_.clear();
offset_ = 0;
search_.clear();
if (arg == "comparison") {
if (arg == "comparison" || arg == "regulations") {
nation_.clear();
league_.clear();
team_.clear();
}
needs_refresh_ = true;
});
else if (action == "compare-open" || action == "compare-scope")
else if (action == "regulations-tab") {
regulations_game_ = arg == "game";
search_.clear();
nation_.clear();
needs_refresh_ = true;
} else if (action == "regulation-select") {
(regulations_game_ ? game_rule_id_ : regulation_id_) = arg;
needs_refresh_ = true;
} else if (action == "regulation-source") {
regulations_source_ = !regulations_source_;
needs_refresh_ = true;
} else if (action == "compare-open" || action == "compare-scope")
leave_fields([this, action, arg] {
comparison_table_ =
action == "compare-open" ? (table() == "competitions" ? "leagues" : table()) : arg;