cleanup ContentControl
This commit is contained in:
@@ -30,7 +30,13 @@ ContentControl::ContentControl(
|
||||
: paths(paths),
|
||||
input(input),
|
||||
postContent(std::move(postContent)),
|
||||
basePacks(io::read_list("res:config/builtins.list")) {
|
||||
basePacks(io::read_list("res:config/builtins.list")),
|
||||
manager(std::make_unique<PacksManager>()) {
|
||||
manager->setSources({
|
||||
"world:content",
|
||||
"user:content",
|
||||
"res:content",
|
||||
});
|
||||
}
|
||||
|
||||
ContentControl::~ContentControl() = default;
|
||||
@@ -57,29 +63,22 @@ void ContentControl::resetContent() {
|
||||
resRoots.push_back({"core", pack.folder});
|
||||
load_configs(input, pack.folder);
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources({
|
||||
"user:content",
|
||||
"res:content",
|
||||
});
|
||||
manager.scan();
|
||||
for (const auto& pack : manager.getAll(basePacks)) {
|
||||
manager->scan();
|
||||
for (const auto& pack : manager->getAll(basePacks)) {
|
||||
resRoots.push_back({pack.id, pack.folder});
|
||||
}
|
||||
paths.resPaths = ResPaths(resRoots);
|
||||
content.reset();
|
||||
|
||||
contentPacks.clear();
|
||||
contentPacks = manager.getAll(basePacks);
|
||||
contentPacks = manager->getAll(basePacks);
|
||||
|
||||
postContent();
|
||||
}
|
||||
|
||||
void ContentControl::loadContent(const std::vector<std::string>& names) {
|
||||
PacksManager manager;
|
||||
manager.setSources(getDefaultSources());
|
||||
manager.scan();
|
||||
contentPacks = manager.getAll(manager.assemble(names));
|
||||
manager->scan();
|
||||
contentPacks = manager->getAll(manager->assemble(names));
|
||||
loadContent();
|
||||
}
|
||||
|
||||
@@ -90,12 +89,9 @@ void ContentControl::loadContent() {
|
||||
for (auto& pack : contentPacks) {
|
||||
names.push_back(pack.id);
|
||||
}
|
||||
|
||||
PacksManager manager;
|
||||
manager.setSources(getDefaultSources());
|
||||
manager.scan();
|
||||
names = manager.assemble(names);
|
||||
contentPacks = manager.getAll(names);
|
||||
manager->scan();
|
||||
names = manager->assemble(names);
|
||||
contentPacks = manager->getAll(names);
|
||||
|
||||
std::vector<PathsRoot> entryPoints;
|
||||
for (auto& pack : contentPacks) {
|
||||
@@ -130,14 +126,6 @@ void ContentControl::loadContent() {
|
||||
postContent();
|
||||
}
|
||||
|
||||
std::vector<io::path> ContentControl::getDefaultSources() {
|
||||
return {
|
||||
"world:content",
|
||||
"user:content",
|
||||
"res:content",
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<ContentPack>& ContentControl::getContentPacks() {
|
||||
return contentPacks;
|
||||
}
|
||||
@@ -147,3 +135,8 @@ std::vector<ContentPack> ContentControl::getAllContentPacks() {
|
||||
packs.insert(packs.begin(), ContentPack::createCore(paths));
|
||||
return packs;
|
||||
}
|
||||
|
||||
PacksManager& ContentControl::scan() {
|
||||
manager->scan();
|
||||
return *manager;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "ContentPack.hpp"
|
||||
|
||||
class Content;
|
||||
struct ContentPack;
|
||||
class PacksManager;
|
||||
class EnginePaths;
|
||||
class Input;
|
||||
|
||||
@@ -36,14 +36,16 @@ public:
|
||||
|
||||
void loadContent();
|
||||
|
||||
std::vector<io::path> getDefaultSources();
|
||||
std::vector<ContentPack>& getContentPacks();
|
||||
std::vector<ContentPack> getAllContentPacks();
|
||||
|
||||
PacksManager& scan();
|
||||
private:
|
||||
EnginePaths& paths;
|
||||
Input& input;
|
||||
std::unique_ptr<Content> content;
|
||||
std::function<void()> postContent;
|
||||
std::vector<std::string> basePacks;
|
||||
std::unique_ptr<PacksManager> manager;
|
||||
std::vector<ContentPack> contentPacks;
|
||||
};
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace fs = std::filesystem;
|
||||
|
||||
ContentPack ContentPack::createCore(const EnginePaths& paths) {
|
||||
return ContentPack {
|
||||
"core", "Core", ENGINE_VERSION_STRING, "", "", "res:", "res:", {}
|
||||
"core", "Core", ENGINE_VERSION_STRING, "", "", "res:", {}
|
||||
};
|
||||
}
|
||||
|
||||
const std::vector<std::string> ContentPack::RESERVED_NAMES = {
|
||||
"res", "abs", "local", "core", "user", "world", "none", "null"};
|
||||
"res", "abs", "local", "core", "user", "world", "none", "null"
|
||||
};
|
||||
|
||||
contentpack_error::contentpack_error(
|
||||
std::string packId, io::path folder, const std::string& message
|
||||
@@ -70,7 +71,7 @@ static void checkContentPackId(const std::string& id, const io::path& folder) {
|
||||
}
|
||||
}
|
||||
|
||||
ContentPack ContentPack::read(const std::string& path, const io::path& folder) {
|
||||
ContentPack ContentPack::read(const io::path& folder) {
|
||||
auto root = io::read_json(folder / PACKAGE_FILENAME);
|
||||
ContentPack pack;
|
||||
root.at("id").get(pack.id);
|
||||
@@ -90,7 +91,6 @@ ContentPack ContentPack::read(const std::string& path, const io::path& folder) {
|
||||
root.at("description").get(pack.description);
|
||||
root.at("source").get(pack.source);
|
||||
pack.folder = folder;
|
||||
pack.path = path;
|
||||
|
||||
if (auto found = root.at("dependencies")) {
|
||||
const auto& dependencies = *found;
|
||||
@@ -133,7 +133,7 @@ void ContentPack::scanFolder(
|
||||
if (!io::is_directory(packFolder)) continue;
|
||||
if (!is_pack(packFolder)) continue;
|
||||
try {
|
||||
packs.push_back(read(packFolder.string(), packFolder));
|
||||
packs.push_back(read(packFolder));
|
||||
} catch (const contentpack_error& err) {
|
||||
std::cerr << "package.json error at " << err.getFolder().string();
|
||||
std::cerr << ": " << err.what() << std::endl;
|
||||
|
||||
@@ -43,7 +43,6 @@ struct ContentPack {
|
||||
std::string creator = "";
|
||||
std::string description = "no description";
|
||||
io::path folder;
|
||||
std::string path;
|
||||
std::vector<DependencyPack> dependencies;
|
||||
std::string source = "";
|
||||
|
||||
@@ -58,7 +57,7 @@ struct ContentPack {
|
||||
static const std::vector<std::string> RESERVED_NAMES;
|
||||
|
||||
static bool is_pack(const io::path& folder);
|
||||
static ContentPack read(const std::string& path, const io::path& folder);
|
||||
static ContentPack read(const io::path& folder);
|
||||
|
||||
static void scanFolder(
|
||||
const io::path& folder, std::vector<ContentPack>& packs
|
||||
|
||||
Reference in New Issue
Block a user