Create real careers from the native wizard and preserve manager presentation (by Codex)

This commit is contained in:
Codex committed 2026-10-29 01:11:41 +01:00
1 parent 738ecc7a09
commit ce1535fe2d
38 files changed
+466 -75

No files matched your search

+35
View File
@@ -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"})