From b3d8a64e7970270151a8e47c7cf4d08568dc6fb4 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 8 Jan 2025 12:10:53 -0600 Subject: [PATCH] start implementing scenario editor launch function --- src/fileio/fileio_scen.cpp | 18 ++++++++++++++---- src/pcedit/pc.fileio.cpp | 1 + src/scenedit/scen.main.cpp | 30 +++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/fileio/fileio_scen.cpp b/src/fileio/fileio_scen.cpp index 12f86f2e..b9751f0e 100644 --- a/src/fileio/fileio_scen.cpp +++ b/src/fileio/fileio_scen.cpp @@ -35,6 +35,7 @@ bool cur_scen_is_mac = true; extern cCustomGraphics spec_scen_g; extern fs::path tempDir, scenDir, progDir; +extern std::string last_load_file; void load_spec_graphics_v1(fs::path scen_file); void load_spec_graphics_v2(int num_sheets); @@ -160,10 +161,19 @@ bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header) showError("That is not a Blades of Exile scenario."); return false; } else try { - if(fname.substr(dot) == ".boes") - return load_scenario_v2(file_to_load, scenario, only_header); - else if(fname.substr(dot) == ".exs") - return load_scenario_v1(file_to_load, scenario, only_header); + if(fname.substr(dot) == ".boes"){ + if(load_scenario_v2(file_to_load, scenario, only_header)){ + last_load_file = file_to_load.string(); + return true; + } + return false; + }else if(fname.substr(dot) == ".exs"){ + if(load_scenario_v1(file_to_load, scenario, only_header)){ + last_load_file = file_to_load.string(); + return true; + } + return false; + } } catch(std::exception& x) { showError("There was an error loading the scenario. The details of the error are given below; you may be able to decompress the scenario package, fix the error, and repack it.", x.what()); return false; diff --git a/src/pcedit/pc.fileio.cpp b/src/pcedit/pc.fileio.cpp index ac4db66e..caa33faa 100644 --- a/src/pcedit/pc.fileio.cpp +++ b/src/pcedit/pc.fileio.cpp @@ -16,6 +16,7 @@ extern void update_item_menu(); void load_base_item_defs(); extern fs::path progDir; +std::string last_load_file = "Blades of Exile Save"; void leave_town() { univ.party.town_num = 200; diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp index 807e92dd..f737608c 100644 --- a/src/scenedit/scen.main.cpp +++ b/src/scenedit/scen.main.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include "cli.hpp" @@ -85,10 +87,17 @@ extern void set_up_apple_events(); std::unordered_map> event_listeners; cDrawableManager drawable_mgr; +fs::path scenedit_dir; +fs::path game_dir; +fs::path game_binary; + +void launch_scenario() { + +} + //Changed to ISO C specified argument and return type. int main(int argc, char* argv[]) { try { - init_scened(argc, argv); if(ae_loading) @@ -218,8 +227,24 @@ static void process_args(int argc, char* argv[]) { } } +void init_game_paths(std::string binary_path) { + fs::path path = binary_path; + scenedit_dir = path.parent_path(); + game_dir = scenedit_dir; +#ifdef SFML_SYSTEM_MACOS + // Get the directory containing the app bundle + game_dir = game_dir/".."/".."/".."; + game_binary = game_dir/"Blades of Exile.app"/"Contents"/"MacOS"/"Blades of Exile"; +#elif SFML_SYSTEM_WINDOWS + game_binary = game_dir/"Blades of Exile.exe"; +#elif SFML_SYSTEM_LINUX + game_binary = game_dir/"Blades of Exile"; +#endif +} + void init_scened(int argc, char* argv[]) { init_directories(argv[0]); + init_game_paths(argv[0]); sync_prefs(); adjust_windows(mainPtr, mainView); //init_menubar(); @@ -425,6 +450,9 @@ void handle_menu_choice(eMenu item_hit) { editKey.k = key_selectall; isEdit = true; break; + case eMenu::LAUNCH: + launch_scenario(); + break; case eMenu::TOWN_CREATE: if(scenario.towns.size() >= 200) { showError("You have reached the limit of 200 towns you can have in one scenario.");