Manage real OBS careers in native save and load dialogs (by Codex)
This commit is contained in:
1 parent
693744a961
commit
e3ea03a05d
25 files changed
+539
-39
No files matched your search
@@ -3,13 +3,26 @@
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "modern/content/world_save.hpp"
|
||||
#include "modern/content/world_expand.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/career_files.hpp"
|
||||
#include "content/digest.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
Json from_engine(const cli::Json &v) { return Json::parse(cli::dump_json(v)); }
|
||||
}
|
||||
namespace {
|
||||
Json session_snapshot(modern::app::ModernSession &session,uint64_t revision) {
|
||||
Json bundle=Json::object();
|
||||
for(const auto *kind:{"session","desktop","camps","squad","lineup","tactics","training","bank","stadium","credit","environment","advertising","contracts","friendly-plan"})bundle[kind]=from_engine(session.ui_read(cli::Json::Object{{"kind",kind}},revision));
|
||||
validate_engine_desk(bundle);const auto &season=bundle.at("desktop").at("meta").at("season");
|
||||
bundle["calendar"]=from_engine(session.ui_read(cli::Json::Object{{"kind","calendar"},{"from",season.at("startDate").get<std::string>()},{"until",season.at("endDate").get<std::string>()}},revision));
|
||||
bundle["scheduling"]=from_engine(session.ui_read(cli::Json::Object{{"kind","scheduling"}},revision));return bundle;
|
||||
}
|
||||
}
|
||||
struct EngineBridge::Impl {
|
||||
modern::WorldPackage package;
|
||||
std::unique_ptr<content::Mount> mount;
|
||||
@@ -63,22 +76,35 @@ std::shared_ptr<EngineBridge> EngineBridge::create(const fs::path &world,const J
|
||||
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"})
|
||||
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
|
||||
validate_engine_desk(bundle);
|
||||
const auto &season = bundle.at("desktop").at("meta").at("season");
|
||||
bundle["calendar"] = read({{"kind", "calendar"}, {"from", season.at("startDate")}, {"until", season.at("endDate")}});
|
||||
bundle["scheduling"] = read({{"kind", "scheduling"}});
|
||||
return bundle;
|
||||
}
|
||||
Json EngineBridge::snapshot() const {return session_snapshot(*impl_->session,impl_->revision);}
|
||||
Json EngineBridge::command(const Json &request) {
|
||||
return from_engine(impl_->session->ui_command(cli::parse_json(request.dump()), impl_->revision));
|
||||
}
|
||||
Json EngineBridge::read(const Json &request) const {
|
||||
return from_engine(impl_->session->ui_read(cli::parse_json(request.dump()), impl_->revision));
|
||||
}
|
||||
CareerFiles make_career_files(const fs::path &directory,const fs::path &world) {
|
||||
const auto model=modern::open_world_package(world).world;
|
||||
return CareerFiles(directory,[model](const fs::path &file){
|
||||
try{return from_engine(modern::read_world_career_metadata(file,*model));}
|
||||
catch(const std::exception &e){const std::string reason=e.what();if(reason.starts_with("the save belongs to another world"))throw editor::Error("Dieser Spielstand gehört zu einer anderen Mod oder Datensatzversion.");throw editor::Error("Dieser Spielstand ist beschädigt oder wird nicht unterstützt.");}
|
||||
});
|
||||
}
|
||||
Json EngineBridge::file_metadata() const {
|
||||
const auto reply=read({{"kind","file-metadata"}});
|
||||
if(reply.value("messageType","")!="snapshot")throw editor::Error("Spielstandangaben nicht verfügbar.");
|
||||
return reply.at("data");
|
||||
}
|
||||
Json EngineBridge::load_same_world(const fs::path &path,const std::string &expected_token) {
|
||||
const auto check=[&]{if(!expected_token.empty()&&content::sha256(editor::read_file(path,256*1024*1024))!=expected_token)throw editor::Error("Dieser Spielstand wurde inzwischen geändert. Bitte erneut auswählen.");};
|
||||
check();(void)modern::load_world_career(path,*impl_->package.world);
|
||||
try {
|
||||
auto staged=std::make_unique<modern::app::ModernSession>(impl_->mount->root(),1u,path,false);
|
||||
(void)session_snapshot(*staged,0);check();
|
||||
impl_->session=std::move(staged);impl_->input=fs::weakly_canonical(path);impl_->revision=0;
|
||||
}catch(...){modern::install_world_dimensions(*impl_->package.world);throw;}
|
||||
return {{"messageType","loaded"}};
|
||||
}
|
||||
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.");
|
||||
|
||||
Reference in new issue
Block a user