content pack dependency levels draft
This commit is contained in:
@@ -75,7 +75,9 @@ ContentPack ContentPack::read(fs::path folder) {
|
|||||||
auto dependencies = root->list("dependencies");
|
auto dependencies = root->list("dependencies");
|
||||||
if (dependencies) {
|
if (dependencies) {
|
||||||
for (size_t i = 0; i < dependencies->size(); i++) {
|
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)}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,19 @@ public:
|
|||||||
fs::path getFolder() const;
|
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 {
|
struct ContentPack {
|
||||||
std::string id = "none";
|
std::string id = "none";
|
||||||
std::string title = "untitled";
|
std::string title = "untitled";
|
||||||
@@ -33,7 +46,7 @@ struct ContentPack {
|
|||||||
std::string creator = "";
|
std::string creator = "";
|
||||||
std::string description = "no description";
|
std::string description = "no description";
|
||||||
fs::path folder;
|
fs::path folder;
|
||||||
std::vector<std::string> dependencies;
|
std::vector<DependencyPack> dependencies;
|
||||||
|
|
||||||
fs::path getContentFile() const;
|
fs::path getContentFile() const;
|
||||||
|
|
||||||
|
|||||||
+10
-9
@@ -205,11 +205,11 @@ Engine::~Engine() {
|
|||||||
|
|
||||||
inline const std::string checkPacks(
|
inline const std::string checkPacks(
|
||||||
const std::unordered_set<std::string>& packs,
|
const std::unordered_set<std::string>& packs,
|
||||||
const std::vector<std::string>& dependencies
|
const std::vector<DependencyPack>& dependencies
|
||||||
) {
|
) {
|
||||||
for (const std::string& str : dependencies) {
|
for (const auto& dependency : dependencies) {
|
||||||
if (packs.find(str) == packs.end()) {
|
if (packs.find(dependency.id) == packs.end()) {
|
||||||
return str;
|
return dependency.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -232,6 +232,7 @@ void Engine::loadContent() {
|
|||||||
existingPacks.insert(item.id);
|
existingPacks.insert(item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: dependency levels
|
||||||
while (existingPacks.size() > loadedPacks.size()) {
|
while (existingPacks.size() > loadedPacks.size()) {
|
||||||
for (auto& pack : srcPacks) {
|
for (auto& pack : srcPacks) {
|
||||||
if(loadedPacks.find(pack.id) != loadedPacks.end()) {
|
if(loadedPacks.find(pack.id) != loadedPacks.end()) {
|
||||||
@@ -252,14 +253,14 @@ void Engine::loadContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content.reset(contentBuilder.build());
|
content.reset(contentBuilder.build());
|
||||||
resPaths.reset(new ResPaths(resdir, resRoots));
|
resPaths = std::make_unique<ResPaths>(resdir, resRoots);
|
||||||
|
|
||||||
Shader::preprocessor->setPaths(resPaths.get());
|
|
||||||
|
|
||||||
langs::setup(resdir, langs::current->getId(), contentPacks);
|
langs::setup(resdir, langs::current->getId(), contentPacks);
|
||||||
|
|
||||||
std::unique_ptr<Assets> new_assets(new Assets());
|
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
|
|
||||||
|
auto new_assets = std::make_unique<Assets>();
|
||||||
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||||
AssetsLoader::addDefaults(loader, content.get());
|
AssetsLoader::addDefaults(loader, content.get());
|
||||||
while (loader.hasNext()) {
|
while (loader.hasNext()) {
|
||||||
@@ -268,7 +269,7 @@ void Engine::loadContent() {
|
|||||||
throw std::runtime_error("could not to load assets");
|
throw std::runtime_error("could not to load assets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assets->extend(*new_assets.get());
|
assets->extend(*new_assets);
|
||||||
onAssetsLoaded();
|
onAssetsLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,21 +115,21 @@ static void reopen_world(Engine* engine, World* world) {
|
|||||||
menus::open_world(wname, engine, true);
|
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) {
|
static bool try_add_dependency(Engine* engine, World* world, const ContentPack& pack, std::string& missing) {
|
||||||
auto paths = engine->getPaths();
|
auto paths = engine->getPaths();
|
||||||
for (const auto& dependency : pack.dependencies) {
|
for (const auto& dependency : pack.dependencies) {
|
||||||
fs::path folder = ContentPack::findPack(
|
fs::path folder = ContentPack::findPack(
|
||||||
paths,
|
paths,
|
||||||
world->wfile->directory,
|
world->wfile->directory,
|
||||||
dependency
|
dependency.id
|
||||||
);
|
);
|
||||||
if (!fs::is_directory(folder)) {
|
if (!fs::is_directory(folder)) {
|
||||||
missing = dependency;
|
missing = dependency.id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!world->hasPack(dependency)) {
|
if (!world->hasPack(dependency.id)) {
|
||||||
world->wfile->addPack(world, dependency);
|
world->wfile->addPack(world, dependency.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
world->wfile->addPack(world, pack.id);
|
world->wfile->addPack(world, pack.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user