diff --git a/src/boe.main.cpp b/src/boe.main.cpp index 9c270cc1..e8652cce 100644 --- a/src/boe.main.cpp +++ b/src/boe.main.cpp @@ -65,6 +65,7 @@ bool give_intro_hint = true; bool in_scen_debug = false; bool show_startup_splash = true; bool belt_present = false; +std::string scenario_temp_dir_name = "scenario"; /* Display globals */ short combat_posing_monster = -1, current_working_monster = -1; // 0-5 PC 100 + x - monster x diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp index aceed642..e4d2f422 100644 --- a/src/pcedit/pc.main.cpp +++ b/src/pcedit/pc.main.cpp @@ -33,6 +33,7 @@ rectangle traits_rect; //Holds the string "Traits:" rectangle pc_traits_rect[16]; //Holds pc traits rectangle pc_race_rect; //Holds current pc's race rectangle edit_rect[5][2]; //Buttons that bring up pc edit dialog boxs +std::string scenario_temp_dir_name = "pc_scenario"; short current_active_pc = 0; diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 62dbb338..1129970f 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -3332,10 +3332,12 @@ static void set_dlg_custom_sheet(cDialog& me, size_t sheet) { } extern fs::path tempDir; +extern std::string scenario_temp_dir_name; + void edit_custom_sheets() { int max_pic = -1; std::vector all_pics; - fs::path pic_dir = tempDir/"scenario/graphics"; + fs::path pic_dir = tempDir/scenario_temp_dir_name/"graphics"; if(!fs::exists(pic_dir)) fs::create_directories(pic_dir); for(fs::directory_iterator iter(pic_dir); iter != fs::directory_iterator(); iter++) { std::string fname = iter->path().filename().string().c_str(); @@ -3572,7 +3574,7 @@ static bool edit_custom_sound_action(cDialog& me, std::string action, std::vecto size_t a_len = action.length(); int which_snd = (curPage + 1) * 100 + (action[a_len-1] - '0'); action.erase(action.end() - 1); - fs::path sndpath = tempDir/"scenario/sounds"; + fs::path sndpath = tempDir/scenario_temp_dir_name/"sounds"; std::string sndbasenm = "SND" + std::to_string(which_snd); fs::path sndfile = sndpath/(sndbasenm + ".wav"); if(action != "open" && !fs::exists(sndfile)) { @@ -3648,7 +3650,7 @@ void edit_custom_sounds() { snd_dlg["okay"].attachClickHandler(std::bind(&cDialog::toast, &snd_dlg, true)); int max_snd = 99; - fs::path snd_dir = tempDir/"scenario/sounds"; + fs::path snd_dir = tempDir/scenario_temp_dir_name/"sounds"; if(!fs::exists(snd_dir)) fs::create_directories(snd_dir); for(fs::directory_iterator iter(snd_dir); iter != fs::directory_iterator(); iter++) { std::string fname = iter->path().filename().string().c_str(); diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index 8d3c80d7..b4d5c950 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -917,6 +917,7 @@ struct overrides_sheet { } }; +std::string scenario_temp_dir_name = "ed_scenario"; void save_scenario(bool rename) { fs::path toFile = scenario.scen_file; if(rename || toFile.empty()) { @@ -1024,7 +1025,7 @@ void save_scenario(bool rename) { fin.close(); } } else { - fs::path picPath = tempDir/"scenario"/"graphics"; + fs::path picPath = tempDir/scenario_temp_dir_name/"graphics"; if(fs::exists(picPath) && fs::is_directory(picPath)) { // First build a list of overridable sheets std::set sheet_names; @@ -1062,7 +1063,7 @@ void save_scenario(bool rename) { } // And also sounds! - fs::path sndPath = tempDir/"scenario"/"sounds"; + fs::path sndPath = tempDir/scenario_temp_dir_name/"sounds"; if(fs::exists(sndPath) && fs::is_directory(sndPath)) { fs::directory_iterator dir_iter(sndPath); while(dir_iter != fs::directory_iterator()) { diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index 97dec892..54059c64 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -153,6 +153,7 @@ short choose_background(short cur_choice, cDialog* parent) { } // TODO: I have two functions that do this. (The other one is pick_picture.) +extern std::string scenario_temp_dir_name; pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) { extern fs::path tempDir; int i = 0; @@ -176,11 +177,11 @@ pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) { case PIC_SCEN_LG: total_pics = 4; break; case PIC_TER_MAP: total_pics = 980; break; case PIC_FULL: - if(!fs::is_directory(tempDir/"scenario/graphics")) { + if(!fs::is_directory(tempDir/scenario_temp_dir_name/"graphics")) { giveError("You have no custom graphics, so it's not possible to select this kind of picture!",parent); return NO_PIC; } - for(fs::directory_iterator iter(tempDir/"scenario/graphics"); iter != fs::directory_iterator(); iter++) { + for(fs::directory_iterator iter(tempDir/scenario_temp_dir_name/"graphics"); iter != fs::directory_iterator(); iter++) { std::string fname = iter->path().filename().string().c_str(); size_t dot = fname.find_last_of('.'); if(dot == std::string::npos) continue; diff --git a/src/tools/fileio_scen.cpp b/src/tools/fileio_scen.cpp index 88f8975c..8f3813aa 100644 --- a/src/tools/fileio_scen.cpp +++ b/src/tools/fileio_scen.cpp @@ -1957,6 +1957,7 @@ static void readSpecialNodesFromStream(std::istream& stream, std::vector std::istream& { - if(is_packed) return pack.getFile(relpath); + if(is_packed) return pack.getFile("scenario/" + relpath); if(fin.is_open()) fin.close(); fin.clear(); fin.open((file_to_load/relpath).string().c_str()); @@ -1997,29 +1998,29 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head TiXmlBase::SetCondenseWhiteSpace(true); // Make sure this is enabled, because the dialog engine disables it { // First, load up the binary header data. - std::istream& header = getFile("scenario/header.exs"); + std::istream& header = getFile("header.exs"); header.read(reinterpret_cast(&scenario.format), sizeof(scenario_header_flags)); // Then, the main scenario data. - std::istream& scen_data = getFile("scenario/scenario.xml"); + std::istream& scen_data = getFile("scenario.xml"); readScenarioFromXml(xmlDocFromStream(scen_data, "scenario.xml"), scenario); if(only_header) return true; // Next, terrain types... - std::istream& terrain = getFile("scenario/terrain.xml"); + std::istream& terrain = getFile("terrain.xml"); readTerrainFromXml(xmlDocFromStream(terrain, "terrain.xml"), scenario); // ...items... - std::istream& items = getFile("scenario/items.xml"); + std::istream& items = getFile("items.xml"); readItemsFromXml(xmlDocFromStream(items, "items.xml"), scenario); // ...and monsters. - std::istream& monsters = getFile("scenario/monsters.xml"); + std::istream& monsters = getFile("monsters.xml"); readMonstersFromXml(xmlDocFromStream(monsters, "monsters.xml"), scenario); // Finally, the special nodes. - std::istream& nodes = getFile("scenario/scenario.spec"); + std::istream& nodes = getFile("scenario.spec"); readSpecialNodesFromStream(nodes, scenario.scen_specials, "scenario.spec"); } @@ -2029,15 +2030,15 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head scenario.outdoors[x][y] = new cOutdoors(scenario); std::string file_basename = "out" + std::to_string(x) + '~' + std::to_string(y); // First the main data. - std::istream& outdoors = getFile("scenario/out/" + file_basename + ".xml"); + std::istream& outdoors = getFile("out/" + file_basename + ".xml"); readOutdoorsFromXml(xmlDocFromStream(outdoors, file_basename + ".xml"), *scenario.outdoors[x][y]); // Then the map. - std::istream& out_map = getFile("scenario/out/" + file_basename + ".map"); + std::istream& out_map = getFile("out/" + file_basename + ".map"); loadOutMapData(load_map(out_map, false, file_basename + ".map"), loc(x,y), scenario); // And the special nodes. - std::istream& out_spec = getFile("scenario/out/" + file_basename + ".spec"); + std::istream& out_spec = getFile("out/" + file_basename + ".spec"); readSpecialNodesFromStream(out_spec, scenario.outdoors[x][y]->specials, file_basename + ".spec"); } } @@ -2046,19 +2047,19 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head for(size_t i = 0; i < scenario.towns.size(); i++) { std::string file_basename = "town" + std::to_string(i); // First the main data. - std::istream& town = getFile("scenario/towns/" + file_basename + ".xml"); + std::istream& town = getFile("towns/" + file_basename + ".xml"); readTownFromXml(xmlDocFromStream(town, file_basename + ".xml"), scenario.towns[i], scenario); // Then the map. - std::istream& town_map = getFile("scenario/towns/" + file_basename + ".map"); + std::istream& town_map = getFile("towns/" + file_basename + ".map"); loadTownMapData(load_map(town_map, true, file_basename + ".map"), i, scenario); // And the special nodes. - std::istream& town_spec = getFile("scenario/towns/" + file_basename + ".spec"); + std::istream& town_spec = getFile("towns/" + file_basename + ".spec"); readSpecialNodesFromStream(town_spec, scenario.towns[i]->specials, file_basename + ".spec"); // Don't forget the dialogue nodes. - std::istream& town_talk = getFile("scenario/towns/talk" + std::to_string(i) + ".xml"); + std::istream& town_talk = getFile("towns/talk" + std::to_string(i) + ".xml"); readDialogueFromXml(xmlDocFromStream(town_talk, "talk.xml"), scenario.towns[i]->talking, i); } @@ -2066,7 +2067,7 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head // First figure out where they are in the filesystem. The implementation of this depends on whether the scenario is packed. int num_graphic_sheets = 0; if(is_packed) { - fs::remove_all(tempDir/"scenario"); + fs::remove_all(tempDir/scenario_temp_dir_name); std::bitset<65536> have_pic = {0}; for(auto& file : pack) { std::string fname = file.filename; @@ -2089,9 +2090,10 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head if(fname.substr(dot,4) != ".wav") continue; if(!std::all_of(fname.begin() + 19, fname.begin() + dot, isdigit)) continue; } else continue; - fs::path path = tempDir/fname; + fname = fname.substr(9); + fs::path path = tempDir/scenario_temp_dir_name/fname; fs::create_directories(path.parent_path()); - std::istream& f = pack.getFile(fname); + std::istream& f = file.contents; std::ofstream fout(path.string().c_str(), std::ios::binary); fout << f.rdbuf(); fout.close(); @@ -2099,8 +2101,8 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head // This is a bit of trickery to get it to only count the first consecutive range of sheets while(have_pic[num_graphic_sheets]) num_graphic_sheets++; - ResMgr::pushPath(tempDir/"scenario"/"graphics"); - ResMgr::pushPath(tempDir/"scenario"/"sounds"); + ResMgr::pushPath(tempDir/scenario_temp_dir_name/"graphics"); + ResMgr::pushPath(tempDir/scenario_temp_dir_name/"sounds"); } else { if(fs::is_directory(file_to_load/"graphics")) ResMgr::pushPath(file_to_load/"graphics"); @@ -2338,8 +2340,8 @@ bool tryLoadPictFromResourceFile(fs::path& gpath, sf::Image& graphics_store); void load_spec_graphics_v1(fs::path scen_file) { static const char*const noGraphics = "The game will still work without the custom graphics, but some things will not look right."; - fs::remove_all(tempDir/"scenario/graphics"); - fs::remove_all(tempDir/"scenario/sounds"); + fs::remove_all(tempDir/scenario_temp_dir_name/"graphics"); + fs::remove_all(tempDir/scenario_temp_dir_name/"sounds"); fs::path path(scen_file); std::cout << "Loading scenario graphics... (" << path << ")\n"; // Tried path.replace_extension, but that only deleted the extension, so I have to do it manually diff --git a/src/tools/graphtool.cpp b/src/tools/graphtool.cpp index 232608db..80f11c09 100644 --- a/src/tools/graphtool.cpp +++ b/src/tools/graphtool.cpp @@ -489,6 +489,7 @@ void cCustomGraphics::copy_graphic(pic_num_t dest, pic_num_t src, size_t numSlot *last_src = temp.getTexture(); } +extern std::string scenario_temp_dir_name; void cCustomGraphics::convert_sheets() { if(!is_old) return; int num_graphics = count(); @@ -499,7 +500,7 @@ void cCustomGraphics::convert_sheets() { if(num_graphics % 100) numSheets++; sheets = new sf::Texture[numSheets]; extern fs::path tempDir; - fs::path pic_dir = tempDir/"scenario/graphics"; + fs::path pic_dir = tempDir/scenario_temp_dir_name/"graphics"; for(size_t i = 0; i < numSheets; i++) { sf::IntRect subrect; subrect.top = i * 280; @@ -525,7 +526,7 @@ void cCustomGraphics::replace_sheet(size_t num, sf::Image& newSheet) { // Then we need to do some extra stuff to ensure the dialog engine also sees the change extern fs::path tempDir; std::string sheetname = "sheet" + std::to_string(num); - fs::path tmpPath = tempDir/"scenario/graphics"/(sheetname + ".png"); + fs::path tmpPath = tempDir/scenario_temp_dir_name/"graphics"/(sheetname + ".png"); newSheet.saveToFile(tmpPath.string().c_str()); ResMgr::free(sheetname); }