Minor refactor

This commit is contained in:
MihailRis
2023-12-20 23:22:48 +03:00
parent e0aee76f41
commit 170e6b86ea
3 changed files with 21 additions and 15 deletions
+9
View File
@@ -78,3 +78,12 @@ fs::path ContentPack::findPack(const EnginePaths* paths, std::string name) {
} }
return folder; return folder;
} }
void ContentPack::readPacks(const EnginePaths* paths,
std::vector<ContentPack>& packs,
const std::vector<std::string>& packnames) {
for (const auto& name : packnames) {
fs::path packfolder = ContentPack::findPack(paths, name);
packs.push_back(ContentPack::read(packfolder));
}
}
+3
View File
@@ -36,6 +36,9 @@ struct ContentPack {
std::vector<ContentPack>& packs); std::vector<ContentPack>& packs);
static std::vector<std::string> worldPacksList(std::filesystem::path folder); static std::vector<std::string> 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::string name);
static void readPacks(const EnginePaths* paths,
std::vector<ContentPack>& packs,
const std::vector<std::string>& names);
}; };
#endif // CONTENT_CONTENT_PACK_H_ #endif // CONTENT_CONTENT_PACK_H_
+9 -15
View File
@@ -147,25 +147,19 @@ void create_languages_panel(Engine* engine, PagesControl* menu) {
} }
void open_world(std::string name, Engine* engine) { void open_world(std::string name, Engine* engine) {
// TODO: complete and move somewhere
auto paths = engine->getPaths(); auto paths = engine->getPaths();
auto resdir = paths->getResources();
auto folder = paths->getWorldsFolder()/fs::u8path(name); auto folder = paths->getWorldsFolder()/fs::u8path(name);
auto& packs = engine->getContentPacks(); auto& packs = engine->getContentPacks();
packs.clear(); packs.clear();
auto packnames = ContentPack::worldPacksList(folder); try {
for (auto name : packnames) { auto packNames = ContentPack::worldPacksList(folder);
try { ContentPack::readPacks(paths, packs, packNames);
fs::path packfolder = ContentPack::findPack(paths, name); } catch (contentpack_error& error) {
packs.push_back(ContentPack::read(packfolder)); // could not to find or read pack
} catch (contentpack_error& error) { guiutil::alert(engine->getGUI(),
// could not to find or read pack langs::get(L"error.pack-not-found")+
guiutil::alert(engine->getGUI(), L": "+util::str2wstr_utf8(error.getPackId()));
langs::get(L"error.pack-not-found")+ return;
L": "+util::str2wstr_utf8(error.getPackId()));
return;
}
} }
engine->loadContent(); engine->loadContent();