Modern UI contract: bank credits
The credit read previews the loan dialog (bank or another human lender) with per-field bounds, fees and refund; bank.commit action credit books the same edits. The bank read now points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06445c24ef
commit
74c1504e3a
3 files changed
+97
-5
No files matched your search
@@ -40,7 +40,8 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
| `environment` | das Umfeld (Diamond 3.6): drei Jugendteams, Co-Trainer, Arzt, Physiotherapeut (`environment:<Bereich>`), je Stufe 0–6, Monatskosten, Kosten je Stufe; die Jugendteams mit Stärke, Platz, Liga; ob die Akademie läuft |
|
||||
| `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` |
|
||||
| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; `credit` verweist auf den Read `credit`, der Aktientipp zieht Zufall und kommt als `quote.request` |
|
||||
| `credit` | der Kreditdialog (`lenderId` `bank` oder die Manager-ID eines anderen Menschen): `saved` (Darlehen, Gesamtbetrag, Rate, Laufzeit, vergangene Monate, Zahlungen), `fields` (acht Felder mit `field`, `label`, `value`, `editable`, `min`, `max`; Werte in ganzen Euro bzw. Monaten), `fees`, `refund`, `principalPaid` (`Money`). Optional `edits` [{field, value}] als Vorschau, nichts wird gebucht; Fehler `unknown_lender`, `credit_unavailable`, `invalid_credit_edit` |
|
||||
| `postmatch` | das Nachspiel des letzten `session.advance` (auch am Bundestrainer-Schreibtisch): `steps` (`results`, `report`, `team_of_the_day`, `overview`, `table` je mit `available`), `matches` (alle Spiele des Anstoßes im Almanach-Format), `reportMatchIds` (Spiele menschlicher Manager), `teamOfTheDay` (die Sportschau-Elf der Engine je Wettbewerb mit Spieler, Verein, Wertung; nur mit der Sportschau-Option der EXE, sonst leer und `team_of_the_day` nicht verfügbar), `tables` (die aktuellen Tabellen der Ligen des Spieltags). Rückblick und Abspielen ändern nichts; weiter geht es mit `session.advance` |
|
||||
|
||||
Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`.
|
||||
@@ -94,7 +95,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
|
||||
| `live.substitute` | `outPlayerId`, `inPlayerId` | Wechsel wie im Spielfeld-Bildschirm des Originals (öffnen, tauschen, schließen; ab Minute 3); Fehler `substitution_refused` |
|
||||
| `live.tactics` | `values` (8) | Taktik wie im Taktik-Bildschirm während des Spiels; Fehler `invalid_tactic` |
|
||||
| `live.finish` | `{}` | spielt den Spieltag ohne weiteren Halt zu Ende; Antwort wie `session.advance` (bei fehlender Vertragsentscheidung wird der ganze Live-Spieltag zurückgerollt: `decision_pending`) |
|
||||
| `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:<n>`, `fund:<n>`) und `count` | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. |
|
||||
| `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:<n>`, `fund:<n>`) und `count` oder `credit` mit `lenderId` (optional), `edits` wie im Read `credit` und `acceptFees` (Gebühren wie im Original bestätigen) | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. |
|
||||
| `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) |
|
||||
| `tactics.commit` | `values`: die acht Werte | jede geänderte Einstellung über die Prüfung der Taktiktafel (eine gesetzte Grundausrichtung beendet die Steuerung durch den Assistenten); Fehler `invalid_tactic` |
|
||||
| `training.commit` | optional `types` (4), `areas` (9), `players [{playerId, intensity}]` | richtet das Training bei Bedarf ein, setzt erst die Senkungen, dann die Erhöhungen (jeder Zwischenstand bleibt in den Grenzen); Fehler `training_unavailable`, `unknown_player` und die Gründe der Engine |
|
||||
|
||||
@@ -8901,7 +8901,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
const int manager = context.manager;
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch"))
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit"))
|
||||
return modern::ui_read(g_, context, request);
|
||||
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
|
||||
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
|
||||
@@ -9132,6 +9132,44 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "contracts"}, {"teamId", modern::ui_team_id(g_, team)}, {"players", std::move(players)}, {"quote", std::move(quote)}});
|
||||
}
|
||||
if (kind == "credit") {
|
||||
// the credit dialog (bank or another human manager as lender): the saved loan, the draft after
|
||||
// the request's edits [{field, value}] with labels, bounds per field, fees and refund. Pure:
|
||||
// the edits only preview what bank.commit {action: credit} would book.
|
||||
int counterparty = 0;
|
||||
if (const std::string lender = ui_text(request, "lenderId"); !lender.empty() && lender != "bank") {
|
||||
for (int m = 0; m < int(g_.manager_teams.size()); ++m)
|
||||
if (m != manager && modern::ui_manager_id(g_, m) == lender) counterparty = m + 1;
|
||||
if (counterparty == 0) return modern::ui_error(request_id, "unknown_lender", "Unbekannter Kreditgeber.", revision, false);
|
||||
}
|
||||
const BankCreditContext credit = modern::bank_credit_context(g_, exe_, manager, counterparty);
|
||||
if (!credit.available) return modern::ui_error(request_id, "credit_unavailable", "Kein Kredit möglich.", revision, false);
|
||||
BankCreditDraft draft = modern::bank_credit_draft(credit);
|
||||
if (const cli::Json* edits = ui_field(request, "edits"); edits && edits->array())
|
||||
for (const auto& e : *edits->array()) {
|
||||
const cli::Json* f = ui_field(e, "field");
|
||||
const cli::Json* v = ui_field(e, "value");
|
||||
if (!f || !f->integer() || !v || !v->integer() || !modern::edit_bank_credit(credit, draft, int(*f->integer()), uint32_t(*v->integer())))
|
||||
return modern::ui_error(request_id, "invalid_credit_edit", "Diese Änderung ist nicht möglich.", revision, false);
|
||||
}
|
||||
ui::BankState b;
|
||||
try { b = ui::bank_from_game(g_, exe_, revision); } catch (const std::exception&) {}
|
||||
A fields, saved;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
const BankCreditBounds bounds = modern::bank_credit_bounds(credit, draft, i);
|
||||
fields.push_back(O{{"field", i}, {"label", b.credit_labels[size_t(i)]}, {"value", int64_t(draft.values[size_t(i)])},
|
||||
{"editable", bounds.available},
|
||||
{"min", bounds.available ? cli::Json(int64_t(bounds.minimum)) : cli::Json(nullptr)},
|
||||
{"max", bounds.available ? cli::Json(int64_t(bounds.maximum)) : cli::Json(nullptr)}});
|
||||
}
|
||||
// the saved loan record: principal, total, monthly payment, term, elapsed months, payments made
|
||||
for (uint32_t v : credit.saved) saved.push_back(int64_t(v));
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "credit"}, {"lenderId", counterparty == 0 ? cli::Json("bank") : cli::Json(modern::ui_manager_id(g_, counterparty - 1))},
|
||||
{"saved", std::move(saved)}, {"fields", std::move(fields)}, {"fees", modern::ui_money(draft.fees)},
|
||||
{"refund", modern::ui_money(draft.refund)}, {"principalPaid", modern::ui_money(draft.principal_paid)},
|
||||
{"note", "Werte der Felder in ganzen Euro bzw. Monaten wie im Original-Dialog"}});
|
||||
}
|
||||
if (kind == "bank") {
|
||||
// account, fixed deposit, credit line, the 12 stocks and 6 funds (prices in whole euros,
|
||||
// converted to Money); the stock tip draws a random number and is no read
|
||||
@@ -9160,7 +9198,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
{"accounts", O{{"cash", modern::ui_money(b.balance)}, {"deposit", modern::ui_money(b.deposit)},
|
||||
{"creditLine", modern::ui_money(b.credit_line)}, {"investments", modern::ui_money(b.investment_balance)}}},
|
||||
{"stocks", std::move(stocks)}, {"funds", std::move(funds)},
|
||||
{"credit", O{{"status", "unavailable"}, {"reasonCode", "not_yet_in_contract"}, {"missingFields", A{}}}}});
|
||||
{"credit", O{{"status", "available"}, {"read", "credit"}, {"command", "bank.commit"}}}});
|
||||
}
|
||||
if (kind == "tactics") {
|
||||
// the eight settings (record +0xd2..+0xd9) with the executable's maxima; the meaning of
|
||||
@@ -10270,8 +10308,31 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
r.count = int(*count->integer());
|
||||
r.kind = stock ? (action == "buy" ? ui::BankRequestKind::buy_shares : ui::BankRequestKind::sell_shares)
|
||||
: (action == "buy" ? ui::BankRequestKind::buy_fund : ui::BankRequestKind::sell_fund);
|
||||
} else if (action == "credit") {
|
||||
// {lenderId?: "bank" | managerId, edits: [{field, value}], acceptFees}: the draft of the
|
||||
// credit read, replayed against the saved loan and booked (fees as the original asks)
|
||||
int counterparty = 0;
|
||||
if (const std::string lender = ui_text(*payload, "lenderId"); !lender.empty() && lender != "bank") {
|
||||
for (int m = 0; m < int(g_.manager_teams.size()); ++m)
|
||||
if (m != manager && modern::ui_manager_id(g_, m) == lender) counterparty = m + 1;
|
||||
if (counterparty == 0) return refuse("unknown_lender", "Unbekannter Kreditgeber.");
|
||||
}
|
||||
const BankCreditContext credit = modern::bank_credit_context(g_, exe_, manager, counterparty);
|
||||
if (!credit.available) return refuse("credit_unavailable", "Kein Kredit möglich.");
|
||||
r.kind = ui::BankRequestKind::bank_credit;
|
||||
r.expected_credit = credit.saved;
|
||||
r.credit_counterparty = counterparty;
|
||||
const cli::Json* fees = ui_field(*payload, "acceptFees");
|
||||
r.accept_credit_fees = fees && std::holds_alternative<bool>(fees->value) && std::get<bool>(fees->value);
|
||||
if (const cli::Json* edits = ui_field(*payload, "edits"); edits && edits->array())
|
||||
for (const auto& e : *edits->array()) {
|
||||
const cli::Json* f = ui_field(e, "field");
|
||||
const cli::Json* v = ui_field(e, "value");
|
||||
if (!f || !f->integer() || !v || !v->integer()) return refuse("invalid_payload", "edits sind {field, value}.");
|
||||
r.credit_edits.push_back({int(*f->integer()), uint32_t(*v->integer())});
|
||||
}
|
||||
} else {
|
||||
return refuse("invalid_payload", "action ist deposit, withdraw, buy oder sell.");
|
||||
return refuse("invalid_payload", "action ist deposit, withdraw, buy, sell oder credit.");
|
||||
}
|
||||
if (!dispatch_bank(r, revision, error)) { restore(); return refuse(error, "Bankauftrag abgelehnt: " + error); }
|
||||
revision = previous + 1;
|
||||
|
||||
@@ -432,6 +432,36 @@ int main(int argc, char** argv) {
|
||||
check(s(at(booked, "messageType")) == "command_result" && rev == before + 1, "friendly booked");
|
||||
}
|
||||
}
|
||||
// a bank credit: draft with an edit within its bounds, preview, booking
|
||||
{
|
||||
const J credit = session.ui_read(O{{"kind", "credit"}}, rev);
|
||||
const auto* fields = at(at(credit, "data"), "fields").array();
|
||||
if (s(at(credit, "messageType")) != "snapshot") std::fprintf(stderr, "credit: %s\n", cli::dump_json(credit).c_str());
|
||||
check(fields && fields->size() == 8, "credit read with eight fields");
|
||||
int field = -1;
|
||||
int64_t value = 0;
|
||||
if (fields)
|
||||
for (const auto& f : *fields)
|
||||
if (field < 0 && truth(at(f, "editable")) && *at(f, "max").integer() > *at(f, "min").integer()) {
|
||||
field = int(*at(f, "field").integer());
|
||||
value = (*at(f, "min").integer() + *at(f, "max").integer()) / 2;
|
||||
}
|
||||
if (field >= 0) {
|
||||
const J::Array edits{J(O{{"field", field}, {"value", value}})};
|
||||
const J preview = session.ui_read(O{{"kind", "credit"}, {"edits", edits}}, rev);
|
||||
check(s(at(preview, "messageType")) == "snapshot", "credit preview");
|
||||
int64_t too_high = 0;
|
||||
for (const auto& f : *fields)
|
||||
if (*at(f, "field").integer() == field) too_high = *at(f, "max").integer() + 1;
|
||||
const J::Array bad{J(O{{"field", field}, {"value", too_high}})};
|
||||
const J refused = session.ui_read(O{{"kind", "credit"}, {"edits", bad}}, rev);
|
||||
check(s(at(refused, "code")) == "invalid_credit_edit", "credit edit beyond its bound refused");
|
||||
const uint64_t before = rev;
|
||||
const J booked = session.ui_command(cmd("request:k9", "bank.commit", O{{"action", "credit"}, {"edits", edits}, {"acceptFees", true}}), rev);
|
||||
std::printf("(credit field %d to %lld: %s)\n", field, (long long)value, cli::dump_json(booked).substr(0, 160).c_str());
|
||||
check(s(at(booked, "messageType")) == "command_result" && rev == before + 1, "credit booked");
|
||||
}
|
||||
}
|
||||
// the surroundings: six budgets 0-6
|
||||
{
|
||||
const J env = session.ui_read(O{{"kind", "environment"}}, rev);
|
||||
|
||||
Reference in new issue
Block a user