Bind original settings and automation to atomic native drafts (by Codex)

This commit is contained in:
Codex committed 2026-10-29 18:52:41 +01:00
1 parent 2ce563a4b9
commit 98cff2185d
23 files changed
+959 -189

No files matched your search

+37 -11
View File
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
bool App::settings_global_only() const { return scene_ == "main" || !source_; }
bool App::settings_global_only() const { return !engine_mode_ && (scene_ == "main" || !source_); }
fs::path App::ui_preferences_file() const {
return config_.preferences.empty()
? (config_.userdata.empty() ? root_ / "userdata" : config_.userdata) / "modern-ui-preferences.json"
@@ -23,7 +23,11 @@ void App::begin_settings() {
if (!settings_draft_.is_null())
return;
settings_draft_ = {{"global", ui_preferences_}};
if (!settings_global_only()) {
if (engine_mode_) {
settings_draft_["local"] = engine_settings_value_.at("local");
engine_settings_context_ = engine_data_.at("desktop").at("meta");
settings_world_ = world_;
} else if (!settings_global_only()) {
const auto s = snap();
settings_draft_["local"] = s.state.at("settings");
settings_revision_ = s.revision;
@@ -41,6 +45,7 @@ bool App::settings_valid() const {
return false;
if (settings_global_only())
return true;
if (engine_mode_) return engine_settings_valid();
auto copy = snap().state;
return edit_demo_settings(copy, settings_draft_.at("local")).empty();
}
@@ -92,6 +97,11 @@ std::string App::settings_option(const Json &option) const {
const auto &value =
settings_draft_.at("local").at("cells")[size_t(settings_index(code))];
const auto type = option.at("type").get<std::string>();
if (engine_mode_ && !engine_settings_editable("cell", code)) {
const auto shown = value.is_number_integer() ? (type == "toggle" ? (value == 1 ? std::string("An") : std::string("Aus")) : number(value)) : std::string("—");
return settings_row(id, option.at("label"), option.value("help", ""), "<span class=\"settings-readonly\">" + esc(shown) + "</span>");
}
const int maximum = engine_mode_ ? engine_settings_value_.at("cells").at(code).at("max").get<int>() : option.value("max",99);
std::string control;
if (type == "toggle")
control = settings_switch(id, "cell", code, value == 1);
@@ -110,8 +120,8 @@ std::string App::settings_option(const Json &option) const {
"\" data-settings-scope=\"number\" data-settings-key=\"" + code +
"\" data-settings-title=\"" +
esc(option.at("label").get<std::string>()) + "\" data-settings-max=\"" +
std::to_string(option.at("max").get<int>()) +
"\" maxlength=\"2\" value=\"" +
std::to_string(maximum) +
"\" maxlength=\"3\" value=\"" +
(value.is_number_integer() ? std::to_string(value.get<int>()) : "") +
"\"/>";
return settings_row(id, option.at("label").get<std::string>(),
@@ -235,7 +245,12 @@ std::string App::render_settings() {
"\" aria-pressed=\"" +
(p.at("theme") == type ? "true" : "false") + "\"");
}
pane += "</div></div><div class=\"settings-group\"><h3>Bildschirm</h3>";
pane += "</div></div>";
if (engine_mode_) {
int width=0,height=0; SDL_GetWindowSize(video_.window,&width,&height);
pane += "<div class=\"settings-group\"><h3>Fenster</h3><p>" + std::to_string(width) + " × " + std::to_string(height) + " · Automatische Anpassung</p></div>";
} else {
pane += "<div class=\"settings-group\"><h3>Bildschirm</h3>";
const auto pref =
[&](const char *key, const char *label,
const std::vector<std::pair<std::string, std::string>> &rows,
@@ -261,7 +276,13 @@ std::string App::render_settings() {
"</div><div class=\"settings-group\"><h3>Sprache</h3>" +
pref("language", "Sprache", {{"de", "Deutsch"}, {"en", "Englisch"}}) +
"</div>";
}
} else if (settings_category_ == "sound") {
if (engine_mode_) {
pane="<div class=\"settings-group\"><h3>Spielton</h3>";
for (const auto &o:live_settings_catalogue().at("sound")) pane+=settings_option(o);
pane+="</div>";
} else {
const auto &s = p.at("sound");
pane = "<div class=\"settings-group\"><h3>Lautstärke und Effekte</h3>";
pane += settings_row(
@@ -288,17 +309,16 @@ std::string App::render_settings() {
pane += settings_option(o);
pane += "</div>";
}
}
} else if (settings_category_ == "automation") {
const auto &a = settings_draft_.at("local").at("automation");
int on = 0;
for (const auto &[k, v] : a.items())
if (v == true)
++on;
int on = 0, total = 0;
for (const auto &[k, v] : a.items()) if (engine_settings_editable("automation",k)) { ++total; if (v == true) ++on; }
pane = "<div class=\"settings-automation-master\">" +
settings_row("automation-all", "Alles automatisch",
"Alle fünf Bereiche gemeinsam ein- oder ausschalten.",
engine_mode_ ? "Alle verfügbaren Bereiche gemeinsam ein- oder ausschalten." : "Alle fünf Bereiche gemeinsam ein- oder ausschalten.",
settings_switch("automation-all", "automation", "all",
on == 5, on > 0 && on < 5)) +
total > 0 && on == total, on > 0 && on < total)) +
"</div><div class=\"settings-group\"><h3>Aufgaben an den Co-Trainer "
"abgeben</h3><p class=\"settings-group-help\">Die fünf "
"Automatikfunktionen des Originals. Änderungen werden erst mit "
@@ -310,6 +330,12 @@ std::string App::render_settings() {
settings_switch("automation-" + key, "automation",
key, a.at(key).get<bool>()));
}
if (engine_mode_) {
std::vector<std::pair<std::string,std::string>> choices;
for (const auto &slot:engine_settings_value_.at("formations")) choices.emplace_back(std::to_string(slot.at("value").get<int>()),slot.at("label"));
if (choices.empty()) choices.emplace_back("0","Keine gespeicherte Aufstellung");
pane += settings_row("automation-formation","Gespeicherte Aufstellung","Für die automatische Aufstellung.",settings_select("automation-formation",choices,std::to_string(settings_draft_.at("local").at("formation").get<int>()),"formation","",""));
}
pane += "</div>";
} else {
std::vector<std::pair<std::string, std::string>> groups;