From 6198ca22f63a291d5213c9c554b891fa8dce6449 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 3 Jan 2024 15:22:52 +0300 Subject: [PATCH] world/content added to packs search paths --- src/content/ContentPack.cpp | 21 +++++++++++++-------- src/content/ContentPack.h | 9 +++++++-- src/frontend/menu.cpp | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/content/ContentPack.cpp b/src/content/ContentPack.cpp index c1fbacdd..e79a664a 100644 --- a/src/content/ContentPack.cpp +++ b/src/content/ContentPack.cpp @@ -71,20 +71,25 @@ std::vector ContentPack::worldPacksList(fs::path folder) { return files::read_list(listfile); } -fs::path ContentPack::findPack(const EnginePaths* paths, std::string name) { - auto folder = paths->getResources() / fs::path("content") / fs::path(name); - if (!fs::is_directory(folder)) { - throw contentpack_error(name, folder, - "could not to find pack '"+name+"'"); +fs::path ContentPack::findPack(const EnginePaths* paths, fs::path worldDir, std::string name) { + fs::path folder = worldDir / fs::path("content") / fs::path(name); + if (fs::is_directory(folder)) { + return folder; } - return folder; + folder = paths->getResources() / fs::path("content") / fs::path(name); + if (fs::is_directory(folder)) { + return folder; + } + throw contentpack_error(name, folder, + "could not to find pack '"+name+"'"); } void ContentPack::readPacks(const EnginePaths* paths, std::vector& packs, - const std::vector& packnames) { + const std::vector& packnames, + std::filesystem::path worldDir) { for (const auto& name : packnames) { - fs::path packfolder = ContentPack::findPack(paths, name); + fs::path packfolder = ContentPack::findPack(paths, worldDir, name); packs.push_back(ContentPack::read(packfolder)); } } diff --git a/src/content/ContentPack.h b/src/content/ContentPack.h index 3e920879..98ef7db9 100644 --- a/src/content/ContentPack.h +++ b/src/content/ContentPack.h @@ -37,10 +37,15 @@ struct ContentPack { static void scan(std::filesystem::path folder, std::vector& packs); static std::vector worldPacksList(std::filesystem::path folder); - static std::filesystem::path findPack(const EnginePaths* paths, std::string name); + + static std::filesystem::path findPack( + const EnginePaths* paths, + std::filesystem::path worldDir, + std::string name); static void readPacks(const EnginePaths* paths, std::vector& packs, - const std::vector& names); + const std::vector& names, + std::filesystem::path worldDir); }; #endif // CONTENT_CONTENT_PACK_H_ diff --git a/src/frontend/menu.cpp b/src/frontend/menu.cpp index 1000b7ce..6484bc0c 100644 --- a/src/frontend/menu.cpp +++ b/src/frontend/menu.cpp @@ -153,7 +153,7 @@ void open_world(std::string name, Engine* engine) { packs.clear(); try { auto packNames = ContentPack::worldPacksList(folder); - ContentPack::readPacks(paths, packs, packNames); + ContentPack::readPacks(paths, packs, packNames, folder); } catch (contentpack_error& error) { // could not to find or read pack guiutil::alert(engine->getGUI(),