content pack dependency levels draft
This commit is contained in:
parent
13ae6c6950
commit
f298d6ef1d
@ -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)}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<std::string> dependencies;
|
||||
std::vector<DependencyPack> dependencies;
|
||||
|
||||
fs::path getContentFile() const;
|
||||
|
||||
|
||||
@ -205,11 +205,11 @@ Engine::~Engine() {
|
||||
|
||||
inline const std::string checkPacks(
|
||||
const std::unordered_set<std::string>& packs,
|
||||
const std::vector<std::string>& dependencies
|
||||
const std::vector<DependencyPack>& 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<ResPaths>(resdir, resRoots);
|
||||
|
||||
langs::setup(resdir, langs::current->getId(), contentPacks);
|
||||
|
||||
std::unique_ptr<Assets> new_assets(new Assets());
|
||||
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::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();
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user