Bind environment and advertising to confirmed engine actions (by Codex)
This commit is contained in:
1 parent
dcf42f2da7
commit
e9483048f4
19 files changed
+395
-23
No files matched your search
@@ -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 = "<strong><span>" + std::string(headings[size_t(i)]) + "</span></strong><div class=\"advertising-art\">" +
|
||||
img("advertising.panel." + std::to_string(i), 510, 510, false, false, 1000) + "</div>";
|
||||
if (i == 0) body += brand(view.at("slots")[14]);
|
||||
else body += "<output><span>" + esc(cash(view.at("spending")[size_t(i - 1)].at("amount").get<int64_t>())) + "</span></output>";
|
||||
else body += "<output class=\"" + (engine_mode_ ? money_classes(view.at("spending")[size_t(i - 1)].at("amount")) : std::string()) + "\"><span>" + esc(ad_cash(view.at("spending")[size_t(i - 1)].at("amount").get<int64_t>())) + "</span></output>";
|
||||
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 += "<div class=\"advertising-hint\"><h2>Werbung und Vereinsausgaben</h2>"
|
||||
"<p>Bande, Trikot oder TV-Rechte auswählen.</p><p>Die drei Ausgabenbilder öffnen die Zahleneingabe.</p></div>";
|
||||
} 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<bool>() : !active;
|
||||
const bool accept = engine_mode_ ? quote.at("can_accept").get<bool>() : !active;
|
||||
out += "<div class=\"advertising-offer\"><div class=\"ad-offer-mark\">" + brand(quote) +
|
||||
"</div><div class=\"ad-offer-arrows\">" +
|
||||
btn("ad-offer", "<span>‹</span>", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(active ? "disabled" : "")) +
|
||||
btn("ad-offer", "<span>›</span>", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(active ? "disabled" : "")) +
|
||||
btn("ad-offer", "<span>‹</span>", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(cycle ? "" : "disabled")) +
|
||||
btn("ad-offer", "<span>›</span>", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(cycle ? "" : "disabled")) +
|
||||
"</div><div class=\"ad-offer-facts\"><div><span>" + esc(quote.at("label").get<std::string>()) + "</span><strong>" +
|
||||
esc(quote.at("name").get<std::string>()) + "</strong></div><div><span>Dauer</span><strong>" + std::to_string(quote.at("months").get<int>()) +
|
||||
" Monate</strong></div><div><span>" + (active ? "Vertrag" : "Angebot") + "</span><strong>" +
|
||||
esc(cash(quote.at("amount").get<int64_t>())) + " / Monat</strong></div></div></div><nav class=\"advertising-actions\">" +
|
||||
" Monate" + (engine_mode_ && quote.at("boards") > 1 ? " · " + std::to_string(quote.at("boards").get<int>()) + " Banden" : std::string()) + "</strong></div><div><span>" + (active ? "Vertrag" : "Angebot") + "</span><strong>" +
|
||||
esc(ad_cash(quote.at("amount").get<int64_t>())) + " / Monat</strong></div></div></div><nav class=\"advertising-actions\">" +
|
||||
btn("ad-cancel", active ? "Schließen" : "Abbrechen", "advertising-control", "id=\"ad-cancel\"") +
|
||||
btn("ad-accept", active ? "Vertrag läuft" : "Annehmen", "advertising-control", "id=\"ad-accept\" " + std::string(active ? "disabled" : "")) + "</nav>";
|
||||
btn("ad-accept", active ? "Vertrag läuft" : accept ? "Annehmen" : "Nicht verfügbar", "advertising-control", "id=\"ad-accept\" " + std::string(accept ? "" : "disabled")) + "</nav>";
|
||||
}
|
||||
out += "<div class=\"advertising-totals\">";
|
||||
if (engine_mode_) out += "<span class=\"engine-ad-preview-label\">Vereinsprognose / Monat</span>";
|
||||
out += "<div class=\"advertising-totals\" aria-label=\"" + std::string(engine_mode_ ? "Monatliche Vereinsprognose der Engine" : "Werbevorschau") + "\">";
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}})
|
||||
out += "<div><span>" + std::string(label) + "</span><output>" + esc(cash(view.at(key).get<int64_t>())) + "</output></div>";
|
||||
out += "<div><span>" + std::string(label) + "</span><output class=\"" + (engine_mode_ ? money_classes(view.at(key)) : std::string()) + "\">" + esc(ad_cash(view.at(key).get<int64_t>())) + "</output></div>";
|
||||
return out + "</div></section></div>";
|
||||
}
|
||||
Reference in new issue
Block a user