Bind environment and advertising to confirmed engine actions (by Codex)
This commit is contained in:
1 parent
dcf42f2da7
commit
e9483048f4
19 files changed
+395
-23
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::advertising_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("ad-")) return false;
|
||||
if (engine_mode_) return engine_commerce_action(action, target);
|
||||
if (menu_ != "advertising" || !source_ || !world_) return true;
|
||||
if (action == "ad-contract" && target) {
|
||||
const int slot = target->GetAttribute<int>("data-id", -1);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_advertising() {
|
||||
const auto snapshot = snap();
|
||||
const auto view = demo_advertising_view(snapshot.state, *world_);
|
||||
const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap();
|
||||
const auto view = engine_mode_ ? engine_advertising_projection(engine_data_) : demo_advertising_view(snapshot.state, *world_);
|
||||
const auto ad_cash = [&](int64_t value) { return engine_mode_ ? money(value, {{"code", "EUR"}, {"minor_units", 2}}) : cash(value); };
|
||||
if (!view.value("ok", false)) return {};
|
||||
const auto brand = [&](const Json &c) {
|
||||
if (c.at("sponsor") == -1) return std::string();
|
||||
@@ -23,7 +24,7 @@ std::string App::render_advertising() {
|
||||
std::string body = "<strong><span>" + std::string(headings[size_t(i)]) + "</span></strong><div class=\"advertising-art\">" +
|
||||
img("advertising.panel." + std::to_string(i), 510, 510, false, false, 1000) + "</div>";
|
||||
if (i == 0) body += brand(view.at("slots")[14]);
|
||||
else body += "<output><span>" + esc(cash(view.at("spending")[size_t(i - 1)].at("amount").get<int64_t>())) + "</span></output>";
|
||||
else body += "<output class=\"" + (engine_mode_ ? money_classes(view.at("spending")[size_t(i - 1)].at("amount")) : std::string()) + "\"><span>" + esc(ad_cash(view.at("spending")[size_t(i - 1)].at("amount").get<int64_t>())) + "</span></output>";
|
||||
out += btn(i == 0 ? "ad-contract" : "ad-spending", body,
|
||||
"advertising-card advertising-panel " + std::string(i == 0 ? "advertising-shirt " : "") + (i == 0 && advertising_selected_ == 14 ? "selected" : ""),
|
||||
"id=\"" + std::string(i == 0 ? "ad-contract-14" : "ad-spending-" + std::to_string(i - 1)) + "\" data-id=\"" + std::to_string(i == 0 ? 14 : i - 1) +
|
||||
@@ -40,21 +41,26 @@ std::string App::render_advertising() {
|
||||
out += "<div class=\"advertising-hint\"><h2>Werbung und Vereinsausgaben</h2>"
|
||||
"<p>Bande, Trikot oder TV-Rechte auswählen.</p><p>Die drei Ausgabenbilder öffnen die Zahleneingabe.</p></div>";
|
||||
} else {
|
||||
const auto quote = demo_advertising_quote(snapshot.state, advertising_selected_, advertising_offer_, *world_);
|
||||
const auto &choices = engine_mode_ ? view.at("slots")[size_t(advertising_selected_)].at("choices") : Json::array();
|
||||
if (engine_mode_) advertising_offer_ = std::clamp(advertising_offer_, 0, int(choices.size()) - 1);
|
||||
const auto quote = engine_mode_ ? engine_advertising_quote(engine_data_, advertising_selected_, advertising_offer_) : demo_advertising_quote(snapshot.state, advertising_selected_, advertising_offer_, *world_);
|
||||
const bool active = quote.at("active");
|
||||
const bool cycle = engine_mode_ ? quote.at("can_cycle").get<bool>() : !active;
|
||||
const bool accept = engine_mode_ ? quote.at("can_accept").get<bool>() : !active;
|
||||
out += "<div class=\"advertising-offer\"><div class=\"ad-offer-mark\">" + brand(quote) +
|
||||
"</div><div class=\"ad-offer-arrows\">" +
|
||||
btn("ad-offer", "<span>‹</span>", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(active ? "disabled" : "")) +
|
||||
btn("ad-offer", "<span>›</span>", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(active ? "disabled" : "")) +
|
||||
btn("ad-offer", "<span>‹</span>", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(cycle ? "" : "disabled")) +
|
||||
btn("ad-offer", "<span>›</span>", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(cycle ? "" : "disabled")) +
|
||||
"</div><div class=\"ad-offer-facts\"><div><span>" + esc(quote.at("label").get<std::string>()) + "</span><strong>" +
|
||||
esc(quote.at("name").get<std::string>()) + "</strong></div><div><span>Dauer</span><strong>" + std::to_string(quote.at("months").get<int>()) +
|
||||
" Monate</strong></div><div><span>" + (active ? "Vertrag" : "Angebot") + "</span><strong>" +
|
||||
esc(cash(quote.at("amount").get<int64_t>())) + " / Monat</strong></div></div></div><nav class=\"advertising-actions\">" +
|
||||
" Monate" + (engine_mode_ && quote.at("boards") > 1 ? " · " + std::to_string(quote.at("boards").get<int>()) + " Banden" : std::string()) + "</strong></div><div><span>" + (active ? "Vertrag" : "Angebot") + "</span><strong>" +
|
||||
esc(ad_cash(quote.at("amount").get<int64_t>())) + " / Monat</strong></div></div></div><nav class=\"advertising-actions\">" +
|
||||
btn("ad-cancel", active ? "Schließen" : "Abbrechen", "advertising-control", "id=\"ad-cancel\"") +
|
||||
btn("ad-accept", active ? "Vertrag läuft" : "Annehmen", "advertising-control", "id=\"ad-accept\" " + std::string(active ? "disabled" : "")) + "</nav>";
|
||||
btn("ad-accept", active ? "Vertrag läuft" : accept ? "Annehmen" : "Nicht verfügbar", "advertising-control", "id=\"ad-accept\" " + std::string(accept ? "" : "disabled")) + "</nav>";
|
||||
}
|
||||
out += "<div class=\"advertising-totals\">";
|
||||
if (engine_mode_) out += "<span class=\"engine-ad-preview-label\">Vereinsprognose / Monat</span>";
|
||||
out += "<div class=\"advertising-totals\" aria-label=\"" + std::string(engine_mode_ ? "Monatliche Vereinsprognose der Engine" : "Werbevorschau") + "\">";
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}})
|
||||
out += "<div><span>" + std::string(label) + "</span><output>" + esc(cash(view.at(key).get<int64_t>())) + "</output></div>";
|
||||
out += "<div><span>" + std::string(label) + "</span><output class=\"" + (engine_mode_ ? money_classes(view.at(key)) : std::string()) + "\">" + esc(ad_cash(view.at(key).get<int64_t>())) + "</output></div>";
|
||||
return out + "</div></section></div>";
|
||||
}
|
||||
@@ -30,7 +30,7 @@ std::shared_ptr<EngineBridge> EngineBridge::open(const fs::path &world, const fs
|
||||
}
|
||||
Json EngineBridge::snapshot() const {
|
||||
Json bundle = Json::object();
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training", "bank", "stadium", "credit"})
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training", "bank", "stadium", "credit", "environment", "advertising"})
|
||||
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
|
||||
validate_engine_desk(bundle);
|
||||
return bundle;
|
||||
|
||||
@@ -26,6 +26,13 @@ Json engine_credit_command(const Json &bundle, const Json &read, const Json &edi
|
||||
Json engine_ticket_projection(const Json &bundle);
|
||||
Json engine_ticket_command(const Json &bundle, int euros, const std::string &request_id);
|
||||
|
||||
Json engine_environment_projection(const Json &bundle);
|
||||
Json engine_environment_command(const Json &bundle, const std::string &item, int level, const std::string &request_id);
|
||||
Json engine_advertising_projection(const Json &bundle);
|
||||
Json engine_advertising_quote(const Json &bundle, int slot, int choice);
|
||||
Json engine_advertising_command(const Json &bundle, const std::string &offer, const std::string &request_id);
|
||||
Json engine_budget_command(const Json &bundle, const std::string &budget, int64_t euros, const std::string &request_id);
|
||||
|
||||
// Single-session facade. Its owner serializes all calls on a background worker.
|
||||
// No RmlUI objects or callbacks cross this boundary.
|
||||
class EngineBridge {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::engine_commerce_action(const std::string &action, Rml::Element *target) {
|
||||
if (!engine_fresh_ || engine_busy_) return true;
|
||||
if (action == "environment-level" && menu_ == "environment" && target) {
|
||||
const int index = target->GetAttribute<int>("data-index", -1), level = target->GetAttribute<int>("data-id", -1);
|
||||
if (index < 0 || index > 5) return true;
|
||||
const auto row = engine_environment_projection(engine_data_).at("rows")[size_t(index)];
|
||||
const auto command = engine_environment_command(engine_data_, row.at("engine_id"), level, editor::new_id("request:ui-"));
|
||||
const auto current = money(row.at("cost"), {{"code", "EUR"}, {"minor_units", 2}});
|
||||
const auto next = money(row.at("step").get<int64_t>() * level, {{"code", "EUR"}, {"minor_units", 2}});
|
||||
const auto focus = target->GetId();
|
||||
confirmation(row.at("name").get<std::string>() + ": Monatsbudget von " + current + " auf " + next + " setzen?", [this, command, focus] {
|
||||
focus_after_render_ = focus; engine_finance_submit(command);
|
||||
}); return true;
|
||||
}
|
||||
if (!action.starts_with("ad-") || menu_ != "advertising") return false;
|
||||
const auto view = engine_advertising_projection(engine_data_);
|
||||
if (action == "ad-contract" && target) {
|
||||
const int slot = target->GetAttribute<int>("data-id", -1);
|
||||
if (slot < 0 || slot > 15) return true;
|
||||
advertising_selected_ = slot; advertising_offer_ = 0;
|
||||
focus_after_render_ = target->GetId(); refresh(); return true;
|
||||
}
|
||||
if (action == "ad-cancel") {
|
||||
if (advertising_selected_ >= 0) focus_after_render_ = "ad-contract-" + std::to_string(advertising_selected_);
|
||||
advertising_selected_ = -1; advertising_offer_ = 0; refresh(); return true;
|
||||
}
|
||||
if (action == "ad-offer" && target && advertising_selected_ >= 0) {
|
||||
const int step = target->GetAttribute<int>("data-step", 0), count = int(view.at("slots")[size_t(advertising_selected_)].at("choices").size());
|
||||
if (step == 1 || step == -1) { advertising_offer_ = (advertising_offer_ + step + count) % count; focus_after_render_ = target->GetId(); refresh(); }
|
||||
return true;
|
||||
}
|
||||
if (action == "ad-accept" && advertising_selected_ >= 0) {
|
||||
const auto quote = engine_advertising_quote(engine_data_, advertising_selected_, advertising_offer_);
|
||||
if (quote.at("can_accept") != true) return true;
|
||||
const auto command = engine_advertising_command(engine_data_, quote.at("offer_id"), editor::new_id("request:ui-"));
|
||||
confirmation(quote.at("label").get<std::string>() + ": " + quote.at("name").get<std::string>() + " für " +
|
||||
std::to_string(quote.at("months").get<int>()) + " Monate zu " + money(quote.at("amount"), {{"code", "EUR"}, {"minor_units", 2}}) +
|
||||
" pro Monat verbindlich annehmen?" + (quote.at("boards").get<int>() > 1 ? " Umfasst " + std::to_string(quote.at("boards").get<int>()) + " Banden." : ""), [this, command] {
|
||||
focus_after_render_ = "window-close"; engine_finance_submit(command);
|
||||
}); return true;
|
||||
}
|
||||
if (action == "ad-spending" && target) {
|
||||
const int index = target->GetAttribute<int>("data-id", -1); if (index < 0 || index > 2) return true;
|
||||
const auto row = view.at("spending")[size_t(index)];
|
||||
if (row.at("available") != true || row.at("delivery_weeks") != 0) {
|
||||
message(row.at("delivery_weeks").get<int>() > 0 ? "Die Lieferung läuft noch: " + std::to_string(row.at("delivery_weeks").get<int>()) + " Wochen." : "Dieses Budget ist derzeit nicht verfügbar."); return true;
|
||||
}
|
||||
const auto meta = engine_data_.at("desktop").at("meta");
|
||||
AmountRequest request; request.title = row.at("name"); request.review_text = [index](int64_t) { return index == 0 ? "Fanartikel verbindlich bestellen." : "Monatliches Budget für den Verein."; }; request.unit = "€"; request.return_focus = target->GetId();
|
||||
request.value = row.at("amount").get<int64_t>() / 100; request.min = 0; request.max = std::min<int64_t>(99999999, row.at("max").get<int64_t>() / 100);
|
||||
request.step = 1; request.suggestion_step = row.at("suggestion_step"); request.review = true;
|
||||
request.accept = [this, meta, row](int64_t value) {
|
||||
if (engine_busy_ || !engine_fresh_ || menu_ != "advertising" || meta != engine_data_.at("desktop").at("meta")) return false;
|
||||
engine_finance_submit(engine_budget_command(engine_data_, row.at("id"), value, editor::new_id("request:ui-"))); return true;
|
||||
};
|
||||
open_amount(std::move(request)); return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ void App::engine_poll() {
|
||||
} else if (engine_response_.value("messageType", "") == "saved") {
|
||||
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
|
||||
} else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
|
||||
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
|
||||
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
|
||||
engine_ticket_bind();
|
||||
engine_sports_reset();
|
||||
@@ -98,6 +99,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (ticket_ && ticket_->is_open()) return;
|
||||
if (amount_event(event)) return;
|
||||
if (!engine_busy_ && bank_event(event)) return;
|
||||
if (!engine_busy_ && advertising_event(event)) return;
|
||||
if (engine_sports_event(event)) return;
|
||||
Rml::ElementFormControl *range = nullptr;
|
||||
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
|
||||
@@ -160,6 +162,8 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
|
||||
return;
|
||||
}
|
||||
if (environment_action(action, node)) return;
|
||||
if (advertising_action(action, node)) return;
|
||||
if (bank_action(action, node)) return;
|
||||
if (engine_sports_action(action, id, node)) return;
|
||||
if (engine_lineup_action(action, id, node)) return;
|
||||
@@ -168,6 +172,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
const auto price = engine_ticket_projection(engine_data_);
|
||||
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
|
||||
}
|
||||
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
|
||||
else if (action == "engine-open" && id == "bank") { bank_view_ = "entrance"; bank_hint_.clear(); menu_ = "bank"; refresh(); }
|
||||
else if (action == "engine-open" && id == "save") engine_save();
|
||||
else if (action == "engine-open" && (id == "training" || id == "tactics")) { engine_sports_reset(); menu_ = id; refresh(); }
|
||||
|
||||
@@ -387,4 +387,119 @@ Json engine_credit_command(const Json &bundle, const Json &read, const Json &edi
|
||||
// The engine replays this ordered edit list and owns fees and all loan maths.
|
||||
return sports_command(bundle, "bank.commit", {{"action", "credit"}, {"lenderId", "bank"}, {"edits", edits}, {"acceptFees", true}}, request_id);
|
||||
}
|
||||
|
||||
Json engine_environment_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &data = lineup_read(bundle, "environment");
|
||||
require(bundle.at("desktop").at("meta").at("scope").at("role") == "club", "Umfeld ist nur am Vereinsschreibtisch verfügbar.");
|
||||
const std::array<const char *, 6> keys{"youth_youngest", "youth_academy", "youth_oldest", "co_trainer", "doctor", "physio"};
|
||||
const std::array<const char *, 6> ids{"youth-a", "youth-b", "youth-c", "coach", "doctor", "physio"};
|
||||
const std::array<const char *, 6> names{"Nachwuchs · Jüngste", "Nachwuchs · Mittlere", "Nachwuchs · Ältere", "Co-Trainer", "Vereinsarzt", "Masseur"};
|
||||
require(data.at("items").is_array() && data.at("items").size() == 6 && data.at("youth").is_array() && data.at("youth").size() == 3, "Unvollständiges Umfeld.");
|
||||
Json rows = Json::array(); std::set<std::string> seen;
|
||||
for (size_t i = 0; i < keys.size(); ++i) {
|
||||
const std::string id = std::string("environment:") + keys[i];
|
||||
const Json *item = nullptr, *youth = nullptr;
|
||||
for (const auto &r : data.at("items")) if (r.at("id") == id) { require(!item, "Doppelte Umfeld-ID."); item = &r; }
|
||||
require(item, "Unbekannte Umfeldzuordnung.");
|
||||
const int max = whole_in_range(item->at("maxLevel"), 0, 6), level = whole_in_range(item->at("level"), 0, max);
|
||||
const auto cost = engine_money_minor(item->at("monthly")), step = engine_money_minor(item->at("stepCost"));
|
||||
require(cost >= 0 && step >= 0 && step <= std::numeric_limits<int64_t>::max() / 6, "Ungültige Umfeldkosten.");
|
||||
Json row = {{"id", ids[i]}, {"engine_id", id}, {"name", names[i]}, {"level", level}, {"max", max}, {"cost", cost}, {"step", step},
|
||||
{"image", i < 3 ? "youth" : "staff"}, {"cell", i < 3 ? int(i) : int(i - 3)}, {"rank", nullptr}, {"league", nullptr}};
|
||||
if (i < 3) {
|
||||
for (const auto &y : data.at("youth")) if (y.at("id") == std::string("youth:") + keys[i]) { require(!youth, "Doppelte Nachwuchs-ID."); youth = &y; }
|
||||
require(youth, "Nachwuchsmannschaft fehlt.");
|
||||
// Like the original presenter: the stored place/league are zero-based.
|
||||
row["rank"] = whole_in_range(youth->at("place"), 0, 11) + 1;
|
||||
row["league"] = whole_in_range(youth->at("league"), 0, 2) + 1;
|
||||
}
|
||||
rows.push_back(row);
|
||||
}
|
||||
return {{"ok", true}, {"rows", rows}};
|
||||
}
|
||||
Json engine_environment_command(const Json &bundle, const std::string &id, int level, const std::string &request_id) {
|
||||
const auto view = engine_environment_projection(bundle);
|
||||
const Json *item = nullptr;
|
||||
for (const auto &row : view.at("rows")) if (row.at("engine_id") == id) item = &row;
|
||||
require(item && level >= 0 && level <= item->at("max").get<int>(), "Unbekannte Umfeldstufe.");
|
||||
return sports_command(bundle, "environment.commit", {{"itemId", id}, {"level", level}}, request_id);
|
||||
}
|
||||
namespace {
|
||||
std::string business_text(const Json &v) {
|
||||
if (v.is_null()) return "—";
|
||||
return v.is_string() ? v.get<std::string>() : v.value("text", "—");
|
||||
}
|
||||
}
|
||||
Json engine_advertising_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &data = lineup_read(bundle, "advertising");
|
||||
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Werbung gehört einer anderen Mannschaft.");
|
||||
require(data.at("boards").is_array() && data.at("boards").size() == 14 && data.at("budgets").is_array() && data.at("budgets").size() == 3, "Unvollständige Werbung.");
|
||||
const auto commands = bundle.at("desktop").at("meta").at("scope").value("allowedCommands", Json::array());
|
||||
const bool contracts_allowed = commands.is_array() && std::find(commands.begin(), commands.end(), Json("advertising.accept")) != commands.end();
|
||||
const bool budgets_allowed = commands.is_array() && std::find(commands.begin(), commands.end(), Json("budget.commit")) != commands.end();
|
||||
Json slots = Json::array(), spending = Json::array();
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
const std::string id = i < 14 ? "ad:board/" + std::to_string(i) : i == 14 ? "ad:shirt" : "ad:tv";
|
||||
const std::string label = i < 14 ? "Bande " + std::to_string(i + 1) : i == 14 ? "Trikotwerbung" : "TV-Rechte";
|
||||
const Json *raw = i == 14 ? &data.at("shirt") : i == 15 ? &data.at("television") : nullptr;
|
||||
if (i < 14) for (const auto &row : data.at("boards")) if (row.at("id") == id) { require(!raw, "Doppelte Werbefläche."); raw = &row; }
|
||||
require(raw && raw->at("id") == id && raw->at("active").is_boolean(), "Ungültige Werbefläche.");
|
||||
const bool active = raw->at("active");
|
||||
const auto amount = engine_money_minor(raw->at("monthly"));
|
||||
require(amount >= 0, "Ungültiger Werbebetrag.");
|
||||
Json slot = {{"id", id}, {"slot", i}, {"label", label}, {"active", active}, {"name", active ? business_text(raw->at("sponsor")) : "Platz frei"},
|
||||
{"sponsor", active ? 0 : -1}, {"amount", amount}, {"months", whole_in_range(raw->at("monthsRemaining"), 0, 255)}, {"choices", Json::array()}};
|
||||
// sponsor here is only an artwork switch; commands use the exact offer ID.
|
||||
auto current = slot; current.erase("choices"); current["can_accept"] = false; current["boards"] = 1; current["offer_id"] = nullptr;
|
||||
if (active) slot["choices"].push_back(current);
|
||||
require(raw->at("offers").is_array() && raw->at("offers").size() <= 200, "Ungültige Angebotsliste.");
|
||||
std::set<std::string> seen;
|
||||
for (const auto &offer : raw->at("offers")) {
|
||||
const auto offer_id = offer.at("id").get<std::string>(), prefix = "offer:ad-" + std::to_string(i) + "-";
|
||||
require(offer_id.starts_with(prefix) && offer_id.size() > prefix.size() &&
|
||||
offer_id.find_first_not_of("0123456789", prefix.size()) == std::string::npos && seen.insert(offer_id).second, "Angebot gehört einer anderen Werbefläche.");
|
||||
require(offer.at("allowed").is_boolean(), "Angebotssperre fehlt.");
|
||||
const auto monthly = engine_money_minor(offer.at("monthly")); require(monthly >= 0, "Ungültiger Angebotspreis.");
|
||||
slot["choices"].push_back({{"offer_id", offer_id}, {"name", business_text(offer.at("sponsor"))}, {"label", label}, {"sponsor", 0},
|
||||
{"amount", monthly}, {"months", whole_in_range(offer.at("months"), 1, 255)}, {"boards", whole_in_range(offer.at("boards"), 1, 14)}, {"active", false}, {"can_accept", offer.at("allowed") == true && contracts_allowed}});
|
||||
}
|
||||
if (slot["choices"].empty()) { current["name"] = "Keine Angebote"; slot["choices"].push_back(current); }
|
||||
slots.push_back(slot);
|
||||
}
|
||||
const std::array<const char *, 3> budget_ids{"budget:merchandise", "budget:press", "budget:fans"}, names{"Fanartikel", "Öffentlichkeitsarbeit", "Fanbetreuung"};
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
const Json *row = nullptr;
|
||||
for (const auto &r : data.at("budgets")) if (r.at("id") == budget_ids[i]) { require(!row, "Doppeltes Werbebudget."); row = &r; }
|
||||
require(row && row->at("available").is_boolean(), "Werbebudget fehlt.");
|
||||
const auto current = engine_money_minor(row->at("current")), max = engine_money_minor(row->at("maximum"));
|
||||
require(current >= 0 && current % 100 == 0 && max >= 0 && max % 100 == 0, "Ungültige Budgetgrenzen.");
|
||||
spending.push_back({{"id", budget_ids[i]}, {"name", names[i]}, {"amount", current}, {"max", max}, {"available", row->at("available") == true && budgets_allowed},
|
||||
{"delivery_weeks", whole_in_range(row->at("deliveryWeeks"), 0, 255)}, {"suggestion_step", i == 0 ? 50000 : 5000}});
|
||||
}
|
||||
return {{"ok", true}, {"slots", slots}, {"spending", spending}, {"income", engine_money_minor(data.at("preview").at("income"))},
|
||||
{"expenses", engine_money_minor(data.at("preview").at("expenses"))}, {"balance", engine_money_minor(data.at("preview").at("balance"))}};
|
||||
}
|
||||
Json engine_advertising_quote(const Json &bundle, int slot, int choice) {
|
||||
const auto view = engine_advertising_projection(bundle);
|
||||
require(slot >= 0 && slot < 16, "Unbekannte Werbefläche.");
|
||||
const auto &choices = view.at("slots")[size_t(slot)].at("choices");
|
||||
require(choice >= 0 && size_t(choice) < choices.size(), "Unbekanntes Werbeangebot.");
|
||||
auto out = choices[size_t(choice)]; out["can_cycle"] = choices.size() > 1;
|
||||
return out;
|
||||
}
|
||||
Json engine_advertising_command(const Json &bundle, const std::string &id, const std::string &request_id) {
|
||||
const auto view = engine_advertising_projection(bundle); bool allowed = false;
|
||||
for (const auto &s : view.at("slots")) for (const auto &c : s.at("choices")) if (c.at("offer_id") == id) allowed = c.at("can_accept");
|
||||
require(allowed, "Dieses Werbeangebot ist nicht mehr verfügbar.");
|
||||
return sports_command(bundle, "advertising.accept", {{"offerId", id}}, request_id);
|
||||
}
|
||||
Json engine_budget_command(const Json &bundle, const std::string &id, int64_t euros, const std::string &request_id) {
|
||||
const auto view = engine_advertising_projection(bundle); const Json *row = nullptr;
|
||||
for (const auto &r : view.at("spending")) if (r.at("id") == id) row = &r;
|
||||
require(row && row->at("available") == true && row->at("delivery_weeks") == 0 && euros >= 0 && euros <= 99999999 && euros <= row->at("max").get<int64_t>() / 100,
|
||||
"Budget ist gesperrt oder außerhalb des verfügbaren Bereichs.");
|
||||
return sports_command(bundle, "budget.commit", {{"budgetId", id}, {"amount", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(euros * 100)}}}}, request_id);
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -66,6 +66,11 @@ void App::engine_render() {
|
||||
const auto allowed = meta.at("scope").value("allowedCommands", Json::array());
|
||||
bank_available = bank_available && std::find(allowed.begin(), allowed.end(), Json("bank.commit")) != allowed.end();
|
||||
ticket_available = ticket_available && std::find(allowed.begin(), allowed.end(), Json("ticket.commit")) != allowed.end();
|
||||
bool environment_available = false, advertising_available = false;
|
||||
try { (void)engine_environment_projection(engine_data_); environment_available = true; } catch (const std::exception &) {}
|
||||
try { (void)engine_advertising_projection(engine_data_); advertising_available = true; } catch (const std::exception &) {}
|
||||
environment_available = environment_available && std::find(allowed.begin(), allowed.end(), Json("environment.commit")) != allowed.end();
|
||||
advertising_available = advertising_available && (std::find(allowed.begin(), allowed.end(), Json("advertising.accept")) != allowed.end() || std::find(allowed.begin(), allowed.end(), Json("budget.commit")) != allowed.end());
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
@@ -98,18 +103,20 @@ void App::engine_render() {
|
||||
const auto route = id.substr(4);
|
||||
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
const bool supported = (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
const bool supported = (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
|
||||
}
|
||||
}
|
||||
out += "</div>";
|
||||
if (menu_ == "environment") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Umfeld", render_environment()) + "</div>";
|
||||
if (menu_ == "advertising") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Werbung", render_advertising()) + "</div>";
|
||||
if (menu_ == "bank") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Bank", render_bank()) + "</div>";
|
||||
if (menu_ == "training") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Training", render_training()) + "</div>";
|
||||
if (menu_ == "tactics") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Taktik", render_tactics()) + "</div>";
|
||||
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
|
||||
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
|
||||
}
|
||||
if (menu_ == "bank" && !amount_) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising") && !amount_) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
element("canvas")->SetInnerRML(out); ++document_generation_;
|
||||
scale_chalk_shadow();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
Json engine_data_, engine_response_, engine_focus_, engine_training_draft_, engine_tactics_draft_;
|
||||
std::string engine_camp_, engine_operation_, engine_notice_, engine_player_;
|
||||
Json engine_credit_, engine_credit_edits_ = Json::array();
|
||||
bool engine_commerce_action(const std::string &, Rml::Element *);
|
||||
bool engine_bank_action(const std::string &, Rml::Element *);
|
||||
std::string engine_credit_view();
|
||||
void engine_finance_submit(const Json &);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::environment_action(const std::string &action, Rml::Element *target) {
|
||||
if (action != "environment-level") return false;
|
||||
if (engine_mode_) return engine_commerce_action(action, target);
|
||||
if (menu_ != "environment" || !source_ || !target) return true;
|
||||
const auto index = target->GetAttribute<Rml::String>("data-index", "");
|
||||
const auto value = target->GetAttribute<Rml::String>("data-id", "");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_environment() {
|
||||
const auto snapshot = snap();
|
||||
const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap();
|
||||
if (!snapshot.world) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
|
||||
const auto view = demo_environment_rows(snapshot.state, *snapshot.world);
|
||||
const auto view = engine_mode_ ? engine_environment_projection(engine_data_) : demo_environment_rows(snapshot.state, *snapshot.world);
|
||||
if (!view.value("ok", false)) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
|
||||
const auto funded = theme_ == "silver" ? "#805b18" : theme_ == "matchday" ? "#e1c68b" : "#e5cd8c";
|
||||
const auto unfunded = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#6f8595";
|
||||
@@ -39,7 +39,7 @@ std::string App::render_environment() {
|
||||
"\" data-index=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(value) +
|
||||
"\" aria-pressed=\"" + (selected ? "true" : "false") + "\" aria-label=\"" +
|
||||
esc(name + ": " + std::to_string(value) + (value == 1 ? " Stern" : " Sterne")) +
|
||||
"\" title=\"" + (value ? std::to_string(value) + (value == 1 ? " Stern" : " Sterne") : "Budget auf null setzen") + "\"");
|
||||
"\" " + std::string(engine_mode_ && value > row.at("max").get<int>() ? "disabled " : "") + "title=\"" + (value ? std::to_string(value) + (value == 1 ? " Stern" : " Sterne") : "Budget auf null setzen") + "\"");
|
||||
}
|
||||
out += "</div><div class=\"environment-picture\" style=\"" + rect(18, 138, inner, panel.image_h) + "\">" +
|
||||
img("environment." + row.at("image").get<std::string>() + "." + std::to_string(row.at("cell").get<int>()),
|
||||
@@ -47,7 +47,7 @@ std::string App::render_environment() {
|
||||
"</div><div class=\"environment-caption\" style=\"top:" + scalar(152 + panel.image_h) + "dp;height:" +
|
||||
scalar(i < 3 ? 74.546875 : 60) + "dp;\"><span class=\"environment-cost\" id=\"environment-cost-" + std::to_string(i) +
|
||||
"\" aria-label=\"" + esc(name + " Monatskosten") + "\">" +
|
||||
esc(money(row.at("cost").get<int64_t>(), snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + "</span>";
|
||||
esc(money(row.at("cost").get<int64_t>(), engine_mode_ ? Json{{"code", "EUR"}, {"minor_units", 2}} : snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + "</span>";
|
||||
if (i < 3)
|
||||
out += "<span class=\"environment-standing\">" + std::to_string(row.at("rank").get<int>()) + ". / " +
|
||||
std::to_string(row.at("league").get<int>()) + ". Liga</span>";
|
||||
@@ -55,8 +55,8 @@ std::string App::render_environment() {
|
||||
}
|
||||
out += "<div class=\"environment-emblem\"><div class=\"environment-ball\">" +
|
||||
img("art.environment-ball-v1.png", 400, 400, false, false, 640) + "</div>";
|
||||
const auto &managers = snapshot.state.at("managers");
|
||||
const auto managed = managers.is_array() && !managers.empty() ? demo_career_manager(snapshot.state).value("club", "") : "";
|
||||
const bool demo_manager = !engine_mode_ && snapshot.state.at("managers").is_array() && !snapshot.state.at("managers").empty();
|
||||
const auto managed = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : demo_manager ? demo_career_manager(snapshot.state).value("club", "") : "";
|
||||
const auto *club = snapshot.world->find("clubs", managed);
|
||||
out += "<div class=\"environment-crest\" aria-label=\"" + esc(club ? snapshot.world->name(*club) : "Vereinswappen nicht verfügbar") + "\">" +
|
||||
(club ? img(club->value("crest", ""), 162, 162, true) : "<span>—</span>") + "</div></div></div>";
|
||||
|
||||
@@ -1517,6 +1517,7 @@ public:
|
||||
#include "modern/ui/engine_lineup.inc"
|
||||
#include "modern/ui/engine_sports.inc"
|
||||
#include "modern/ui/engine_finance.inc"
|
||||
#include "modern/ui/engine_commerce.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user