diff --git a/assets/modern/advertising.rcss b/assets/modern/advertising.rcss index 7746dea..ada08e6 100644 --- a/assets/modern/advertising.rcss +++ b/assets/modern/advertising.rcss @@ -62,3 +62,11 @@ body.matchday .advertising-free,body.matchday .advertising-hint,body.matchday .a body.matchday .ad-offer-arrow {color:#efeded;} body.matchday .advertising-card>output,body.matchday .advertising-totals>div:last-child>output {color:#efb2aa;} body.matchday .advertising-control {decorator:linear-gradient(180deg,#e8d6dc12,#a1a0aa0d);} + +/* Engine money keeps its sign semantics independently of the skin accent. */ +body .advertising-page .advertising-card>output.money-amount, +body .advertising-page .advertising-totals>div>output.money-amount {color:var(--money);} +body .advertising-page .advertising-card>output.money-amount.is-negative, +body .advertising-page .advertising-totals>div>output.money-amount.is-negative {color:var(--danger);} + +.engine-ad-preview-label {position:absolute;left:32dp;right:32dp;bottom:150dp;height:34dp;font-size:25dp;line-height:30dp;color:var(--muted);} diff --git a/docs/new_ui/NATIVE_STATUS.md b/docs/new_ui/NATIVE_STATUS.md index 3678902..2d5c427 100644 --- a/docs/new_ui/NATIVE_STATUS.md +++ b/docs/new_ui/NATIVE_STATUS.md @@ -6,7 +6,7 @@ Die normale Classic-Konfiguration bleibt unverändert; die neue Oberfläche wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut. Der [opt-in Engine-Einstieg](integration/ENGINE_ENTRY.md) lädt inzwischen eine -echte Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager, Aufstellung, Taktik, Training, Bank und Eintrittspreis an die +echte Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager, Aufstellung, Taktik, Training, Bank, Eintrittspreis, Umfeld und Werbung an die Session. Kader und Profile zeigen die tatsächlichen Sessionwerte; Spielertausch verwendet die bestätigte Engineaktion. Preisbestätigung, Buchung und Speichern als neue OBS-Datei sind echte Engineoperationen. Dieser Einstieg ist auf diesen Umfang begrenzt; die übrigen diff --git a/docs/new_ui/desktop/advertising/README.md b/docs/new_ui/desktop/advertising/README.md index 1fec101..3645165 100644 --- a/docs/new_ui/desktop/advertising/README.md +++ b/docs/new_ui/desktop/advertising/README.md @@ -1,5 +1,40 @@ # Werbung und Vereinsausgaben · native Modern UI +## Echter Engine-Einstieg · 28. Oktober 2026 + +`--ui-career` bindet denselben Presenter an `advertising`: vierzehn Banden, +Trikot, TV, alle gemeldeten Angebote und die drei Budgets. Firmen, Beträge, +Laufzeiten, Bandenanzahl, Sperren und Limits kommen aus der Engine. Die Pfeile +blättern durch die tatsächliche Angebotsliste, einschließlich ausgelassener +Poolplätze. Ein laufender Vertrag bleibt sichtbar; zusätzlich gelieferte +Angebote können angesehen werden. Nur ausdrücklich erlaubte Angebote lassen +sich bestätigen. Angebote werden beim Blättern nicht neu erzeugt. + +Annehmen öffnet eine eigene Zusammenfassung mit Firma, Laufzeit, Monatsbetrag +und gegebenenfalls mehreren Banden. Erst Bestätigen sendet +`advertising.accept` mit der unveränderten Offer-ID und dem gemeinsamen +Karriere-/Manager-/Revisionskontext. Da die Engine Banden danach umsortieren +kann, wird die lokale Vertragsauswahl nach einer Buchung aufgehoben. + +Fanartikel, Öffentlichkeitsarbeit und Fanbetreuung verwenden den gemeinsamen +Zahleneditor mit Engine-Limits. Nach seiner zweiten Bestätigung sendet +`budget.commit` genau einmal die Umrechnung ganzer Euro in Minor Units. +Fanartikel sind als verbindliche Bestellung, die anderen Ausgaben als +Monatsbudget bezeichnet. Laufende Lieferungen und fehlende Capabilities +sperren erneutes Bestellen; ein Klick erklärt die gemeldeten Restwochen. + +Die untere Vorschau ist als **Vereinsprognose / Monat** beschriftet: Sie zeigt +die drei gelieferten Engine-Finanzwerte, keine vom Frontend aus Werbeverträgen +berechnete Teilbilanz. Positive Beträge verwenden die Geldfarbe, negative +Salden die Warnfarbe, auch im Matchday-Theme. Abbruch und Browsing bleiben +schreibgeschützt. Bestätigte Verträge und Budgets bleiben in einer neuen +OBS-Datei und nach vollständigem Prozessneustart erhalten. + +Private Nachweise: `bmh_4k_ui/docs/qa/engine-commerce-2026-10-28/`. +Siehe [Engine-Einstieg](../../integration/ENGINE_ENTRY.md). + +## Getrennte Präsentationsdemo + Stand: 24. Oktober 2026. Die native Ansicht übernimmt das private HTML-Mockup `bmh_4k_ui`, Referenzrevision `9db6926d7f3d89a7c4219ae38f274766f060783a`. Maßgeblich sind diff --git a/docs/new_ui/desktop/environment/README.md b/docs/new_ui/desktop/environment/README.md index d584413..dff2e95 100644 --- a/docs/new_ui/desktop/environment/README.md +++ b/docs/new_ui/desktop/environment/README.md @@ -1,5 +1,29 @@ # Umfeld +## Echter Engine-Einstieg · 28. Oktober 2026 + +Mit `--ui-career` verwendet dieselbe Ansicht die sechs Einträge des Reads +`environment`. Sterne, aktuelle Beträge und Stufenkosten stammen aus der +Engine. Die drei Nachwuchsränge/-ligen werden wie im Original von ihrer +nullbasierten Speicherung in die sichtbaren Werte übersetzt. Demo-Kosten, +Demo-Ränge und feste Startwerte werden nicht als echte Werte verwendet. +Das Wappen gehört zum aktiven Engine-Team. + +Ein Sternklick zeigt vor der Übernahme das bisherige und neue Monatsbudget. +Erst Bestätigen sendet `environment.commit` mit stabiler Eintrags-ID, Karriere, +Manager und erwarteter Revision. Der Client multipliziert nur die gelieferte +Stufenkosteneinheit mit der gewählten Stufe; die tatsächliche Anwendung bleibt +bei der Engine. Ein monatliches Budget bucht nicht sofort Guthaben ab. Abbruch +ändert nichts; ein bestätigter unveränderter Wert macht die Karriere nicht +ungespeichert. Nach dem Commit kehrt der Tastaturfokus zur gewählten Stufe zurück. + +Die App ist ohne passende Engine-Capability gesperrt, insbesondere am +National-Schreibtisch. Neue OBS-Dateien erhalten die bestätigten Budgets. +Private Nachweise mit allen drei Themes und 720p sowie passenden Spielständen: +`bmh_4k_ui/docs/qa/engine-commerce-2026-10-28/`. + +## Getrennte Präsentationsdemo + Stand: 24. Oktober 2026. Die native Ansicht übernimmt die Diamond-3.6- Anordnung des privaten HTML-Golds `bmh_4k_ui`, Revision `9db6926d`: `desktop/submenus.js`, `submenus.css` und `table-window.css`. Sechs Karten diff --git a/docs/new_ui/integration/ENGINE_ENTRY.md b/docs/new_ui/integration/ENGINE_ENTRY.md index 296a3ca..c87104c 100644 --- a/docs/new_ui/integration/ENGINE_ENTRY.md +++ b/docs/new_ui/integration/ENGINE_ENTRY.md @@ -17,7 +17,7 @@ werden. Die Quelle wird nicht in DemoSource überführt. ## Gebundener Umfang -- `ModernSession::ui_read`: `session`, `desktop`, `camps`, `squad`, `lineup`, `tactics`, `training`, `bank`, `stadium`, `credit`. Karriere, Manager, +- `ModernSession::ui_read`: `session`, `desktop`, `camps`, `squad`, `lineup`, `tactics`, `training`, `bank`, `stadium`, `credit`, `environment`, `advertising`. Karriere, Manager, Mannschaft, Datum, Saison, Geld, Lagerqualitäten und Angebote kommen aus der Engine. Katalog und Engine müssen dieselbe Welt-ID und Datenrevision haben. - Der bestehende RmlUI-Schreibtisch verwendet die gemeinsamen App-Buttons und @@ -111,6 +111,30 @@ ein asynchroner Client veröffentlicht ausschließlich die spätere Engineantwor Preise und Vermögenswerte überleben die neue OBS-Datei und den Neustart. Private Belege: `bmh_4k_ui/docs/qa/engine-finance-2026-10-28/`. +## Umfeld und Werbung + +Die sechs [Umfeldkarten](../desktop/environment/README.md) zeigen tatsächliche +Sterne, Monatskosten und Nachwuchsränge/-ligen. Jede Änderung fragt nach +Bestätigung des Monatsbudgets und sendet dann `environment.commit`. Es wird +kein Guthaben sofort abgebucht und keine Nachwuchsentwicklung im UI simuliert. + +[Werbung](../desktop/advertising/README.md) zeigt alle von der Engine gelieferten +Angebote für vierzehn Banden, Trikot und TV. Eine eigene Bestätigung bindet Firma, +Laufzeit und Preis an die genaue, revisionierte Offer-ID. Navigation verwendet +die tatsächliche Länge der Liste, auch bei ausgelassenen Angebotsplätzen oder +vorhandenen Vertrags-/Optionszeilen. Nach einem Commit wird die lokale Auswahl +verworfen, damit eine von der Engine umsortierte Bande nicht falsch markiert bleibt. + +Die drei Vereinsbudgets verwenden denselben Zahleneditor samt Review. +`budget.commit` erhält die jeweilige ID und den Betrag exakt einmal in Minor +Units. Capabilities, verfügbare Budgets, Höchstbeträge und laufende Lieferungen +werden auch im Frontend beachtet. Die Finanzvorschau ist die gelieferte +monatliche Vereinsprognose, keine UI-Summe nur der Werbeverträge. + +Native Tests bestätigen acht echte Änderungen, schreibgeschützte Abbrüche, +einen sauberen bestätigten No-op, bestehende Liefersperren und OBS-Neustarts. +Nachweise: `bmh_4k_ui/docs/qa/engine-commerce-2026-10-28/`. + ## Ausführung und Dateien Laden, Reads nach einer Aktion, Buchen und Speichern laufen seriell über einen diff --git a/src/modern/ui/advertising_controls.inc b/src/modern/ui/advertising_controls.inc index 026355f..2bb099e 100644 --- a/src/modern/ui/advertising_controls.inc +++ b/src/modern/ui/advertising_controls.inc @@ -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("data-id", -1); diff --git a/src/modern/ui/advertising_screens.inc b/src/modern/ui/advertising_screens.inc index 348dfe5..62e84a6 100644 --- a/src/modern/ui/advertising_screens.inc +++ b/src/modern/ui/advertising_screens.inc @@ -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 = "" + std::string(headings[size_t(i)]) + "
" + img("advertising.panel." + std::to_string(i), 510, 510, false, false, 1000) + "
"; if (i == 0) body += brand(view.at("slots")[14]); - else body += "" + esc(cash(view.at("spending")[size_t(i - 1)].at("amount").get())) + ""; + else body += "" + esc(ad_cash(view.at("spending")[size_t(i - 1)].at("amount").get())) + ""; 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 += "

Werbung und Vereinsausgaben

" "

Bande, Trikot oder TV-Rechte auswählen.

Die drei Ausgabenbilder öffnen die Zahleneingabe.

"; } 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() : !active; + const bool accept = engine_mode_ ? quote.at("can_accept").get() : !active; out += "
" + brand(quote) + "
" + - btn("ad-offer", "‹", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(active ? "disabled" : "")) + - btn("ad-offer", "›", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(active ? "disabled" : "")) + + btn("ad-offer", "‹", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(cycle ? "" : "disabled")) + + btn("ad-offer", "›", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(cycle ? "" : "disabled")) + "
" + esc(quote.at("label").get()) + "" + esc(quote.at("name").get()) + "
Dauer" + std::to_string(quote.at("months").get()) + - " Monate
" + (active ? "Vertrag" : "Angebot") + "" + - esc(cash(quote.at("amount").get())) + " / Monat
"; } - out += "
"; + if (engine_mode_) out += "Vereinsprognose / Monat"; + out += "
"; for (const auto &[label, key] : std::array, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}}) - out += "
" + std::string(label) + "" + esc(cash(view.at(key).get())) + "
"; + out += "
" + std::string(label) + "" + esc(ad_cash(view.at(key).get())) + "
"; return out + "
"; } diff --git a/src/modern/ui/engine_bridge.cpp b/src/modern/ui/engine_bridge.cpp index 266e7db..334a6e2 100644 --- a/src/modern/ui/engine_bridge.cpp +++ b/src/modern/ui/engine_bridge.cpp @@ -30,7 +30,7 @@ std::shared_ptr 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; diff --git a/src/modern/ui/engine_bridge.hpp b/src/modern/ui/engine_bridge.hpp index 8813854..00b1092 100644 --- a/src/modern/ui/engine_bridge.hpp +++ b/src/modern/ui/engine_bridge.hpp @@ -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 { diff --git a/src/modern/ui/engine_commerce.inc b/src/modern/ui/engine_commerce.inc new file mode 100644 index 0000000..e8973e5 --- /dev/null +++ b/src/modern/ui/engine_commerce.inc @@ -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("data-index", -1), level = target->GetAttribute("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() * level, {{"code", "EUR"}, {"minor_units", 2}}); + const auto focus = target->GetId(); + confirmation(row.at("name").get() + ": 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("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("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() + ": " + quote.at("name").get() + " für " + + std::to_string(quote.at("months").get()) + " Monate zu " + money(quote.at("amount"), {{"code", "EUR"}, {"minor_units", 2}}) + + " pro Monat verbindlich annehmen?" + (quote.at("boards").get() > 1 ? " Umfasst " + std::to_string(quote.at("boards").get()) + " Banden." : ""), [this, command] { + focus_after_render_ = "window-close"; engine_finance_submit(command); + }); return true; + } + if (action == "ad-spending" && target) { + const int index = target->GetAttribute("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() > 0 ? "Die Lieferung läuft noch: " + std::to_string(row.at("delivery_weeks").get()) + " 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() / 100; request.min = 0; request.max = std::min(99999999, row.at("max").get() / 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; +} diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 6877ca3..056d22d 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -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(); } diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index 0e0e37b..41e10ac 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -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 keys{"youth_youngest", "youth_academy", "youth_oldest", "co_trainer", "doctor", "physio"}; + const std::array ids{"youth-a", "youth-b", "youth-c", "coach", "doctor", "physio"}; + const std::array 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 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::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(), "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() : 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 seen; + for (const auto &offer : raw->at("offers")) { + const auto offer_id = offer.at("id").get(), 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 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() / 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 diff --git a/src/modern/ui/engine_screens.inc b/src/modern/ui/engine_screens.inc index 78b7267..37383de 100644 --- a/src/modern/ui/engine_screens.inc +++ b/src/modern/ui/engine_screens.inc @@ -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 += ""; + if (menu_ == "environment") out += "
" + window("Umfeld", render_environment()) + "
"; + if (menu_ == "advertising") out += "
" + window("Werbung", render_advertising()) + "
"; if (menu_ == "bank") out += "
" + window("Bank", render_bank()) + "
"; if (menu_ == "training") out += "
" + window("Training", render_training()) + "
"; if (menu_ == "tactics") out += "
" + window("Taktik", render_tactics()) + "
"; if (menu_ == "lineup") out += "
" + window("Aufstellung", render_lineup()) + "
"; if (menu_ == "camp") out += "
" + window("Trainingslager", render_camp()) + "
"; } - if (menu_ == "bank" && !amount_) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; + if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising") && !amount_) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; if (menu_.empty() || engine_data_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; element("canvas")->SetInnerRML(out); ++document_generation_; scale_chalk_shadow(); diff --git a/src/modern/ui/engine_state.inc b/src/modern/ui/engine_state.inc index 834a832..41e8ae3 100644 --- a/src/modern/ui/engine_state.inc +++ b/src/modern/ui/engine_state.inc @@ -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 &); diff --git a/src/modern/ui/environment_controls.inc b/src/modern/ui/environment_controls.inc index 8d11859..dc3b3d4 100644 --- a/src/modern/ui/environment_controls.inc +++ b/src/modern/ui/environment_controls.inc @@ -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("data-index", ""); const auto value = target->GetAttribute("data-id", ""); diff --git a/src/modern/ui/environment_screens.inc b/src/modern/ui/environment_screens.inc index 23d2b5b..318d100 100644 --- a/src/modern/ui/environment_screens.inc +++ b/src/modern/ui/environment_screens.inc @@ -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 "

Die Umfeldvorschau ist derzeit nicht verfügbar.

"; - 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 "

Die Umfeldvorschau ist derzeit nicht verfügbar.

"; 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() ? "disabled " : "") + "title=\"" + (value ? std::to_string(value) + (value == 1 ? " Stern" : " Sterne") : "Budget auf null setzen") + "\""); } out += "
" + img("environment." + row.at("image").get() + "." + std::to_string(row.at("cell").get()), @@ -47,7 +47,7 @@ std::string App::render_environment() { "
" + - esc(money(row.at("cost").get(), snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + ""; + esc(money(row.at("cost").get(), engine_mode_ ? Json{{"code", "EUR"}, {"minor_units", 2}} : snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + ""; if (i < 3) out += "" + std::to_string(row.at("rank").get()) + ". / " + std::to_string(row.at("league").get()) + ". Liga"; @@ -55,8 +55,8 @@ std::string App::render_environment() { } out += "
" + img("art.environment-ball-v1.png", 400, 400, false, false, 640) + "
"; - 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() : demo_manager ? demo_career_manager(snapshot.state).value("club", "") : ""; const auto *club = snapshot.world->find("clubs", managed); out += "
name(*club) : "Vereinswappen nicht verfügbar") + "\">" + (club ? img(club->value("crest", ""), 162, 162, true) : "—") + "
"; diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index f51e71b..6a8a2ae 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -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 { diff --git a/tests/modern_engine_bridge_probe.cpp b/tests/modern_engine_bridge_probe.cpp index 1678c0a..522d364 100644 --- a/tests/modern_engine_bridge_probe.cpp +++ b/tests/modern_engine_bridge_probe.cpp @@ -4,11 +4,12 @@ #include "modern/app/modern_session.hpp" #include "modern/content/world_package.hpp" #include +#include using namespace bmh; using namespace bmh::modern_ui; int main(int argc, char **argv) { try { - if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports" && std::string(argv[1]) != "verify-bank")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports|verify-bank "); + if (argc != 4 || (std::string(argv[1]) != "inspect" && std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports" && std::string(argv[1]) != "verify-bank" && std::string(argv[1]) != "verify-commerce")) throw std::runtime_error("usage: modern_engine_bridge_probe inspect|prepare|verify|verify-lineup|verify-sports|verify-bank|verify-commerce "); const fs::path world = argv[2], out = argv[3]; fs::create_directories(out); const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); }; if (std::string(argv[1]) == "prepare") { @@ -115,6 +116,33 @@ int main(int argc, char **argv) { link = EngineBridge::open(world,out / "bank.obs"); const auto loaded = link->snapshot(); write("bank-loaded.json",loaded); for (const auto *kind : {"bank","credit","stadium"}) if (loaded.at(kind).at("data") != after.at(kind).at("data")) throw std::runtime_error("finance lost during OBS round trip"); } + + if (std::string(argv[1]) == "verify-commerce") { + const auto run = [&](const Json &request, const std::string &name) { + const auto response=link->command(request);write((name+"-response.json").c_str(),response); + if(response.value("messageType","")!="command_result" || link->command(request)!=response)throw std::runtime_error(response.dump()); + }; + run(engine_environment_command(before,"environment:doctor",3,"request:environment"),"environment"); + const auto env=link->snapshot();write("environment-after.json",env); + if(env.at("desktop").at("data").at("accounts")!=before.at("desktop").at("data").at("accounts"))throw std::runtime_error("monthly environment budget debited immediately"); + for(int slot:{0,14,15}) { + const auto now=link->snapshot(),view=engine_advertising_projection(now); + const auto &choices=view.at("slots")[size_t(slot)].at("choices"); + auto chosen=std::find_if(choices.begin(),choices.end(),[](const auto &q){return q.at("can_accept")==true;}); + if(chosen==choices.end())throw std::runtime_error("no test advertising offer"); + run(engine_advertising_command(now,chosen->at("offer_id"),"request:ad-"+std::to_string(slot)),"ad-"+std::to_string(slot)); + } + for(const auto *id:{"budget:press","budget:fans","budget:merchandise"}) { + run(engine_budget_command(link->snapshot(),id,1000,std::string("request:")+id),std::string(id).substr(7)); + } + const auto after=link->snapshot();write("commerce-after.json",after); + auto stale=engine_environment_command(before,"environment:doctor",4,"request:commerce-stale"); + const auto rejected=link->command(stale);write("stale-rejected.json",rejected); + if(rejected.value("code","")!="stale_revision" || link->snapshot()!=after)throw std::runtime_error("stale commerce command mutated state"); + write("commerce-saved.json",link->save_copy(out/"commerce.obs"));link.reset();link=EngineBridge::open(world,out/"commerce.obs"); + const auto loaded=link->snapshot();write("commerce-loaded.json",loaded); + for(const auto *kind:{"environment","advertising","bank"})if(loaded.at(kind).at("data")!=after.at(kind).at("data"))throw std::runtime_error("commerce OBS round trip lost state"); + } std::cout << "engine bridge " << argv[1] << " passed\n"; return 0; } catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; } } diff --git a/tests/modern_engine_dto_tests.cpp b/tests/modern_engine_dto_tests.cpp index 5754480..bb968c6 100644 --- a/tests/modern_engine_dto_tests.cpp +++ b/tests/modern_engine_dto_tests.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/engine_bridge.hpp" #include +#include #include #include #include @@ -171,6 +172,54 @@ int main() { broken_bank = bank; broken_bank["desktop"]["meta"]["scope"]["allowedCommands"] = Json::array(); for (auto &[kind,row] : broken_bank.items()) row["meta"]["scope"]["allowedCommands"] = Json::array(); rejects([&] { engine_ticket_command(broken_bank,10,"r"); }); + + auto commerce = fixture(); + for (auto &[kind,row] : commerce.items()) row["meta"]["scope"]["allowedCommands"] = {"environment.commit","advertising.accept","budget.commit"}; + const auto cm = commerce.at("desktop").at("meta"); + Json items = Json::array(), youth = Json::array(); + const std::array ek{"youth_youngest","youth_academy","youth_oldest","co_trainer","doctor","physio"}; + for (int i=0;i<6;++i) { + items.push_back({{"id","environment:"+ek[i]},{"level",1},{"maxLevel",6},{"monthly",M(1000000+i)},{"stepCost",M(200000+i)}}); + if(i<3) youth.push_back({{"id","youth:"+ek[i]},{"place",i},{"league",i},{"strength",80}}); + } + commerce["environment"]={{"messageType","snapshot"},{"meta",cm},{"data",{{"kind","environment"},{"items",items},{"youth",youth},{"academyActive",true}}}}; + auto ep = engine_environment_projection(commerce); + require(ep.at("rows")[1].at("cost")==1000001 && ep.at("rows")[2].at("rank")==3 && ep.at("rows")[2].at("league")==3,"environment replaced actual budgets or used zero-based display positions"); + std::reverse(commerce["environment"]["data"]["items"].begin(),commerce["environment"]["data"]["items"].end()); + require(engine_environment_projection(commerce)==ep,"environment IDs depend on transport order"); + require(engine_environment_command(commerce,"environment:doctor",6,"r").at("payload").at("level")==6,"environment level wrong"); + rejects([&]{engine_environment_command(commerce,"environment:unknown",1,"r");}); + rejects([&]{engine_environment_command(commerce,"environment:doctor",7,"r");}); + Json boards=Json::array(); + auto contract=[&](const std::string &id) {return Json{{"id",id},{"active",false},{"sponsor",nullptr},{"monthly",M(0)},{"monthsRemaining",0},{"offers",Json::array()}};}; + for(int i=0;i<14;++i)boards.push_back(contract("ad:board/"+std::to_string(i))); + boards[0]["offers"]={{{"id","offer:ad-0-7"},{"sponsor","Synthetic & Co"},{"monthly",M(123400)},{"months",18},{"boards",2},{"allowed",true}},{{"id","offer:ad-0-9"},{"sponsor","Unavailable"},{"monthly",M(120000)},{"months",12},{"boards",1},{"allowed",false}}}; + auto shirt=contract("ad:shirt"),tv=contract("ad:tv");shirt["active"]=true;shirt["sponsor"]="Existing";shirt["monthly"]=M(200000);shirt["monthsRemaining"]=5; + shirt["offers"]={{{"id","offer:ad-14-4"},{"sponsor","Extension"},{"monthly",M(220000)},{"months",12},{"boards",1},{"allowed",true}}}; + Json budgets=Json::array();for(const auto *id:{"budget:merchandise","budget:press","budget:fans"})budgets.push_back({{"id",id},{"current",M(1000)},{"maximum",M(50000)},{"available",true},{"deliveryWeeks",0}}); + commerce["advertising"]={{"messageType","snapshot"},{"meta",cm},{"data",{{"kind","advertising"},{"teamId","club:6"},{"boards",boards},{"shirt",shirt},{"television",tv},{"budgets",budgets},{"preview",{{"income",M(11)},{"expenses",M(99)},{"balance",M(-88)}}}}}}; + const auto unchanged_commerce=commerce,ap=engine_advertising_projection(commerce); + require(ap.at("balance")==-88 && ap.at("slots")[0].at("choices").size()==2,"advertising invented preview or offers"); + require(engine_advertising_quote(commerce,0,0).at("boards")==2 && engine_advertising_quote(commerce,0,1).at("can_accept")==false,"bundle size or offer restriction lost"); + require(engine_advertising_quote(commerce,14,0).at("active")==true && engine_advertising_quote(commerce,14,1).at("can_accept")==true,"existing contract hides valid extension"); + require(engine_advertising_quote(commerce,15,0).at("can_accept")==false,"empty TV offer fabricated"); + require(engine_advertising_command(commerce,"offer:ad-0-7","r").at("payload").at("offerId")=="offer:ad-0-7","sparse offer ID replaced by index"); + rejects([&]{engine_advertising_command(commerce,"offer:ad-0-9","r");}); + rejects([&]{engine_advertising_command(commerce,"offer:ad-0-0","r");}); + require(engine_budget_command(commerce,"budget:press",500,"r").at("payload").at("amount")==M(50000),"budget money converted twice"); + rejects([&]{engine_budget_command(commerce,"budget:press",501,"r");}); + auto blocked=commerce;blocked["advertising"]["data"]["budgets"][0]["deliveryWeeks"]=2; + rejects([&]{engine_budget_command(blocked,"budget:merchandise",1,"r");}); + blocked=commerce;blocked["advertising"]["meta"]["scope"]["managerId"]="foreign"; + rejects([&]{engine_advertising_projection(blocked);}); + blocked=commerce;blocked["environment"]["meta"]["stateRevision"]="1"; + rejects([&]{engine_environment_projection(blocked);}); + blocked=commerce; + for (auto &[kind,row] : blocked.items()) row["meta"]["scope"]["allowedCommands"]=Json::array(); + require(engine_advertising_quote(blocked,0,0).at("can_accept")==false && engine_advertising_projection(blocked).at("spending")[0].at("available")==false,"missing capabilities remain interactively enabled"); + rejects([&]{engine_environment_command(blocked,"environment:doctor",2,"r");}); + rejects([&]{engine_budget_command(blocked,"budget:press",0,"r");}); + require(commerce==unchanged_commerce,"commerce projections mutated source data"); std::cout << "engine DTO, exact money, scope and booking tests passed\n"; return 0; } catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }