Merge branch 'main' into heightmaps

This commit is contained in:
MihailRis 2024-08-14 00:38:35 +03:00
commit 7da8e133a5
5 changed files with 22 additions and 22 deletions

View File

@ -4,6 +4,7 @@
#include <iostream>
#include <utility>
#include "constants.hpp"
#include "coders/json.hpp"
#include "data/dynamic.hpp"
#include "files/engine_paths.hpp"
@ -11,6 +12,12 @@
namespace fs = std::filesystem;
ContentPack ContentPack::createCore(const EnginePaths* paths) {
return ContentPack {
"core", "Core", ENGINE_VERSION_STRING, "", "", paths->getResourcesFolder(), {}
};
}
const std::vector<std::string> ContentPack::RESERVED_NAMES = {
"res", "abs", "local", "core", "user", "world", "none", "null"};

View File

@ -67,6 +67,8 @@ struct ContentPack {
const fs::path& worldDir,
const std::string& name
);
static ContentPack createCore(const EnginePaths*);
};
struct ContentPackStats {

View File

@ -313,12 +313,17 @@ void Engine::loadContent() {
contentPacks = manager.getAll(names);
std::vector<PathsRoot> resRoots;
{
auto pack = ContentPack::createCore(paths);
resRoots.push_back({"core", pack.folder});
ContentLoader(&pack, contentBuilder).load();
load_configs(pack.folder);
}
for (auto& pack : contentPacks) {
resRoots.push_back({pack.id, pack.folder});
ContentLoader(&pack, contentBuilder).load();
load_configs(pack.folder);
}
load_configs(paths->getResourcesFolder());
content = contentBuilder.build();
resPaths = std::make_unique<ResPaths>(resdir, resRoots);
@ -330,7 +335,13 @@ void Engine::loadContent() {
void Engine::resetContent() {
auto resdir = paths->getResourcesFolder();
resPaths = std::make_unique<ResPaths>(resdir, std::vector<PathsRoot>());
std::vector<PathsRoot> resRoots;
{
auto pack = ContentPack::createCore(paths);
resRoots.push_back({"core", pack.folder});
load_configs(pack.folder);
}
resPaths = std::make_unique<ResPaths>(resdir, resRoots);
contentPacks.clear();
content.reset();

View File

@ -218,10 +218,6 @@ std::string ResPaths::findRaw(const std::string& filename) const {
return root.name + ":" + filename;
}
}
auto resDir = mainRoot;
if (fs::exists(resDir / std::filesystem::path(filename))) {
return "core:" + filename;
}
throw std::runtime_error("could not to find file " + util::quote(filename));
}
@ -236,14 +232,6 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
entries.emplace_back(root.name + ":" + folderName + "/" + name);
}
}
{
auto folder = mainRoot / fs::u8path(folderName);
if (!fs::is_directory(folder)) return entries;
for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string();
entries.emplace_back("core:" + folderName + "/" + name);
}
}
return entries;
}
@ -259,13 +247,6 @@ std::vector<std::filesystem::path> ResPaths::listdir(
entries.push_back(entry.path());
}
}
{
auto folder = mainRoot / fs::u8path(folderName);
if (!fs::is_directory(folder)) return entries;
for (const auto& entry : fs::directory_iterator(folder)) {
entries.push_back(entry.path());
}
}
return entries;
}

View File

@ -39,7 +39,6 @@ LevelController* scripting::controller = nullptr;
static void load_script(const fs::path& name, bool throwable) {
auto paths = scripting::engine->getPaths();
fs::path file = paths->getResourcesFolder() / fs::path("scripts") / name;
std::string src = files::read_string(file);
auto L = lua::get_main_thread();
lua::loadbuffer(L, 0, src, file.u8string());