Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 20, 2023
1 parent e0aee76 commit 170e6b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/content/ContentPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ fs::path ContentPack::findPack(const EnginePaths* paths, std::string name) {
}
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 changes: 3 additions & 0 deletions src/content/ContentPack.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct ContentPack {
std::vector<ContentPack>& packs);
static std::vector<std::string> worldPacksList(std::filesystem::path folder);
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_
24 changes: 9 additions & 15 deletions src/frontend/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,19 @@ void create_languages_panel(Engine* engine, PagesControl* menu) {
}

void open_world(std::string name, Engine* engine) {
// TODO: complete and move somewhere
auto paths = engine->getPaths();
auto resdir = paths->getResources();
auto folder = paths->getWorldsFolder()/fs::u8path(name);

auto& packs = engine->getContentPacks();
packs.clear();
auto packnames = ContentPack::worldPacksList(folder);
for (auto name : packnames) {
try {
fs::path packfolder = ContentPack::findPack(paths, name);
packs.push_back(ContentPack::read(packfolder));
} catch (contentpack_error& error) {
// could not to find or read pack
guiutil::alert(engine->getGUI(),
langs::get(L"error.pack-not-found")+
L": "+util::str2wstr_utf8(error.getPackId()));
return;
}
try {
auto packNames = ContentPack::worldPacksList(folder);
ContentPack::readPacks(paths, packs, packNames);
} catch (contentpack_error& error) {
// could not to find or read pack
guiutil::alert(engine->getGUI(),
langs::get(L"error.pack-not-found")+
L": "+util::str2wstr_utf8(error.getPackId()));
return;
}
engine->loadContent();

Expand Down

0 comments on commit 170e6b8

Please sign in to comment.