Bind confirmed bank and ticket actions to real careers (by Codex)
This commit is contained in:
1 parent
f75e0f8e49
commit
dcf42f2da7
23 files changed
+535
-56
No files matched your search
@@ -1,15 +1,18 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_bank() {
|
||||
const auto snapshot = snap();
|
||||
const auto assets = demo_bank_assets(*world_);
|
||||
const auto summary = demo_bank_summary(snapshot.state, *world_);
|
||||
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, 5);
|
||||
bank_stock_ = std::clamp(bank_stock_, 0, 11);
|
||||
bank_owned_ = std::clamp(bank_owned_, 0, 5);
|
||||
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 < 6; ++i)
|
||||
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 "<nav class=\"bank-actions\">" +
|
||||
@@ -41,29 +44,29 @@ std::string App::render_bank() {
|
||||
if (bank_view_ == "savings") {
|
||||
out += "<div class=\"passbook\">" + img("art.bank-passbook-v1.png", 2100, 1293.109375, false, false, 2400) +
|
||||
"<div class=\"passbook-left\"><h2>Waldpark Bank</h2><h3>Sparbuch</h3><p class=\"passbook-note-one\">Bitte beachten Sie:</p>"
|
||||
"<p class=\"passbook-note-two\">Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht.</p>"
|
||||
"<p class=\"passbook-note-three\">2,5 % Beispielzins</p></div><div class=\"passbook-right\"><h2>Guthaben</h2><output>" +
|
||||
esc(cash(snapshot.state.at("deposit").get<int64_t>())) + "</output></div></div>" + actions("Einzahlen", "deposit", "Abheben", "withdraw");
|
||||
"<p class=\"passbook-note-two\">" + std::string(engine_mode_ ? "Einzahlungen und Abhebungen werden nach Bestätigung im Spielstand verbucht." : "Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht.") + "</p>"
|
||||
"<p class=\"passbook-note-three\">" + (engine_mode_ ? "" : "2,5 % Beispielzins") + "</p></div><div class=\"passbook-right\"><h2>Guthaben</h2><output>" +
|
||||
esc(bank_money(snapshot.state.at("deposit").get<int64_t>())) + "</output></div></div>" + actions("Einzahlen", "deposit", "Abheben", "withdraw");
|
||||
} else if (bank_view_ == "properties") {
|
||||
out += "<h2>Immobilien</h2>";
|
||||
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<int64_t>();
|
||||
out += "<div class=\"property-row owned-property\"><div class=\"property-description\"><h3>Ihre Immobilien</h3>" +
|
||||
(count ? "<p>" + std::to_string(count) + " × " + esc(owned.at("name").get<std::string>()) + "</p><p>Wert: " +
|
||||
esc(cash(count * owned.at("price").get<int64_t>())) + "</p>" : "<p>Keine Immobilien im Bestand</p>") +
|
||||
"</div>" + btn("property-owned-next", count ? img("bank.property." + std::to_string(bank_owned_), 996, 566, false, false, 1200)
|
||||
esc(bank_money(count * owned.at("price").get<int64_t>())) + "</p>" : "<p>Keine Immobilien im Bestand</p>") +
|
||||
"</div>" + btn("property-owned-next", count ? img(engine_mode_ ? owned.at("image").get<std::string>() : "bank.property." + std::to_string(bank_owned_), 996, 566, false, false, 1200)
|
||||
: "<span class=\"property-empty\"></span>", "property-picture", "id=\"property-owned-next\" aria-label=\"Nächste eigene Immobilie\" " + std::string(count ? "" : "disabled")) + "</div>";
|
||||
out += "<div class=\"property-row offered-property\"><div class=\"property-description\"><h3>Kaufangebot</h3><p>" +
|
||||
esc(offer.at("name").get<std::string>()) + "</p><p>Kaufpreis: " + esc(cash(offer.at("price").get<int64_t>())) +
|
||||
"</p></div>" + btn("property-next", img("bank.property." + std::to_string(bank_property_), 996, 566, false, false, 1200),
|
||||
esc(offer.at("name").get<std::string>()) + "</p><p>Kaufpreis: " + esc(bank_money(offer.at("price").get<int64_t>())) +
|
||||
"</p></div>" + btn("property-next", img(engine_mode_ ? offer.at("image").get<std::string>() : "bank.property." + std::to_string(bank_property_), 996, 566, false, false, 1200),
|
||||
"property-picture", "id=\"property-next\" aria-label=\"Nächstes Immobilienangebot\"") + "</div>" +
|
||||
actions("Kaufen", "property-buy", "Verkaufen", "property-sell");
|
||||
} else if (bank_view_ == "stocks") {
|
||||
out += "<h2>Aktien</h2><div class=\"stock-table\"><div class=\"stock-row stock-head\">";
|
||||
for (const auto *label : {"Wert", "Kurs", "Vortag", "Bestand"}) out += "<div><span>" + std::string(label) + "</span></div>";
|
||||
out += "</div>";
|
||||
const auto factor = finance_currency_factor(*world_);
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
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 += "<div class=\"stock-row\"><div>" + btn("bank-stock", esc(s.at("name").get<std::string>()), "stock-name",
|
||||
"id=\"bank-stock-" + std::to_string(i) + "\" data-bank-stock=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
|
||||
@@ -72,32 +75,36 @@ std::string App::render_bank() {
|
||||
"</span></div><div><span>" + number(finance.at("stocks")[size_t(i)].get<int64_t>()) + "</span></div></div>";
|
||||
}
|
||||
const double price = assets.at("stocks")[size_t(bank_stock_)].at("price").get<double>() / factor;
|
||||
std::array<double, 30> history{};
|
||||
for (int i = 0; i < 30; ++i) history[size_t(i)] = price * (.85 + .08 * std::sin(i * .6 + bank_stock_) + i * .003);
|
||||
const double lo = *std::min_element(history.begin(), history.end()) * .95, hi = *std::max_element(history.begin(), history.end()) * 1.05;
|
||||
std::vector<double> history;
|
||||
if (engine_mode_) {
|
||||
for (const auto &value : assets.at("stocks")[size_t(bank_stock_)].at("history")) history.push_back(value.get<double>() / 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 (int i = 0; i < 30; ++i) points += scalar(20 + i * 690. / 29) + "," + scalar(900 - (history[size_t(i)] - lo) / (hi - lo) * 830) + " ";
|
||||
for (size_t i = 0; i < history.size(); ++i) points += scalar(20 + i * 690. / std::max<size_t>(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 = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"740\" height=\"1320\" viewBox=\"0 0 740 950\">"
|
||||
"<path d=\"M10 10V930H730\" fill=\"none\" stroke=\"" + std::string(axis) + "\" stroke-width=\"5\"/>"
|
||||
"<polyline points=\"" + points + "\" fill=\"none\" stroke=\"" + stroke + "\" stroke-width=\"9\"/></svg>";
|
||||
out += "</div><div class=\"stock-chart\" role=\"img\" aria-label=\"Erfundener Kursverlauf für " +
|
||||
out += "</div><div class=\"stock-chart\" role=\"img\" aria-label=\"" + std::string(engine_mode_ ? "Kursverlauf aus dem Spielstand für " : "Erfundener Kursverlauf für ") +
|
||||
esc(assets.at("stocks")[size_t(bank_stock_)].at("name").get<std::string>()) + "\">" +
|
||||
picture(renderer_.diagram("bank-stock", svg, 1600), 740, 1320) + "</div>" + actions("Kaufen", "stock-buy", "Verkaufen", "stock-sell");
|
||||
} else if (bank_view_ == "credit") {
|
||||
if (engine_mode_) return out + engine_credit_view() + "</section></div>";
|
||||
out += "<h2>Kredit</h2><div class=\"credit-portrait\">" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) +
|
||||
"</div><div class=\"credit-facts\">";
|
||||
const auto fact = [&](const char *label, const std::string &value, int row) {
|
||||
constexpr std::array<int, 5> y{0, 83, 166, 273, 356};
|
||||
return "<div class=\"credit-fact\" style=\"top:" + std::to_string(y[size_t(row)]) + "dp;\"><span>" + label + "</span><strong>" + value + "</strong></div>";
|
||||
};
|
||||
out += fact("Restschuld", esc(cash(summary.at("debt").get<int64_t>())), 0) + fact("Beispielzins", "8 % pro Jahr", 1);
|
||||
out += fact("Restschuld", esc(bank_money(summary.at("debt").get<int64_t>())), 0) + fact("Beispielzins", "8 % pro Jahr", 1);
|
||||
std::string select = "<select id=\"bank-term\" aria-label=\"Kreditlaufzeit\" " + std::string(summary.at("debt") == 0 ? "" : "disabled") + ">";
|
||||
for (const auto &term : demo_bank_terms()) select += "<option value=\"" + std::to_string(term.get<int>()) + "\" " +
|
||||
std::string(term == finance.at("term") ? "selected" : "") + ">" + std::to_string(term.get<int>()) + " Monate</option>";
|
||||
out += fact("Laufzeit", select + "</select>", 2) + fact("Monatsrate, Beispiel", esc(cash(summary.at("monthly_rate").get<int64_t>())), 3) +
|
||||
fact("Maximaler Kredit", esc(cash(5000000 * finance_currency_factor(*world_))), 4) + "</div>";
|
||||
out += fact("Laufzeit", select + "</select>", 2) + fact("Monatsrate, Beispiel", esc(bank_money(summary.at("monthly_rate").get<int64_t>())), 3) +
|
||||
fact("Maximaler Kredit", esc(bank_money(5000000 * finance_currency_factor(*world_))), 4) + "</div>";
|
||||
const int term = finance.at("term");
|
||||
const auto principal = summary.at("schedule_principal").get<int64_t>();
|
||||
const auto color = theme_ == "silver" ? "#233443" : theme_ == "matchday" ? "#efeded" : "#a8c0cf";
|
||||
@@ -110,7 +117,7 @@ std::string App::render_bank() {
|
||||
const auto y = 30 + i * 77.5;
|
||||
svg += "<line x1=\"220\" y1=\"" + scalar(y) + "\" x2=\"2180\" y2=\"" + scalar(y) + "\" stroke=\"" + grid_color + "\" stroke-width=\"2\"/>"
|
||||
"<text x=\"184\" y=\"" + scalar(y + 9) + "\" text-anchor=\"end\" fill=\"" + color + "\" font-size=\"28\" font-family=\"Arial, Liberation Sans, sans-serif\">" +
|
||||
esc(cash((principal * (4 - i) + 2) / 4)) + "</text>";
|
||||
esc(bank_money((principal * (4 - i) + 2) / 4)) + "</text>";
|
||||
}
|
||||
const int interval = term <= 12 ? 3 : term <= 24 ? 6 : 12;
|
||||
std::vector<int> labels;
|
||||
@@ -128,7 +135,7 @@ std::string App::render_bank() {
|
||||
accent + "\" stroke-width=\"6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/><circle cx=\"220\" cy=\"30\" r=\"7\" fill=\"#c1ecdf\" stroke=\"#294553\" stroke-width=\"4\"/>"
|
||||
"<circle cx=\"2180\" cy=\"340\" r=\"7\" fill=\"#c1ecdf\" stroke=\"#294553\" stroke-width=\"4\"/></svg>";
|
||||
out += "<figure class=\"credit-schedule\"><div class=\"credit-schedule-caption\"><h3>Restschuld über die Laufzeit</h3><p class=\"credit-schedule-amount\">" +
|
||||
esc(cash(principal)) + " <span>→</span> " + esc(cash(0)) + "</p><div class=\"credit-schedule-context\"><span>" + std::to_string(term) +
|
||||
esc(bank_money(principal)) + " <span>→</span> " + esc(bank_money(0)) + "</p><div class=\"credit-schedule-context\"><span>" + std::to_string(term) +
|
||||
" Monate</span><p>" + (summary.at("schedule_example") == true ? "Beispiel · kein laufender Kredit" : "Aktueller Kredit") +
|
||||
"</p></div></div><div class=\"credit-chart\" role=\"img\" aria-label=\"Restschuld über " + std::to_string(term) +
|
||||
" Monate bei gleichmäßiger Tilgung ohne Zinsen\">" + picture(renderer_.diagram("bank-credit", svg, 2400), 2432, 420) +
|
||||
@@ -136,13 +143,21 @@ std::string App::render_bank() {
|
||||
"<p class=\"bank-note credit-note\">Fiktiver Kredit. Im POC erfolgen keine Zins- oder Ratenbuchungen.</p>" + actions("Aufnehmen", "loan", "Tilgen", "repay");
|
||||
} else if (bank_view_ == "overview") {
|
||||
out += "<h2>Finanzübersicht</h2><div class=\"bank-overview\">";
|
||||
if (engine_mode_) {
|
||||
const std::array<std::pair<const char *, const char *>, 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<int64_t>();
|
||||
out += "<div class=\"bank-overview-row\"><span>" + std::string(label) + "</span><strong class=\"" + money_classes(value) + "\">" + esc(bank_money(value)) + "</strong></div>";
|
||||
}
|
||||
return out + "</div><p class=\"bank-note overview-note\">Bestände und Kurse aus dem Spielstand · Kredite beim Bankberater.</p></section></div>";
|
||||
}
|
||||
const std::array<std::pair<const char *, int64_t>, 6> fields{{
|
||||
{"Konto", summary.at("cash")}, {"Sparbuch", summary.at("deposit")},
|
||||
{"Immobilien", summary.at("properties")}, {"Aktien", summary.at("stocks")},
|
||||
{"Kredit", -summary.at("debt").get<int64_t>()}, {"Saldo", summary.at("net")}}};
|
||||
for (size_t i = 0; i < fields.size(); ++i)
|
||||
out += "<div class=\"bank-overview-row " + std::string(i == 5 ? "bank-overview-total" : "") + "\"><span>" +
|
||||
fields[i].first + "</span><strong>" + (i == 4 ? "-" + esc(cash(summary.at("debt").get<int64_t>())) : esc(cash(fields[i].second))) + "</strong></div>";
|
||||
fields[i].first + "</span><strong>" + (i == 4 ? "-" + esc(bank_money(summary.at("debt").get<int64_t>())) : esc(bank_money(fields[i].second))) + "</strong></div>";
|
||||
out += "</div><p class=\"bank-note overview-note\">Erfundene Bestände · Änderungen betreffen ausschließlich die Bankvorschau.</p>";
|
||||
}
|
||||
return out + "</section></div>";
|
||||
|
||||
Reference in new issue
Block a user