Bind native desk and training camps to Modern OBS careers (by Codex)
This commit is contained in:
1 parent
1fb6499b15
commit
85a1fe5a95
19 files changed
+733
-46
No files matched your search
@@ -52,9 +52,9 @@ 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_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 --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_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 --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_)" -LE external-data --output-on-failure --output-junit modern-ui-results.xml
|
||||
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_)" -LE external-data --output-on-failure --output-junit modern-ui-results.xml
|
||||
- name: Upload test report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
|
||||
@@ -5,6 +5,12 @@ bedienbarer Durchlauf. Noch keine vollständige Umsetzung des HTML-Mockups.**
|
||||
Die normale Classic-Konfiguration bleibt unverändert; die neue Oberfläche
|
||||
wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
|
||||
|
||||
Der [opt-in Engine-Einstieg](integration/ENGINE_ENTRY.md) lädt inzwischen eine
|
||||
echte Modern-OBS-Karriere und bindet Schreibtisch plus Trainingslager an die
|
||||
Session. Preisbestätigung, Buchung und Speichern als neue OBS-Datei sind echte
|
||||
Engineoperationen. Dieser Einstieg ist auf diesen Umfang begrenzt; die übrigen
|
||||
nachfolgend beschriebenen Menüpakete sind weiterhin Präsentationsdemos.
|
||||
|
||||
## Vorhanden
|
||||
|
||||
- [Gemeinsame Auswahlmenüs](controls/selects/README.md) für alle bestehenden
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<!-- SPDX-License-Identifier: GPL-3.0-only -->
|
||||
# Erster nativer Engine-Durchlauf: Schreibtisch und Trainingslager
|
||||
|
||||
Der opt-in Einstieg lädt eine bestehende Modern-Karriere aus einer OBS-Datei.
|
||||
Er ist ein erster vertikaler Integrationsschritt, kein vollständiger spielbarer
|
||||
Modern-Frontend-Ersatz. Der bisherige UI-Demomodus bleibt separat erhalten.
|
||||
|
||||
```sh
|
||||
./OpenBMH --mod /path/to/Diamond_Modern.obw \
|
||||
--ui-career /path/to/career.obs --gui-assets /path/to/gui-resources
|
||||
```
|
||||
|
||||
`--ui-scene camp` öffnet unmittelbar das Trainingslager. `--ui-theme` und
|
||||
`--ui-size` bleiben als visuelle Overrides verfügbar. `--ui-state` bezeichnet
|
||||
weiterhin einen Demo-JSON-Stand und kann nicht mit `--ui-career` kombiniert
|
||||
werden. Die Quelle wird nicht in DemoSource überführt.
|
||||
|
||||
## Gebundener Umfang
|
||||
|
||||
- `ModernSession::ui_read`: `session`, `desktop`, `camps`. Karriere, Manager,
|
||||
Mannschaft, Datum, Saison, Geld, Lagerqualitäten und Angebote kommen aus der
|
||||
Engine. Katalog und Engine müssen dieselbe Welt-ID und Datenrevision haben.
|
||||
- Der bestehende RmlUI-Schreibtisch verwendet die gemeinsamen App-Buttons und
|
||||
Styles. Kalender, Vereinskasse, Porträt und ein tatsächlich gemeldeter nächster
|
||||
Gegner sind gebunden; fehlende Beträge bleiben unbekannt. Andere Widgets werden
|
||||
noch nicht befüllt. Ungebundene Menüs bleiben deaktiviert.
|
||||
- Die vorhandene Trainingslageransicht erhält alle drei Regionen und 18 Lager
|
||||
aus dem Enginevertrag. Aus dem GUI-Katalog kommen ausschließlich Bildschlüssel
|
||||
und fehlende Kartenpositionen, keine Preise, Qualitäten oder Spielregeln.
|
||||
- `camp.book` wird erst nach sichtbarer Preisbestätigung gesendet. Die Anfrage
|
||||
erhält Karriere, stabilen Manager, Revision und Lager-ID aus dem gebundenen
|
||||
Angebot. Lokale Schwerpunkte sind Entwürfe bis zur bestätigten Buchung.
|
||||
Erholung wird nach der Buchung von der Engine übernommen.
|
||||
- `allowedCommands` und bindende Angebotssperren gelten auch im Frontend.
|
||||
Ausreichendes Bargeld wird nicht als zusätzliche erfundene Grenze eingeführt;
|
||||
maßgeblich bleibt die Engine mit ihrer vorhandenen Kreditlogik.
|
||||
|
||||
## Ausführung und Dateien
|
||||
|
||||
Laden, Reads nach einer Aktion, Buchen und Speichern laufen seriell über einen
|
||||
Hintergrundauftrag. RmlUI-Objekte bleiben auf dem UI-Thread. Während eines
|
||||
Auftrags sind Bestätigungen gesperrt. Die DTO-Grenze prüft übereinstimmende
|
||||
Kontexte; Geld wird einmal exakt als ganzzahlige Minor Units gelesen. Es gibt
|
||||
keine Rundreise über Fließkommazahlen und keine zusätzliche Preiskalkulation.
|
||||
Nach einem unklaren Mutationsfehler bleibt der Stand vorsichtshalber ungespeichert
|
||||
markiert und weitere Buchungen gesperrt.
|
||||
|
||||
Die Diskette schreibt eine **neue** OBS-Datei. Die Eingangsdatei und bereits
|
||||
bestehende Ziele werden nicht überschrieben. `--ui-file-export /new/file.obs`
|
||||
setzt das Ziel für automatisierte QA; sonst erscheint der native Dateidialog.
|
||||
Beim Beenden mit ungespeicherten Änderungen erscheint eine Bestätigung.
|
||||
Noch offen sind das vollständige Laden-/Speichern-Menü, Überschreiben mit
|
||||
Bestätigung, Karrierestart, weitere Untermenüs und Anstoß im echten Einstieg.
|
||||
Die Demoabläufe sind davon ausdrücklich getrennt.
|
||||
|
||||
## Prüfung
|
||||
|
||||
`modern_engine_dto_tests` ist synthetisch und prüft Kontextschutz, exakte große
|
||||
Geld-/Revisionswerte, fremde/veraltete Angebote, National-Sperre und ungültige
|
||||
Schwerpunkte. Der opt-in `modern_engine_bridge_probe prepare|verify <world.obw>
|
||||
<new-output-directory>` prüft mit privat bereitgestellten Weltdaten tatsächliche
|
||||
Buchung, Preisabzug, Anfragewiederholung und OBS-Speicherrundreise. Er ist kein
|
||||
bedingungsloser CTest und verteilt keine Originaldaten.
|
||||
|
||||
`--ui-script` unterstützt `engine-wait` zum Abwarten realer Hintergrundaufträge.
|
||||
Snapshots enthalten `engine_view` einschließlich gelesener DTOs, Antwort und
|
||||
lokalem Entwurf. Der Demo-Befehl `checkpoint` lehnt Enginekarrieren ausdrücklich
|
||||
ab; reale Teststände werden über die OBS-Speicheraktion erzeugt.
|
||||
|
||||
Die privaten Bilder, Eingangsspielstände und Replaybefehle liegen unter
|
||||
`bmh_4k_ui/docs/qa/engine-entry-2026-10-27/`. Plattformgrenzen stehen im dortigen
|
||||
Prüfbericht; ein CI-Build ist keine interaktive Windows-/macOS-Abnahme.
|
||||
@@ -1,8 +1,10 @@
|
||||
<!-- SPDX-License-Identifier: GPL-3.0-only -->
|
||||
# Konkrete Anschlussstellen der nativen UI
|
||||
|
||||
Stand: Nachtpaket 27. Oktober 2026. Die Oberfläche läuft weiterhin ausdrücklich
|
||||
als UI-Demo. Diese Übersicht ergänzt den [gestuften Einstieg](MVP_FOR_CLAUDE.md)
|
||||
Stand: 27. Oktober 2026. Neben der UI-Demo gibt es jetzt einen getrennten
|
||||
[opt-in Engine-Einstieg](ENGINE_ENTRY.md) für echte OBS-Karrieren mit Schreibtisch
|
||||
und Trainingslager. Die übrigen hier genannten Presenter laufen weiterhin als
|
||||
UI-Demo. Diese Übersicht ergänzt den [gestuften Einstieg](MVP_FOR_CLAUDE.md)
|
||||
um die tatsächlich vorhandenen C++-Anschlussstellen; sie definiert kein weiteres
|
||||
Protokoll und verlangt keine neue Enginearchitektur.
|
||||
|
||||
|
||||
@@ -130,6 +130,9 @@ int main(int argc, char** argv) {
|
||||
} else if (is("--ui-script") && value) {
|
||||
modern_config.commands = launch::path_from_utf8(args[++i]);
|
||||
modern_demo = true;
|
||||
} else if (is("--ui-career") && value) {
|
||||
modern_config.engine_save = launch::path_from_utf8(args[++i]);
|
||||
modern_demo = true;
|
||||
} else if (is("--ui-state") && value) {
|
||||
modern_config.state = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-preferences") && value) {
|
||||
@@ -179,6 +182,7 @@ int main(int argc, char** argv) {
|
||||
"[--save-directory <directory>] [--mute] [--volume <0..1>] [--no-music] "
|
||||
"[--live-frame-ms <0..1000>]\n");
|
||||
#ifdef OPENBMH_MODERN_UI
|
||||
std::printf("Modern engine entry: --mod <world.obw> --ui-career <career.obs> [--ui-scene camp]\n");
|
||||
std::printf("Modern UI preview: --modern-ui-demo --gui-assets <directory> "
|
||||
"[--ui-scene main|desktop|camp|manager|newgame|tables] "
|
||||
"[--ui-theme midnight|silver|matchday] [--ui-size WIDTHxHEIGHT]\n");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.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 demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp engine_dto.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 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)
|
||||
@@ -26,8 +26,15 @@ else()
|
||||
endif()
|
||||
add_test(NAME modern_select_menu_tests COMMAND modern_select_menu_tests "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
find_package(Threads REQUIRED)
|
||||
add_library(bmh_modern_ui_engine STATIC engine_bridge.cpp)
|
||||
target_link_libraries(bmh_modern_ui_engine PUBLIC bmh_modern_ui_core PRIVATE bmh_modern_session)
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_engine PRIVATE /W4 /utf-8 /bigobj)
|
||||
else()
|
||||
target_compile_options(bmh_modern_ui_engine PRIVATE -Wall -Wextra)
|
||||
endif()
|
||||
add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp)
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_mods bmh_modern_ui_select_menu bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_engine bmh_modern_ui_mods bmh_modern_ui_select_menu bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_core PRIVATE /W4 /utf-8)
|
||||
target_compile_options(bmh_modern_ui PRIVATE /W4 /utf-8 /bigobj)
|
||||
@@ -143,3 +150,14 @@ if(MSVC)
|
||||
target_compile_options(modern_news_catalog_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME modern_news_catalog_tests COMMAND modern_news_catalog_tests "${CMAKE_SOURCE_DIR}/assets/modern/news-catalog.json" "${CMAKE_SOURCE_DIR}/tests/fixtures/modern_news_catalog_reference.json")
|
||||
|
||||
# Pure DTO tests need no proprietary content; the opt-in probe accepts a user's world.
|
||||
add_executable(modern_engine_dto_tests ../../../tests/modern_engine_dto_tests.cpp)
|
||||
target_link_libraries(modern_engine_dto_tests PRIVATE bmh_modern_ui_core)
|
||||
add_test(NAME modern_engine_dto_tests COMMAND modern_engine_dto_tests)
|
||||
add_executable(modern_engine_bridge_probe ../../../tests/modern_engine_bridge_probe.cpp)
|
||||
target_link_libraries(modern_engine_bridge_probe PRIVATE bmh_modern_ui_engine bmh_modern_session)
|
||||
if(MSVC)
|
||||
target_compile_options(modern_engine_dto_tests PRIVATE /utf-8)
|
||||
target_compile_options(modern_engine_bridge_probe PRIVATE /utf-8 /bigobj)
|
||||
endif()
|
||||
@@ -123,6 +123,7 @@ void App::drag_event(Rml::Event &event) {
|
||||
}
|
||||
void App::ProcessEvent(Rml::Event &event) try {
|
||||
const auto type = event.GetType();
|
||||
if (engine_mode_) { engine_event(event); return; }
|
||||
// Native widgets can emit intermediate selected values while their options
|
||||
// are being constructed. Opening a squad menu must stay read-only.
|
||||
if (setting_menu_markup_ && (menu_ == "lineup" || menu_ == "transfer" || menu_ == "news" || menu_ == "settings" || menu_=="widgets" || menu_=="save" || menu_=="load" || menu_=="view-save" || menu_=="view-load") &&
|
||||
@@ -898,7 +899,11 @@ void App::script() {
|
||||
try {
|
||||
const auto command = Json::parse(line);
|
||||
const auto type = command.value("type", std::string());
|
||||
if(type=="window-resize-probe"){
|
||||
if (type == "engine-wait") {
|
||||
const auto until = SDL_GetTicks64() + command.value("timeout_ms", uint64_t(300000));
|
||||
while (engine_busy_ && SDL_GetTicks64() < until) { pump_events(); frame(); SDL_Delay(10); }
|
||||
if (engine_busy_) throw editor::Error("Engine-Vorgang hat das QA-Zeitlimit überschritten.");
|
||||
} else if(type=="window-resize-probe"){
|
||||
// QA-only synthetic event: no OS window or mouse coordinate is changed.
|
||||
int w,h,pw,ph;SDL_GetWindowSize(video_.window,&w,&h);video_.drawable_size(pw,ph);
|
||||
const auto before=context_->GetDimensions();SDL_Event probe{};probe.type=SDL_WINDOWEVENT;probe.window.windowID=SDL_GetWindowID(video_.window);probe.window.event=SDL_WINDOWEVENT_SIZE_CHANGED;probe.window.data1=std::max(1,w/2);probe.window.data2=std::max(1,h/2);handle_event(probe);
|
||||
@@ -975,6 +980,7 @@ void App::script() {
|
||||
} else if (type == "screenshot")
|
||||
screenshot(editor::path(command.at("path").get<std::string>()));
|
||||
else if (type == "checkpoint") {
|
||||
if (engine_mode_) throw editor::Error("Der UI-Demo-Checkpoint speichert keine Enginekarriere. Bitte die OBS-Speicheraktion verwenden.");
|
||||
init_desktop();
|
||||
source_->save(editor::path(command.at("path").get<std::string>()),
|
||||
desktop_);
|
||||
@@ -984,6 +990,7 @@ void App::script() {
|
||||
Json{{"scene", scene_},
|
||||
{"menu", menu_},
|
||||
{"live_view", live_snapshot()},
|
||||
{"engine_view", engine_snapshot()},
|
||||
{"report_picker", report_picker_},
|
||||
{"planning_dialog", planning_dialog_},
|
||||
{"bank_view", bank_view_}, {"bank_property", bank_property_}, {"bank_stock", bank_stock_},
|
||||
@@ -1004,7 +1011,7 @@ void App::script() {
|
||||
{"amount_editor", amount_ ? Json{{"title", amount_->request.title}, {"raw", amount_->raw}, {"review", amount_->review}, {"error", amount_error()}} : Json()},
|
||||
{"display_metrics",[&](){int w,h,pw,ph;SDL_GetWindowSize(video_.window,&w,&h);video_.drawable_size(pw,ph);const auto d=context_->GetDimensions();return Json{{"logical",{w,h}},{"drawable",{pw,ph}},{"context",{d.x,d.y}}};}()},
|
||||
{"source_revision", source_ ? Json(snap().revision) : Json()},
|
||||
{"game_dirty", source_ && source_->dirty()},
|
||||
{"game_dirty", engine_mode_ ? engine_dirty_ : source_ && source_->dirty()},
|
||||
{"desktop_dirty", desktop_ != saved_desktop_},
|
||||
{"almanac_view", {{"year", almanac_year_}, {"date", almanac_day_}, {"id", almanac_match_}, {"tab", almanac_tab_}}},
|
||||
{"report_detail", {{"kind", report_detail_kind_},
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
Json from_engine(const cli::Json &v) { return Json::parse(cli::dump_json(v)); }
|
||||
}
|
||||
struct EngineBridge::Impl {
|
||||
modern::WorldPackage package;
|
||||
std::unique_ptr<content::Mount> mount;
|
||||
std::unique_ptr<modern::app::ModernSession> session;
|
||||
fs::path input;
|
||||
uint64_t revision = 0;
|
||||
Impl(const fs::path &world, const fs::path &save) : package(modern::open_world_package(world)), input(fs::weakly_canonical(save)) {
|
||||
if (!fs::is_regular_file(save)) throw editor::Error("Modern-Spielstand nicht gefunden.");
|
||||
modern::set_current_world(package.world);
|
||||
try {
|
||||
mount = std::make_unique<content::Mount>(world, package.classic);
|
||||
session = std::make_unique<modern::app::ModernSession>(mount->root(), 1u, save, false);
|
||||
} catch (...) { modern::set_current_world(nullptr); throw; }
|
||||
}
|
||||
~Impl() { session.reset(); mount.reset(); modern::set_current_world(nullptr); }
|
||||
};
|
||||
EngineBridge::EngineBridge(std::unique_ptr<Impl> p) : impl_(std::move(p)) {}
|
||||
EngineBridge::~EngineBridge() = default;
|
||||
std::shared_ptr<EngineBridge> EngineBridge::open(const fs::path &world, const fs::path &save) {
|
||||
return std::shared_ptr<EngineBridge>(new EngineBridge(std::make_unique<Impl>(world, save)));
|
||||
}
|
||||
Json EngineBridge::snapshot() const {
|
||||
Json bundle = Json::object();
|
||||
for (const auto *kind : {"session", "desktop", "camps"})
|
||||
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
|
||||
validate_engine_desk(bundle);
|
||||
return bundle;
|
||||
}
|
||||
Json EngineBridge::command(const Json &request) {
|
||||
return from_engine(impl_->session->ui_command(cli::parse_json(request.dump()), impl_->revision));
|
||||
}
|
||||
Json EngineBridge::save_copy(const fs::path &path) {
|
||||
if (fs::weakly_canonical(path) == impl_->input || fs::exists(path))
|
||||
throw editor::Error("Bitte eine neue Datei wählen. Der geladene Spielstand wird nicht überschrieben.");
|
||||
const auto bundle = snapshot();
|
||||
const auto slot = bundle.at("desktop").at("data").at("manager").at("slot").get<int>();
|
||||
std::string error;
|
||||
if (!impl_->session->save_game(path, slot, false, error)) throw editor::Error(error);
|
||||
return {{"messageType", "saved"}, {"path", editor::utf8(path)}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Engine DTOs remain separate from DemoSource's presentation checkpoints.
|
||||
void validate_engine_desk(const Json &bundle);
|
||||
int64_t engine_money_minor(const Json &money);
|
||||
Json engine_camp_command(const Json &bundle, const std::string &camp,
|
||||
const Json &focus, const std::string &request_id);
|
||||
|
||||
// Single-session facade. Its owner serializes all calls on a background worker.
|
||||
// No RmlUI objects or callbacks cross this boundary.
|
||||
class EngineBridge {
|
||||
public:
|
||||
static std::shared_ptr<EngineBridge> open(const fs::path &world, const fs::path &save);
|
||||
~EngineBridge();
|
||||
Json snapshot() const;
|
||||
Json command(const Json &request);
|
||||
Json save_copy(const fs::path &path);
|
||||
private:
|
||||
struct Impl;
|
||||
explicit EngineBridge(std::unique_ptr<Impl>);
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
struct EngineReply {
|
||||
std::shared_ptr<EngineBridge> connection;
|
||||
Json bundle, response;
|
||||
std::shared_ptr<const Catalog> catalog;
|
||||
};
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,147 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::engine_start(std::string label, std::function<EngineReply()> job, bool mutating) {
|
||||
if (engine_busy_) return;
|
||||
engine_base_dirty_ = engine_dirty_;
|
||||
if (mutating) { engine_dirty_ = true; engine_fresh_ = false; }
|
||||
engine_operation_ = std::move(label); engine_busy_ = true;
|
||||
engine_job_ = std::async(std::launch::async, std::move(job)); refresh();
|
||||
}
|
||||
void App::engine_poll() {
|
||||
if (!engine_busy_ || engine_job_.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) return;
|
||||
engine_busy_ = false;
|
||||
try {
|
||||
auto result = engine_job_.get();
|
||||
validate_engine_desk(result.bundle);
|
||||
engine_fresh_ = true;
|
||||
if (result.catalog) { world_ = std::move(result.catalog); bind_world(world_); }
|
||||
engine_link_ = std::move(result.connection); engine_data_ = std::move(result.bundle);
|
||||
engine_response_ = std::move(result.response);
|
||||
if (engine_response_.value("messageType", "") == "command_result") {
|
||||
engine_dirty_ = true; engine_notice_ = "Trainingslager gebucht · Änderungen noch nicht gespeichert.";
|
||||
} else if (engine_response_.value("messageType", "") == "error") {
|
||||
engine_dirty_ = engine_base_dirty_;
|
||||
engine_notice_ = "Buchung abgewiesen: " + engine_response_.value("code", "unknown_error");
|
||||
} else if (engine_response_.value("messageType", "") == "saved") {
|
||||
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
|
||||
} else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
|
||||
const auto &f = engine_data_.at("camps").at("data").at("focus");
|
||||
engine_focus_ = {{"condition", f.at("condition")}, {"technique", f.at("technique")}, {"play", f.at("play")}};
|
||||
if (engine_camp_.empty() && !engine_data_.at("camps").at("data").at("camps").empty())
|
||||
engine_camp_ = engine_data_.at("camps").at("data").at("camps").front().at("id");
|
||||
} catch (const std::exception &e) { engine_notice_ = e.what(); }
|
||||
refresh();
|
||||
}
|
||||
void App::engine_frame() {
|
||||
engine_poll();
|
||||
if (needs_render_) engine_render();
|
||||
render_popup(); context_->Update();
|
||||
if (popup_.empty() && !focus_after_render_.empty()) {
|
||||
if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_);
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); renderer_.EndFrame(); video_.present(); dirty_ = false;
|
||||
}
|
||||
void App::engine_save() {
|
||||
if (engine_busy_ || !engine_link_) return;
|
||||
auto output = config_.file_export;
|
||||
if (output.empty()) {
|
||||
NFD::Guard guard; NFD::UniquePath chosen;
|
||||
const nfdfilteritem_t filters[] = {{"OpenBMH-Spielstand", "obs"}};
|
||||
const auto result = NFD::SaveDialog(chosen, filters, 1, nullptr, "openbmh-career.obs");
|
||||
if (result == NFD_CANCEL) return;
|
||||
if (result != NFD_OKAY) throw editor::Error("Die Dateiauswahl konnte nicht geöffnet werden.");
|
||||
output = editor::path(chosen.get());
|
||||
}
|
||||
auto link = engine_link_;
|
||||
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_notice_ = "Bitte den laufenden Vorgang abwarten."; dirty_ = true; return; }
|
||||
if (engine_dirty_) confirmation("Ungespeicherte Änderungen verwerfen und beenden? Über die Diskette kannst du zuvor eine neue OBS-Datei speichern.", [this] { closed_ = true; });
|
||||
else closed_ = true;
|
||||
}
|
||||
void App::engine_event(Rml::Event &event) {
|
||||
const auto type = event.GetType(); auto *target = event.GetTargetElement();
|
||||
if (type == "keydown") keyboard_navigation_ = true;
|
||||
if (type == "mousedown") keyboard_navigation_ = false;
|
||||
Rml::ElementFormControl *range = nullptr;
|
||||
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
|
||||
if (node->GetId().starts_with("camp-focus-") && !node->HasAttribute("disabled")) {
|
||||
range = dynamic_cast<Rml::ElementFormControl *>(node); break;
|
||||
}
|
||||
if (popup_.empty() && !engine_busy_ && range && type == "mouseup") {
|
||||
focus_after_render_ = range->GetId(); dirty_ = true;
|
||||
}
|
||||
if (popup_.empty() && !engine_busy_ && range && type == "keydown") {
|
||||
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (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 int index = range->GetAttribute<int>("data-id", -1);
|
||||
if (index >= 0 && index < 3) {
|
||||
const int value = key == Rml::Input::KI_HOME ? 0 : key == Rml::Input::KI_END ? 15 : std::clamp(std::stoi(range->GetValue()) + (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN ? -1 : 1), 0, 15);
|
||||
range->SetValue(std::to_string(value));
|
||||
engine_focus_[std::array<const char *, 3>{"condition", "technique", "play"}[size_t(index)]] = value;
|
||||
element("camp-value-" + std::to_string(index))->SetInnerRML(std::to_string(value) + " / 15");
|
||||
element("camp-value-3")->SetInnerRML("—"); element("camp-focus-3")->SetProperty("visibility", "hidden");
|
||||
dirty_ = true; event.StopImmediatePropagation(); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) {
|
||||
if (!popup_.empty()) { popup_.clear(); confirm_ = {}; dirty_ = true; }
|
||||
else if (!engine_busy_ && !menu_.empty()) { menu_.clear(); refresh(); }
|
||||
else engine_quit();
|
||||
event.StopImmediatePropagation(); return;
|
||||
}
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_TAB) {
|
||||
auto *root = !popup_.empty() ? element("popup") : !menu_.empty() ? doc_->QuerySelector(".window") : element("canvas"); Rml::ElementList controls;
|
||||
if (!root) return;
|
||||
root->QuerySelectorAll(controls, "button,input");
|
||||
controls.erase(std::remove_if(controls.begin(), controls.end(), [](auto *node) { return !node->IsVisible(true) || node->HasAttribute("disabled"); }), controls.end());
|
||||
if (!controls.empty()) {
|
||||
const auto found = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
||||
const int index = found == controls.end() ? -1 : int(found - controls.begin());
|
||||
controls[size_t((index + int(controls.size()) + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % int(controls.size()))]->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation(); return;
|
||||
}
|
||||
if (engine_busy_) return;
|
||||
if ((type == "input" || type == "change") && menu_ == "camp" && popup_.empty() && target->GetId().starts_with("camp-focus-")) {
|
||||
const int index = target->GetAttribute<int>("data-id", -1);
|
||||
if (index < 0 || index > 2) return;
|
||||
const int value = std::stoi(dynamic_cast<Rml::ElementFormControl *>(target)->GetValue());
|
||||
if (value < 0 || value > 15) return;
|
||||
engine_focus_[std::array<const char *, 3>{"condition", "technique", "play"}[size_t(index)]] = value;
|
||||
element("camp-value-" + std::to_string(index))->SetInnerRML(std::to_string(value) + " / 15");
|
||||
element("camp-value-3")->SetInnerRML("—");
|
||||
element("camp-focus-3")->SetProperty("visibility", "hidden"); dirty_ = true; return;
|
||||
}
|
||||
if (type != "click") return;
|
||||
for (auto *node = target; node && node != doc_; node = node->GetParentNode()) {
|
||||
if (!node->HasAttribute("data-action") || node->HasAttribute("disabled")) continue;
|
||||
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
|
||||
if (!popup_.empty()) {
|
||||
if (action == "popup-close") { popup_.clear(); confirm_ = {}; dirty_ = true; }
|
||||
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
|
||||
return;
|
||||
}
|
||||
if (action == "close") { menu_.clear(); refresh(); }
|
||||
else if (action == "engine-open" && id == "save") engine_save();
|
||||
else if (action == "engine-open" && id == "camp") { menu_ = "camp"; refresh(); }
|
||||
else if (action == "camp-region") { selections_["camp-region"] = id; refresh(); }
|
||||
else if (action == "camp-select") { engine_camp_ = id; refresh(); }
|
||||
else if (action == "camp-remember" && engine_fresh_) {
|
||||
const auto command = engine_camp_command(engine_data_, engine_camp_, engine_focus_, editor::new_id("request:ui-"));
|
||||
const auto &camps = engine_data_.at("camps").at("data").at("camps");
|
||||
const auto chosen = std::find_if(camps.begin(), camps.end(), [&](const auto &camp) { return camp.at("id") == engine_camp_; });
|
||||
confirmation(engine_text(chosen->at("name")) + " für " + engine_price(chosen->at("quote").at("total")) + " verbindlich buchen?", [this, command] {
|
||||
auto link = engine_link_;
|
||||
engine_start("Trainingslager wird gebucht …", [link, command] { auto response = link->command(command); return EngineReply{link, link->snapshot(), response, nullptr}; }, true);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
Json App::engine_snapshot() const {
|
||||
return {{"mode", engine_mode_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"response", engine_response_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void require(bool yes, const char *message) {
|
||||
if (!yes) throw editor::Error(message);
|
||||
}
|
||||
uint64_t revision(const Json &v) {
|
||||
require(v.is_string(), "Engine-Revision ist keine Dezimalzeichenkette.");
|
||||
const auto &s = v.get_ref<const std::string &>();
|
||||
uint64_t n = 0;
|
||||
const auto r = std::from_chars(s.data(), s.data() + s.size(), n);
|
||||
require(!s.empty() && r.ec == std::errc() && r.ptr == s.data() + s.size(),
|
||||
"Ungültige Engine-Revision.");
|
||||
return n;
|
||||
}
|
||||
}
|
||||
int64_t engine_money_minor(const Json &money) {
|
||||
require(money.is_object() && money.value("currency", "") == "EUR" &&
|
||||
money.value("minorUnits", -1) == 2 && money.at("minor").is_string(),
|
||||
"Nicht unterstützte Engine-Geldeinheit.");
|
||||
const auto &s = money.at("minor").get_ref<const std::string &>();
|
||||
int64_t n = 0;
|
||||
const auto r = std::from_chars(s.data(), s.data() + s.size(), n);
|
||||
require(!s.empty() && r.ec == std::errc() && r.ptr == s.data() + s.size(),
|
||||
"Ungültiger Engine-Geldbetrag.");
|
||||
return n;
|
||||
}
|
||||
void validate_engine_desk(const Json &bundle) {
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
(void)revision(meta.at("stateRevision"));
|
||||
require(meta.at("careerId").is_string() && !meta.at("careerId").get<std::string>().empty() &&
|
||||
meta.at("worldId").is_string() && meta.at("scope").at("managerId").is_string(),
|
||||
"Engine-Kontext fehlt.");
|
||||
for (const auto *kind : {"session", "desktop", "camps"}) {
|
||||
const auto &item = bundle.at(kind);
|
||||
require(item.value("messageType", "") == "snapshot" && item.at("data").value("kind", "") == kind,
|
||||
"Engine-Ansicht ist nicht verfügbar.");
|
||||
const auto &other = item.at("meta");
|
||||
for (const auto *key : {"contractVersion", "careerId", "worldId", "worldRevision", "stateRevision", "scope"})
|
||||
require(other.at(key) == meta.at(key), "Engine-Ansichten haben unterschiedliche Kontexte.");
|
||||
require(other.value("contractVersion", "") == "bmh-modern-ui@draft1", "Unbekannter Engine-Vertrag.");
|
||||
}
|
||||
const auto &desk = bundle.at("desktop").at("data");
|
||||
require(desk.at("manager").at("id") == meta.at("scope").at("managerId") &&
|
||||
desk.at("team").at("id") == meta.at("scope").at("teamId"),
|
||||
"Manager oder Mannschaft passen nicht zum Engine-Kontext.");
|
||||
(void)engine_money_minor(desk.at("accounts").at("cash"));
|
||||
std::set<std::string> ids;
|
||||
for (const auto &camp : bundle.at("camps").at("data").at("camps"))
|
||||
require(camp.at("id").is_string() && ids.insert(camp.at("id").get<std::string>()).second,
|
||||
"Doppelte Trainingslager-ID.");
|
||||
}
|
||||
Json engine_camp_command(const Json &bundle, const std::string &id,
|
||||
const Json &focus, const std::string &request_id) {
|
||||
validate_engine_desk(bundle);
|
||||
require(!request_id.empty(), "Anfrage-ID fehlt.");
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
require(commands.is_array() && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end(), "Trainingslagerbuchung ist in diesem Kontext gesperrt.");
|
||||
require(meta.at("scope").at("role") == "club", "Trainingslager sind am National-Schreibtisch gesperrt.");
|
||||
const Json *chosen = nullptr;
|
||||
for (const auto &camp : bundle.at("camps").at("data").at("camps"))
|
||||
if (camp.at("id") == id) chosen = &camp;
|
||||
require(chosen, "Unbekanntes Trainingslager.");
|
||||
const auto "e = chosen->at("quote");
|
||||
require(quote.is_object() && quote.value("allowed", false), "Dieses Trainingslager kann derzeit nicht gebucht werden.");
|
||||
require(quote.at("expectedRevision") == meta.at("stateRevision") &&
|
||||
quote.at("ownerManagerId") == meta.at("scope").at("managerId") &&
|
||||
quote.at("teamId") == meta.at("scope").at("teamId") &&
|
||||
quote.at("scopeId") == meta.at("scope").at("scopeId"),
|
||||
"Das Trainingslagerangebot ist veraltet oder gehört einem anderen Manager.");
|
||||
require(engine_money_minor(quote.at("total")) >= 0, "Ungültiger Trainingslagerpreis.");
|
||||
require(focus.is_object() && focus.size() == 3, "Ungültige Trainingsschwerpunkte.");
|
||||
for (const auto *key : {"condition", "technique", "play"})
|
||||
require(focus.at(key).is_number_integer() && focus.at(key).get<int64_t>() >= 0 &&
|
||||
focus.at(key).get<uint64_t>() <= 15, "Trainingsschwerpunkt außerhalb des Bereichs 0–15.");
|
||||
return {{"messageType", "command"}, {"requestId", request_id},
|
||||
{"careerId", meta.at("careerId")}, {"expectedRevision", meta.at("stateRevision")},
|
||||
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", "camp.book"}, {"payload", {{"campId", id}, {"focus", focus}}}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,102 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
std::string engine_text(const Json &v) {
|
||||
return v.is_string() ? v.get<std::string>() : v.is_object() ? v.value("text", "") : "—";
|
||||
}
|
||||
std::string engine_price(const Json &v) {
|
||||
return money(engine_money_minor(v), {{"code", "EUR"}, {"minor_units", 2}});
|
||||
}
|
||||
}
|
||||
Json App::engine_camp_view() const {
|
||||
const auto art = Json::parse(editor::read_file(gui_.root() / "gui-assets.json")).at("demo");
|
||||
const auto &data = engine_data_.at("camps").at("data");
|
||||
Json camps = Json::array(), maps = Json::array();
|
||||
for (const auto &map : data.at("maps"))
|
||||
maps.push_back({{"id", map.at("id")}, {"name", engine_text(map.at("name"))}});
|
||||
for (const auto &item : data.at("camps")) {
|
||||
const auto &q = item.at("quality");
|
||||
Json camp = {{"id", item.at("id")}, {"map", item.at("mapId")},
|
||||
{"name", engine_text(item.at("name"))}, {"place", item.at("place")},
|
||||
{"quality", {q.at("pitch"), q.at("fitness"), q.at("catering"), q.at("lodging")}},
|
||||
{"price", nullptr}, {"gui_image", ""}, {"positioned", false}};
|
||||
// GUI placement is presentation metadata only. Never copy prices, quality,
|
||||
// focus or booking rules from the GUI resource catalogue into a real career.
|
||||
for (const auto &ref : art.at("training_camps"))
|
||||
if (ref.at("id") == item.at("id") && ref.at("map") == item.at("mapId")) {
|
||||
camp["x"] = ref.at("x"); camp["y"] = ref.at("y"); camp["positioned"] = true;
|
||||
}
|
||||
if (item.at("position").is_object()) {
|
||||
camp["x"] = item.at("position").at("x"); camp["y"] = item.at("position").at("y"); camp["positioned"] = true;
|
||||
}
|
||||
auto image = item.value("guiImageKey", "");
|
||||
if (image.starts_with("gui:camp/")) camp["gui_image"] = "camp." + image.substr(9);
|
||||
if (item.at("quote").is_object()) camp["price"] = engine_money_minor(item.at("quote").at("total"));
|
||||
camps.push_back(std::move(camp));
|
||||
}
|
||||
return {{"maps", maps}, {"training_camps", camps}};
|
||||
}
|
||||
void App::engine_render() {
|
||||
doc_->SetClassNames(theme_);
|
||||
std::string out;
|
||||
if (engine_data_.empty()) {
|
||||
out = "<div class=\"fill center\"><div class=\"panel\" style=\"padding:70dp;\"><h1>OpenBMH</h1><p>" +
|
||||
esc(engine_busy_ ? "Spielstand wird geladen …" : engine_notice_) + "</p></div></div>";
|
||||
} else {
|
||||
const auto &desk = engine_data_.at("desktop").at("data"), &meta = engine_data_.at("desktop").at("meta");
|
||||
const auto &team = desk.at("team"), &person = desk.at("manager");
|
||||
const auto *club = world_->find("clubs", team.at("id").get<std::string>());
|
||||
out = "<div class=\"desktop-layer\"><div class=\"info-bar\"><div class=\"identity\">" + crest(club, 82) +
|
||||
"<span><strong>" + esc(engine_text(team.at("name"))) + "</strong><small>" + esc(engine_text(person.at("name"))) +
|
||||
"</small></span></div><div class=\"info-date\">" + esc(meta.at("date").get<std::string>()) + "<small>" +
|
||||
esc(meta.at("season").at("label").get<std::string>()) + "</small></div><div class=\"info-cash\"><small>Guthaben</small><strong id=\"engine-cash\">" +
|
||||
esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div></div>";
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
const auto style = rect(o.at("x"), o.at("y"), o.at("w"), o.at("h"));
|
||||
if (o.value("widget", false)) {
|
||||
std::string body;
|
||||
if (id == "portrait") {
|
||||
auto portrait = person.value("portraitGuiKey", "");
|
||||
if (portrait.starts_with("gui:manager/photo/"))
|
||||
body = img("manager." + portrait.substr(18), o.at("w"), o.at("h"), false, false, 768);
|
||||
body += "<div class=\"desk-portrait-caption\"><small>Manager</small><strong>" + esc(person.at("name").get<std::string>()) + "</strong></div>";
|
||||
} else if (id == "calendar") {
|
||||
const auto date = meta.at("date").get<std::string>();
|
||||
const int y = std::stoi(date.substr(0, 4)), m = std::stoi(date.substr(5, 2)), d = std::stoi(date.substr(8, 2));
|
||||
const auto ymd = std::chrono::year_month_day{std::chrono::year(y), std::chrono::month(unsigned(m)), std::chrono::day(unsigned(d))};
|
||||
if (!ymd.ok()) throw editor::Error("Ungültiges Engine-Datum.");
|
||||
const std::array<const char *, 12> months{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
const std::array<const char *, 7> weekdays{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};
|
||||
body = "<div class=\"desk-calendar-month\"><span>" + std::string(months[size_t(m - 1)]) + " " + std::to_string(y) + "</span></div><div class=\"desk-calendar-body\"><span>" + weekdays[std::chrono::weekday{std::chrono::sys_days(ymd)}.c_encoding()] + "</span><strong>" + std::to_string(d) + "</strong><small>" + esc(meta.at("season").at("label").get<std::string>()) + "</small></div>";
|
||||
} else if (id == "account") {
|
||||
const auto savings = desk.at("accounts").at("savings");
|
||||
body = widget_heading("Vereinskasse", false) + "<div class=\"desk-account-main\"><span>Guthaben</span><strong>" + esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div><div class=\"desk-account-bottom\"><div><span>Sparbuch</span><strong>" + (savings.is_null() ? std::string("—") : esc(engine_price(savings))) + "</strong></div>" + btn("engine-unavailable", glyph("ticket", 36) + "<span><span>Eintritt</span><strong>—</strong></span>", "desk-ticket", "disabled") + "</div>";
|
||||
} else if (id == "opponent-crest" && desk.at("nextFixture").is_object()) {
|
||||
const auto &next = desk.at("nextFixture");
|
||||
const auto &other = next.at(next.at("home").at("id") == team.at("id") ? "away" : "home");
|
||||
body = widget_heading("Nächster Gegner", false) + "<div class=\"center\" style=\"padding:30dp;\">" + crest(world_->find("clubs", other.at("id").get<std::string>()), 220) + "<p>" + esc(engine_text(other.at("name"))) + "</p></div>";
|
||||
}
|
||||
if (!body.empty()) out += "<div class=\"desktop-card desk-card\" style=\"" + style + "\">" + body + "</div>";
|
||||
} else {
|
||||
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 == "save" || (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_);
|
||||
}
|
||||
}
|
||||
out += "</div>";
|
||||
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</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>";
|
||||
element("canvas")->SetInnerRML(out); ++document_generation_;
|
||||
const auto size = context_->GetDimensions();
|
||||
element("background")->SetInnerRML(img("background", size.x / scale_, size.y / scale_, false, true, 2048));
|
||||
element("background")->SetProperty("filter", theme_ == "silver" ? "saturate(0.2) brightness(0.9)" : theme_ == "matchday" ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)");
|
||||
if (engine_busy_) {
|
||||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input");
|
||||
for (auto *node : controls) node->SetAttribute("disabled", true);
|
||||
}
|
||||
needs_render_ = false; dirty_ = true;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool engine_mode_ = false, engine_busy_ = false, engine_dirty_ = false, engine_fresh_ = false, engine_base_dirty_ = false;
|
||||
std::shared_ptr<EngineBridge> engine_link_;
|
||||
std::future<EngineReply> engine_job_;
|
||||
Json engine_data_, engine_response_, engine_focus_;
|
||||
std::string engine_camp_, engine_operation_, engine_notice_;
|
||||
void engine_start(std::string, std::function<EngineReply()>, bool mutating = false);
|
||||
void engine_poll();
|
||||
void engine_render();
|
||||
void engine_frame();
|
||||
void engine_event(Rml::Event &);
|
||||
void engine_save();
|
||||
void engine_quit();
|
||||
Json engine_camp_view() const;
|
||||
Json engine_snapshot() const;
|
||||
@@ -194,6 +194,7 @@ void App::opening_tick() {
|
||||
}
|
||||
void App::handle_event(SDL_Event &event) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
if (engine_mode_) { engine_quit(); return; }
|
||||
if (front_busy_) {
|
||||
front_feedback_ = "Bitte den laufenden Import abwarten.";
|
||||
dirty_ = true;
|
||||
|
||||
+48
-33
@@ -13,6 +13,33 @@ void App::init_desktop() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string App::desktop_button(const std::string &id, const Json &o, const std::string &action, bool enabled) {
|
||||
const auto route = id.substr(4);
|
||||
const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224), o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";";
|
||||
const std::array<std::string, 32> colors = {
|
||||
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
|
||||
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
|
||||
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
|
||||
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
|
||||
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
|
||||
"#ac5e63", "#806c98"};
|
||||
const auto i = std::find(routes.begin(), routes.end(), route);
|
||||
const auto color = colors[size_t(i - routes.begin())];
|
||||
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
|
||||
: mixed_color(color, "#c5ddf1", .1);
|
||||
const auto bottom =
|
||||
theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38);
|
||||
return "<button id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
|
||||
"\" data-action=\"" + action +
|
||||
"\" data-id=\"" + route + "\" class=\"desktop-app\" style=\"" + style +
|
||||
"\" " + std::string(enabled ? "" : "disabled ") + "><div class=\"app-tile\" "
|
||||
"style=\"decorator:linear-gradient(140deg," +
|
||||
top + "," + bottom + ");\">" +
|
||||
img("button." + route, 146, 146, false, false, 256) +
|
||||
"</div><span class=\"app-name\">" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "</span>" +
|
||||
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
|
||||
"</button>";
|
||||
}
|
||||
std::string App::render_desktop() {
|
||||
init_desktop();
|
||||
const auto s = snap();
|
||||
@@ -46,29 +73,7 @@ std::string App::render_desktop() {
|
||||
"</div>";
|
||||
} else {
|
||||
const auto route = id.substr(4);
|
||||
const std::array<std::string, 32> colors = {
|
||||
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
|
||||
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
|
||||
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
|
||||
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
|
||||
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
|
||||
"#ac5e63", "#806c98"};
|
||||
const auto i = std::find(routes.begin(), routes.end(), route);
|
||||
const auto color = colors[size_t(i - routes.begin())];
|
||||
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
|
||||
: mixed_color(color, "#c5ddf1", .1);
|
||||
const auto bottom =
|
||||
theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38);
|
||||
out += "<button id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
|
||||
"\" data-action=\"open:" + route +
|
||||
"\" class=\"desktop-app\" style=\"" + style +
|
||||
"\"><div class=\"app-tile\" "
|
||||
"style=\"decorator:linear-gradient(140deg," +
|
||||
top + "," + bottom + ");\">" +
|
||||
img("button." + route, 146, 146, false, false, 256) +
|
||||
"</div><span class=\"app-name\">" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "</span>" +
|
||||
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
|
||||
"</button>";
|
||||
out += desktop_button(id, o, "open:" + route);
|
||||
}
|
||||
}
|
||||
return out + "</div>";
|
||||
@@ -76,9 +81,9 @@ std::string App::render_desktop() {
|
||||
std::string App::render_camp() {
|
||||
const auto index_file =
|
||||
Json::parse(editor::read_file(gui_.root() / "gui-assets.json"));
|
||||
const auto demo = index_file.at("demo"), camps = demo.at("training_camps");
|
||||
const auto s = snap();
|
||||
const auto id = s.state.at("camp").value("selected", std::string("resort:4"));
|
||||
const auto demo = engine_mode_ ? engine_camp_view() : index_file.at("demo"), camps = demo.at("training_camps");
|
||||
const auto state = engine_mode_ ? Json{{"camp", {{"selected", engine_camp_}, {"focus", {engine_focus_.at("condition"), engine_focus_.at("technique"), engine_focus_.at("play")}}}}} : snap().state;
|
||||
const auto id = state.at("camp").value("selected", std::string("resort:4"));
|
||||
const Json *chosen = nullptr;
|
||||
for (const auto &c : camps)
|
||||
if (c.value("id", "") == id)
|
||||
@@ -100,7 +105,7 @@ std::string App::render_camp() {
|
||||
"2dp;overflow:hidden;border-radius:22dp;\">" +
|
||||
img("map." + region.substr(4), 1440, 1603.2, false, false, 1600);
|
||||
for (const auto &c : camps)
|
||||
if (c.value("map", "") == region) {
|
||||
if (c.value("map", "") == region && c.value("positioned", true)) {
|
||||
const double x = c.value("x", 0) * 1.2, y = c.value("y", 0) * 1.2;
|
||||
body += btn("camp-select",
|
||||
"<span "
|
||||
@@ -135,30 +140,40 @@ std::string App::render_camp() {
|
||||
}
|
||||
body += "<div class=\"field-row\"><strong>Preis</strong><strong "
|
||||
"class=\"accent\">" +
|
||||
cash(chosen->value("price", int64_t(0))) + "</strong></div>";
|
||||
(chosen->at("price").is_null() ? std::string("—") : (engine_mode_ ? money(chosen->at("price").get<int64_t>(), {{"code", "EUR"}, {"minor_units", 2}}) : cash(chosen->at("price").get<int64_t>()))) + "</strong></div>";
|
||||
const std::array<const char *, 4> focus = {"Kondition", "Technik", "Spiel",
|
||||
"Erholung"};
|
||||
const auto values = s.state.at("camp").at("focus");
|
||||
const auto values = state.at("camp").at("focus");
|
||||
int sum = 0;
|
||||
for (const auto &v : values)
|
||||
sum += v.get<int>();
|
||||
const bool focus_changed = engine_mode_ && (engine_focus_.at("condition") != engine_data_.at("camps").at("data").at("focus").at("condition") || engine_focus_.at("technique") != engine_data_.at("camps").at("data").at("focus").at("technique") || engine_focus_.at("play") != engine_data_.at("camps").at("data").at("focus").at("play"));
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const int value = i == 3 ? 15 - sum / 3 : values[size_t(i)].get<int>();
|
||||
const int recovery = engine_mode_ ? engine_data_.at("camps").at("data").at("focus").value("recovery", 0) : 15 - sum / 3;
|
||||
const int value = i == 3 ? recovery : values[size_t(i)].get<int>();
|
||||
body += "<div class=\"field-row\" style=\"min-height:100dp;padding:8dp "
|
||||
"0;\"><label>" +
|
||||
std::string(focus[size_t(i)]) +
|
||||
"</label><input type=\"range\" id=\"camp-focus-" +
|
||||
std::to_string(i) + "\" data-input=\"camp-focus\" data-id=\"" +
|
||||
std::to_string(i) + "\" min=\"0\" max=\"15\" step=\"1\" value=\"" +
|
||||
std::to_string(value) + "\" style=\"width:400dp;\" " +
|
||||
std::to_string(value) + "\" style=\"width:400dp;" + std::string(i == 3 && focus_changed ? "visibility:hidden;" : "") + "\" " +
|
||||
(i == 3 ? "disabled" : "") + "/><span id=\"camp-value-" +
|
||||
std::to_string(i) +
|
||||
"\" style=\"width:145dp;flex-shrink:0;text-align:right;\">" +
|
||||
std::to_string(value) + " / 15</span></div>";
|
||||
(i == 3 && focus_changed ? std::string("—") : std::to_string(value) + " / 15") + "</span></div>";
|
||||
}
|
||||
std::string booking_note;
|
||||
if (engine_mode_) for (const auto &camp : engine_data_.at("camps").at("data").at("camps")) if (camp.at("id") == id && camp.at("quote").is_object()) {
|
||||
const auto "e = camp.at("quote");
|
||||
const auto reason = quote.at("reasonCode");
|
||||
if (reason == "booked_this_week") booking_note = "Diese Woche wurde bereits ein Trainingslager gebucht.";
|
||||
else if (reason == "visit_limit") booking_note = "Das Trainingslagerlimit dieser Saison ist erreicht.";
|
||||
else if (quote.value("exceedsCash", false)) booking_note = "Der Preis übersteigt das aktuelle Guthaben.";
|
||||
}
|
||||
body += "<div class=\"row\" "
|
||||
"style=\"margin-top:26dp;justify-content:flex-end;\">" +
|
||||
btn("camp-remember", "Vormerken", "primary") + "</div></div>";
|
||||
btn("camp-remember", engine_mode_ ? "Verbindlich buchen" : "Vormerken", "primary", "id=\"camp-book\" " + std::string(engine_mode_ && ![&]() { for (const auto &camp : engine_data_.at("camps").at("data").at("camps")) if (camp.at("id") == id) return engine_fresh_ && camp.at("quote").is_object() && camp.at("quote").value("allowed", false); return false; }() ? "disabled" : "")) + "</div>" + (engine_mode_ ? "<p class=\"small muted\" style=\"margin-top:22dp;\">" + esc(engine_busy_ ? engine_operation_ : (booking_note.empty() ? engine_notice_ : booking_note)) + "</p>" : "") + "</div>";
|
||||
return body;
|
||||
}
|
||||
std::string App::render_menu(const std::string &key) {
|
||||
|
||||
+30
-3
@@ -5,6 +5,7 @@
|
||||
#include "launch/rml_path.hpp"
|
||||
#include "launch/rml_video.hpp"
|
||||
#include "modern/ui/controls.hpp"
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include "modern/ui/live_match_info.hpp"
|
||||
#include "modern/ui/script_locator.hpp"
|
||||
#include "modern/ui/select_menu.hpp"
|
||||
@@ -454,6 +455,7 @@ class App final : public Rml::EventListener {
|
||||
bool opening_io_blocked_ = false;
|
||||
int last_tactic_ = 0;
|
||||
|
||||
#include "modern/ui/engine_state.inc"
|
||||
#include "modern/ui/settings_state.inc"
|
||||
#include "modern/ui/widgets_state.inc"
|
||||
#include "modern/ui/files_state.inc"
|
||||
@@ -681,6 +683,7 @@ class App final : public Rml::EventListener {
|
||||
std::string main_menu();
|
||||
std::string mods_page();
|
||||
std::string render_desktop();
|
||||
std::string desktop_button(const std::string &, const Json &, const std::string &, bool enabled = true);
|
||||
void init_desktop();
|
||||
std::string widget(const std::string &, const Json &);
|
||||
std::string render_reports(const std::string &);
|
||||
@@ -879,6 +882,7 @@ class App final : public Rml::EventListener {
|
||||
}
|
||||
}
|
||||
void render() {
|
||||
if (engine_mode_) { engine_render(); return; }
|
||||
if (select_menu_) select_menu_->before_render();
|
||||
if (source_ && scene_=="desktop" && snap().state.value("career",Json::object()).value("ended",false)){scene_="main";menu_.clear();}
|
||||
if (scene_ == "desktop" && !files_capturing_ && opening_pending()) {
|
||||
@@ -1094,6 +1098,7 @@ class App final : public Rml::EventListener {
|
||||
return true;
|
||||
}
|
||||
void frame() {
|
||||
if (engine_mode_) { engine_frame(); return; }
|
||||
front_poll();
|
||||
flush_selects();
|
||||
if (ticket_)
|
||||
@@ -1336,9 +1341,10 @@ public:
|
||||
if (theme_ != "midnight" && theme_ != "silver" && theme_ != "matchday")
|
||||
throw editor::Error("Unbekanntes Modern-Theme.");
|
||||
front_external_override_=!config_.world.empty();
|
||||
collect_mods();
|
||||
engine_mode_ = !config_.engine_save.empty();
|
||||
if (!engine_mode_) collect_mods();
|
||||
if(config_.world.empty() && config_.scene=="mods")scene_="mods";
|
||||
if (!config_.world.empty()) {
|
||||
if (!config_.world.empty() && !engine_mode_) {
|
||||
active_mod_.clear();
|
||||
load_world(config_.world);
|
||||
scene_ = config_.scene;
|
||||
@@ -1360,7 +1366,23 @@ public:
|
||||
// A capture/CLI override is visual only and never edits a career.
|
||||
ui_preferences_["theme"]=theme_;
|
||||
}
|
||||
opening_restore_startup();
|
||||
if (engine_mode_) {
|
||||
if (config_.world.empty() || !config_.state.empty()) throw editor::Error("--ui-career benötigt --mod und unterstützt keine UI-Demostände.");
|
||||
scene_ = "engine"; menu_ = config_.scene == "camp" ? "camp" : "";
|
||||
const auto file = config_.world, save = config_.engine_save;
|
||||
engine_start("Spielstand wird geladen …", [file, save] {
|
||||
auto link = EngineBridge::open(file, save);
|
||||
auto catalog = Catalog::open(file);
|
||||
auto bundle = link->snapshot();
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
std::string data_revision;
|
||||
for (const auto *extension : {"x-diamond-modern", "x-world"})
|
||||
if (catalog->manifest().contains(extension)) data_revision = catalog->manifest().at(extension).value("data_revision", "");
|
||||
if (catalog->manifest().at("id").get<std::string>() != meta.at("worldId").get<std::string>() || data_revision != meta.at("worldRevision").get<std::string>())
|
||||
throw editor::Error("Bildkatalog und Engine verwenden unterschiedliche Weltdaten.");
|
||||
return EngineReply{link, std::move(bundle), Json::object(), std::move(catalog)};
|
||||
});
|
||||
} else opening_restore_startup();
|
||||
if (scene_ == "manager" && selections_["manager-name"].empty())
|
||||
selections_["manager-name"] = "Alex Berger";
|
||||
doc_->Show();
|
||||
@@ -1375,6 +1397,8 @@ public:
|
||||
}
|
||||
}
|
||||
void shutdown() {
|
||||
if (engine_job_.valid()) engine_job_.wait();
|
||||
engine_link_.reset();
|
||||
select_capture_.handler = {};
|
||||
if (doc_)
|
||||
for (const char *event : select_capture_events_)
|
||||
@@ -1407,6 +1431,7 @@ public:
|
||||
}
|
||||
while (!closed_) {
|
||||
front_poll();
|
||||
if (engine_mode_) engine_poll();
|
||||
opening_tick();
|
||||
live_tick();
|
||||
if (needs_render_ || dirty_)
|
||||
@@ -1485,6 +1510,8 @@ public:
|
||||
#include "modern/ui/live_controls.inc"
|
||||
#include "modern/ui/postmatch_screens.inc"
|
||||
#include "modern/ui/postmatch_controls.inc"
|
||||
#include "modern/ui/engine_screens.inc"
|
||||
#include "modern/ui/engine_controls.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
namespace bmh::modern_ui {
|
||||
struct Config {
|
||||
std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export, mods, mod_import;
|
||||
std::filesystem::path engine_save;
|
||||
std::string scene = "main", theme;
|
||||
int width = 1280, height = 720;
|
||||
};
|
||||
// Returns before Classic initialization. The demonstration never starts a
|
||||
// match.
|
||||
// Returns before Classic initialization. The demo never starts a match; the
|
||||
// opt-in career bridge loads an existing Modern OBS and binds desktop/camps.
|
||||
int run(const std::filesystem::path &executable, const launch::SaveMigrator &,
|
||||
const Config &);
|
||||
bool is_modern_world(const std::filesystem::path &);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Opt-in private-data probe. Never registered as an unconditional CTest.
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include <iostream>
|
||||
using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify <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)); };
|
||||
if (std::string(argv[1]) == "prepare") {
|
||||
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(), 17u);
|
||||
ui::SetupOptions options; options.mode = 3;
|
||||
ui::ManagerChoice manager; manager.name = "Codex Engine QA"; manager.master_club = 0;
|
||||
std::string error; ui::CareerInitializationResult result;
|
||||
if (!session.confirm_manager(options, manager, error) || !session.finish(result, error) ||
|
||||
!session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
|
||||
modern::set_current_world(nullptr);
|
||||
}
|
||||
auto link = EngineBridge::open(world, out / "input.obs");
|
||||
const auto before = link->snapshot(); write("before.json", before);
|
||||
if (before != link->snapshot()) throw std::runtime_error("reads changed the engine projection");
|
||||
if (std::string(argv[1]) == "verify") {
|
||||
auto camp = before.at("camps").at("data").at("camps").front();
|
||||
const auto command = engine_camp_command(before, camp.at("id"), {{"condition", 3}, {"technique", 4}, {"play", 5}}, "request:probe-book");
|
||||
const auto response = link->command(command); write("command.json", command); write("response.json", response);
|
||||
if (response.value("messageType", "") != "command_result") throw std::runtime_error(response.dump());
|
||||
if (link->command(command) != response) throw std::runtime_error("identical request was not idempotent");
|
||||
const auto after = link->snapshot(); write("after.json", after);
|
||||
if (!after.at("camps").at("data").at("bookedThisWeek").get<bool>()) throw std::runtime_error("camp not booked");
|
||||
const auto delta = engine_money_minor(before.at("desktop").at("data").at("accounts").at("cash")) - engine_money_minor(after.at("desktop").at("data").at("accounts").at("cash"));
|
||||
if (delta != engine_money_minor(camp.at("quote").at("total"))) throw std::runtime_error("wrong actual booking cost");
|
||||
write("saved.json", link->save_copy(out / "booked.obs")); link.reset();
|
||||
link = EngineBridge::open(world, out / "booked.obs"); const auto loaded = link->snapshot(); write("loaded.json", loaded);
|
||||
if (loaded.at("desktop").at("data").at("accounts") != after.at("desktop").at("data").at("accounts") || !loaded.at("camps").at("data").at("bookedThisWeek").get<bool>()) throw std::runtime_error("OBS round trip lost booking");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool v, const char *why) { if (!v) throw std::runtime_error(why); }
|
||||
template<class F> void rejects(F f) { bool rejected = false; try { f(); } catch (const std::exception &) { rejected = true; } require(rejected, "invalid DTO accepted"); }
|
||||
Json fixture() {
|
||||
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"}, {"careerId", "career:synthetic"},
|
||||
{"worldId", "world:synthetic"}, {"worldRevision", "1"}, {"stateRevision", "18446744073709551615"},
|
||||
{"scope", {{"role", "club"}, {"managerId", "manager:99"}, {"teamId", "club:6"}, {"scopeId", "scope:test"}, {"allowedCommands", {"camp.book"}}}}};
|
||||
Json out;
|
||||
for (const auto *kind : {"session", "desktop", "camps"}) out[kind] = {{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", kind}}}};
|
||||
out["desktop"]["data"].update({{"manager", {{"id", "manager:99"}}}, {"team", {{"id", "club:6"}}},
|
||||
{"accounts", {{"cash", {{"minor", "9007199254740993"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}});
|
||||
out["camps"]["data"]["camps"] = Json::array({{{"id", "resort:16"}, {"quote", {{"allowed", true}, {"expectedRevision", meta.at("stateRevision")},
|
||||
{"ownerManagerId", "manager:99"}, {"teamId", "club:6"}, {"scopeId", "scope:test"},
|
||||
{"total", {{"minor", "123400"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}}});
|
||||
return out;
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
try {
|
||||
const auto bundle = fixture(), original = bundle;
|
||||
validate_engine_desk(bundle);
|
||||
require(engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash")) == 9007199254740993LL, "money rounded through double");
|
||||
const auto focus = Json{{"condition", 0}, {"technique", 15}, {"play", 5}};
|
||||
const auto command = engine_camp_command(bundle, "resort:16", focus, "request:stable");
|
||||
require(command.at("owner").at("managerId") == "manager:99" && command.at("expectedRevision") == "18446744073709551615" &&
|
||||
command.at("payload").at("focus") == focus && bundle == original, "command lost authoritative identity/revision or changed snapshot");
|
||||
for (const auto &v : Json::array({Json{{"minor", "9223372036854775808"}, {"currency", "EUR"}, {"minorUnits", 2}},
|
||||
Json{{"minor", "10.25"}, {"currency", "EUR"}, {"minorUnits", 2}},
|
||||
Json{{"minor", "1000"}, {"currency", "GBP"}, {"minorUnits", 2}}}))
|
||||
rejects([&] { engine_money_minor(v); });
|
||||
for (int fault = 0; fault < 10; ++fault) {
|
||||
auto bad = bundle;
|
||||
if (fault == 0) bad["camps"]["meta"]["stateRevision"] = "2";
|
||||
if (fault == 1) bad["session"]["meta"]["careerId"] = "career:other";
|
||||
if (fault == 2) bad["desktop"]["data"]["manager"]["id"] = "manager:portrait-0";
|
||||
if (fault == 3) bad["camps"]["data"]["camps"][0]["quote"]["ownerManagerId"] = "manager:1";
|
||||
if (fault == 4) bad["camps"]["data"]["camps"][0]["quote"]["expectedRevision"] = "2";
|
||||
if (fault == 5) bad["camps"]["data"]["camps"][0]["quote"]["allowed"] = false;
|
||||
if (fault == 6) bad["camps"]["data"]["camps"][0]["quote"] = nullptr;
|
||||
if (fault == 7) for (auto &item : bad) item["meta"]["scope"]["role"] = "national";
|
||||
if (fault == 8) bad["camps"]["data"]["camps"].push_back(bad["camps"]["data"]["camps"][0]);
|
||||
if (fault == 9) for (auto &item : bad) item["meta"]["stateRevision"] = "18446744073709551616";
|
||||
rejects([&] { engine_camp_command(bad, "resort:16", focus, "request:stable"); });
|
||||
}
|
||||
rejects([&] { engine_camp_command(bundle, "resort:unknown", focus, "request:stable"); });
|
||||
auto invalid_focus = focus; invalid_focus["play"] = 16;
|
||||
rejects([&] { engine_camp_command(bundle, "resort:16", invalid_focus, "request:stable"); });
|
||||
std::cout << "engine DTO, exact money, scope and booking tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
Reference in new issue
Block a user