Bind tactics and training drafts to confirmed engine commits (by Codex)
This commit is contained in:
1 parent
7d3b3f1101
commit
f75e0f8e49
18 files changed
+398
-43
No files matched your search
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::engine_sports_reset() {
|
||||
try { engine_training_draft_ = engine_training_projection(engine_data_); } catch (const std::exception &) { engine_training_draft_ = Json(); }
|
||||
try { engine_tactics_draft_ = engine_tactics_projection(engine_data_); } catch (const std::exception &) { engine_tactics_draft_ = Json(); }
|
||||
}
|
||||
bool App::engine_sports_dirty() const {
|
||||
if (menu_ == "training") return !engine_training_draft_.is_null() &&
|
||||
(!engine_training_draft_.at("initialized").get<bool>() || engine_training_draft_ != engine_training_projection(engine_data_));
|
||||
if (menu_ == "tactics") return !engine_tactics_draft_.is_null() &&
|
||||
engine_tactics_draft_.at("values") != engine_tactics_projection(engine_data_).at("values");
|
||||
return false;
|
||||
}
|
||||
std::string App::engine_sports_footer() {
|
||||
const bool training = menu_ == "training";
|
||||
return "<p id=\"sports-note\" class=\"small muted\" style=\"position:absolute;" +
|
||||
(training ? rect(0, 1580, 1060, 112) : rect(0, 1514, 2300, 112)) + "\"></p>"
|
||||
"<div class=\"row\" style=\"position:absolute;" +
|
||||
(training ? rect(0, 1720, 1060, 94) : rect(0, 1650, 2300, 94)) + "\">" +
|
||||
btn("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\" style=\"width:440dp;height:94dp;\"") +
|
||||
btn("sports-apply", "Anwenden", "primary", "id=\"sports-apply\" style=\"width:440dp;height:94dp;\"") + "</div>";
|
||||
}
|
||||
void App::engine_sports_update() {
|
||||
if (menu_ != "training" && menu_ != "tactics") return;
|
||||
bool changed = false, valid = false; std::string note;
|
||||
try {
|
||||
changed = engine_sports_dirty();
|
||||
if (menu_ == "training") (void)engine_training_command(engine_data_, engine_training_draft_, "request:validate-only");
|
||||
else (void)engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), "request:validate-only");
|
||||
valid = true;
|
||||
note = changed ? "Entwurf · Änderungen werden erst mit Anwenden übernommen." : engine_notice_;
|
||||
if (menu_ == "training" && !engine_training_draft_.at("initialized").get<bool>()) note = "Mit Anwenden wird das Training erstmals eingerichtet.";
|
||||
} catch (const std::exception &e) { note = e.what(); }
|
||||
if (auto *button = element("sports-apply")) {
|
||||
if (valid && changed && engine_fresh_ && !engine_busy_) button->RemoveAttribute("disabled");
|
||||
else button->SetAttribute("disabled", true);
|
||||
}
|
||||
if (auto *button = element("sports-reset")) {
|
||||
if (changed && !engine_busy_) button->RemoveAttribute("disabled");
|
||||
else button->SetAttribute("disabled", true);
|
||||
}
|
||||
if (auto *text = element("sports-note")) {
|
||||
const auto value = esc(engine_busy_ ? engine_operation_ : note);
|
||||
if (text->GetInnerRML() != value) text->SetInnerRML(value);
|
||||
text->SetProperty("color", valid ? "var(--muted)" : "var(--danger)");
|
||||
}
|
||||
}
|
||||
bool App::engine_sports_action(const std::string &action, const std::string &id, Rml::Element *target) {
|
||||
if (menu_ != "training" && menu_ != "tactics") return false;
|
||||
if (action == "close") { engine_sports_reset(); menu_.clear(); refresh(); return true; }
|
||||
if (action == "sports-reset") { engine_sports_reset(); focus_after_render_ = "sports-reset"; refresh(); return true; }
|
||||
if (action == "sports-apply" && engine_fresh_ && engine_sports_dirty()) {
|
||||
const auto command = menu_ == "training"
|
||||
? engine_training_command(engine_data_, engine_training_draft_, editor::new_id("request:ui-"))
|
||||
: engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), editor::new_id("request:ui-"));
|
||||
confirmation(menu_ == "training" ? "Diesen Trainingsplan übernehmen?" : "Diese Taktikeinstellungen übernehmen?", [this, command] {
|
||||
auto link = engine_link_;
|
||||
engine_start("Änderungen werden übernommen …", [link, command] {
|
||||
auto response = link->command(command); return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
}, true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "tactic-cycle" && menu_ == "tactics" && engine_fresh_) {
|
||||
const int i = std::stoi(id); if (i < 0 || i > 6) return true;
|
||||
const int lo = engine_tactics_draft_.at("minima")[size_t(i)], hi = engine_tactics_draft_.at("limits")[size_t(i)];
|
||||
auto &v = engine_tactics_draft_["values"][size_t(i)]; v = v.get<int>() == hi ? lo : v.get<int>() + 1;
|
||||
last_tactic_ = i; focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
if (action == "training-ball" && menu_ == "training" && engine_fresh_) {
|
||||
const auto group = target->GetAttribute<Rml::String>("data-group", "");
|
||||
const int i = std::stoi(id), value = target->GetAttribute<int>("data-value", 0);
|
||||
if (value < 1 || value > 3) return true;
|
||||
if ((group == "type" && i >= 0 && i < 4) || (group == "area" && i >= 0 && i < 9))
|
||||
engine_training_draft_[group == "type" ? "types" : "areas"][size_t(i)] = value;
|
||||
else if (group == "player") {
|
||||
const auto player = target->GetAttribute<Rml::String>("data-player", "");
|
||||
if (engine_training_draft_.at("players").contains(player)) engine_training_draft_["players"][player]["intensity"] = value;
|
||||
}
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
return action.starts_with("training-") || action.starts_with("sports-");
|
||||
}
|
||||
bool App::engine_sports_event(Rml::Event &event) {
|
||||
if (menu_ != "tactics" || !popup_.empty() || engine_busy_) return false;
|
||||
Rml::ElementFormControl *range = nullptr;
|
||||
for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode())
|
||||
if (node->GetId() == "tactic-effort") { range = dynamic_cast<Rml::ElementFormControl *>(node); break; }
|
||||
if (!range) return false;
|
||||
const auto type = event.GetType();
|
||||
int value = std::stoi(range->GetValue()); bool change = type == "input" || type == "change";
|
||||
if (type == "mouseup") { focus_after_render_ = "tactic-effort"; dirty_ = true; }
|
||||
if (type == "keydown") {
|
||||
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
const int lo = engine_tactics_draft_.at("minima")[7], hi = engine_tactics_draft_.at("limits")[7];
|
||||
if (key == Rml::Input::KI_HOME) value = lo;
|
||||
else if (key == Rml::Input::KI_END) value = hi;
|
||||
else if (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN) value = std::max(lo, value - 1);
|
||||
else if (key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_UP) value = std::min(hi, value + 1);
|
||||
else return false;
|
||||
event.StopImmediatePropagation(); range->SetValue(std::to_string(value)); change = true;
|
||||
}
|
||||
if (!change) return false;
|
||||
engine_tactics_draft_["values"][7] = value; last_tactic_ = 7;
|
||||
element("tactic-effort-value")->SetInnerRML(std::string(size_t(value), '!'));
|
||||
element("tactic-hint")->SetInnerRML(esc(engine_tactics_draft_.at("labels")[7].get<std::string>() + ": " + std::to_string(value) + " / " + std::to_string(engine_tactics_draft_.at("limits")[7].get<int>())));
|
||||
engine_sports_update(); dirty_ = true; return true;
|
||||
}
|
||||
Reference in new issue
Block a user