Bind stadium construction and historical data to scoped engine offers (by Codex)

This commit is contained in:
Codex committed 2026-10-29 06:09:10 +01:00
1 parent dfb972abbd
commit 0edf208405
22 files changed
+1037 -40

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ jobs:
- name: Configure opt-in UI without external assets
run: cmake -S . -B build-ui -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_MODERN_UI=ON -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA=
- name: Compile native frontend and synthetic checks
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_career_files_tests modern_statistics_projection_tests modern_toto_projection_tests modern_toto_quote_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests modern_entry_ui_tests modern_opening_ui_tests modern_select_menu_tests modern_career_ui_tests modern_live_ui_tests modern_national_ui_tests modern_news_catalog_tests modern_post_match_ui_tests modern_engine_dto_tests modern_report_read_tests modern_other_read_tests modern_rankings_read_tests modern_winners_read_tests modern_manager_presentation_tests modern_coach_identity_tests --parallel 2
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_career_files_tests modern_statistics_projection_tests modern_toto_projection_tests modern_toto_quote_tests modern_stadium_ui_tests modern_stadium_projection_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests modern_entry_ui_tests modern_opening_ui_tests modern_select_menu_tests modern_career_ui_tests modern_live_ui_tests modern_national_ui_tests modern_news_catalog_tests modern_post_match_ui_tests modern_engine_dto_tests modern_report_read_tests modern_other_read_tests modern_rankings_read_tests modern_winners_read_tests modern_manager_presentation_tests modern_coach_identity_tests --parallel 2
- name: Check controls, fonts, density and draft cancellation
run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_|mods_ui_|entry_ui_|opening_ui_|select_menu_|career_ui_|live_ui_|national_ui_|news_catalog_|post_match_ui_|engine_dto_|report_read_)" -LE external-data --output-on-failure --output-junit modern-ui-results.xml
- name: Upload test report
+3
View File
@@ -145,3 +145,6 @@ body.silver .stadium-block[disabled],body.matchday .stadium-block[disabled] {opa
.stadium-nav-button.half {width:1295dp;}
.stadium-screen.periphery .stadium-nav {top:1704.625dp;}
body.midnight .stadium-summary strong.money-amount,body.silver .stadium-summary strong.money-amount,body.matchday .stadium-summary strong.money-amount {color:var(--money);}
body .stadium-summary strong.money-amount.is-negative {color:var(--danger);}
+16
View File
@@ -111,3 +111,19 @@ hier ausschließlich über `ModernSession::ui_read`.
`available`-/`reason`-Verhalten bleiben erhalten. Vorhandene aktuelle Transfer-
und Analytics-Projektionen ergänzen die belegten Almanachauswertungen. Der
Read ist rein; weder OBS-/OBW-Format noch Spielregeln werden geändert.
### Stadionangebote bearbeiten
`quote.request` kann ein bestehendes Block-/Ausstattungsangebot mit dessen
`quoteId` erneut adressieren. Kennung, Art und Block/Ausstattung müssen zum
aktuellen Besitzer passen. Der vorhandene Firmenpreis bleibt erhalten;
reine Ziel-/Stufenwahl zieht keine neue Zufallszahl. Ohne `quoteId` bleibt
es eine neue Anfrage, die vorhandene offene Angebote weiterhin abweist.
`stadium.commit` bestätigt bzw. verwirft das genaue Angebot und schließt es.
Der UI-Standardbau verwendet den bereits vorhandenen Weg ohne Beschleunigung.
Der Stadion-Read ergänzt tatsächliche geplante Kapazität/Ausstattung und
vorhandene Messreihen/Tabellen. Bei Ausbau sind aktuelle und geplante Werte
getrennt. Weitere Parkplatzstufen aus der Grafikstudie werden nicht erfunden:
die aktuelle Engine kennt neben der mehrstufigen Anbindung binäre Außenobjekte.
Kein neues Welt-/Spielstandformat und keine neue Bau- oder Finanzregel.
+1 -1
View File
@@ -6,7 +6,7 @@ Die normale Classic-Konfiguration bleibt unverändert; die neue Oberfläche
wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
Der [Engine-Einstieg](integration/ENGINE_ENTRY.md) erzeugt über den
vorhandenen Wizard eine echte Karriere oder lädt eine Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager, Aufstellung, Taktik, Training, Bank, Eintrittspreis, Umfeld, Werbung, Spielerverträge, Vereinskalender, Spielverlegung, Vereins-/Nationalfreundschaftsspiele, den Almanach sowie Tabellen, Stärken, Ligaspiele, übrige Spiele, Spielerstatistiken, Fairplay, die große Statistikansicht und Toto an die
vorhandenen Wizard eine echte Karriere oder lädt eine Modern-OBS-Karriere und bindet Schreibtisch, Trainingslager, Aufstellung, Taktik, Training, Bank, Eintrittspreis, Umfeld, Werbung, Spielerverträge, Vereinskalender, Spielverlegung, Vereins-/Nationalfreundschaftsspiele, den Almanach sowie Tabellen, Stärken, Ligaspiele, übrige Spiele, Spielerstatistiken, Fairplay, die große Statistikansicht, Toto und die Stadionansichten samt Bauangeboten an die
Session. Kader und Profile zeigen die tatsächlichen Sessionwerte; Spielertausch
verwendet die bestätigte Engineaktion. Preisbestätigung, Buchung und Speichern als neue OBS-Datei sind echte
Engineoperationen. Die vorhandenen Speichern-/Laden-Fenster verwalten echte OBS-Dateien
+64
View File
@@ -215,3 +215,67 @@ gehört zur nativen UI-Demo; sie ändert weder Classic noch eine Engineberechnun
Baufortschritt, Fertigstellung und Abbruch eines
gebuchten Auftrags bleiben offene Engineentscheidungen. Die Prüfung belegt
keine Windows-/macOS-Laufzeitabnahme und keine neue Classic-Freigabe.
## Reale Modern-Karriere (29.10.2026)
Der Engine-Einstieg verwendet dieselben Ansichten und GUI-Bilder mit tatsächlichen
Stadiondaten. Acht Blöcke A–H, acht Ausstattungskategorien und vierzehn Außenobjekte
kommen aus dem Session-Read. Aktuelle und geplante Plätze, Sitzplätze, Dach und
Ausstattungsstufen bleiben getrennt. Ein gesperrter Block trägt aktuell keine
verfügbaren Plätze bei; die Zukunftsansicht verwendet dessen beauftragtes Ziel.
Das Superstadion setzt die tatsächlichen Maxima aller Blöcke mit Sitzplätzen und
Dach voraus. Ausreichende Gesamtkapazität allein schaltet es nicht frei.
Bauangebote werden durch `quote.request` erzeugt. Beim Bearbeiten des gleichen
Blocks bzw. der gleichen Ausstattung nennt die Anfrage die vorhandene `quoteId`.
Die Engine behält Firma, Preisfaktor und Besitzer bei; reine Ziel-/Stufenänderungen
ziehen keine weiteren Zufallszahlen. Fremde oder veraltete Angebote werden
abgewiesen. Die UI verwendet keine Preis- oder Bauzeitvorlagen aus dem POC.
Grundpreise und Firmenkondition sind erkennbar; der tatsächliche Gesamtbetrag wird
vor `stadium.commit` bestätigt. Die Standardbauzeit wird ohne die optionale
Beschleunigung beauftragt. Deren zusätzlicher Dialog ist hier noch nicht angebunden.
Eine neue Angebotsöffnung verwendet die originalen Zufallsziehungen. Verwerfen
bucht kein Geld und dreht diese Ziehungen nicht zurück. Innen-/Außenansicht,
Zukunftsschalter und Stadionstatistik sind reine Ansichten. Beim Beenden mit
offenem Angebot verwirft die UI zuerst genau dieses Angebot und bietet danach
Speichern/Verwerfen an; es bleibt kein Modalbesitzer beim Speichern hängen.
Die Außenansicht verwendet die kalibrierte Grafikstudie. Hover nennt das Objekt
bzw. seine restliche Bauzeit aus dem tatsächlichen Enginezählwert. Die Anbindung
wird jeweils um eine Stufe erweitert. Die derzeitige Engine kennt bei den übrigen
Außenobjekten nur einmaligen Bau; zusätzliche Parkplatzstufen der Grafikstudie
werden nicht als echte Ausbauten angeboten. Die vorhandene GUI-Komposition erhält
nur tatsächliche Kapazitäten, Ausbaustufen und Bauaufträge, keine POC-Finanzdaten.
Stadiondaten zeigen die gespeicherten Messreihen mit den tatsächlichen Original-
Beschriftungen und Skalen sowie die vorhandenen Zuschauer-/Einnahmenrekorde.
Zahlen-Füllzeichen des ursprünglichen Bitmapformatters werden entfernt; Gegner-
texte bleiben die gespeicherten historischen Texte. Einzelne Messpunkte bleiben
auch vor einer zweiten Beobachtung sichtbar. Der Eintritt verwendet die aktuelle
Engine-Spanne und wird vor der tatsächlichen Änderung bestätigt. Erforderlicher
Zuschauerschnitt und Tabellenwerte werden von der Engine neu gelesen.
Alle Engine-Beträge werden ausdrücklich mit EUR und zwei Nachkommastellen
angezeigt. Das ganzzahlige Importwährungsformat des Weltpakets ist keine Einheit
für diese Werte. Die Kassenfarbe entspricht der Infoleiste, auch im Matchday-Theme.
Anstoß und Spielregeln werden durch dieses Paket nicht verändert.
### Prüfung des Engine-Meilensteins
61 synthetische Regressionstests, 132 Haupt-GUI-Prüfungen, 21 zusätzliche
Bau-/Eingabe-/Beenden-Prüfungen, zehn Abschluss-/Einzelmesspunktprüfungen,
1.252 Positionsprüfungen und zwei native Demo-Prüfungen bestanden. Drei Themes
in 1080p, Silver zusätzlich in 720p. Drei abschließende Layout-/Stadiontests
sind ebenfalls grün. Der direkte Session-Gegenfall belegt dieselben Zufallsstände
und dieselbe Angebotskennung vor/nach Block- und Ausstattungsänderungen; falsche
Angebotskennungen bleiben wirkungslos. Echte Bauaufträge, Zahleneditor,
Sitz-/Dachoptionen, Eintrittsbestätigung und OBS-Neustart sind geprüft.
Reguläres Betriebssystem-Schließen während eines offenen Angebots gibt den
Besitzer frei und ermöglicht danach Speichern und Beenden. Ein Außenobjekt
wurde über tatsächliche `session.advance`-Aufrufe fertiggestellt und anschließend
in der aktuellen und zukünftigen Ansicht gleich dargestellt. Die Statistik
nach dem ersten echten Heimspiel prüft auch einzelne Messpunkte. Linux x64/SDL2
wurde ausgeführt; native Windows-/macOS-Ausführung ist offen. Private Bilder,
Rohantworten, Prüfsummen und passende OBS: `bmh_4k_ui/docs/qa/engine-stadium-2026-10-29/`.
+10
View File
@@ -372,3 +372,13 @@ Die bestehende Sechs-Spalten-Oberfläche ist an den tatsächlichen
[Toto-Read und die Abgabe](../desktop/toto/README.md) angebunden. Entwürfe,
Vorschläge und Kostenprüfungen sind rein; erst die bestätigte Abgabe oder
Rücknahme ändert die Karriere. Die Abrechnung bleibt am Spieltagsende.
## Stadionangebote und Bauzustand
[Stadion](../desktop/stadium/README.md) verwendet tatsächliche Blöcke,
Ausstattungen, Außenobjekte und Statistikdaten. Exakte Angebote können innerhalb
ihres Besitzers bearbeitet, bestätigt oder verworfen werden. Der Firmenpreis
bleibt bei Zieländerungen erhalten; Kosten und Bauzeiten kommen aus der Session.
Die GUI hält keine eigene Bau- oder Finanzsimulation. Beim Beenden werden
Angebotsbesitzer vor dem Speichern freigegeben.
+26 -17
View File
@@ -9141,33 +9141,38 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
const auto& f = st.investments[i];
facilities.push_back(O{{"id", std::string("facility:") + kFacilities[i]}, {"name", text(734 + i)},
{"level", int(f.current_level)}, {"maxLevel", i == 2 || i == 3 ? 2 : 4},
{"constructionWeeks", int(f.construction_weeks)}, {"upgradeAvailable", f.available}});
{"constructionWeeks", int(f.construction_weeks)}, {"plannedLevel", int(f.construction_weeks?((f.current_status>>4)&7):f.current_level)}, {"upgradeAvailable", f.available}});
}
for (size_t b = 0; b < st.blocks.size(); ++b) {
const auto& k = st.blocks[b];
blocks.push_back(O{{"id", "block:" + std::string(1, char('a' + b))}, {"name", text(742 + b)},
{"places", int64_t(k.capacity_level) * 1000},
{"maxPlaces", int64_t(exe_.u8(::bmh::layout::CareerSession_Invalid_RuntimeField + uint32_t(b))) * 1000},
{"seats", (k.flags & 1) != 0}, {"roof", (k.flags & 2) != 0},
{"seats", (k.flags & 1) != 0}, {"roof", (k.flags & 2) != 0}, {"seatsAfterConstruction", (k.flags & (k.construction_weeks?0x10:1)) != 0}, {"roofAfterConstruction", (k.flags & (k.construction_weeks?0x20:2)) != 0},
{"constructionWeeks", int(k.construction_weeks)}, {"placesAfterConstruction", int64_t(k.capacity) * 1000}});
}
A history,table;
for(size_t curve=0;curve<6;++curve){A values,absolute,relative;for(const auto value:data.series[curve])values.push_back(int64_t(value));auto graph=data;bool absolute_ok=true,relative_ok=true;try{graph.flags=0x7f;for(const auto& [x,y]:ui::stadium_data_points(graph,exe_,int(curve)))absolute.push_back(A{cli::Json(x),cli::Json(y)});}catch(const std::exception&){absolute_ok=false;}try{graph.flags=0xbf;for(const auto& [x,y]:ui::stadium_data_points(graph,exe_,int(curve)))relative.push_back(A{cli::Json(x),cli::Json(y)});}catch(const std::exception&){relative_ok=false;}history.push_back(O{{"name",ui::original_to_utf8(exe_.cstring(exe_.u32(::bmh::layout::Analytics_FormatError_ExecutableField+(6+uint32_t(curve))*4)))},{"values",std::move(values)},{"absolute",std::move(absolute)},{"relative",std::move(relative)},{"absoluteAvailable",absolute_ok},{"relativeAvailable",relative_ok}});}
for(size_t row=0;row<data.table.size();++row){A cells;for(const auto& value:data.table[row]){auto text=ui::original_to_utf8(value);if(row!=1&&row!=3)text.erase(0,text.find_first_not_of("% "));cells.push_back(std::move(text));}table.push_back(std::move(cells));}
std::string stadium_name;const size_t name_at=size_t(team)*2;if(name_at+1<g_.club_heap_bc.size()){const size_t offset=size_t(g_.club_heap_bc[name_at])|(size_t(g_.club_heap_bc[name_at+1])<<8);if(offset<g_.stadium_names.size())for(size_t at=offset;at<g_.stadium_names.size()&&g_.stadium_names[at];++at)stadium_name.push_back(char(g_.stadium_names[at]));}stadium_name=ui::original_to_utf8(stadium_name);if(stadium_name.empty())stadium_name="Stadion";
// the open offer of the stadium dialog (quote.request), answered by stadium.commit
cli::Json quote = nullptr;
if (stadium_.opened && stadium_.manager == manager) {
const std::string id = "quote:stadium-" + std::to_string(stadium_.scope);
if (stadium_.periphery_quote)
quote = O{{"id", id}, {"kind", "periphery"}, {"objectId", "periphery:" + std::to_string(stadium_.periphery_quote->first)},
{"price", modern::ui_money(stadium_.periphery_quote->second)}};
else if (stadium_.investment && stadium_.option)
quote = O{{"id", id}, {"kind", "facility"}, {"facilityId", std::string("facility:") + kFacilities[size_t(*stadium_.investment)]},
{"toLevel", int(stadium_.option->target_level)}, {"price", modern::ui_money(stadium_.option->base_price)},
{"weeks", int(stadium_.option->base_weeks)}, {"tipPercent", O{{"min", 6}, {"max", 14}}}};
{"price", modern::ui_money(stadium_.periphery_quote->second)},{"weeks",modern::periphery_build_weeks(stadium_.periphery_quote->first)}};
else if (stadium_.investment && stadium_.option) {
StadiumInvestmentConstants constants;for(unsigned i=0;i<8;++i){constants.price[i]=exe_.u32(::bmh::layout::CareerSession_DispatchStadium_RuntimeField+i*4);constants.weeks[i]=exe_.u8(::bmh::layout::CareerSession_DispatchStadium_RuntimeField2+(14+i)*5);}
A options;for(const auto& option:modern::stadium_investment_options_source(g_,manager,*stadium_.investment,stadium_.price_percent,constants))options.push_back(O{{"toLevel",int(option.target_level)},{"price",modern::ui_money(option.base_price)},{"weeks",int(option.base_weeks)}});
quote=O{{"id",id},{"kind","facility"},{"facilityId",std::string("facility:")+kFacilities[size_t(*stadium_.investment)]},{"toLevel",int(stadium_.option->target_level)},{"price",modern::ui_money(stadium_.option->base_price)},{"pricePercent",stadium_.price_percent},{"weeks",int(stadium_.option->base_weeks)},{"options",std::move(options)},{"tipPercent",O{{"min",6},{"max",14}}}};
}
else if (stadium_.block_expansion) {
const auto& q = stadium_.block_expansion->quote;
quote = O{{"id", id}, {"kind", "block"}, {"blockId", "block:" + std::string(1, char('a' + int(q.slot)))},
{"places", int64_t(q.total_target_places)}, {"maxPlaces", int64_t(q.max_places)}, {"newPlaces", int64_t(q.new_places)},
{"seats", (stadium_.block_expansion->desired_features & 1) != 0}, {"roof", (stadium_.block_expansion->desired_features & 2) != 0},
{"price", modern::ui_money(q.base_price)},
{"price", modern::ui_money(q.base_price)}, {"pricePercent",stadium_.price_percent},
{"breakdown", A{O{{"code", "places"}, {"amount", modern::ui_money(q.new_places_cost)}},
O{{"code", "seats"}, {"amount", modern::ui_money(q.seats_cost)}},
O{{"code", "roof"}, {"amount", modern::ui_money(q.roof_cost)}}}},
@@ -9175,9 +9180,9 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
}
}
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"quote", std::move(quote)}, {"periphery", std::move(periphery)},
O{{"kind", "stadium"}, {"name",stadium_name}, {"teamId", modern::ui_team_id(g_, team)}, {"quote", std::move(quote)}, {"periphery", std::move(periphery)},
{"facilities", std::move(facilities)}, {"blocks", std::move(blocks)},
{"ticketPrice", modern::ui_money(data.ticket_price)}, {"ticketPriceRange", O{{"min", modern::ui_money(8)}, {"max", modern::ui_money(25)}}}});
{"history",std::move(history)},{"table",std::move(table)},{"requiredAttendanceText",ui::original_to_utf8(data.required_attendance_text)},{"ticketPrice", modern::ui_money(data.ticket_price)}, {"ticketPriceRange", O{{"min", modern::ui_money(8)}, {"max", modern::ui_money(25)}}}});
}
if (kind == "advertising") {
// the 14 boards, the shirt and the TV rights with their contract, the open offers per place,
@@ -9941,18 +9946,20 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
static constexpr const char* kFacilities[8] = {"floodlights", "scoreboard", "pitch_heating", "vip_lounge", "pitch", "comfort", "condition", "safety"};
if (kind == "quote.request" && ui_text(*payload, "kind") == "block") {
// {blockId: "block:a".."block:h", places: target total, seats?, roof?}
if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment || stadium_.block_expansion))
return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit).");
const auto quote_id=ui_text(*payload,"quoteId");const bool updating=!quote_id.empty();
if(updating){if(!stadium_.opened||!stadium_.block_expansion||quote_id!="quote:stadium-"+std::to_string(stadium_.scope))return refuse("stale_quote","Dieses Stadionangebot gilt nicht mehr.");}
else if(stadium_.opened&&(stadium_.periphery_quote||stadium_.investment||stadium_.block_expansion))return refuse("quote_open","Ein Stadionangebot ist noch offen (stadium.commit).");
const std::string id = ui_text(*payload, "blockId");
const int slot = id.size() == 7 && id.starts_with("block:") && id[6] >= 'a' && id[6] <= 'h' ? id[6] - 'a' : -1;
const cli::Json* places = ui_field(*payload, "places");
if (slot < 0 || !places || !places->integer() || *places->integer() < 0) return refuse("invalid_payload", "blockId und places nötig.");
if (slot < 0 || !places || !places->integer() || (*places->integer() < 0 || *places->integer()>UINT32_MAX)) return refuse("invalid_payload", "blockId und places nötig.");
const auto flag = [&](const char* key) {
const cli::Json* v = ui_field(*payload, key);
return v && std::holds_alternative<bool>(v->value) && std::get<bool>(v->value);
};
if(updating&&int(stadium_.block_expansion->quote.slot)!=slot)return refuse("stale_quote","Das Angebot gehört zu einem anderen Block.");
if (!stadium_.opened) step(ui::StadiumRequestKind::open);
block_step(ui::StadiumRequestKind::expansion_select, slot, 0, 0);
if(!updating)block_step(ui::StadiumRequestKind::expansion_select, slot, 0, 0);
if (ok) {
auto& d = *stadium_.block_expansion;
const uint32_t total = uint32_t(*places->integer());
@@ -9972,8 +9979,9 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Angebot liegt vor.");
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
} else if (kind == "quote.request") {
if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment || stadium_.block_expansion))
return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit).");
const auto quote_id=ui_text(*payload,"quoteId");const bool updating=!quote_id.empty();
if(updating){if(ui_text(*payload,"kind")!="facility"||!stadium_.opened||!stadium_.investment||!stadium_.option||quote_id!="quote:stadium-"+std::to_string(stadium_.scope))return refuse("stale_quote","Dieses Stadionangebot gilt nicht mehr.");}
else if(stadium_.opened&&(stadium_.periphery_quote||stadium_.investment||stadium_.block_expansion))return refuse("quote_open","Ein Stadionangebot ist noch offen (stadium.commit).");
if (!stadium_.opened) step(ui::StadiumRequestKind::open);
if (ui_text(*payload, "kind") == "periphery") {
int object = -1;
@@ -9989,7 +9997,8 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
if (facility < 0 || !inc || !inc->integer() || *inc->integer() < 1 || *inc->integer() > 3) {
restore(); return refuse("invalid_payload", "facilityId und increment (1 bis 3) nötig.");
}
step(ui::StadiumRequestKind::select_investment, facility);
if(updating&&int(*stadium_.investment)!=facility)return refuse("stale_quote","Das Angebot gehört zu einer anderen Ausstattung.");
if(!updating)step(ui::StadiumRequestKind::select_investment, facility);
if (ok) {
StadiumInvestmentConstants constants;
for (unsigned i = 0; i < 8; ++i) {
+2
View File
@@ -1672,6 +1672,8 @@ bool pay_construction(ModernState& g, int manager, uint32_t price, bool sponsor,
return paid;
}
int periphery_build_weeks(int object) {if(object<0||object>=14)throw FormatError("stadium: invalid periphery object");return kPeripheryDays[object];}
bool build_periphery(ModernState& g, int manager, int object, uint32_t price, WatcomRandom& rand,
const ConstructionNoticeHook& notice) {
if (!modern::pay_construction(g, manager, price, true, rand, notice)) return false;
+1
View File
@@ -227,6 +227,7 @@ bool pay_construction(ModernState& g, int manager, uint32_t price, bool sponsor,
// "Ja" on the offer: pay_construction(price, sponsor) and the construction time of the
// object (CareerSession_DispatchStadium_RuntimeField2[object * 5]) is entered at record +0x1e + object.
int periphery_build_weeks(int object);
bool build_periphery(ModernState& g, int manager, int object, uint32_t price, WatcomRandom& rand,
const ConstructionNoticeHook& notice = {});
+2 -2
View File
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-3.0-only
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
@@ -49,7 +49,7 @@ foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss report
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
endforeach()
foreach(component career_reports rankings career_files statistics_projection toto_projection)
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection)
add_executable(modern_${component}_tests ../../../tests/modern_${component}_tests.cpp)
target_link_libraries(modern_${component}_tests PRIVATE bmh_modern_ui_core)
if(MSVC)
+5
View File
@@ -62,6 +62,11 @@ Json engine_other_projection(const Json &bundle,const Json &index,const Json &re
Json engine_rankings_projection(const Json &bundle,const Json &index,const Json &read,const std::string &league,int scope);
Json engine_fairplay_projection(const Json &bundle,const Json &index,const Json &read);
Json engine_stadium_projection(const Json &bundle,bool future);
Json engine_stadium_quote(const Json &bundle,const Json &draft);
Json engine_stadium_request(const Json &bundle,const Json &draft,const std::string &request_id,bool update=false);
Json engine_stadium_commit(const Json &bundle,bool accept,const std::string &request_id);
Json engine_toto_projection(const Json &bundle);
Json engine_toto_command(const Json &bundle,const Json &quote,const std::string &request_id);
+6 -1
View File
@@ -30,6 +30,7 @@ void App::engine_accept(EngineReply result) {
engine_almanac_sync();
engine_ticket_bind();
engine_toto_poll();
engine_stadium_poll();
engine_contracts_poll();
engine_calendar_sync();
engine_friendly_sync();
@@ -133,6 +134,7 @@ void App::engine_save() {
engine_start("Spielstand wird gespeichert …", [link, output] { auto response = link->save_copy(output); return EngineReply{link, link->snapshot(), response, nullptr}; });
}
void App::engine_quit() {
if(!engine_busy_&&engine_data_.value("stadium",Json()).is_object()&&engine_data_.at("stadium").value("messageType","")=="snapshot"&&engine_data_.at("stadium").at("data").at("quote").is_object()){engine_stadium_exit_=true;engine_stadium_send(engine_stadium_commit(engine_data_,false,editor::new_id("request:ui-")),"cancel");return;}
if (engine_busy_ || engine_files_busy_) { engine_notice_ = "Bitte den laufenden Vorgang abwarten."; dirty_ = true; return; }
if (engine_dirty_) {
confirmation("Die Partie enthält ungespeicherte Änderungen. Vor dem Beenden speichern?",[this]{closed_=true;});
@@ -163,6 +165,7 @@ void App::engine_event(Rml::Event &event) {
if (engine_reports_event(event)) return;
if(menu_=="statistics"&&statistics_event(event))return;
if(menu_=="toto"&&toto_event(event))return;
if(menu_=="stadium"&&stadium_event(event))return;
if(!engine_busy_&&popup_.empty()&&rankings_event(event))return;
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && (menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="statistics") && report_picker_event(event)) return;
@@ -256,6 +259,7 @@ void App::engine_event(Rml::Event &event) {
if (engine_reports_action(action,node)) return;
if(menu_=="statistics"&&statistics_action(action,node))return;
if(menu_=="toto"&&toto_action(action,node))return;
if(menu_=="stadium"&&stadium_action(action,node))return;
if (almanac_action(action,node)) return;
if (engine_friendly_action(action, node)) return;
if ((menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="statistics") && report_picker_action(action,node)) return;
@@ -272,6 +276,7 @@ void App::engine_event(Rml::Event &event) {
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
}
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
else if(action=="engine-open"&&id=="stadium"){menu_=id;stadium_view_=Json::object();stadium_view_defaults(stadium_view_);engine_stadium_sync();refresh();}
else if(action=="engine-open"&&id=="toto"){menu_=id;engine_toto_sync();refresh();}
else if(action=="engine-open"&&id=="statistics"){menu_=id;engine_reports_sync();engine_statistics_load();}
else if(action=="engine-open"&&id=="load"){engine_files_begin("load");}
@@ -305,5 +310,5 @@ void App::engine_event(Rml::Event &event) {
}
Json App::engine_snapshot() const {
return {{"mode", engine_mode_}, {"creation_busy",engine_creation_busy_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
{"response", engine_response_}, {"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
{"response", engine_response_}, {"stadium_view",stadium_view_},{"stadium_value",engine_stadium_value_},{"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
}
+1 -1
View File
@@ -21,7 +21,7 @@ void App::engine_files_poll() {
try {
auto result=engine_files_job_.get();
if(result.operation=="loaded") {
engine_toto_context_=Json();engine_toto_quote_=Json();engine_reports_context_=Json();engine_almanac_context_=Json();engine_friendly_read_=Json();engine_friendly_stage_=0;engine_calendar_season_.clear();engine_calendar_day_=-1;engine_move_id_.clear();report_detail_kind_.clear();engine_player_.clear();lineup_selected_.clear();engine_opening_state_=Json();engine_opening_read_=Json();
stadium_view_=Json::object();engine_stadium_context_=Json();engine_toto_context_=Json();engine_toto_quote_=Json();engine_reports_context_=Json();engine_almanac_context_=Json();engine_friendly_read_=Json();engine_friendly_stage_=0;engine_calendar_season_.clear();engine_calendar_day_=-1;engine_move_id_.clear();report_detail_kind_.clear();engine_player_.clear();lineup_selected_.clear();engine_opening_state_=Json();engine_opening_read_=Json();
engine_mode_=true;engine_dirty_=engine_base_dirty_=false;engine_accept(std::move(*result.engine));source_.reset();entry_catalog_.reset();engine_files_current_id_=result.selected;engine_files_pending_load_.reset();scene_="engine";menu_.clear();reset_files();refresh();return;
}
files_rows_=std::move(result.rows);if(result.metadata.is_object())engine_files_metadata_=std::move(result.metadata);
+4 -2
View File
@@ -120,7 +120,7 @@ void App::engine_render() {
const auto route = id.substr(4);
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
const bool supported = ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
const bool supported = ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
}
}
@@ -129,6 +129,7 @@ void App::engine_render() {
if(menu_=="scorers")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"<div class=\"fill center\">"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"</div>")+"</div>";
if(menu_=="fairplay")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"<div class=\"fill center\">"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"</div>")+"</div>";
if(menu_=="other")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"<div class=\"fill center\">"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"</div>")+"</div>";
if(menu_=="stadium")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Stadion",render_stadium())+"</div>";
if(menu_=="toto")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Toto",render_toto())+"</div>";
if(menu_=="statistics")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Statistiken",engine_statistics_value_.is_object()?render_statistics():"<div class=\"fill center\">"+esc(engine_busy_?"Statistik wird geladen …":engine_notice_)+"</div>")+"</div>";
if(menu_=="league")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"<div class=\"fill center\">"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"</div>")+"</div>";
@@ -146,7 +147,7 @@ void App::engine_render() {
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
}
if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="fairplay") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if ((menu_ == "stadium" || menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="fairplay") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if(menu_=="statistics")out+=render_statistics_trophy();
element("canvas")->SetProperty("overflow",statistics_trophy_.contains("asset")?"visible":"hidden");
@@ -172,6 +173,7 @@ void App::engine_render() {
for (auto *node : underlay) { node->SetProperty("pointer-events", "none"); node->SetProperty("filter", "blur(10dp)"); }
}
if(!report_detail_kind_.empty()&&(menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other"||menu_=="scorers"||menu_=="fairplay"||menu_=="statistics")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#report-underlay button,.rankings-scorers button,.rankings-fairplay button,.statistics-native button,#window-close");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
if(menu_=="stadium"&&stadium_view_.value("dialog",std::string())!=""){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#stadium-underlay button,.window>.titlebar button");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
if(!toto_dialog_.empty()){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#toto-underlay button,.window>.titlebar button");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
if(statistics_trophy_.contains("asset")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".window button,.window input");for(auto *n:nodes)n->SetAttribute("disabled",true);}
if (engine_busy_) {
+208
View File
@@ -0,0 +1,208 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/engine_bridge.hpp"
#include <algorithm>
#include <array>
namespace bmh::modern_ui {
namespace {
void check(bool yes, const char *message) {
if (!yes)
throw editor::Error(message);
}
const Json &read(const Json &bundle) {
validate_engine_desk(bundle);
const auto &r = bundle.at("stadium");
check(r.value("messageType", "") == "snapshot" && r.at("data").value("kind", "") == "stadium",
"Stadion ist derzeit nicht verfügbar.");
for (const auto *key : {"careerId", "worldId", "worldRevision", "stateRevision", "scope"})
check(r.at("meta").at(key) == bundle.at("desktop").at("meta").at(key),
"Der Stadionkontext hat sich geändert.");
return r.at("data");
}
Json command(const Json &b, const std::string &kind, const Json &payload, const std::string &id) {
const auto &m = b.at("desktop").at("meta");
const auto &allowed = m.at("scope").at("allowedCommands");
check(std::find(allowed.begin(), allowed.end(), Json(kind)) != allowed.end(),
"Diese Stadionaktion ist derzeit gesperrt.");
return {{"messageType", "command"},
{"contractVersion", m.at("contractVersion")},
{"careerId", m.at("careerId")},
{"requestId", id},
{"expectedRevision", m.at("stateRevision")},
{"owner", {{"managerId", m.at("scope").at("managerId")}}},
{"kind", kind},
{"payload", payload}};
}
} // namespace
Json engine_stadium_projection(const Json &bundle, bool future) {
const auto &d = read(bundle);
check(d.at("blocks").size() == 8 && d.at("facilities").size() == 8 &&
d.at("periphery").size() == 14,
"Unvollständiges Stadion.");
Json blocks = Json::array(), facilities = Json::array(), periphery = Json::array();
int64_t available = 0, planned = 0, physical = 0;
bool super = true;
for (size_t i = 0; i < 8; ++i) {
const auto &b = d.at("blocks")[i];
const int weeks = b.at("constructionWeeks");
const bool busy = weeks > 0;
const int64_t current = b.at("places"),
target = busy ? b.at("placesAfterConstruction").get<int64_t>() : current;
const bool seats = future && busy ? b.at("seatsAfterConstruction").get<bool>()
: b.at("seats").get<bool>(),
roof = future && busy ? b.at("roofAfterConstruction").get<bool>()
: b.at("roof").get<bool>();
const int64_t display = busy && !future ? 0 : future ? target : current;
blocks.push_back({{"id", b.at("id")},
{"index", i},
{"letter", std::string(1, char('A' + i))},
{"name", b.at("name")},
{"places", current},
{"max_places", b.at("maxPlaces")},
{"seats", b.at("seats")},
{"roof", b.at("roof")},
{"building", busy},
{"display_places", display},
{"display_seats", seats},
{"display_roof", roof},
{"weeks", 0},
{"job", busy ? Json{{"places", target},
{"seats", b.at("seatsAfterConstruction")},
{"roof", b.at("roofAfterConstruction")},
{"weeks", weeks}}
: Json()}});
available += busy ? 0 : current;
physical += current;
planned += target;
super =
super && (future ? target : current) == b.at("maxPlaces").get<int64_t>() && seats && roof;
}
for (size_t i = 0; i < 8; ++i) {
const auto &f = d.at("facilities")[i];
const int level = f.at("level"), weeks = f.at("constructionWeeks"),
target = f.value("plannedLevel", level), shown = future && weeks > 0 ? target : level;
Json labels = i == 2 || i == 3 ? Json({"—", "nicht vorhanden", "vorhanden"})
: i < 2 ? Json({"—", "klein", "mittel", "groß", "mega"})
: Json({"—", "schlecht", "ausreichend", "gut", "sehr gut"});
check(shown >= 0 && shown < int(labels.size()), "Ungültige Ausstattungsstufe.");
facilities.push_back({{"id", f.at("id")},
{"index", i},
{"name", f.at("name")},
{"level", level},
{"max_level", f.at("maxLevel")},
{"display_level", shown},
{"display_label", labels[size_t(shown)]},
{"levels", labels},
{"weeks", 0},
{"rate", nullptr},
{"building", weeks > 0},
{"available", f.at("upgradeAvailable")},
{"job", weeks > 0 ? Json{{"level", target}, {"weeks", weeks}} : Json()}});
}
for (size_t i = 0; i < 14; ++i) {
const auto &p = d.at("periphery")[i];
const int level = i == 0 ? p.at("stage").get<int>()
: p.at("built") == true ? 1
: 0,
max = i == 0 ? p.at("maxStage").get<int>() : 1, days = p.at("constructionDays");
const bool busy = days > 0;
const int target = std::min(max, level + 1);
periphery.push_back({{"id", p.at("id")},
{"index", i},
{"name", p.at("name")},
{"level", level},
{"max_level", max},
{"display_level", future && busy ? target : level},
{"building", busy},
{"job", busy ? Json{{"level", target}, {"weeks", days}} : Json()}});
}
return {{"ok", true},
{"club", d.at("teamId")},
{"name", d.value("name", std::string("Stadion"))},
{"budget", engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash"))},
{"blocks", blocks},
{"facilities", facilities},
{"periphery", periphery},
{"available_capacity", available},
{"planned_capacity", planned},
{"physical_capacity", future ? planned : physical},
{"capacity", future ? planned : available},
{"super_stadium", super}};
}
Json engine_stadium_quote(const Json &bundle, const Json &draft) {
const auto &d = read(bundle);
const auto &q = d.at("quote");
if (!q.is_object())
return {{"ok", false}, {"can_build", false}};
const auto kind = draft.at("kind").get<std::string>();
check(q.at("kind") == kind, "Das Angebot gehört zu einer anderen Ausbauart.");
const int index = draft.at("index");
const auto &row = d.at(kind == "block" ? "blocks"
: kind == "facility" ? "facilities"
: "periphery")
.at(size_t(index));
check(q.at(kind == "block" ? "blockId"
: kind == "facility" ? "facilityId"
: "objectId") == row.at("id"),
"Das Angebot gehört zu einem anderen Objekt.");
const int64_t cost = engine_money_minor(q.at("price"));
Json result = {{"ok", true},
{"can_build", cost > 0},
{"cost", cost},
{"company_percent", q.value("pricePercent", 100)},
{"weeks", q.value("weeks", 0)},
{"options", Json::array()}};
if (kind == "block") {
check(q.at("places") == draft.at("places") && q.at("seats") == draft.at("seats") &&
q.at("roof") == draft.at("roof"),
"Das Blockangebot passt nicht zum Entwurf.");
for (const auto &part : q.at("breakdown")) {
const auto code = part.at("code").get<std::string>();
result[code == "places" ? "placesCost"
: code == "seats" ? "seatsCost"
: "roofCost"] = engine_money_minor(part.at("amount"));
}
}
if (kind == "facility") {
check(q.at("toLevel") == draft.at("level"), "Die Angebotsstufe hat sich geändert.");
for (const auto &option : q.at("options"))
result["options"].push_back(
{{"level", option.at("toLevel")}, {"cost", engine_money_minor(option.at("price"))}});
}
return result;
}
Json engine_stadium_request(const Json &bundle, const Json &draft, const std::string &id,
bool update) {
const auto &d = read(bundle);
const auto kind = draft.at("kind").get<std::string>();
check(kind == "block" || kind == "facility" || kind == "periphery", "Unbekannte Ausbauart.");
const int index = draft.at("index");
const auto &rows = d.at(kind == "block" ? "blocks"
: kind == "facility" ? "facilities"
: "periphery");
check(index >= 0 && size_t(index) < rows.size(), "Unbekanntes Stadionobjekt.");
const auto &row = rows[size_t(index)];
Json payload = {{"kind", kind}};
if (kind == "block") {
payload["blockId"] = row.at("id");
payload["places"] = draft.at("places");
payload["seats"] = draft.at("seats");
payload["roof"] = draft.at("roof");
} else if (kind == "facility") {
payload["facilityId"] = row.at("id");
payload["increment"] = draft.at("level").get<int>() - row.at("level").get<int>();
} else
payload["objectId"] = row.at("id");
if (update) {
check(kind != "periphery" && d.at("quote").is_object(),
"Kein bearbeitbares Angebot vorhanden.");
payload["quoteId"] = d.at("quote").at("id");
}
return command(bundle, "quote.request", payload, id);
}
Json engine_stadium_commit(const Json &bundle, bool accept, const std::string &id) {
const auto &d = read(bundle);
check(d.at("quote").is_object(), "Kein Stadionangebot vorhanden.");
return command(bundle, "stadium.commit",
{{"quoteId", d.at("quote").at("id")}, {"accept", accept}, {"tip", false}}, id);
}
} // namespace bmh::modern_ui
+491
View File
@@ -0,0 +1,491 @@
// SPDX-License-Identifier: GPL-3.0-only
Json App::stadium_overview(bool future) const {
if (!engine_mode_) {
const auto s = snap();
return demo_stadium_view(s.state, *s.world, future, stadium_managed(s));
}
auto value = engine_stadium_projection(engine_data_, future);
const auto club = value.at("club").get<std::string>();
const auto *team = world_->find("clubs", club);
const Json *stadium = nullptr;
if (team && team->value("stadium", Json()).is_string())
stadium = world_->find("stadiums", team->at("stadium"));
if (!stadium)
for (const auto &row : world_->rows("stadiums"))
if (row.value("owner", Json()) == club) {
stadium = &row;
break;
}
if (stadium)
value["name"] = world_->name(*stadium);
return value;
}
Json App::stadium_quote_value() const {
if (engine_mode_) {
try {
return engine_stadium_quote(engine_data_, stadium_view_.at("draft"));
} catch (const std::exception &) {
return {{"ok", false}, {"can_build", false}};
}
}
const auto s = snap();
return demo_stadium_quote(s.state, stadium_view_.at("draft"), *s.world, stadium_managed(s));
}
std::string App::stadium_cash(const Json &value) const {
return engine_mode_ ? (value.is_number_integer()
? money(value.get<int64_t>(), {{"code", "EUR"}, {"minor_units", 2}})
: "—")
: stadium_money(value, *world_);
}
std::string App::stadium_offer_feedback(const Json &quote, bool invalid) const {
if (!engine_mode_)
return stadium_feedback(quote, invalid);
if (invalid)
return "Bitte die Anzahl der Plätze prüfen.";
if (!quote.value("ok", false))
return "Angebot wird aktualisiert …";
if (!quote.value("can_build", false))
return "Bitte einen Ausbau auswählen.";
const int percent = quote.value("company_percent", 100);
return percent != 100 ? "Firmenangebot: " + std::to_string(percent) +
" % des Grundpreises. Bauauftrag erst nach Bestätigung."
: "Bauauftrag erst nach Bestätigung des Gesamtbetrags.";
}
void App::engine_stadium_sync() {
stadium_view_defaults(stadium_view_);
engine_stadium_value_ = Json();
try {
engine_stadium_value_ = stadium_overview(stadium_view_.at("future"));
} catch (const std::exception &) {
}
engine_stadium_context_ = engine_data_.at("desktop").at("meta");
}
void App::engine_stadium_poll() {
engine_stadium_sync();
if (engine_stadium_operation_.empty())
return;
const auto operation = std::exchange(engine_stadium_operation_, std::string());
const bool success = engine_response_.value("messageType", "") == "command_result";
if (!success) {
engine_stadium_exit_ = false;
if (engine_stadium_confirmed_.is_object())
stadium_view_["draft"] = engine_stadium_confirmed_;
stadium_view_["feedback"] = engine_notice_;
return;
}
if (operation == "quote" || operation == "update") {
engine_stadium_confirmed_ = stadium_view_.at("draft");
stadium_view_["feedback"] = "";
focus_after_render_ =
stadium_view_.at("dialog") == "block" ? "stadium-place-range" : "stadium-build";
return;
}
if (operation == "build" || operation == "cancel") {
const auto focus = stadium_view_.value("return_focus", std::string("stadium-data"));
bool built = true;
if (operation == "build") {
const auto &d = stadium_view_.at("draft");
const auto now = stadium_overview(false);
built = now.at(d.at("kind") == "block" ? "blocks"
: d.at("kind") == "facility" ? "facilities"
: "periphery")
.at(d.at("index").get<size_t>())
.at("building");
if (!built) {
auto reason = engine_text(engine_response_.at("feedback"));
if (reason.empty() || reason == "Der Bau beginnt." || reason == "—")
reason = "Der Ausbau wurde nicht begonnen.";
engine_notice_ = reason;
message(reason);
}
if (built && d.at("kind") != "periphery")
stadium_view_["future"] = true;
}
stadium_view_["dialog"] = "";
stadium_view_["draft"] = Json();
stadium_view_["feedback"] = "";
stadium_view_["invalid_places"] = false;
stadium_view_["hint"] = "";
engine_stadium_confirmed_ = Json();
focus_after_render_ = focus;
if (engine_stadium_exit_) {
engine_stadium_exit_ = false;
engine_quit();
}
}
}
void App::engine_stadium_send(const Json &request, const std::string &operation) {
if (engine_busy_ || !engine_fresh_)
return;
engine_stadium_operation_ = operation;
auto link = engine_link_;
engine_start(operation == "build" ? "Stadionbau wird beauftragt …"
: operation == "cancel" ? "Angebot wird geschlossen …"
: "Stadionangebot wird berechnet …",
[link, request] {
const auto response = link->command(request);
return EngineReply{link, link->snapshot(), response, nullptr};
});
}
std::string App::engine_stadium_data() {
const auto &data = engine_data_.at("stadium").at("data");
std::string svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2560 456'><path d='M20 "
"10V436H2540' fill='none' stroke='" +
std::string(theme_ == "silver" ? "#627c8f" : "#7d9aae") +
"' stroke-width='2'/>";
constexpr std::array<const char *, 6> colors{"#8fbaa6", "#8cacc9", "#adb7c1",
"#cf9088", "#c5b384", "#729aae"},
names{"Zuschauer", "Eintritt", "Stadionwert", "Zus. Stadion-Einnahmen",
"Einnahmen", "Stadionkosten"};
for (size_t curve = 0; curve < 6; ++curve)
if (stadium_view_.at("curves")[curve] == true) {
svg += "<polyline fill='none' stroke='" + std::string(colors[curve]) +
"' stroke-width='4' points='";
for (const auto &point : data.at("history")[curve].at(
stadium_view_.at("relative") == true ? "relative" : "absolute"))
svg += scalar(20. + (point[0].get<double>() - 13.) * 2520. / 298.) + "," +
scalar(20. + (point[1].get<double>() - 18.) * 416. / 83.) + " ";
svg += "'/>";
const auto &points = data.at("history")[curve].at(
stadium_view_.at("relative") == true ? "relative" : "absolute");
if (points.size() == 1)
svg += "<circle cx='" + scalar(20. + (points[0][0].get<double>() - 13.) * 2520. / 298.) +
"' cy='" + scalar(20. + (points[0][1].get<double>() - 18.) * 416. / 83.) +
"' r='3' fill='" + std::string(colors[curve]) + "'/>";
}
svg += "</svg>";
std::string out = "<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">" +
picture(renderer_.diagram("stadium-engine-graph", svg, 5120), 2560, 456) +
"</div></div>";
for (size_t i = 0; i < 6; ++i)
out += btn("stadium-curve",
"<span class=\"stadium-curve-color\" style=\"background-color:" +
std::string(colors[i]) + ";\"></span><span class=\"stadium-curve-label\">" +
esc(data.at("history")[i].value("name", std::string(names[i]))) + "</span>",
"stadium-curve",
"id=\"stadium-curve-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
"\" aria-pressed=\"" +
(stadium_view_.at("curves")[i] == true ? "true" : "false") + "\" style=\"" +
rect((i % 3) * 754.666666667, 660 + (i / 3) * 90, 732.666666667, 74) + "\"");
for (int i = 0; i < 2; ++i)
out += btn("stadium-scale", i ? "Relativ" : "Absolut", "stadium-scale",
"id=\"stadium-scale-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
"\" aria-pressed=\"" +
(stadium_view_.at("relative") == bool(i) ? "true" : "false") + "\" style=\"" +
rect(2282, 660 + i * 90, 330, 74) + "\"");
const std::array<const char *, 6> labels{"", "Max. Zuschauer", "Max. Einnahmen (€)",
"Heimspiele", "Ø Zuschauer", "Ges. Einnahmen (€)"};
out += "<div class=\"stadium-data-table\">";
for (size_t row = 0; row < 6; ++row) {
out += "<div class=\"stadium-data-row " +
std::string(row == 0 ? "head"
: row % 2 ? "striped"
: "") +
"\">";
for (size_t col = 0; col < 4; ++col) {
std::string value;
if (!col)
value = labels[row];
else if (!row)
value = col == 1 ? "Liga" : col == 2 ? "DFB-Pokal" : "Europapokal";
else {
const size_t source = row == 1 ? 0 : row == 2 ? 2 : row + 1;
value = data.at("table")[source][col - 1];
if (row <= 2) {
const auto other = data.at("table")[source + 1][col - 1].get<std::string>();
if (!other.empty())
value += " · " + other;
}
}
out += "<div class=\"stadium-data-cell " + std::string(col ? "" : "first") + "\"><span>" +
esc(value) + "</span></div>";
}
out += "</div>";
}
out += "</div>";
const int ticket = int(engine_money_minor(data.at("ticketPrice")) / 100);
out += "<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei " +
std::to_string(ticket) + " € Eintritt: </span><span class=\"stadium-required-value\">" +
esc(data.at("requiredAttendanceText").get<std::string>()) +
"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
const int low = int(engine_money_minor(data.at("ticketPriceRange").at("min")) / 100),
high = int(engine_money_minor(data.at("ticketPriceRange").at("max")) / 100);
for (int price = low; price <= high; ++price)
out += btn(
"stadium-ticket", (price < 10 ? "0" : "") + std::to_string(price), "stadium-ticket-price",
"id=\"stadium-ticket-" + std::to_string(price) + "\" data-id=\"" + std::to_string(price) +
"\" aria-pressed=\"" + (ticket == price ? "true" : "false") + "\"");
return out + "</div>";
}
bool App::engine_stadium_action(const std::string &action, Rml::Element *target) {
if (!action.starts_with("stadium-"))
return false;
if (menu_ != "stadium" || engine_busy_ || !engine_fresh_ || !engine_stadium_value_.is_object() ||
amount_ || !popup_.empty())
return true;
stadium_view_defaults(stadium_view_);
const auto value = target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
const auto index = stadium_integer(value, 255);
if (action == "stadium-cancel") {
if (engine_data_.at("stadium").at("data").at("quote").is_object())
engine_stadium_send(engine_stadium_commit(engine_data_, false, editor::new_id("request:ui-")),
"cancel");
else {
stadium_view_["dialog"] = "";
stadium_view_["draft"] = Json();
refresh();
}
return true;
}
if (action == "stadium-build") {
const auto q = stadium_quote_value();
if (!q.value("can_build", false))
return true;
const auto request = engine_stadium_commit(engine_data_, true, editor::new_id("request:ui-")),
context = engine_data_.at("desktop").at("meta");
confirmation("Diesen Ausbau für " + stadium_cash(q.at("cost")) + " beauftragen?",
[this, request, context] {
if (engine_data_.at("desktop").at("meta") != context) {
message("Das Angebot hat sich geändert. Bitte erneut öffnen.");
return;
}
engine_stadium_send(request, "build");
});
return true;
}
if (action == "stadium-option" && stadium_view_.at("dialog") == "facility" && index) {
auto d = stadium_view_.at("draft");
d["level"] = *index;
stadium_view_["draft"] = d;
engine_stadium_send(
engine_stadium_request(engine_data_, d, editor::new_id("request:ui-"), true), "update");
return true;
}
if (action == "stadium-places-editor" && stadium_view_.at("dialog") == "block") {
const auto overview = stadium_overview(false);
const auto row = overview.at("blocks").at(stadium_view_.at("draft").at("index").get<size_t>());
const auto context = engine_data_.at("desktop").at("meta");
AmountRequest r;
r.title = "Neue Gesamtplätze";
r.unit = "Plätze";
r.value = stadium_view_.at("draft").at("places");
r.min = row.at("places");
r.max = row.at("max_places");
r.step = 1000;
r.suggestion_step = 1000;
r.return_focus = "stadium-place-number";
r.review = false;
r.accept = [this, context](int64_t places) {
if (engine_data_.at("desktop").at("meta") != context || places % 1000)
return false;
stadium_view_["draft"]["places"] = places;
engine_stadium_send(engine_stadium_request(engine_data_, stadium_view_.at("draft"),
editor::new_id("request:ui-"), true),
"update");
return true;
};
open_amount(std::move(r));
return true;
}
if (stadium_view_.at("dialog") != "")
return true;
if (action == "stadium-view") {
stadium_view_["view"] = "panorama";
stadium_view_["hint"] = "";
refresh();
return true;
}
if (action == "stadium-back") {
stadium_view_["view"] = "inside";
stadium_view_["hint"] = "";
refresh();
return true;
}
if (action == "stadium-future") {
stadium_view_["future"] = !stadium_view_.at("future").get<bool>();
refresh();
return true;
}
if (action == "stadium-data") {
stadium_view_["view"] = "data";
refresh();
return true;
}
if (action == "stadium-curve" && index && *index < 6) {
stadium_view_["curves"][size_t(*index)] =
!stadium_view_.at("curves")[size_t(*index)].get<bool>();
refresh();
return true;
}
if (action == "stadium-scale" && index && *index < 2) {
stadium_view_["relative"] = bool(*index);
refresh();
return true;
}
if (action == "stadium-ticket" && index) {
const auto request = engine_ticket_command(engine_data_, *index, editor::new_id("request:ui-"));
confirmation("Eintritt auf " + std::to_string(*index) + " € ändern?",
[this, request] { engine_stadium_send(request, "ticket"); });
return true;
}
const bool block = action == "stadium-block", facility = action == "stadium-facility",
periphery = action == "stadium-periphery";
if (!block && !facility && !periphery)
return true;
if (!index || *index >= (periphery ? 14 : 8))
return true;
const auto overview = stadium_overview(false);
const auto &row = overview.at(block ? "blocks"
: facility ? "facilities"
: "periphery")[size_t(*index)];
if (row.at("building") == true)
return true;
if (facility && row.at("available") != true)
return true;
if (periphery && row.at("level").get<int>() >= row.at("max_level").get<int>())
return true;
Json d = {{"kind", block ? "block" : facility ? "facility" : "periphery"}, {"index", *index}};
if (block) {
d["places"] = row.at("places");
d["seats"] = row.at("seats");
d["roof"] = row.at("roof");
} else
d["level"] = row.at("level").get<int>() + 1;
stadium_view_["draft"] = d;
stadium_view_["dialog"] = d.at("kind");
stadium_view_["feedback"] = "";
stadium_view_["return_focus"] = target->GetId();
engine_stadium_confirmed_ = Json();
engine_stadium_send(engine_stadium_request(engine_data_, d, editor::new_id("request:ui-")),
"quote");
return true;
}
bool App::engine_stadium_event(Rml::Event &event) {
if (menu_ != "stadium" || amount_ || !popup_.empty())
return false;
stadium_view_defaults(stadium_view_);
const auto type = event.GetType();
auto *target = event.GetTargetElement();
const bool key_event = type == "keydown";
const auto key = key_event
? Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0))
: Rml::Input::KI_UNKNOWN;
const bool dialog = stadium_view_.at("dialog") != "";
if (engine_busy_) {
event.StopImmediatePropagation();
return true;
}
if ((key_event && key == Rml::Input::KI_ESCAPE) ||
(dialog && type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
if (dialog)
engine_stadium_action("stadium-cancel", nullptr);
else if (stadium_view_.at("view") != "inside")
engine_stadium_action("stadium-back", nullptr);
else
return false;
event.StopImmediatePropagation();
return true;
}
if (!dialog && stadium_view_.at("view") == "panorama" &&
(type == "mousemove" || type == "focus" || type == "blur")) {
std::string hint;
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
if (n->HasAttribute("data-stadium-hint")) {
hint = n->GetAttribute<Rml::String>("data-stadium-hint", "");
break;
}
if (type == "blur")
hint.clear();
if (stadium_view_.at("hint") != hint) {
stadium_view_["hint"] = hint;
if (auto *n = element("stadium-interaction-hint"))
n->SetInnerRML("<span>" +
esc(hint.empty() ? "Ein Element im Stadionumfeld auswählen." : hint) +
"</span>");
dirty_ = true;
}
}
Rml::Element *range = nullptr;
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
if (n->GetId() == "stadium-place-range") {
range = n;
break;
}
const auto update = [&] {
engine_stadium_send(engine_stadium_request(engine_data_, stadium_view_.at("draft"),
editor::new_id("request:ui-"), true),
"update");
};
if (dialog && stadium_view_.at("dialog") == "block") {
if (range && (type == "input" || type == "change")) {
if (auto *control = dynamic_cast<Rml::ElementFormControl *>(range)) {
const auto places = stadium_integer(control->GetValue(), 255000);
if (places) {
stadium_view_["draft"]["places"] = *places;
sync_stadium_draft();
}
}
event.StopImmediatePropagation();
return true;
}
if (range && type == "mouseup") {
if (stadium_view_.at("draft") != engine_stadium_confirmed_)
update();
event.StopImmediatePropagation();
return true;
}
if (range && key_event &&
(key == Rml::Input::KI_HOME || key == Rml::Input::KI_END || key == Rml::Input::KI_LEFT ||
key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN)) {
const auto row = stadium_overview(false).at("blocks").at(
stadium_view_.at("draft").at("index").get<size_t>());
int places = stadium_view_.at("draft").at("places");
places = key == Rml::Input::KI_HOME ? row.at("places").get<int>()
: key == Rml::Input::KI_END
? row.at("max_places").get<int>()
: places + ((key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN) ? -1000
: 1000);
stadium_view_["draft"]["places"] =
std::clamp(places, row.at("places").get<int>(), row.at("max_places").get<int>());
update();
event.StopImmediatePropagation();
return true;
}
if (type == "change" && target && target->HasAttribute("data-stadium-feature")) {
const auto field = target->GetAttribute<Rml::String>("data-stadium-feature", "");
if (field == "seats" || field == "roof") {
stadium_view_["draft"][field] = target->HasAttribute("checked");
update();
event.StopImmediatePropagation();
return true;
}
}
}
if (dialog && key_event && key == Rml::Input::KI_TAB) {
Rml::ElementList nodes;
if (auto *root = element("stadium-draft"))
root->QuerySelectorAll(nodes, "button,input");
std::erase_if(nodes,
[](auto *n) { return n->HasAttribute("disabled") || !n->IsVisible(true); });
if (!nodes.empty()) {
const auto at = std::find(nodes.begin(), nodes.end(), context_->GetFocusElement());
const int current = at == nodes.end() ? -1 : int(at - nodes.begin()),
count = int(nodes.size());
nodes[size_t((current + count + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % count)]
->Focus(true);
}
event.StopImmediatePropagation();
return true;
}
if (dialog) {
bool inside = false;
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
if (n->GetId() == "stadium-modal")
inside = true;
if (!inside && (type == "click" || type == "mousedown" || type == "mouseup" || key_event)) {
event.StopImmediatePropagation();
return true;
}
}
return false;
}
+14
View File
@@ -112,3 +112,17 @@
Json toto_value() const;
Json toto_summary() const;
Json toto_programme() const;
Json engine_stadium_context_,engine_stadium_value_,engine_stadium_confirmed_;
std::string engine_stadium_operation_;
bool engine_stadium_exit_=false;
Json stadium_overview(bool) const;
Json stadium_quote_value() const;
std::string stadium_cash(const Json &) const;
std::string stadium_offer_feedback(const Json &,bool) const;
std::string engine_stadium_data();
void engine_stadium_sync();
void engine_stadium_poll();
void engine_stadium_send(const Json &,const std::string &);
bool engine_stadium_action(const std::string &,Rml::Element *);
bool engine_stadium_event(Rml::Event &);
+3
View File
@@ -8,6 +8,7 @@ std::optional<int> stadium_integer(const std::string &text,int maximum) {
}
} // namespace
void App::sync_stadium_draft() {
if(engine_mode_){if(auto *button=element("stadium-build"))button->SetAttribute("disabled",true);for(const auto *id:{"stadium-quote-total","stadium-cost-placesCost","stadium-cost-seatsCost","stadium-cost-roofCost"})if(auto *n=element(id))n->SetInnerRML("—");if(auto *n=element("stadium-draft-feedback"))n->SetInnerRML("Angebot für die geänderte Auswahl wird aktualisiert.");if(auto *n=element("stadium-place-number"))n->SetInnerRML("<span class=\"control-label\">"+std::to_string(stadium_view_.at("draft").at("places").get<int64_t>())+"</span>");dirty_=true;return;}
stadium_view_defaults(stadium_view_);if(stadium_view_.at("dialog")==""||!stadium_view_.at("draft").is_object())return;
const auto s=snap();const bool fresh=s.world==stadium_world_&&source_.get()==stadium_source_&&s.revision==stadium_revision_&&stadium_managed(s)==stadium_view_.value("bound_club",std::string());
const auto q=fresh?demo_stadium_quote(s.state,stadium_view_.at("draft"),*s.world,stadium_managed(s)):Json{{"ok",false}};
@@ -25,6 +26,7 @@ void App::sync_stadium_draft() {
dirty_=true;
}
bool App::stadium_action(const std::string &action,Rml::Element *target) {
if(engine_mode_)return engine_stadium_action(action,target);
if(!action.starts_with("stadium-"))return false;
if(menu_!="stadium"||!source_||!world_||amount_||!popup_.empty()||!report_detail_kind_.empty())return true;
stadium_view_defaults(stadium_view_);const auto s=snap();const auto club=stadium_managed(s);
@@ -101,6 +103,7 @@ bool App::stadium_action(const std::string &action,Rml::Element *target) {
refresh();return true;
}
bool App::stadium_event(Rml::Event &event) {
if(engine_mode_)return engine_stadium_event(event);
if(menu_!="stadium"||!source_||!report_detail_kind_.empty())return false;
stadium_view_defaults(stadium_view_);const auto type=event.GetType();auto *target=event.GetTargetElement();
const auto key=type=="keydown"?Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0)):Rml::Input::KI_UNKNOWN;
+18 -14
View File
@@ -59,11 +59,11 @@ std::string stadium_graph_svg(const Json &curves,bool relative,const std::string
} // namespace
std::string App::render_stadium() {
stadium_view_defaults(stadium_view_);const auto snapshot=snap();const auto club=stadium_managed(snapshot);
if(!snapshot.world||club.empty())return "<p class=\"stadium-empty\">Die Stadionvorschau ist derzeit nicht verfügbar.</p>";
stadium_view_defaults(stadium_view_);if(!world_)return "";
const bool future=stadium_view_.at("future").get<bool>();
const auto overview=demo_stadium_view(snapshot.state,*snapshot.world,future,club);
const auto overview=stadium_overview(future);const auto club=overview.value("club",std::string());
if(!overview.value("ok",false))return "<p class=\"stadium-empty\">Die Stadionvorschau ist derzeit nicht verfügbar.</p>";
if(engine_mode_)engine_stadium_value_=overview;
const auto view=stadium_view_.at("view").get<std::string>();
const auto feature=[&](const std::string &kind,bool built,double size) {return picture(renderer_.diagram("stadium-feature-"+kind+(built?"-built-":"-empty-")+theme_,stadium_feature_svg(kind,built,theme_),232),size,size);};
const auto art_overlay=[&](int i,int level,double w,double natural_h) {
@@ -87,7 +87,7 @@ std::string App::render_stadium() {
return "<span class=\"stadium-art-overlay\" style=\""+rect(0,0,w,viewport_h)+"\">"+picture(renderer_.diagram("stadium-card-overlay-"+std::to_string(i)+"-"+std::to_string(level)+"-"+theme_,stadium_svg(body,w,viewport_h),1564),w,viewport_h)+"</span>";
};
std::string out="<div class=\"stadium-screen"+std::string(view=="panorama"?" periphery":"")+"\" id=\"stadium-underlay\">";
if(view!="panorama")out+="<header class=\"stadium-heading\"><div class=\"stadium-heading-copy\"><h2>"+esc(overview.at("name").get<std::string>())+"</h2><p>"+(view=="inside"?"Innenansicht":"Stadiondaten")+"</p></div><div class=\"stadium-summary\"><div><span>"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("</span><strong>")+number(overview.at("capacity").get<int64_t>())+" <small>Plätze</small></strong></div><div><span>Ausbaubudget</span><strong>"+esc(stadium_money(overview.at("budget"),*snapshot.world))+"</strong></div></div></header>";
if(view!="panorama")out+="<header class=\"stadium-heading\"><div class=\"stadium-heading-copy\"><h2>"+esc(overview.at("name").get<std::string>())+"</h2><p>"+(view=="inside"?"Innenansicht":"Stadiondaten")+"</p></div><div class=\"stadium-summary\"><div><span>"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("</span><strong>")+number(overview.at("capacity").get<int64_t>())+" <small>Plätze</small></strong></div><div><span>"+std::string(engine_mode_?"Vereinskasse":"Ausbaubudget")+"</span><strong class=\""+std::string(engine_mode_?money_classes(overview.at("budget").get<int64_t>()):"")+"\">"+esc(stadium_cash(overview.at("budget")))+"</strong></div></div></header>";
if(view=="inside") {
constexpr double bowl_h=1430.0*1045/1505;
out+="<div class=\"stadium-bowl\">"+img("art.stadium-interior-v1.png",1426,bowl_h-4,false,false,2048);
@@ -126,6 +126,8 @@ std::string App::render_stadium() {
} catch(const std::exception &) {out+="<p class=\"stadium-empty\">Die Stadionumfeld-Grafiken sind unvollständig.</p>";}
out+="</div><p id=\"stadium-interaction-hint\" role=\"status\" aria-live=\"polite\"><span>"+esc(stadium_view_.at("hint").get<std::string>().empty()?"Ein Element im Stadionumfeld auswählen.":stadium_view_.at("hint").get<std::string>())+"</span></p>";
} else {
if(engine_mode_)out+=engine_stadium_data();
else {const auto snapshot=snap();
const auto graph=stadium_graph_svg(stadium_view_.at("curves"),stadium_view_.at("relative").get<bool>(),theme_);
out+="<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">"+picture(renderer_.diagram("stadium-graph",graph,7200),2560,456)+"</div></div>";
constexpr std::array<const char*,6> colors{"#8fbaa6","#8cacc9","#adb7c1","#cf9088","#c5b384","#729aae"},names{"Zuschauer","Eintritt","Stadionwert","Zus. Stadion-Einnahmen","Einnahmen","Stadionkosten"};
@@ -140,6 +142,7 @@ std::string App::render_stadium() {
out+="<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei "+esc(cash(ticket))+" Eintritt: </span><span class=\"stadium-required-value\">"+(ticket?number((94000+ticket-1)/ticket):"–")+"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
for(int price=0;price<=25;++price)out+=btn("stadium-ticket",(price<10?"0":"")+std::to_string(price),"stadium-ticket-price","id=\"stadium-ticket-"+std::to_string(price)+"\" data-id=\""+std::to_string(price)+"\" aria-pressed=\""+(price==ticket?"true":"false")+"\" aria-label=\"Eintritt "+std::to_string(price)+" "+esc(money_unit())+"\"");
out+="</div>";
}
}
out+="<nav class=\"stadium-nav\">";
if(view=="panorama") {
@@ -157,11 +160,12 @@ std::string App::render_stadium() {
std::string App::render_stadium_dialog() {
stadium_view_defaults(stadium_view_);if(stadium_view_.at("dialog")=="")return "";
const auto s=snap();if(!s.world||!stadium_view_.at("draft").is_object())return "";
if(!world_||!stadium_view_.at("draft").is_object())return "";
const auto &d=stadium_view_.at("draft");const bool block=d.at("kind")=="block";const int index=d.at("index").get<int>();
const auto overview=demo_stadium_view(s.state,*s.world,false,stadium_managed(s));if(!overview.value("ok",false))return "";
const auto overview=stadium_overview(false);if(!overview.value("ok",false))return "";
const bool periphery=d.at("kind")=="periphery";
const auto &row=overview.at(block?"blocks":periphery?"periphery":"facilities")[size_t(index)];const auto q=demo_stadium_quote(s.state,d,*s.world,stadium_managed(s));
const auto &row=overview.at(block?"blocks":periphery?"periphery":"facilities")[size_t(index)];const auto q=stadium_quote_value();
if(engine_mode_&&!q.value("ok",false))return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" style=\""+rect(226,650,2160,480)+"\"><h2>"+esc(row.at("name").get<std::string>())+" ausbauen</h2><p>"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"</p><nav class=\"stadium-draft-actions\" style=\"top:300dp;\">"+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
if(periphery) {
const int level=d.at("level").get<int>();std::string preview;
if(gui_.contains("stadium.scene"))try {
@@ -172,20 +176,20 @@ std::string App::render_stadium_dialog() {
preview="<span class=\"stadium-periphery-preview\" style=\""+rect(680,174,800,height)+"\">"+img("stadium.scene."+asset,800,height,false,false,1600)+"</span>";
} catch(const std::exception &) {}
const auto title=row.at("name").get<std::string>();
return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,377,2160,1110)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen</span></div>"+preview+"<div class=\"stadium-draft-total\" style=\"top:758dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_money(stadium_field(q,"cost"),*s.world))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:850dp;\">"+esc(stadium_feedback(q,false))+"</p><nav class=\"stadium-draft-actions\" style=\"top:946dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(q.value("can_build",false)?"":"disabled=\"disabled\""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,377,2160,1110)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen</span></div>"+preview+"<div class=\"stadium-draft-total\" style=\"top:758dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:850dp;\">"+esc(stadium_offer_feedback(q,false))+"</p><nav class=\"stadium-draft-actions\" style=\"top:946dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(q.value("can_build",false)?"":"disabled=\"disabled\""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
}
struct Option {int level;Picture art;double height;};std::vector<Option> options;double option_h=0;
if(!block)for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level){const auto a=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(level),false,2048);const double h=a.width?592.0*a.height/a.width:325;options.push_back({level,a,h});option_h=std::max(option_h,h+159);}
if(!block)for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level){if(engine_mode_&&std::none_of(q.at("options").begin(),q.at("options").end(),[&](const auto &option){return option.at("level")==level;}))continue;const auto a=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(level),false,2048);const double h=a.width?592.0*a.height/a.width:325;options.push_back({level,a,h});option_h=std::max(option_h,h+159);}
const double height=block?982.5:option_h+499,total_top=block?687.5:option_h+204,feedback_top=block?776.5:option_h+293,actions_top=block?854.5:option_h+371;
const auto title=block?"Block "+row.at("letter").get<std::string>()+" · "+row.at("name").get<std::string>():row.at("name").get<std::string>();
std::string out="<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,(1864-height)/2,2160,height)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>POC-Budget: "+esc(stadium_money(overview.at("budget"),*s.world))+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",row.at("weeks").get<int>()))+" Wochen</span></div>";
std::string out="<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,(1864-height)/2,2160,height)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+std::string(engine_mode_?"Vereinskasse: ":"POC-Budget: ")+esc(stadium_cash(overview.at("budget")))+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",row.at("weeks").get<int>()))+" Wochen</span></div>";
if(block) {
out+="<section class=\"stadium-place-field\"><strong>Block "+row.at("letter").get<std::string>()+"</strong><p>Aktuell: "+number(row.at("places").get<int64_t>())+" Plätze</p><span class=\"stadium-place-label\"><span>Neue Gesamtplätze</span></span>"+btn("stadium-places-editor",std::to_string(d.at("places").get<int64_t>()),"stadium-place-number amount-trigger","id=\"stadium-place-number\"")+"<input type=\"range\" id=\"stadium-place-range\" min=\""+std::to_string(row.at("places").get<int>())+"\" max=\""+std::to_string(row.at("max_places").get<int>())+"\" step=\"1000\" value=\""+std::to_string(d.at("places").get<int>())+"\" aria-label=\"Neue Gesamtplätze\"/></section><div class=\"stadium-features\">";
const std::array<const char*,2> features{"seats","roof"},labels{"Sitzplätze","Überdachung"};
for(size_t i=0;i<2;++i){const bool built=row.at(features[i]).get<bool>();const bool checked=d.at(features[i]).get<bool>();out+="<label class=\"stadium-feature-row\"><input type=\"checkbox\" id=\"stadium-feature-"+std::string(features[i])+"\" data-stadium-feature=\""+features[i]+"\" "+(checked?"checked=\"checked\" ":"")+(built?"disabled=\"disabled\" ":"")+"/><span class=\"stadium-feature-image\" id=\"stadium-feature-image-"+std::string(features[i])+"\">"+picture(renderer_.diagram("stadium-feature-"+std::string(features[i])+(checked?"-built-":"-empty-")+theme_,stadium_feature_svg(features[i],checked,theme_),232),116,116)+"</span><span>"+labels[i]+"</span></label>";}
out+="</div><dl class=\"stadium-costs\">";
const std::array<const char*,3> keys{"placesCost","seatsCost","roofCost"},names{"Neue Plätze","Sitzplätze","Überdachung"};
for(size_t i=0;i<3;++i)out+="<div class=\"stadium-cost-row\" style=\"top:"+scalar(i*51.5)+"dp;\"><dt>"+std::string(names[i])+"</dt><dd id=\"stadium-cost-"+keys[i]+"\">"+esc(stadium_money(stadium_field(q,keys[i]),*s.world))+"</dd></div>";
for(size_t i=0;i<3;++i)out+="<div class=\"stadium-cost-row\" style=\"top:"+scalar(i*51.5)+"dp;\"><dt>"+std::string(names[i])+"</dt><dd id=\"stadium-cost-"+keys[i]+"\">"+esc(stadium_cash(stadium_field(q,keys[i])))+"</dd></div>";
out+="</dl>";
} else {
const double total=options.size()*640+(options.size()-1)*28,left=52+(2052-total)/2;
@@ -200,10 +204,10 @@ std::string App::render_stadium_dialog() {
art+="<span class=\"stadium-art-overlay\" style=\""+rect(592*x,o.height*y,592*rw,o.height*rh)+"\">"+picture(renderer_.diagram("stadium-option-score-"+std::to_string(o.level)+"-"+theme_,svg,1536),592*rw,o.height*rh)+"</span>";
}
if(index==5){const std::string color=theme_=="silver"?"#805b18":theme_=="matchday"?"#e1c68b":"#e0c99b";const auto svg=stadium_svg("<path d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\" fill=\""+color+"\"/>",48,48);const int n=o.level-1;for(int j=0;j<n;++j)art+="<span class=\"stadium-art-overlay\" style=\""+rect((592-(n*52+(n-1)*8))/2+j*60,(o.height-52)/2,52,52)+"\">"+picture(renderer_.diagram("stadium-option-star-"+theme_,svg,104),52,52)+"</span>";}
out+=btn("stadium-option","<span class=\"stadium-option-art\" style=\"height:"+scalar(o.height)+"dp;top:"+scalar(22+group_offset)+"dp;\">"+art+"</span><strong style=\"top:"+scalar(22+o.height+20+group_offset)+"dp;\">"+esc(row.at("levels")[size_t(o.level)].get<std::string>())+"</strong><span class=\"stadium-option-price\" style=\"top:"+scalar(22+o.height+20+37+20+group_offset)+"dp;\">"+esc(stadium_money(Json(int64_t(o.level-row.at("level").get<int>())*row.at("rate").get<int64_t>()),*s.world))+"</span>","stadium-option","id=\"stadium-option-"+std::to_string(o.level)+"\" data-id=\""+std::to_string(o.level)+"\" aria-pressed=\""+(selected?"true":"false")+"\" style=\""+rect(left+i*668,174,640,option_h)+"\"");
out+=btn("stadium-option","<span class=\"stadium-option-art\" style=\"height:"+scalar(o.height)+"dp;top:"+scalar(22+group_offset)+"dp;\">"+art+"</span><strong style=\"top:"+scalar(22+o.height+20+group_offset)+"dp;\">"+esc(row.at("levels")[size_t(o.level)].get<std::string>())+"</strong><span class=\"stadium-option-price\" style=\"top:"+scalar(22+o.height+20+37+20+group_offset)+"dp;\">"+esc(stadium_cash(engine_mode_?[&]()->Json{for(const auto &option:q.at("options"))if(option.at("level")==o.level)return option.at("cost");return Json();}():Json(int64_t(o.level-row.at("level").get<int>())*row.at("rate").get<int64_t>())))+"</span>","stadium-option","id=\"stadium-option-"+std::to_string(o.level)+"\" data-id=\""+std::to_string(o.level)+"\" aria-pressed=\""+(selected?"true":"false")+"\" style=\""+rect(left+i*668,174,640,option_h)+"\"");
}
}
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_feedback(q,stadium_view_.at("invalid_places").get<bool>()):custom;
out+="<div class=\"stadium-draft-total\" style=\"top:"+scalar(total_top)+"dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_money(stadium_field(q,"cost"),*s.world))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:"+scalar(feedback_top)+"dp;\">"+esc(feedback)+"</p><nav class=\"stadium-draft-actions\" style=\"top:"+scalar(actions_top)+"dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||stadium_view_.at("invalid_places").get<bool>()?"disabled=\"disabled\"":""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_offer_feedback(q,stadium_view_.at("invalid_places").get<bool>()):custom;
out+="<div class=\"stadium-draft-total\" style=\"top:"+scalar(total_top)+"dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:"+scalar(feedback_top)+"dp;\">"+esc(feedback)+"</p><nav class=\"stadium-draft-actions\" style=\"top:"+scalar(actions_top)+"dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||stadium_view_.at("invalid_places").get<bool>()?"disabled=\"disabled\"":""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
return out;
}
+1
View File
@@ -1543,6 +1543,7 @@ public:
#include "modern/ui/engine_files.inc"
#include "modern/ui/engine_statistics.inc"
#include "modern/ui/engine_toto.inc"
#include "modern/ui/engine_stadium.inc"
} // namespace
bool is_modern_world(const fs::path &file) {
try {
+18 -1
View File
@@ -15,7 +15,7 @@ using namespace bmh::modern_ui;
int main(int argc, char **argv) {
try {
const std::string mode=argc>1?argv[1]:"";
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics","prepare-toto","verify-toto","settle-toto"};
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics","prepare-toto","verify-toto","settle-toto","verify-stadium","complete-stadium"};
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac|-shootouts]> <world.obw> <new-output-directory>");
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
@@ -133,6 +133,23 @@ int main(int argc, char **argv) {
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);
write("winner-records.json",Json::parse(cli::dump_json(session.read_statistics(cli::Json::Object{{"kind","winners"}}))));modern::set_current_world(nullptr);return 0;
}
if(mode=="complete-stadium") {
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);uint64_t revision=0;Json expiry=Json::object(),log=Json::array();const auto initial=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","stadium"}},revision)));const auto initial_desk=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));const auto own=initial_desk.at("meta").at("scope").at("teamId");Json jobs=Json::array();for(size_t i=0;i<14;++i)if(initial.at("data").at("periphery")[i].at("constructionDays").get<int>()>0)jobs.push_back(i);if(jobs.empty())throw std::runtime_error("completion fixture has no periphery job");bool complete=false;Json final;
for(int step=0;step<100;++step){const auto desk=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));if(desk.at("meta").at("scope").at("teamId")==own){const auto st=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","stadium"}},revision)));if(st.value("messageType","")=="snapshot"){bool done=true;for(const auto &i:jobs)done=done&&st.at("data").at("periphery")[i.get<size_t>()].at("constructionDays")==0;if(done){complete=true;final=st;break;}}}const auto &meta=desk.at("meta");const Json command={{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:complete-stadium-"+std::to_string(step)},{"careerId",meta.at("careerId")},{"expectedRevision",meta.at("stateRevision")},{"owner",{{"managerId",meta.at("scope").at("managerId")}}},{"kind","session.advance"},{"payload",{{"contractExpiry",expiry}}}};const auto reply=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(command.dump()),revision)));log.push_back(reply);if(reply.value("messageType","")!="command_result"){if(reply.value("code","")=="decision_pending"){const auto id=reply.at("message").at("args").at("playerId").get<std::string>();expiry[id]={{"action","release"}};continue;}throw std::runtime_error(reply.dump());}}
if(!complete)throw std::runtime_error("actual construction did not complete");write("before.json",initial);write("completed.json",final);write("advance.json",log);std::string error;const int manager=session.state().memory.u8(::bmh::layout::ActiveManager);if(!session.save_game(out/"completed.obs",manager,false,error))throw std::runtime_error(error);write("receipt.json",{{"status","passed"},{"advanceCommands",log.size()},{"jobs",jobs}});modern::set_current_world(nullptr);std::cout<<"actual periphery construction completed through session.advance\n";return 0;
}
if(mode=="verify-stadium") {
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);uint64_t revision=0;Json records=Json::array();
const auto bundle=[&]{Json b;for(const auto* kind:{"session","desktop","camps","stadium"})b[kind]=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind",kind}},revision)));return b;};
const auto run=[&](const Json &request){const auto r=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(request.dump()),revision)));records.push_back({{"request",request},{"response",r}});return r;};
const auto checkpoint=[&]{const auto c=session.stadium_checkpoint();return Json{{"randSeed",c.rand.seed()},{"randCalls",std::to_string(c.rand.calls())},{"gameSeed",c.game.seed()},{"gameCalls",std::to_string(c.game.calls())}};};
const auto initial=bundle(),random_before=checkpoint();if(initial!=bundle()||checkpoint()!=random_before)throw std::runtime_error("stadium read changed game");write("before.json",initial);int slot=-1;for(size_t i=0;i<8;++i){const auto &b=initial.at("stadium").at("data").at("blocks")[i];if(b.at("constructionWeeks")==0&&b.at("places").get<int>()+2000<=b.at("maxPlaces").get<int>()){slot=int(i);break;}}if(slot<0)throw std::runtime_error("no expandable actual block");const auto base=initial.at("stadium").at("data").at("blocks")[size_t(slot)];Json draft={{"kind","block"},{"index",slot},{"places",base.at("places").get<int>()+1000},{"seats",base.at("seats")},{"roof",base.at("roof")}};
auto response=run(engine_stadium_request(initial,draft,"request:stadium-open"));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());auto quoted=bundle();const auto opened_rng=checkpoint(),quote_id=quoted.at("stadium").at("data").at("quote").at("id");write("block-quote.json",quoted);draft["places"]=base.at("places").get<int>()+2000;response=run(engine_stadium_request(quoted,draft,"request:stadium-update",true));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());const auto updated=bundle();(void)engine_stadium_quote(updated,draft);write("block-updated.json",updated);if(checkpoint()!=opened_rng||updated.at("stadium").at("data").at("quote").at("id")!=quote_id)throw std::runtime_error("block edit rerolled price/owner");
auto bad=engine_stadium_request(updated,draft,"request:stadium-stale",true);bad["payload"]["quoteId"]="quote:stadium-stale";response=run(bad);if(response.value("code","")!="stale_quote"||bundle()!=updated||checkpoint()!=opened_rng)throw std::runtime_error("stale quote modified owner or RNG");response=run(engine_stadium_commit(updated,false,"request:stadium-cancel"));if(response.value("messageType","")!="command_result"||checkpoint()!=opened_rng||bundle().at("stadium").at("data").at("quote").is_object())throw std::runtime_error("cancel did not release unchanged quote");std::string error;if(!session.save_game(out/"cancelled.obs",0,false,error))throw std::runtime_error(error);
auto current=bundle();int facility=-1;for(size_t i=0;i<8;++i){const auto &f=current.at("stadium").at("data").at("facilities")[i];if(f.at("upgradeAvailable")==true&&f.at("level").get<int>()+2<=f.at("maxLevel").get<int>()){facility=int(i);break;}}if(facility<0)throw std::runtime_error("no actual multiple-tier facility");const int level=current.at("stadium").at("data").at("facilities")[size_t(facility)].at("level");Json fd={{"kind","facility"},{"index",facility},{"level",level+1}};response=run(engine_stadium_request(current,fd,"request:facility-open"));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());current=bundle();const auto frng=checkpoint(),fid=current.at("stadium").at("data").at("quote").at("id");fd["level"]=level+2;response=run(engine_stadium_request(current,fd,"request:facility-update",true));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());current=bundle();write("facility-updated.json",current);if(checkpoint()!=frng||current.at("stadium").at("data").at("quote").at("id")!=fid)throw std::runtime_error("tier edit rerolled owner/RNG");(void)engine_stadium_quote(current,fd);run(engine_stadium_commit(current,false,"request:facility-cancel"));
current=bundle();draft["places"]=base.at("places").get<int>()+1000;response=run(engine_stadium_request(current,draft,"request:build-open"));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());current=bundle();write("build-offer.json",current);response=run(engine_stadium_commit(current,true,"request:build"));if(response.value("messageType","")!="command_result")throw std::runtime_error(response.dump());const auto built=bundle();write("built.json",built);if(built.at("stadium").at("data").at("blocks")[size_t(slot)].at("constructionWeeks").get<int>()<=0)throw std::runtime_error("actual block construction not started");if(!session.save_game(out/"built.obs",0,false,error))throw std::runtime_error(error);
write("commands.json",records);write("receipt.json",{{"status","passed"},{"block",slot},{"facility",facility},{"readOnlyViews",true},{"editsPreserveRandomStreams",true},{"editsPreserveQuoteOwner",true},{"staleQuoteRefused",true},{"actualBuild",true}});modern::set_current_world(nullptr);std::cout<<"actual scoped stadium quotes, pure edits, cancellation and construction passed\n";return 0;
}
if(mode=="settle-toto") {
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);uint64_t revision=0;Json expiry=Json::object(),log=Json::array();bool settled=false;
for(int step=0;step<100;++step){const auto before=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));const auto &meta=before.at("meta");const Json command={{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:settle-toto-"+std::to_string(step)},{"careerId",meta.at("careerId")},{"expectedRevision",meta.at("stateRevision")},{"owner",{{"managerId",meta.at("scope").at("managerId")}}},{"kind","session.advance"},{"payload",{{"contractExpiry",expiry}}}};const auto reply=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(command.dump()),revision)));log.push_back(reply);if(reply.value("messageType","")!="command_result"){if(reply.value("code","")=="decision_pending"){const auto id=reply.at("message").at("args").at("playerId").get<std::string>();expiry[id]={{"action","release"}};continue;}throw std::runtime_error(reply.dump());}if(!session.state().pools.empty()&&session.state().pools[0].paid>0){settled=true;break;}}
+142
View File
@@ -0,0 +1,142 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/engine_bridge.hpp"
#include <iostream>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void check(bool yes, const char *why) {
if (!yes)
throw std::runtime_error(why);
}
template <class F> void rejected(F f) {
bool caught = false;
try {
f();
} catch (const std::exception &) {
caught = true;
}
check(caught, "invalid stadium accepted");
}
Json money(int n) {
return {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(n * 100)}};
}
Json fixture() {
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"},
{"careerId", "career:test"},
{"worldId", "world:test"},
{"worldRevision", "1"},
{"stateRevision", "3"},
{"scope",
{{"role", "club"},
{"managerId", "manager:test"},
{"teamId", "club:test"},
{"allowedCommands", {"quote.request", "stadium.commit"}}}}};
Json b;
for (const auto *kind : {"session", "desktop", "camps", "stadium"})
b[kind] = {{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", kind}}}};
b["desktop"]["data"].update({{"manager", {{"id", "manager:test"}}},
{"team", {{"id", "club:test"}}},
{"accounts", {{"cash", money(5000000)}}}});
b["camps"]["data"]["camps"] = Json::array();
auto &d = b["stadium"]["data"];
d.update({{"teamId", "club:test"},
{"quote", nullptr},
{"blocks", Json::array()},
{"facilities", Json::array()},
{"periphery", Json::array()}});
for (int i = 0; i < 8; ++i) {
d["blocks"].push_back({{"id", "block:" + std::string(1, char('a' + i))},
{"name", "Synthetic block"},
{"places", 4000},
{"maxPlaces", 8000},
{"seats", false},
{"roof", false},
{"seatsAfterConstruction", i == 0},
{"roofAfterConstruction", i == 0},
{"constructionWeeks", i == 0 ? 3 : 0},
{"placesAfterConstruction", i == 0 ? 6000 : 0}});
d["facilities"].push_back({{"id", "facility:" + std::to_string(i)},
{"name", "Synthetic facility"},
{"level", 1},
{"maxLevel", i == 2 || i == 3 ? 2 : 4},
{"plannedLevel", i == 0 ? 3 : 1},
{"constructionWeeks", i == 0 ? 4 : 0},
{"upgradeAvailable", i != 0}});
}
for (int i = 0; i < 14; ++i) {
Json p = {{"id", "periphery:" + std::to_string(i)},
{"name", "Synthetic site"},
{"constructionDays", i == 0 ? 5 : 0}};
if (i == 0) {
p["stage"] = 1;
p["maxStage"] = 4;
} else
p["built"] = false;
d["periphery"].push_back(p);
}
return b;
}
} // namespace
int main() try {
const auto b = fixture(), before = b;
const auto now = engine_stadium_projection(b, false), future = engine_stadium_projection(b, true);
check(now.at("available_capacity") == 28000 && future.at("capacity") == 34000,
"pending block capacity not separated");
check(now.at("blocks")[0].at("display_places") == 0 &&
future.at("blocks")[0].at("display_seats") == true,
"construction seats/capacity ignored");
check(now.at("facilities")[0].at("display_level") == 1 &&
future.at("facilities")[0].at("display_level") == 3,
"planned facility replaced current value");
check(now.at("periphery")[0].at("display_level") == 1 &&
future.at("periphery")[0].at("display_level") == 2 &&
future.at("periphery")[4].at("max_level") == 1,
"periphery invented unsupported parking stages");
check(b == before, "projection changed state");
auto full = b;
for (auto &block : full["stadium"]["data"]["blocks"]) {
block["places"] = 8000;
block["seats"] = true;
block["roof"] = true;
block["constructionWeeks"] = 0;
}
check(engine_stadium_projection(full, false).at("super_stadium") == true,
"super stadium ignores actual maxima/features");
auto quote = b;
quote["stadium"]["data"]["quote"] = {{"id", "quote:stadium-test"},
{"kind", "block"},
{"blockId", "block:b"},
{"places", 5000},
{"seats", true},
{"roof", true},
{"price", money(12345)},
{"weeks", 8},
{"breakdown",
{{{"code", "places"}, {"amount", money(10000)}},
{{"code", "seats"}, {"amount", money(2000)}},
{{"code", "roof"}, {"amount", money(345)}}}}};
const Json draft = {
{"kind", "block"}, {"index", 1}, {"places", 5000}, {"seats", true}, {"roof", true}};
const auto value = engine_stadium_quote(quote, draft);
check(value.at("cost") == 1234500 && value.at("roofCost") == 34500,
"authoritative price rounded or rescaled");
const auto edit = engine_stadium_request(quote, draft, "request:edit", true);
check(edit.at("payload").at("quoteId") == "quote:stadium-test" &&
edit.at("payload").at("blockId") == "block:b" && edit.at("expectedRevision") == "3",
"edit loses exact quote/owner");
const auto cancel = engine_stadium_commit(quote, false, "request:cancel");
check(cancel.at("payload").at("accept") == false && cancel.at("payload").at("tip") == false,
"cancel enables unquoted acceleration");
auto changed = draft;
changed["places"] = 6000;
rejected([&] { engine_stadium_quote(quote, changed); });
auto stale = quote;
stale["stadium"]["meta"]["stateRevision"] = "4";
rejected([&] { engine_stadium_quote(stale, draft); });
std::cout << "stadium: actual capacities, future facilities, periphery limits and scoped prices "
"passed\n";
return 0;
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}