Port settings and automation to the Modern UI (by Codex)

This commit is contained in:
Codex committed 2026-10-25 21:36:18 +01:00
1 parent 8222926d9c
commit adb4166a80
26 files changed
+2734 -179

No files matched your search

+10 -3
View File
@@ -113,7 +113,7 @@ int main(int argc, char **argv) try {
std::ostringstream css;
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
"calendar.rcss", "reports.rcss", "report_details.rcss",
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss"}) {
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss", "settings.rcss"}) {
std::ifstream input(root / name);
require(bool(input), "Production stylesheet missing");
css << input.rdbuf() << '\n';
@@ -181,6 +181,13 @@ int main(int argc, char **argv) try {
select("manager-strength") + "</div><div class='bottom-controls'>" +
button_markup("continue", "Continue", {}, "id='footer'") +
select("tall") + "</div></div>";
content += "<div style='position:absolute;left:2700dp;top:800dp;width:1100dp;'>"
"<div class='settings-row'><label><span id='settings-row-label'>Automatische Aufstellung</span>"
"<small id='settings-row-help'>Aufgaben an den Co-Trainer abgeben.</small></label>"
"<select id='settings-control' class='settings-select'><option selected>1920 × 1080</option>"
"<option>3840 × 2160</option></select></div>"
"<div class='settings-jump-label'><select id='settings-jump-test' class='settings-select'>"
"<option selected>Spielablauf und Wettbewerbe</option><option>Ergebnisse</option></select></div></div>";
auto *doc = context->LoadDocumentFromMemory(
"<rml><head><style>" + css.str() + "</style></head><body class='" +
theme + "'>" + content + "</body></rml>");
@@ -196,7 +203,7 @@ int main(int argc, char **argv) try {
context->Render();
}
require(!center_selects(*doc), "Control centering does not settle");
for (const auto *id : {"stats-scale-label", "stats-legend-label", "stats-player-label", "stats-world-label", "stats-from-label", "stats-winner-label", "news-brand-test"}) {
for (const auto *id : {"stats-scale-label", "stats-legend-label", "stats-player-label", "stats-world-label", "stats-from-label", "stats-winner-label", "news-brand-test", "settings-row-label", "settings-row-help"}) {
auto *label = doc->GetElementById(id);
require(label && label->GetBox().GetSize(Rml::BoxArea::Content).x > 0 && visible_text_lines(*label) > 0,
"A production statistics/news label has collapsed or lost its font face");
@@ -215,7 +222,7 @@ int main(int argc, char **argv) try {
rich->QuerySelector(".picture")->GetAbsoluteOffset().y,
"Rich card stacking changed");
for (const auto *id :
{"natural", "toolbar", "tall", "manager-strength"}) {
{"natural", "toolbar", "tall", "manager-strength", "settings-control", "settings-jump-test"}) {
auto *control = doc->GetElementById(id);
auto *caption = select_part(*control, "selectvalue"),
*arrow = select_part(*control, "selectarrow");
+275
View File
@@ -0,0 +1,275 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_settings.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/ui_preferences.hpp"
#include <chrono>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool yes, const char *why) {
if (!yes)
throw std::runtime_error(why);
}
struct Fixture {
fs::path root;
std::shared_ptr<const Catalog> world;
Fixture() {
root = fs::temp_directory_path() /
("openbmh-settings-ui-" +
std::to_string(
std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(root / "world");
const auto write = [&](const std::string &name, const Json &data) {
bmh::editor::write_atomic(root / name, data.dump());
};
write("manifest.json", {{"format", "openbmh-world"},
{"kind", "world"},
{"format_version", "1.1"},
{"id", "world:synthetic-settings"},
{"start_date", "2032-07-01"},
{"requires", {"editor:world-v1"}},
{"x-editor", {{"profile", "editor-world-v1"}}}});
write("world/nations.json",
{{"items", {{{"id", "nation:de"}, {"name", "Synthetic nation"}}}}});
write("world/competitions.json", {{"items",
{{{"id", "competition:settings-test"},
{"type", "league"},
{"nation", "nation:de"},
{"name", "Synthetic league"}}}}});
Json clubs = Json::array();
for (int i = 0; i < 2; ++i)
clubs.push_back({{"id", "club:settings-" + std::to_string(i)},
{"name", "Synthetic Club " + std::to_string(i)},
{"nation", "nation:de"},
{"competition", "competition:settings-test"}});
write("world/clubs.json", {{"items", clubs}});
write("world/players.json", {{"items", Json::array()}});
world = Catalog::open(root);
}
~Fixture() {
std::error_code ec;
fs::remove_all(root, ec);
}
};
void provider() {
Json state = {
{"training", {{"autos", {false, true, false, true}}, {"kept", 41}}},
{"other", 123}};
require(migrate_demo_settings(state) && valid_demo_settings(state),
"Migration failed");
const auto initial = state;
require(migrate_demo_settings(state) && state == initial,
"Migration was not idempotent");
std::set<std::string> codes;
std::vector<Json> options;
for (const auto &g : settings_catalogue().at("groups")) {
if (g.contains("options"))
for (const auto &o : g.at("options"))
options.push_back(o);
else
for (const auto &c : g.at("competitions"))
for (const auto &o : c.at("options"))
options.push_back(o);
}
require(options.size() == 142 &&
settings_catalogue().at("groups").size() == 10,
"Game catalogue incomplete");
for (const auto &o : settings_catalogue().at("sound"))
options.push_back(o);
for (const auto &o : options) {
const auto code = o.at("code").get<std::string>();
require(settings_index(code) >= 0 && codes.insert(code).second,
"Invalid or duplicate option code");
}
require(codes.size() == 145 &&
settings_catalogue().at("automation").size() == 5,
"Visible catalogue incomplete");
require(settings_index("A1") == 0 && settings_index("T9") == 179 &&
settings_index("Z1") == -1,
"Code mapping incorrect");
require(settings_search_key("GROẞEN ÄÖÜ") == "grossen aou",
"German search folding failed");
auto next = state.at("settings");
next["cells"][settings_index("A9")] = 99;
next["cells"][settings_index("G8")] = 3;
next["automation"]["training"] = true;
require(edit_demo_settings(state, next).empty() &&
state.at("training").at("autos") ==
Json({true, true, true, true}) &&
state.at("training").at("kept") == 41,
"Automation or numeric commit failed");
auto preserved = state.at("settings").at("cells");
preserved[settings_index("A9")] = 0;
preserved[settings_index("G8")] = 1;
require(preserved == initial.at("settings").at("cells"),
"Commit changed reserved cells");
state["training"]["autos"][0] = false;
sync_demo_settings_training(state);
require(valid_demo_settings(state) &&
state.at("settings").at("automation").at("training") == false,
"Training aggregate not synchronized");
const auto before = state;
std::vector<Json> invalid;
for (const auto &value : std::vector<Json>{-1, 100, 1.5, nullptr, "2"}) {
auto bad = next;
bad["cells"][8] = value;
invalid.push_back(bad);
}
auto bad = next;
bad["cells"][settings_index("G8")] = 4;
invalid.push_back(bad);
bad = next;
bad["cells"][0] = 2;
invalid.push_back(bad);
bad = next;
bad["version"] = 1.0;
invalid.push_back(bad);
bad = next;
bad["automation"]["training"] = 1;
invalid.push_back(bad);
bad = next;
bad["unexpected"] = true;
invalid.push_back(bad);
bad = next;
bad["cells"].erase(0);
invalid.push_back(bad);
for (const auto &value : invalid) {
require(!edit_demo_settings(state, value).empty() && state == before,
"Invalid action mutated state");
auto imported = state;
imported["settings"] = value;
const auto original = imported;
require(!migrate_demo_settings(imported) && imported == original,
"Malformed block silently repaired");
}
}
void preferences(Fixture &f) {
const auto path = f.root / "userdata" / "prefs.json";
const auto defaults = default_ui_preferences();
require(valid_ui_preferences(defaults) &&
load_ui_preferences(path) == defaults && !fs::exists(path),
"Missing global preferences not read-only");
auto p = defaults;
p["theme"] = "silver";
p["sound"]["volume"] = 0;
p["display"]["resolution"] = "3840x2160";
save_ui_preferences(path, p);
require(load_ui_preferences(path) == p, "Global persistence failed");
const auto original = bmh::editor::read_file(path);
for (const auto &[key, value] :
std::vector<std::pair<std::string, Json>>{{"volume", 101},
{"volume", -1},
{"volume", 2.5},
{"effects", 1},
{"style", "bad"}}) {
auto bad = p;
bad["sound"][key] = value;
bool rejected = false;
try {
save_ui_preferences(path, bad);
} catch (const std::exception &) {
rejected = true;
}
require(rejected && bmh::editor::read_file(path) == original,
"Invalid global preferences overwritten file");
}
auto bad = p;
bad["display"]["language"] = "en";
require(!valid_ui_preferences(bad), "Untranslated language enabled");
bad = p;
bad["display"]["scale"] = "3";
require(!valid_ui_preferences(bad), "Unknown scale accepted");
bad = p;
bad["display"]["mode"] = "borderless";
require(!valid_ui_preferences(bad), "Unknown display mode accepted");
bad = p;
bad["extra"] = 1;
require(!valid_ui_preferences(bad), "Unknown global key accepted");
const auto legacy = legacy_ui_preferences(
{{"theme", "matchday"}, {"volume", 25}, {"sound-style", "modern"}});
require(legacy.at("theme") == "matchday" &&
legacy.at("sound").at("volume") == 25 &&
valid_ui_preferences(legacy),
"Legacy checkpoint migration failed");
bmh::editor::write_atomic(path, "{corrupted");
bool rejected = false;
try {
load_ui_preferences(path);
} catch (const std::exception &) {
rejected = true;
}
require(rejected && bmh::editor::read_file(path) == "{corrupted",
"Corrupt preferences silently overwritten");
}
void source(Fixture &f) {
DemoSource source(f.world);
const auto initial = source.snapshot();
require(valid_demo_settings(initial.state) && !source.dirty(),
"Initial source invalid or dirty");
auto value = initial.state.at("settings");
value["automation"]["training"] = true;
require(source.apply({initial.revision, "settings", value}).ok,
"Source settings commit failed");
const auto applied = source.snapshot();
require(applied.revision == initial.revision + 1 && source.dirty(),
"Source commit revision incorrect");
require(!source.apply({initial.revision, "settings",
initial.state.at("settings")})
.ok &&
source.snapshot().state == applied.state,
"Stale settings action accepted");
const auto file = f.root / "checkpoint.json";
source.save(file, default_desktop());
source.load(file);
require(source.snapshot().state.at("settings") == value && !source.dirty(),
"Checkpoint round trip failed");
auto data = Json::parse(bmh::editor::read_file(file));
data.erase("settings");
bmh::editor::write_atomic(file, data.dump());
source.load(file);
require(valid_demo_settings(source.snapshot().state) &&
source.snapshot()
.state.at("settings")
.at("automation")
.at("training") == true &&
!source.dirty(),
"Old checkpoint migration lost training aggregate");
source.save(file, default_desktop());
data = Json::parse(bmh::editor::read_file(file));
data["settings"]["cells"][0] = 9;
bmh::editor::write_atomic(file, data.dump());
const auto before = source.snapshot();
bool rejected = false;
try {
source.load(file);
} catch (const std::exception &) {
rejected = true;
}
require(rejected && source.snapshot().state == before.state &&
source.snapshot().revision == before.revision && !source.dirty(),
"Malformed load was not atomic");
auto unrelated = applied.state;
unrelated.erase("settings");
unrelated.erase("training");
auto old = initial.state;
old.erase("settings");
old.erase("training");
require(unrelated == old, "Settings modified unrelated presentation fields");
}
} // namespace
int main() {
try {
Fixture f;
provider();
preferences(f);
source(f);
std::cout << "modern settings UI tests passed\n";
return 0;
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}
}
+2
View File
@@ -553,6 +553,8 @@ int main(int argc, char **argv) try {
require(restored_sports.snapshot().state == sports.snapshot().state,
"Training/tactics were lost on restoration");
auto legacy = Json::parse(bmh::editor::read_file(root / "sports.ui.json"));
// A checkpoint predating training also predates the aggregate settings block.
legacy.erase("settings");
legacy.erase("training");
legacy.erase("tactics");
legacy.erase("calendar");