diff --git a/src/content/ContentPack.cpp b/src/content/ContentPack.cpp index 5ad8d9ba..4370c7f8 100644 --- a/src/content/ContentPack.cpp +++ b/src/content/ContentPack.cpp @@ -75,7 +75,9 @@ ContentPack ContentPack::read(fs::path folder) { auto dependencies = root->list("dependencies"); if (dependencies) { for (size_t i = 0; i < dependencies->size(); i++) { - pack.dependencies.push_back(dependencies->str(i)); + pack.dependencies.push_back( + {DependencyLevel::required, dependencies->str(i)} + ); } } diff --git a/src/content/ContentPack.h b/src/content/ContentPack.h index c6ce7c86..e5a61f2d 100644 --- a/src/content/ContentPack.h +++ b/src/content/ContentPack.h @@ -26,6 +26,19 @@ public: fs::path getFolder() const; }; +enum class DependencyLevel { + required, // dependency must be installed + optional, // dependency will be installed if found + weak, // dependency will not be installed automatically +}; + + +/// @brief Content-pack that should be installed before the dependent +struct DependencyPack { + DependencyLevel level; + std::string id; +}; + struct ContentPack { std::string id = "none"; std::string title = "untitled"; @@ -33,7 +46,7 @@ struct ContentPack { std::string creator = ""; std::string description = "no description"; fs::path folder; - std::vector dependencies; + std::vector dependencies; fs::path getContentFile() const; diff --git a/src/engine.cpp b/src/engine.cpp index 42c7deeb..36a005c9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -205,11 +205,11 @@ Engine::~Engine() { inline const std::string checkPacks( const std::unordered_set& packs, - const std::vector& dependencies + const std::vector& dependencies ) { - for (const std::string& str : dependencies) { - if (packs.find(str) == packs.end()) { - return str; + for (const auto& dependency : dependencies) { + if (packs.find(dependency.id) == packs.end()) { + return dependency.id; } } return ""; @@ -232,6 +232,7 @@ void Engine::loadContent() { existingPacks.insert(item.id); } + // FIXME: dependency levels while (existingPacks.size() > loadedPacks.size()) { for (auto& pack : srcPacks) { if(loadedPacks.find(pack.id) != loadedPacks.end()) { @@ -252,14 +253,14 @@ void Engine::loadContent() { } content.reset(contentBuilder.build()); - resPaths.reset(new ResPaths(resdir, resRoots)); - - Shader::preprocessor->setPaths(resPaths.get()); + resPaths = std::make_unique(resdir, resRoots); langs::setup(resdir, langs::current->getId(), contentPacks); - std::unique_ptr new_assets(new Assets()); std::cout << "-- loading assets" << std::endl; + + auto new_assets = std::make_unique(); + Shader::preprocessor->setPaths(resPaths.get()); AssetsLoader loader(new_assets.get(), resPaths.get()); AssetsLoader::addDefaults(loader, content.get()); while (loader.hasNext()) { @@ -268,7 +269,7 @@ void Engine::loadContent() { throw std::runtime_error("could not to load assets"); } } - assets->extend(*new_assets.get()); + assets->extend(*new_assets); onAssetsLoaded(); } diff --git a/src/frontend/menu/menu_pause.cpp b/src/frontend/menu/menu_pause.cpp index 5566a903..7d42c15b 100644 --- a/src/frontend/menu/menu_pause.cpp +++ b/src/frontend/menu/menu_pause.cpp @@ -115,21 +115,21 @@ static void reopen_world(Engine* engine, World* world) { menus::open_world(wname, engine, true); } -// FIXME +// FIXME: dependency levels static bool try_add_dependency(Engine* engine, World* world, const ContentPack& pack, std::string& missing) { auto paths = engine->getPaths(); for (const auto& dependency : pack.dependencies) { fs::path folder = ContentPack::findPack( paths, world->wfile->directory, - dependency + dependency.id ); if (!fs::is_directory(folder)) { - missing = dependency; + missing = dependency.id; return true; } - if (!world->hasPack(dependency)) { - world->wfile->addPack(world, dependency); + if (!world->hasPack(dependency.id)) { + world->wfile->addPack(world, dependency.id); } } world->wfile->addPack(world, pack.id);