// SPDX-License-Identifier: GPL-3.0-only std::string App::render_bank() { const auto projected = engine_mode_ ? engine_bank_projection(engine_data_) : Json(); const auto snapshot = engine_mode_ ? Snapshot{0, world_, projected.at("state")} : snap(); const auto assets = engine_mode_ ? projected.at("assets") : demo_bank_assets(*world_); const auto summary = engine_mode_ ? projected.at("summary") : demo_bank_summary(snapshot.state, *world_); const auto bank_money = [&](int64_t value) { return engine_mode_ ? money(value, {{"code", "EUR"}, {"minor_units", 2}}) : cash(value); }; const int property_count = int(assets.at("properties").size()), stock_count = int(assets.at("stocks").size()); if (!summary.value("ok", false)) return {}; const auto &finance = snapshot.state.at("finance"); bank_property_ = std::clamp(bank_property_, 0, property_count - 1); bank_stock_ = std::clamp(bank_stock_, 0, stock_count - 1); bank_owned_ = std::clamp(bank_owned_, 0, property_count - 1); if (finance.at("properties")[size_t(bank_owned_)] == 0) for (int i = 0; i < property_count; ++i) if (finance.at("properties")[size_t(i)] != 0) { bank_owned_ = i; break; } const auto actions = [&](const char *left, const char *lk, const char *right, const char *rk) { return ""; }; std::string out = "
" + img("art.bank-hall-v1.png", 2608, 1466.016746, false, false, 3000); if (bank_view_ == "entrance") { struct Service { const char *id, *label, *hint; double x, y, w, h; }; const std::array services{{ {"properties", "Immobilien", "Immobilien – Gebäude ansehen, kaufen oder verkaufen.", .5, 18.5, 17.5, 43.5}, {"stocks", "Aktien", "Aktien – Kurse und Bestände ansehen, Aktien kaufen oder verkaufen.", 30, 30, 13.5, 19.5}, {"overview", "Finanzübersicht", "Finanzübersicht – Konto, Sparbuch, Immobilien, Aktien und Kredit im Überblick.", 30.5, 49.5, 13, 14.5}, {"savings", "Sparbuch", "Sparbuch – Guthaben ansehen, Geld einzahlen oder abheben.", 85, 60, 6.5, 7.5}, {"credit", "Kredit", "Kredit – Laufzeit wählen, einen Kredit aufnehmen oder tilgen.", 85.3, 31.5, 13.7, 27.5}}}; out += "
"; for (const auto &s : services) out += btn("bank-view", "", "bank-hotspot", "id=\"bank-view-" + std::string(s.id) + "\" data-view=\"" + s.id + "\" data-bank-hint=\"" + esc(s.hint) + "\" aria-label=\"" + s.label + "\" style=\"left:" + scalar(s.x) + "%;top:" + scalar(s.y) + "%;width:" + scalar(s.w) + "%;height:" + scalar(s.h) + "%;\""); out += "
"; } out += "
"; if (bank_view_ == "entrance") return out + "

" + esc(bank_hint_.empty() ? "Ein Element in der Bankhalle auswählen." : bank_hint_) + "

"; out += "
"; if (bank_view_ == "savings") { out += "
" + img("art.bank-passbook-v1.png", 2100, 1293.109375, false, false, 2400) + "

Waldpark Bank

Sparbuch

Bitte beachten Sie:

" "

" + std::string(engine_mode_ ? "Einzahlungen und Abhebungen werden nach Bestätigung im Spielstand verbucht." : "Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht.") + "

" "

" + (engine_mode_ ? "" : "2,5 % Beispielzins") + "

Guthaben

" + esc(bank_money(snapshot.state.at("deposit").get())) + "
" + actions("Einzahlen", "deposit", "Abheben", "withdraw"); } else if (bank_view_ == "properties") { out += "

Immobilien

"; const auto &owned = assets.at("properties")[size_t(bank_owned_)], &offer = assets.at("properties")[size_t(bank_property_)]; const auto count = finance.at("properties")[size_t(bank_owned_)].get(); out += "

Ihre Immobilien

" + (count ? "

" + std::to_string(count) + " × " + esc(owned.at("name").get()) + "

Wert: " + esc(bank_money(count * owned.at("price").get())) + "

" : "

Keine Immobilien im Bestand

") + "
" + btn("property-owned-next", count ? img(engine_mode_ ? owned.at("image").get() : "bank.property." + std::to_string(bank_owned_), 996, 566, false, false, 1200) : "", "property-picture", "id=\"property-owned-next\" aria-label=\"Nächste eigene Immobilie\" " + std::string(count ? "" : "disabled")) + "
"; out += "

Kaufangebot

" + esc(offer.at("name").get()) + "

Kaufpreis: " + esc(bank_money(offer.at("price").get())) + "

" + btn("property-next", img(engine_mode_ ? offer.at("image").get() : "bank.property." + std::to_string(bank_property_), 996, 566, false, false, 1200), "property-picture", "id=\"property-next\" aria-label=\"Nächstes Immobilienangebot\"") + "
" + actions("Kaufen", "property-buy", "Verkaufen", "property-sell"); } else if (bank_view_ == "stocks") { out += "

Aktien

"; for (const auto *label : {"Wert", "Kurs", "Vortag", "Bestand"}) out += "
" + std::string(label) + "
"; out += "
"; const auto factor = engine_mode_ ? 100 : finance_currency_factor(*world_); for (int i = 0; i < stock_count; ++i) { const auto &s = assets.at("stocks")[size_t(i)]; out += "
" + btn("bank-stock", esc(s.at("name").get()), "stock-name", "id=\"bank-stock-" + std::to_string(i) + "\" data-bank-stock=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-pressed=\"" + (i == bank_stock_ ? "true" : "false") + "\"") + "
" + number(s.at("price").get() / factor) + "
" + number(s.at("previous").get() / factor) + "
" + number(finance.at("stocks")[size_t(i)].get()) + "
"; } const double price = assets.at("stocks")[size_t(bank_stock_)].at("price").get() / factor; std::vector history; if (engine_mode_) { for (const auto &value : assets.at("stocks")[size_t(bank_stock_)].at("history")) history.push_back(value.get() / factor); } else for (int i = 0; i < 30; ++i) history.push_back(price * (.85 + .08 * std::sin(i * .6 + bank_stock_) + i * .003)); const double lo = history.empty() ? 0 : *std::min_element(history.begin(), history.end()) * .95; const double hi = history.empty() ? 1 : std::max(lo + 1., *std::max_element(history.begin(), history.end()) * 1.05); std::string points; for (size_t i = 0; i < history.size(); ++i) points += scalar(20 + i * 690. / std::max(1, history.size() - 1)) + "," + scalar(900 - (history[size_t(i)] - lo) / (hi - lo) * 830) + " "; const auto stroke = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#9ac7d8"; const auto axis = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#6c8798"; const auto svg = "" "" ""; out += "
()) + "\">" + picture(renderer_.diagram("bank-stock", svg, 1600), 740, 1320) + "
" + actions("Kaufen", "stock-buy", "Verkaufen", "stock-sell"); } else if (bank_view_ == "credit") { if (engine_mode_) return out + engine_credit_view() + "
"; out += "

Kredit

" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) + "
"; const auto fact = [&](const char *label, const std::string &value, int row) { constexpr std::array y{0, 83, 166, 273, 356}; return "
" + label + "" + value + "
"; }; out += fact("Restschuld", esc(bank_money(summary.at("debt").get())), 0) + fact("Beispielzins", "8 % pro Jahr", 1); std::string select = "", 2) + fact("Monatsrate, Beispiel", esc(bank_money(summary.at("monthly_rate").get())), 3) + fact("Maximaler Kredit", esc(bank_money(5000000 * finance_currency_factor(*world_))), 4) + "
"; const int term = finance.at("term"); const auto principal = summary.at("schedule_principal").get(); const auto color = theme_ == "silver" ? "#233443" : theme_ == "matchday" ? "#efeded" : "#a8c0cf"; const auto accent = theme_ == "silver" ? "#25617a" : theme_ == "matchday" ? "#efb2aa" : "#a9dfd1"; const auto grid_color = theme_ == "silver" ? "#58738c38" : "#b7d0de24"; std::string svg = "" "" ""; for (int i = 0; i < 5; ++i) { const auto y = 30 + i * 77.5; svg += "" "" + esc(bank_money((principal * (4 - i) + 2) / 4)) + ""; } const int interval = term <= 12 ? 3 : term <= 24 ? 6 : 12; std::vector labels; for (int month = 0; month <= term; month += interval) labels.push_back(month); if (labels.back() != term) labels.push_back(term); for (const int month : labels) { svg += "" + (month == 0 ? "Heute" : std::to_string(month) + (month == term ? " Monate" : "")) + ""; } std::string points; for (const auto &point : summary.at("schedule")) points += scalar(220 + point.at("month").get() / term * 1960) + "," + scalar(340 - point.at("remaining").get() / principal * 310) + " "; svg += "" ""; out += "

Restschuld über die Laufzeit

" + esc(bank_money(principal)) + " → " + esc(bank_money(0)) + "

" + std::to_string(term) + " Monate

" + (summary.at("schedule_example") == true ? "Beispiel · kein laufender Kredit" : "Aktueller Kredit") + "

" + picture(renderer_.diagram("bank-credit", svg, 2400), 2432, 420) + "

Gleichmäßige monatliche Tilgung · Restschuld ohne Zinsen

" "

Fiktiver Kredit. Im POC erfolgen keine Zins- oder Ratenbuchungen.

" + actions("Aufnehmen", "loan", "Tilgen", "repay"); } else if (bank_view_ == "overview") { out += "

Finanzübersicht

"; if (engine_mode_) { const std::array, 5> fields{{{"Konto", "cash"}, {"Sparbuch", "deposit"}, {"Immobilien", "properties"}, {"Aktien", "stocks"}, {"Kreditlinie", "credit_line"}}}; for (const auto &[label, key] : fields) { const auto value = summary.at(key).get(); out += "
" + std::string(label) + "" + esc(bank_money(value)) + "
"; } return out + "

Bestände und Kurse aus dem Spielstand · Kredite beim Bankberater.

"; } const std::array, 6> fields{{ {"Konto", summary.at("cash")}, {"Sparbuch", summary.at("deposit")}, {"Immobilien", summary.at("properties")}, {"Aktien", summary.at("stocks")}, {"Kredit", -summary.at("debt").get()}, {"Saldo", summary.at("net")}}}; for (size_t i = 0; i < fields.size(); ++i) out += "
" + fields[i].first + "" + (i == 4 ? "-" + esc(bank_money(summary.at("debt").get())) : esc(bank_money(fields[i].second))) + "
"; out += "

Erfundene Bestände · Änderungen betreffen ausschließlich die Bankvorschau.

"; } return out + ""; }