Create real careers from the native wizard and preserve manager presentation (by Codex)
This commit is contained in:
1 parent
738ecc7a09
commit
ce1535fe2d
38 files changed
+466
-75
No files matched your search
@@ -901,8 +901,8 @@ void App::script() {
|
||||
const auto type = command.value("type", std::string());
|
||||
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.");
|
||||
while ((engine_busy_ || engine_creation_busy_) && SDL_GetTicks64() < until) { pump_events(); frame(); SDL_Delay(10); }
|
||||
if (engine_busy_ || engine_creation_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);
|
||||
|
||||
@@ -157,18 +157,11 @@ bool migrate_demo_opening(Json &state, const Catalog &world) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string edit_demo_opening(Json &state, const Json &action,
|
||||
const Catalog &world) {
|
||||
std::string advance_opening_presentation(Json &source,const std::string &kind) {
|
||||
try {
|
||||
if (!action.is_object() || action.size() != 1 || !action.contains("kind") ||
|
||||
!action.at("kind").is_string())
|
||||
return "Ungültige Aktion der Saisonvorbereitung.";
|
||||
auto next = state;
|
||||
if (!migrate_demo_opening(next, world))
|
||||
return "Die gespeicherte Saisonvorbereitung ist ungültig.";
|
||||
auto &flow = next.at("opening_flow");
|
||||
const auto kind = action.at("kind").get<std::string>(),
|
||||
phase = flow.at("phase").get<std::string>();
|
||||
auto flow=source;
|
||||
if(!flow.at("order").is_array()||!flow.at("revealed").is_number_integer()||flow.at("revealed").get<int64_t>()<0||flow.at("revealed").get<uint64_t>()>flow.at("order").size()||!flow.at("playing").is_boolean())return "Ungültiger Darstellungszustand der Saisonvorbereitung.";
|
||||
const auto phase = flow.at("phase").get<std::string>();
|
||||
const auto total = flow.at("order").size();
|
||||
if (kind == "next") {
|
||||
if (phase == "uefa")
|
||||
@@ -212,6 +205,21 @@ std::string edit_demo_opening(Json &state, const Json &action,
|
||||
flow["playing"] = false;
|
||||
} else
|
||||
return "Unbekannte Aktion der Saisonvorbereitung.";
|
||||
source=std::move(flow);return {};
|
||||
}catch(const std::exception&){return "Ungültiger Darstellungszustand der Saisonvorbereitung.";}
|
||||
}
|
||||
std::string edit_demo_opening(Json &state, const Json &action,
|
||||
const Catalog &world) {
|
||||
try {
|
||||
if (!action.is_object() || action.size() != 1 || !action.contains("kind") ||
|
||||
!action.at("kind").is_string())
|
||||
return "Ungültige Aktion der Saisonvorbereitung.";
|
||||
auto next = state;
|
||||
if (!migrate_demo_opening(next, world))
|
||||
return "Die gespeicherte Saisonvorbereitung ist ungültig.";
|
||||
auto &flow = next.at("opening_flow");
|
||||
const auto error=advance_opening_presentation(flow,action.at("kind"));
|
||||
if(!error.empty())return error;
|
||||
const bool done = flow.at("phase").get<std::string>() == "done";
|
||||
next["opening"] = done ? "complete" : "pending";
|
||||
next["opening_created"] = done && flow.at("created").get<bool>();
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace bmh::modern_ui {
|
||||
// Fictional UI participants, derived solely from the immutable catalogue.
|
||||
// No engine draw, actual qualification or gameplay random stream is involved.
|
||||
Json make_demo_opening(const Catalog &, const Json &state, bool created);
|
||||
// Presentation steps never create participants or pairings; used by both sources.
|
||||
std::string advance_opening_presentation(Json &flow,const std::string &kind);
|
||||
// Missing legacy flows are migrated; existing inconsistent flows are rejected.
|
||||
// Both migration and edits leave the input untouched on rejection.
|
||||
bool migrate_demo_opening(Json &state, const Catalog &);
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
@@ -21,6 +24,34 @@ struct EngineBridge::Impl {
|
||||
session = std::make_unique<modern::app::ModernSession>(mount->root(), 1u, save, false);
|
||||
} catch (...) { modern::set_current_world(nullptr); throw; }
|
||||
}
|
||||
Impl(const fs::path &world,const Json &setup,const Json &managers,uint32_t seed) : package(modern::open_world_package(world)) {
|
||||
const auto integer=[&](const char* key,int low,int high){const auto &v=setup.at(key);if(!v.is_number_integer()||v.get<int64_t>()<low||v.get<int64_t>()>high)throw editor::Error("Ungültige Grundeinstellung: "+std::string(key));return v.get<int>();};
|
||||
ui::SetupOptions options;options.mode=integer("mode",3,3);options.duration=integer("duration",0,5);options.difficulty=integer("difficulty",0,9);options.managers=integer("players",1,4);
|
||||
if(!setup.at("league").is_boolean()||!setup.at("world").is_boolean())throw editor::Error("Ungültige Wettbewerbswahl.");options.league=setup.at("league");options.world=setup.at("world");
|
||||
if((!options.league&&!options.world)||!managers.is_array()||managers.size()!=size_t(options.managers))throw editor::Error("Die Manager- oder Wettbewerbswahl ist unvollständig.");
|
||||
std::vector<ui::ManagerChoice> choices;std::vector<std::string> names,styles;std::set<std::string> clubs;std::set<int> portraits;
|
||||
for(const auto &m:managers) {
|
||||
if(!m.at("name").is_string()||!m.at("club").is_string())throw editor::Error("Managername oder Verein fehlt.");const auto name=normalized_manager_name(m.at("name").get<std::string>());if(!name)throw editor::Error("Bitte einen gültigen Managernamen angeben.");
|
||||
const auto id=m.at("club").get<std::string>();const auto *club=package.world->club(id);const modern::WorldLeague *league=nullptr;
|
||||
if(club)for(const auto &l:package.world->leagues)if(l.id==club->competition)league=&l;
|
||||
if(!club||!league||league->index<0||league->index>4||club->legacy_index<0||!clubs.insert(id).second)throw editor::Error("Dieser Verein ist für die Managerwahl nicht verfügbar.");
|
||||
const auto &portrait=m.at("portrait"),&strength=m.at("strength_choice");if(!portrait.is_number_integer()||portrait.get<int64_t>()<0||portrait.get<int64_t>()>11||!portraits.insert(portrait.get<int>()).second||!strength.is_number_integer()||strength.get<int64_t>()<0||strength.get<int64_t>()>2)throw editor::Error("Ungültige Managerdarstellung oder Startstärke.");
|
||||
const auto style=m.value("portrait_style",std::string("photo"));if(style!="photo"&&style!="painted")throw editor::Error("Ungültige Porträtart.");
|
||||
ui::ManagerChoice choice;choice.slot=int(choices.size());choice.master_club=club->legacy_index;choice.start_league=league->index;choice.strength=strength;choice.portrait=portrait;
|
||||
try {choice.name=ui::utf8_to_original(*name);}catch(const std::exception&){choice.name="Manager "+std::to_string(choice.slot+1);}
|
||||
if(choice.name.empty()||choice.name.size()>24)choice.name="Manager "+std::to_string(choice.slot+1);
|
||||
choices.push_back(choice);names.push_back(*name);styles.push_back(style);
|
||||
}
|
||||
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(),seed);std::string error;
|
||||
for(const auto &choice:choices)if(!session->confirm_manager(options,choice,error))throw editor::Error("Die Managerwahl wurde abgewiesen: "+error);
|
||||
auto &state=session->state();modern::ensure_ui_identities(state);
|
||||
for(size_t i=0;i<choices.size();++i)state.manager_presentations.push_back({state.manager_ids.at(i),names[i],styles[i]});
|
||||
ui::CareerInitializationResult result;if(!session->finish(result,error))throw editor::Error("Die Partie konnte nicht gestartet werden: "+error);
|
||||
for(size_t i=0;i<managers.size();++i){const auto status=from_engine(session->ui_read(cli::Json::Object{{"kind","session"}},revision));const auto &all=status.at("data").at("managers");if(all.at(i).at("teamId")!=managers.at(i).at("club"))throw editor::Error("Die Engine hat einen anderen Verein zugeordnet.");}
|
||||
}catch(...){session.reset();mount.reset();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)) {}
|
||||
@@ -28,6 +59,10 @@ 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)));
|
||||
}
|
||||
std::shared_ptr<EngineBridge> EngineBridge::create(const fs::path &world,const Json &setup,const Json &managers,uint32_t seed) {
|
||||
if(modern::current_world())throw editor::Error("Bitte die laufende Partie beenden, bevor eine neue begonnen wird.");
|
||||
return std::shared_ptr<EngineBridge>(new EngineBridge(std::make_unique<Impl>(world,setup,managers,seed)));
|
||||
}
|
||||
Json EngineBridge::snapshot() const {
|
||||
Json bundle = Json::object();
|
||||
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training", "bank", "stadium", "credit", "environment", "advertising", "contracts", "friendly-plan"})
|
||||
|
||||
@@ -62,11 +62,14 @@ 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_opening_projection(const Json &bundle,const Json &read);
|
||||
|
||||
// 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);
|
||||
static std::shared_ptr<EngineBridge> create(const fs::path &world,const Json &setup,const Json &managers,uint32_t seed);
|
||||
~EngineBridge();
|
||||
Json snapshot() const;
|
||||
Json read(const Json &request) const;
|
||||
|
||||
@@ -6,6 +6,38 @@ void App::engine_start(std::string label, std::function<EngineReply()> job, bool
|
||||
engine_operation_ = std::move(label); engine_busy_ = true;
|
||||
engine_job_ = std::async(std::launch::async, std::move(job)); refresh();
|
||||
}
|
||||
void App::engine_accept(EngineReply result) {
|
||||
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_ = engine_base_dirty_ || engine_response_.at("newRevision") != engine_response_.at("previousRevision");
|
||||
engine_notice_ = engine_text(engine_response_.at("feedback")) + (engine_dirty_ ? " · Änderungen noch nicht gespeichert." : "");
|
||||
} else if (engine_response_.value("messageType", "") == "error") {
|
||||
engine_dirty_ = engine_base_dirty_;
|
||||
auto reason = engine_text(engine_response_.value("message", Json()));
|
||||
if (reason.empty() || reason == "—") reason = engine_response_.value("code", "unknown_error");
|
||||
engine_notice_ = "Änderung abgewiesen: " + reason;
|
||||
} else if (engine_response_.value("messageType", "") == "saved") {
|
||||
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
|
||||
if(engine_exit_after_save_){engine_exit_after_save_=false;closed_=true;}
|
||||
} else if(engine_response_.value("messageType","")=="created"){engine_dirty_=true;engine_notice_="Neue Partie · Noch nicht gespeichert.";}
|
||||
else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
|
||||
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
|
||||
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
|
||||
engine_reports_sync();
|
||||
engine_almanac_sync();
|
||||
engine_ticket_bind();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
engine_friendly_sync();
|
||||
engine_sports_reset();
|
||||
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");
|
||||
}
|
||||
void App::engine_poll() {
|
||||
if (!engine_busy_ || engine_job_.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) return;
|
||||
engine_busy_ = false;
|
||||
@@ -37,35 +69,8 @@ void App::engine_poll() {
|
||||
}
|
||||
refresh(); return;
|
||||
}
|
||||
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_ = engine_base_dirty_ || engine_response_.at("newRevision") != engine_response_.at("previousRevision");
|
||||
engine_notice_ = engine_text(engine_response_.at("feedback")) + (engine_dirty_ ? " · Änderungen noch nicht gespeichert." : "");
|
||||
} else if (engine_response_.value("messageType", "") == "error") {
|
||||
engine_dirty_ = engine_base_dirty_;
|
||||
auto reason = engine_text(engine_response_.value("message", Json()));
|
||||
if (reason.empty() || reason == "—") reason = engine_response_.value("code", "unknown_error");
|
||||
engine_notice_ = "Änderung abgewiesen: " + reason;
|
||||
} 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.";
|
||||
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
|
||||
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
|
||||
engine_reports_sync();
|
||||
engine_almanac_sync();
|
||||
engine_ticket_bind();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
engine_friendly_sync();
|
||||
engine_sports_reset();
|
||||
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(); }
|
||||
engine_accept(std::move(result));
|
||||
} catch (const std::exception &e) { engine_notice_ = e.what(); if(engine_exit_after_save_){engine_exit_after_save_=false;message("Der Spielstand konnte nicht gespeichert werden: "+std::string(e.what()));} }
|
||||
refresh();
|
||||
}
|
||||
void App::engine_frame() {
|
||||
@@ -115,7 +120,7 @@ void App::engine_save() {
|
||||
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_CANCEL) {engine_exit_after_save_=false;return;}
|
||||
if (result != NFD_OKAY) throw editor::Error("Die Dateiauswahl konnte nicht geöffnet werden.");
|
||||
output = editor::path(chosen.get());
|
||||
}
|
||||
@@ -124,7 +129,11 @@ void App::engine_save() {
|
||||
}
|
||||
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; });
|
||||
if (engine_dirty_) {
|
||||
confirmation("Die Partie enthält ungespeicherte Änderungen. Vor dem Beenden speichern?",[this]{closed_=true;});
|
||||
popup_accept_="Ohne Speichern beenden";
|
||||
popup_extra_=btn("engine-save-exit","Speichern und beenden","primary","id=\"engine-save-exit\"");
|
||||
}
|
||||
else closed_ = true;
|
||||
}
|
||||
void App::engine_event(Rml::Event &event) {
|
||||
@@ -138,6 +147,13 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (!engine_busy_ && bank_event(event)) return;
|
||||
if (!engine_busy_ && advertising_event(event)) return;
|
||||
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
|
||||
if(engine_opening_active()&&popup_.empty()) {
|
||||
if(type=="keydown") {const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
||||
if(key==Rml::Input::KI_TAB){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".opening-actions button");std::erase_if(nodes,[](auto *n){return n->HasAttribute("disabled");});if(!nodes.empty()){const auto it=std::find(nodes.begin(),nodes.end(),context_->GetFocusElement());const int i=it==nodes.end()?-1:int(it-nodes.begin()),n=int(nodes.size());nodes[size_t((i+n+(event.GetParameter<int>("shift_key",0)?-1:1))%n)]->Focus(true);}event.StopImmediatePropagation();return;}
|
||||
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE){for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->GetTagName()=="button"&&!n->HasAttribute("disabled")){n->DispatchEvent("click",{});break;}}}
|
||||
if(type=="click")for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-action")){opening_action(n->GetAttribute<Rml::String>("data-action",""),n);break;}
|
||||
event.StopImmediatePropagation();return;
|
||||
}
|
||||
if (engine_reports_event(event)) return;
|
||||
if(!engine_busy_&&popup_.empty()&&rankings_event(event))return;
|
||||
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
|
||||
@@ -218,6 +234,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
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=="engine-save-exit"){reset_popup();popup_.clear();engine_exit_after_save_=true;try{engine_save();}catch(const std::exception &e){engine_exit_after_save_=false;message(e.what());}return;}
|
||||
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
|
||||
return;
|
||||
}
|
||||
@@ -268,6 +285,6 @@ void App::engine_event(Rml::Event &event) {
|
||||
}
|
||||
}
|
||||
Json App::engine_snapshot() const {
|
||||
return {{"mode", engine_mode_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"response", engine_response_}, {"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_}};
|
||||
return {{"mode", engine_mode_}, {"creation_busy",engine_creation_busy_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"response", engine_response_}, {"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_}};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::engine_opening_active() const {
|
||||
return engine_mode_&&engine_opening_state_.is_object()&&engine_opening_state_.at("opening_flow").at("phase")!="done";
|
||||
}
|
||||
void App::engine_create(const std::shared_ptr<const Catalog> &catalog,const Json &managers) {
|
||||
if(engine_creation_busy_||engine_mode_)return;
|
||||
const auto file=catalog->source();const auto setup=start_options_;
|
||||
const uint32_t seed=config_.creation_seed.value_or(uint32_t(SDL_GetPerformanceCounter()));
|
||||
engine_creation_busy_=true;manager_confirm_=false;focus_after_render_.clear();
|
||||
engine_creation_job_=std::async(std::launch::async,[file,setup,managers,seed] {
|
||||
auto link=EngineBridge::create(file,setup,managers,seed);auto loaded=Catalog::open(file);auto bundle=link->snapshot();auto opening=link->read({{"kind","opening"}});const auto state=engine_opening_projection(bundle,opening);
|
||||
if(loaded->manifest().at("id")!=bundle.at("desktop").at("meta").at("worldId"))throw editor::Error("Bildkatalog und Partie gehören nicht zur selben Welt.");
|
||||
for(const auto &id:state.at("opening_flow").at("order"))if(!loaded->find("clubs",id))throw editor::Error("Ein ausgeloster Verein fehlt im Bildkatalog.");
|
||||
for(const auto &ids:state.at("opening_flow").at("entrants"))for(const auto &id:ids)if(!loaded->find("clubs",id))throw editor::Error("Ein Europapokalteilnehmer fehlt im Bildkatalog.");
|
||||
return EngineReply{link,bundle,{{"messageType","created"},{"opening",opening}},loaded};
|
||||
});refresh();
|
||||
}
|
||||
void App::engine_create_poll() {
|
||||
if(!engine_creation_busy_||engine_creation_job_.wait_for(std::chrono::milliseconds(0))!=std::future_status::ready)return;
|
||||
engine_creation_busy_=false;const auto previous=world_;
|
||||
try {
|
||||
auto result=engine_creation_job_.get();validate_engine_desk(result.bundle);auto opening=engine_opening_projection(result.bundle,result.response.at("opening"));
|
||||
engine_mode_=true;engine_accept(std::move(result));engine_opening_read_=engine_response_.at("opening");engine_opening_state_=std::move(opening);source_.reset();entry_catalog_.reset();managers_draft_=Json::array();scene_="engine";menu_.clear();manager_confirm_=manager_success_=false;opening_due_=0;opening_io_blocked_=false;focus_after_render_=engine_opening_active()?(engine_opening_state_.at("opening_flow").at("phase")=="draw"?"opening-play":"opening-next"):"";engine_creation_busy_=false;
|
||||
}catch(const std::exception &e){engine_mode_=false;engine_link_.reset();engine_data_=Json();engine_fresh_=false;world_=previous;if(entry_catalog_)bind_world(entry_catalog_);else bind_world(world_);manager_confirm_=true;message("Die Partie konnte nicht gestartet werden: "+std::string(e.what()));}
|
||||
refresh();
|
||||
}
|
||||
@@ -896,4 +896,14 @@ Json engine_fairplay_projection(const Json &bundle,const Json &index,const Json
|
||||
const auto &league=catalogue.at("leagues")[0];require(data.at("rows").is_array()&&data.at("rows").size()==league.at("members").size(),"Unvollständige Fairplayliste.");std::set<std::string> ids;int previous=-1,rank=0;for(auto &r:data["rows"]){const auto id=r.at("team").at("id").get<std::string>();require(ids.insert(id).second&&std::find(league.at("members").begin(),league.at("members").end(),Json(id))!=league.at("members").end()&&r.at("team").at("name").is_string(),"Doppelter/fremder Fairplayverein.");const int y=whole_in_range(r.at("yellow"),0,10000000),red=whole_in_range(r.at("red"),0,10000000),points=whole_in_range(r.at("points"),0,50000000);require(points==y+4*red&&points>=previous&&r.at("rank")==++rank,"Ungültige Fairplaywertung.");previous=points;r["club"]=id;}
|
||||
(void)whole_in_range(data.at("recordedMatches"),0,10000000);data["league"]=league;return data;
|
||||
}
|
||||
Json engine_opening_projection(const Json &bundle,const Json &read) {
|
||||
validate_engine_desk(bundle);auto context=bundle;context["opening"]=read;const auto &data=lineup_read(context,"opening");
|
||||
require(data.at("enabled").is_boolean()&&data.at("showEntrants").is_boolean()&&data.at("entrants").is_object()&&data.at("order").is_array()&&data.at("order").size()%2==0&&data.at("fixtureIds").is_array()&&data.at("fixtureIds").size()*2==data.at("order").size(),"Unvollständige Saisonvorbereitung.");
|
||||
Json entrants=Json::object(),order=Json::array(),managers=Json::array();
|
||||
for(const auto *kind:{"uefa","champions","winners"}){require(data.at("entrants").at(kind).is_array(),"Teilnehmerliste fehlt.");std::set<std::string> seen;entrants[kind]=Json::array();for(const auto &t:data.at("entrants").at(kind)){const auto id=t.at("id").get<std::string>();require(!id.empty()&&seen.insert(id).second&&t.at("name").is_string(),"Doppelter oder unbenannter Europapokalteilnehmer.");entrants[kind].push_back(id);}}
|
||||
std::set<std::string> teams,fixtures;for(const auto &t:data.at("order")){const auto id=t.at("id").get<std::string>();require(!id.empty()&&teams.insert(id).second&&t.at("name").is_string(),"Doppelter Pokalteilnehmer.");order.push_back(id);}for(const auto &id:data.at("fixtureIds")){require(id.is_string()&&!id.get<std::string>().empty()&&fixtures.insert(id.get<std::string>()).second,"Doppelte Pokalpaarung.");}
|
||||
require(data.at("enabled").get<bool>()||order.empty(),"Deaktivierter Vereinswettbewerb hat Auftaktpaarungen.");for(const auto &m:bundle.at("session").at("data").at("managers"))managers.push_back({{"club",m.at("teamId")}});
|
||||
const bool enabled=data.at("enabled"),show=data.at("showEntrants");const auto phase=!enabled?"done":show?"uefa":order.empty()?"done":"draw";
|
||||
return {{"date",bundle.at("desktop").at("meta").at("date")},{"managers",managers},{"opening_flow",{{"created",true},{"phase",phase},{"playing",std::string_view(phase)=="draw"},{"revealed",0},{"order",order},{"entrants",entrants}}}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -51,6 +51,8 @@ void App::engine_render() {
|
||||
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 if(engine_opening_active()) {
|
||||
out=main_menu()+"<div class=\"fill\" style=\"z-index:100;\">"+render_opening()+"</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");
|
||||
@@ -93,6 +95,7 @@ void App::engine_render() {
|
||||
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);
|
||||
else if(portrait.starts_with("gui:manager/painted/"))body=img("manager-painted."+portrait.substr(20),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>();
|
||||
|
||||
@@ -86,3 +86,12 @@
|
||||
bool engine_sports_action(const std::string &, const std::string &, Rml::Element *);
|
||||
bool engine_sports_event(Rml::Event &);
|
||||
Json engine_snapshot() const;
|
||||
|
||||
bool engine_exit_after_save_=false;
|
||||
bool engine_creation_busy_=false;
|
||||
std::future<EngineReply> engine_creation_job_;
|
||||
Json engine_opening_state_,engine_opening_read_;
|
||||
void engine_create(const std::shared_ptr<const Catalog> &,const Json &);
|
||||
void engine_create_poll();
|
||||
void engine_accept(EngineReply);
|
||||
bool engine_opening_active() const;
|
||||
@@ -69,6 +69,10 @@ void App::entry_begin() {
|
||||
message("Bitte eine Modern-Mod aktivieren.");
|
||||
return;
|
||||
}
|
||||
if(!config_.preview_only) {
|
||||
const auto requirements=next->manifest().value("requires",Json::array());
|
||||
if(!requirements.is_array()||std::find(requirements.begin(),requirements.end(),Json("runtime:modern-v1"))==requirements.end()){message("Diese Mod ist nicht als spielbare Modern-Welt freigegeben.");return;}
|
||||
}
|
||||
const auto clubs = next->clubs();
|
||||
if (std::none_of(clubs.begin(), clubs.end(), [&](auto *c) {
|
||||
return next->manageable(c->value("id", ""));
|
||||
@@ -146,7 +150,7 @@ void App::entry_cancel() {
|
||||
refresh();
|
||||
}
|
||||
void App::entry_confirm() {
|
||||
if (!manager_confirm_ || entry_full())
|
||||
if (engine_creation_busy_ || !manager_confirm_ || entry_full())
|
||||
return;
|
||||
const auto name = normalized_manager_name(selections_["manager-name"]);
|
||||
const auto catalog = entry_world();
|
||||
@@ -191,6 +195,7 @@ void App::entry_confirm() {
|
||||
manager_success_ = true;
|
||||
focus_after_render_ = "manager-success-close";
|
||||
} else {
|
||||
if(!config_.preview_only) {engine_create(catalog,candidate);return;}
|
||||
// Construct and validate before releasing any part of the current session.
|
||||
auto demo = std::make_unique<DemoSource>(catalog);
|
||||
Json start={{"setup",start_options_},{"managers",candidate}};
|
||||
@@ -217,6 +222,7 @@ void App::entry_confirm() {
|
||||
refresh();
|
||||
}
|
||||
bool App::entry_action(const std::string &action, Rml::Element *target) {
|
||||
if (engine_creation_busy_) return scene_=="newgame"||scene_=="manager";
|
||||
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty() || menu_ == "quit")
|
||||
return false;
|
||||
const auto id =
|
||||
@@ -410,6 +416,7 @@ bool App::entry_input(Rml::Element *target) {
|
||||
return true;
|
||||
}
|
||||
bool App::entry_event(Rml::Event &event) {
|
||||
if(engine_creation_busy_){event.StopImmediatePropagation();return true;}
|
||||
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty() || menu_ == "quit")
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
|
||||
@@ -86,6 +86,11 @@ void App::opening_restore_startup() {
|
||||
}
|
||||
}
|
||||
bool App::opening_change(const std::string &kind) {
|
||||
if(engine_mode_) {
|
||||
if(!engine_opening_active())return false;
|
||||
auto next=engine_opening_state_.at("opening_flow");const auto error=advance_opening_presentation(next,kind);if(!error.empty())return false;
|
||||
engine_opening_state_["opening_flow"]=std::move(next);opening_due_=0;refresh();return true;
|
||||
}
|
||||
if (!source_)
|
||||
return false;
|
||||
const auto before = snap();
|
||||
@@ -116,7 +121,7 @@ bool App::opening_change(const std::string &kind) {
|
||||
return true;
|
||||
}
|
||||
bool App::opening_action(const std::string &action, Rml::Element *) {
|
||||
if (scene_ != "opening" || !menu_.empty() || !popup_.empty())
|
||||
if ((!engine_mode_&&scene_ != "opening") || (engine_mode_&&!engine_opening_active()) || !menu_.empty() || !popup_.empty())
|
||||
return false;
|
||||
if (action == "close")
|
||||
return true;
|
||||
@@ -125,14 +130,14 @@ bool App::opening_action(const std::string &action, Rml::Element *) {
|
||||
kind = "next";
|
||||
else if (action == "opening-play")
|
||||
kind = opening_io_blocked_ &&
|
||||
snap().state.at("opening_flow").at("playing").get<bool>()
|
||||
(engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("playing").get<bool>()
|
||||
? "reveal"
|
||||
: "toggle";
|
||||
else if (action == "opening-all")
|
||||
kind = "skip";
|
||||
else if (action == "opening-finish") {
|
||||
const auto phase =
|
||||
snap().state.at("opening_flow").at("phase").get<std::string>();
|
||||
(engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("phase").get<std::string>();
|
||||
if (phase == "done") {
|
||||
scene_ = "desktop";
|
||||
opening_due_ = 0;
|
||||
@@ -145,7 +150,7 @@ bool App::opening_action(const std::string &action, Rml::Element *) {
|
||||
if (!opening_change(kind))
|
||||
return true;
|
||||
const auto phase =
|
||||
snap().state.at("opening_flow").at("phase").get<std::string>();
|
||||
(engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("phase").get<std::string>();
|
||||
if (phase == "done") {
|
||||
scene_ = "desktop";
|
||||
focus_after_render_.clear();
|
||||
@@ -169,10 +174,10 @@ bool App::opening_event(Rml::Event &event) {
|
||||
return false;
|
||||
}
|
||||
void App::opening_tick() {
|
||||
if (scene_ != "opening" || !source_ || !menu_.empty() || !popup_.empty() ||
|
||||
if ((!engine_mode_&&(scene_ != "opening" || !source_)) || (engine_mode_&&!engine_opening_active()) || !menu_.empty() || !popup_.empty() ||
|
||||
opening_io_blocked_)
|
||||
return;
|
||||
const auto flow = snap().state.at("opening_flow");
|
||||
const auto flow = (engine_mode_?engine_opening_state_:snap().state).at("opening_flow");
|
||||
if (flow.at("phase") != "draw" || !flow.at("playing").get<bool>()) {
|
||||
opening_due_ = 0;
|
||||
return;
|
||||
@@ -187,13 +192,14 @@ void App::opening_tick() {
|
||||
if (now < opening_due_)
|
||||
return;
|
||||
if (opening_change("reveal")) {
|
||||
if (snap().state.at("opening_flow").at("phase") == "overview")
|
||||
if ((engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("phase") == "overview")
|
||||
focus_after_render_ = "opening-finish";
|
||||
opening_due_ = SDL_GetTicks64() + 900;
|
||||
}
|
||||
}
|
||||
void App::handle_event(SDL_Event &event) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
if(engine_creation_busy_){message("Die Partie wird noch vorbereitet. Bitte kurz warten.");return;}
|
||||
if (engine_mode_) { engine_quit(); return; }
|
||||
if (front_busy_) {
|
||||
front_feedback_ = "Bitte den laufenden Import abwarten.";
|
||||
@@ -209,8 +215,8 @@ void App::handle_event(SDL_Event &event) {
|
||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||
desktop_cancel_drag();
|
||||
if (scene_ == "opening" && source_ && !opening_io_blocked_ &&
|
||||
snap().state.at("opening_flow").at("phase") == "draw" &&
|
||||
snap().state.at("opening_flow").at("playing").get<bool>())
|
||||
(engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("phase") == "draw" &&
|
||||
(engine_mode_?engine_opening_state_:snap().state).at("opening_flow").at("playing").get<bool>())
|
||||
opening_change("pause");
|
||||
}
|
||||
resize();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// belong to the controller. No participants or pairings are invented by the
|
||||
// renderer.
|
||||
std::string App::render_opening() {
|
||||
const auto state = snap().state;
|
||||
const auto state = engine_mode_?engine_opening_state_:snap().state;
|
||||
const auto &flow = state.at("opening_flow");
|
||||
const auto phase = flow.at("phase").get<std::string>();
|
||||
const bool playing = flow.value("playing", false) && !opening_io_blocked_;
|
||||
@@ -46,7 +46,8 @@ std::string App::render_opening() {
|
||||
"<span class=\"opening-heading-detail\">" +
|
||||
esc(detail) + "</span></header>";
|
||||
};
|
||||
const auto note = [](const std::string &text) {
|
||||
const auto note = [&](const std::string &text) {
|
||||
if(engine_mode_)return std::string();
|
||||
return "<span class=\"opening-demo-note\">" + esc(text) + "</span>";
|
||||
};
|
||||
const auto pair = [&](int index, int known, int logo_size,
|
||||
@@ -116,8 +117,7 @@ std::string App::render_opening() {
|
||||
if (entrants.empty()) {
|
||||
body += "<div class=\"opening-empty-entrants\"><h3><span>Keine "
|
||||
"Teilnehmer eingetragen</span></h3>"
|
||||
"<p><span>Für diesen Wettbewerb sind in dieser Demo-Welt keine "
|
||||
"Vereine vorgesehen.</span></p></div>";
|
||||
"<p><span>"+std::string(engine_mode_?"Für diesen Wettbewerb sind derzeit keine deutschen Vereine gemeldet.":"Für diesen Wettbewerb sind in dieser Demo-Welt keine Vereine vorgesehen.")+"</span></p></div>";
|
||||
} else {
|
||||
const bool single = entrants.size() == 1;
|
||||
const auto card = [&](const Json *c) {
|
||||
|
||||
@@ -130,6 +130,7 @@ std::string App::render_manager() {
|
||||
return window("Neuer Spieler",
|
||||
"<p>Bitte zuerst eine Modern-Mod aktivieren.</p>");
|
||||
const bool national = career_national_entry();
|
||||
if(engine_creation_busy_)return window("Neues Spiel","<div class=\"fill center\"><h2>Die Partie wird vorbereitet …</h2></div>",false);
|
||||
const bool full = entry_full(), modal = manager_confirm_ || manager_success_;
|
||||
const int limit =
|
||||
adding_manager_ ? (national ? 1 : 4) : start_options_.value("players", 1);
|
||||
|
||||
@@ -1109,6 +1109,7 @@ class App final : public Rml::EventListener {
|
||||
return true;
|
||||
}
|
||||
void frame() {
|
||||
engine_create_poll();
|
||||
if (engine_mode_) { engine_frame(); return; }
|
||||
front_poll();
|
||||
flush_selects();
|
||||
@@ -1393,7 +1394,7 @@ public:
|
||||
throw editor::Error("Bildkatalog und Engine verwenden unterschiedliche Weltdaten.");
|
||||
return EngineReply{link, std::move(bundle), Json::object(), std::move(catalog)};
|
||||
});
|
||||
} else opening_restore_startup();
|
||||
} else if(config_.preview_only) opening_restore_startup();
|
||||
if (scene_ == "manager" && selections_["manager-name"].empty())
|
||||
selections_["manager-name"] = "Alex Berger";
|
||||
doc_->Show();
|
||||
@@ -1442,6 +1443,7 @@ public:
|
||||
}
|
||||
while (!closed_) {
|
||||
front_poll();
|
||||
engine_create_poll();
|
||||
if (engine_mode_) engine_poll();
|
||||
opening_tick();
|
||||
live_tick();
|
||||
@@ -1533,6 +1535,7 @@ public:
|
||||
#include "modern/ui/engine_almanac.inc"
|
||||
#include "modern/ui/engine_reports.inc"
|
||||
#include "modern/ui/engine_rankings.inc"
|
||||
#include "modern/ui/engine_creation.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "launch/mods.hpp"
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
|
||||
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;
|
||||
bool preview_only = false;
|
||||
std::optional<uint32_t> creation_seed;
|
||||
std::string scene = "main", theme;
|
||||
int width = 1280, height = 720;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user