From 43317985e406035f6009d3a280721645ae49031c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 09:29:25 +0100 Subject: [PATCH] Modern UI contract: toto and exclusive sponsor reads and commands toto and sponsor reads in the envelope (amounts as Money), toto.submit with up to six columns and sponsor.answer for a camp's exclusive sponsor offer. Co-Authored-By: Claude Opus 5.5 --- docs/new_engine/ui-anbindung.md | 4 ++++ src/modern/app/modern_session.cpp | 34 ++++++++++++++++++++++++++++++ src/modern/content/ui_contract.cpp | 20 ++++++++++++++++++ tests/modern_ui_contract_tests.cpp | 15 +++++++++++++ 4 files changed, 73 insertions(+) diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index de77396..c660e24 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -34,6 +34,8 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht | `contracts` | je Spieler Restlaufzeit, Monatsgehalt, Versicherung, Prämien; das offene Angebot (`quote`: ID, Spieler, Monatsforderung für 1–4 Jahre, Höchstgehalt 200.000 €) | | `advertising` | 14 Banden (`ad:board/`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad--`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals | | `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` 0–3, sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) | +| `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung | +| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) | | `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; Kredite noch `unavailable` (folgen), der Aktientipp zieht Zufall und kommt als `quote.request` | Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`. @@ -63,6 +65,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `advertising.accept` | `offerId` | nimmt ein Angebot an wie am Schreibtisch; Fehler `unknown_offer`, `advertising_refused` | | `budget.commit` | `budgetId` (`budget:merchandise`, `budget:press`, `budget:fans`), `amount` (`Money`) | setzt ein Budget; Fehler `unknown_budget`, `invalid_amount`, `advertising_refused` (z. B. Lieferung läuft, zu wenig Geld) | | `ticket.commit` | `price` (`Money`, 8–25 €) | der Eintrittspreis; Fehler `invalid_amount`, `ticket_refused` | +| `toto.submit` | `stake` (`Money` je Spalte), `columns` (bis 6 Spalten mit 11 Tipps: 1 Heim, 0 Unentschieden, 2 Auswärts) | gibt den Tippschein ab; Fehler `toto_refused` (z. B. kein offener Schein, Einsatzgrenzen, doppelte Spalte) | +| `sponsor.answer` | `accept` | Antwort auf das Exklusiv-Sponsor-Angebot: beginnt sofort, wird vorgemerkt oder abgelehnt | | `quote.request` (Stadion) | `kind: periphery`, `objectId` oder `kind: facility`, `facilityId`, `increment` 1–3 | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen; `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) | | `stadium.commit` | `quoteId`, `accept`, bei Anlagen `tip` | baut (Anlagen mit oder ohne Trinkgeld für schnelleres Bauen, wie das Original fragt) oder lehnt ab und schließt den Dialog; Fehler `stale_quote`, `stadium_refused` | | `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:`, `fund:`) und `count` | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 703a24c..ff50d18 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9492,6 +9492,40 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision revision = previous + 1; answer = modern::ui_command_result(request_id, previous, revision, {"advertising", "desktop", "bank"}, kind == "advertising.accept" ? "Werbevertrag abgeschlossen." : "Budget gesetzt."); + } else if (kind == "toto.submit") { + // payload {stake: Money per column, columns: [[11 tips: 1 home, 0 draw, 2 away], ... up to 6]} + const cli::Json* stake = ui_field(*payload, "stake"); + const cli::Json* columns = ui_field(*payload, "columns"); + int64_t cents = -1; + try { cents = stake ? std::stoll(ui_text(*stake, "minor")) : -1; } catch (const std::exception&) { cents = -1; } + if (cents <= 0 || cents % 100 || !columns || !columns->array()) return refuse("invalid_payload", "stake (Money) und columns nötig."); + std::vector> tips; + for (const auto& column : *columns->array()) { + const auto* c = column.array(); + if (!c || c->size() != 11) return refuse("invalid_payload", "Jede Spalte hat elf Tipps."); + std::array t{}; + for (size_t i = 0; i < 11; ++i) { + if (!(*c)[i].integer() || *(*c)[i].integer() < 0 || *(*c)[i].integer() > 2) return refuse("invalid_payload", "Tipps sind 0, 1 oder 2."); + t[i] = uint8_t(*(*c)[i].integer()); + } + tips.push_back(t); + } + if (!dispatch_pools_columns(manager, uint32_t(cents / 100), tips, revision, error)) { restore(); return refuse("toto_refused", error); } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"toto", "desktop"}, "Tippschein abgegeben."); + } else if (kind == "sponsor.answer") { + // payload {accept: bool}: the answer to the exclusive sponsor offer from a camp stay + const cli::Json* accept = ui_field(*payload, "accept"); + if (!accept || !std::holds_alternative(accept->value)) return refuse("invalid_payload", "accept (true/false) nötig."); + std::string result; + if (!dispatch_exclusive_sponsor(manager, std::get(accept->value), revision, result, error)) { + restore(); return refuse(error.empty() ? "sponsor_refused" : error, "Kein Sponsorangebot offen."); + } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"sponsor", "advertising", "desktop"}, + result == "started" ? "Der Exklusiv-Sponsor beginnt sofort." : + result == "queued" ? "Der Exklusiv-Sponsor beginnt, sobald die Fläche frei ist." : + "Angebot abgelehnt."); } else if (kind == "ticket.commit") { // payload {price: Money}: the admission price, 8 to 25 euros const cli::Json* price = ui_field(*payload, "price"); diff --git a/src/modern/content/ui_contract.cpp b/src/modern/content/ui_contract.cpp index 1ecefd5..1af346b 100644 --- a/src/modern/content/ui_contract.cpp +++ b/src/modern/content/ui_contract.cpp @@ -10,6 +10,7 @@ #include "formats/executable_layout.hpp" #include "game/state.hpp" #include "game/table.hpp" +#include "modern/content/projections.hpp" #include "modern/content/world_package.hpp" #include "modern/game/almanac.hpp" #include "modern/game/desk_actions.hpp" @@ -367,6 +368,25 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c)); if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today)); if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision))); + if (kind == "toto" || kind == "sponsor") { + // the existing projections (ui-abfragen.md), amounts as Money + J p = query_projection(g, c.manager, O{{"kind", kind}}); + auto* o = std::get_if(&p.value); + if (!o || !(*o)["ok"].value.index() || !std::get((*o)["ok"].value)) + return failure(request_id, "unavailable", "Nicht verfügbar.", c.state_revision); + o->erase("ok"); + const auto money = [](J& v) { if (v.integer()) v = ui_money(*v.integer()); }; + if (kind == "toto") { + money((*o)["stake"]), money((*o)["cost"]); + auto& last = std::get((*o)["last"].value); + money(last["paid"]), money(last["won"]); + } else { + for (const char* key : {"offer", "queued"}) + if (auto* row = std::get_if(&(*o)[key].value)) money((*row)["monthly"]); + } + (*o)["kind"] = kind; + return snapshot(request_id, std::move(m), std::move(p)); + } if (kind == "squad") { const int team = requested_team(g, c, request); if (team < 0 || !fields_players(g, team)) diff --git a/tests/modern_ui_contract_tests.cpp b/tests/modern_ui_contract_tests.cpp index 251dda0..587ba3b 100644 --- a/tests/modern_ui_contract_tests.cpp +++ b/tests/modern_ui_contract_tests.cpp @@ -342,6 +342,21 @@ int main(int argc, char** argv) { } } } + // toto and the exclusive sponsor + { + const J toto = session.ui_read(O{{"kind", "toto"}}, rev); + check(s(at(toto, "messageType")) == "snapshot" && at(at(at(toto, "data"), "stake"), "minor").string(), "toto read with Money"); + const J::Array column{J(1), J(0), J(2), J(1), J(1), J(0), J(2), J(1), J(1), J(0), J(2)}; + const uint64_t before = rev; + const J done = session.ui_command(cmd("request:o1", "toto.submit", + O{{"stake", O{{"minor", "5000000"}, {"currency", "EUR"}, {"minorUnits", 2}}}, {"columns", J::Array{J(column), J(column)}}}), rev); + if (truth(at(at(toto, "data"), "open"))) + check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "two toto columns submitted"); + else + check(s(at(done, "code")) == "toto_refused" && rev == before, "toto closed: refused without change"); + check(s(at(session.ui_command(cmd("request:o2", "sponsor.answer", O{{"accept", true}}), rev), "messageType")) == "error", + "no sponsor offer to answer"); + } // session.advance: three kickoffs, each one revision, the date moves on { const std::string date_before = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));