Auto content packs detection

This commit is contained in:
MihailRis
2023-12-20 20:54:03 +03:00
parent bcfdc55277
commit 3ad903449e
8 changed files with 93 additions and 100 deletions
+12 -4
View File
@@ -40,10 +40,11 @@ using std::unique_ptr;
using std::shared_ptr;
using std::string;
using std::vector;
using std::filesystem::path;
using glm::vec3;
using gui::GUI;
namespace fs = std::filesystem;
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
: settings(settings), paths(paths) {
if (Window::initialize(settings.display)){
@@ -53,7 +54,7 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
auto resdir = paths->getResources();
std::cout << "-- loading assets" << std::endl;
std::vector<path> roots {resdir};
std::vector<fs::path> roots {resdir};
resPaths.reset(new ResPaths(resdir, roots));
assets.reset(new Assets());
AssetsLoader loader(assets.get(), resPaths.get());
@@ -89,7 +90,7 @@ void Engine::updateHotkeys() {
if (Events::jpressed(keycode::F2)) {
unique_ptr<ImageData> image(Window::takeScreenshot());
image->flipY();
path filename = paths->getScreenshotFile("png");
fs::path filename = paths->getScreenshotFile("png");
png::write_image(filename.string(), image.get());
std::cout << "saved screenshot as " << filename << std::endl;
}
@@ -173,7 +174,7 @@ void Engine::loadContent() {
ContentBuilder contentBuilder;
setup_definitions(&contentBuilder);
vector<path> resRoots;
vector<fs::path> resRoots;
for (auto& pack : contentPacks) {
ContentLoader loader(&pack);
loader.load(&contentBuilder);
@@ -197,3 +198,10 @@ void Engine::loadContent() {
}
assets->extend(*new_assets.get());
}
void Engine::loadAllPacks() {
auto resdir = paths->getResources();
contentPacks.clear();
ContentPack::scan(resdir/fs::path("content"), contentPacks);
loadContent();
}