packs dependencies fix + dofile patch
This commit is contained in:
+20
-3
@@ -11,9 +11,6 @@ function is_array(x)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local __cached_scripts = {}
|
|
||||||
local __cached_results = {}
|
|
||||||
|
|
||||||
-- Get entry-point and filename from `entry-point:filename` path
|
-- Get entry-point and filename from `entry-point:filename` path
|
||||||
function parse_path(path)
|
function parse_path(path)
|
||||||
local index = string.find(path, ':')
|
local index = string.find(path, ':')
|
||||||
@@ -23,6 +20,9 @@ function parse_path(path)
|
|||||||
return string.sub(path, 1, index-1), string.sub(path, index+1, -1)
|
return string.sub(path, 1, index-1), string.sub(path, index+1, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local __cached_scripts = {}
|
||||||
|
local __cached_results = {}
|
||||||
|
|
||||||
-- Load script with caching
|
-- Load script with caching
|
||||||
--
|
--
|
||||||
-- path - script path `contentpack:filename`.
|
-- path - script path `contentpack:filename`.
|
||||||
@@ -56,3 +56,20 @@ function sleep(timesec)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_dofile = dofile
|
||||||
|
-- Replaces dofile('*/content/packid/*') with load_script('packid:*')
|
||||||
|
function dofile(path)
|
||||||
|
local index = string.find(path, "/content/")
|
||||||
|
if index then
|
||||||
|
local newpath = string.sub(path, index+9)
|
||||||
|
index = string.find(newpath, "/")
|
||||||
|
if index then
|
||||||
|
local label = string.sub(newpath, 1, index-1)
|
||||||
|
newpath = label..':'..string.sub(newpath, index+1)
|
||||||
|
if file.isfile(newpath) then
|
||||||
|
return load_script(newpath, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return _dofile(path)
|
||||||
|
end
|
||||||
|
|||||||
+47
-4
@@ -134,18 +134,62 @@ Engine::~Engine() {
|
|||||||
std::cout << "-- engine finished" << std::endl;
|
std::cout << "-- engine finished" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t npos = std::numeric_limits<size_t>::max();
|
||||||
|
|
||||||
|
inline size_t findPack(const std::string& id, const std::vector<ContentPack>& packs) {
|
||||||
|
for (size_t i = 0; i < packs.size(); i++) {
|
||||||
|
if (packs[i].id == id) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void addPack(
|
||||||
|
const ContentPack& pack,
|
||||||
|
const std::vector<ContentPack>& srcPacks,
|
||||||
|
std::vector<ContentPack>& contentPacks
|
||||||
|
) {
|
||||||
|
if (findPack(pack.id, contentPacks) != npos) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto& dependecy : pack.dependencies) {
|
||||||
|
size_t index = findPack(dependecy, srcPacks);
|
||||||
|
if (index == npos)
|
||||||
|
throw contentpack_error(pack.id, pack.folder,
|
||||||
|
"missing dependency '"+dependecy+"'");
|
||||||
|
addPack(srcPacks[index], srcPacks, contentPacks);
|
||||||
|
}
|
||||||
|
contentPacks.push_back(pack);
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::loadContent() {
|
void Engine::loadContent() {
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
ContentBuilder contentBuilder;
|
ContentBuilder contentBuilder;
|
||||||
setup_definitions(&contentBuilder);
|
setup_definitions(&contentBuilder);
|
||||||
paths->setContentPacks(&contentPacks);
|
paths->setContentPacks(&contentPacks);
|
||||||
|
|
||||||
std::vector<fs::path> resRoots;
|
std::vector<fs::path> resRoots;
|
||||||
for (auto& pack : contentPacks) {
|
std::vector<ContentPack> srcPacks = contentPacks;
|
||||||
|
contentPacks.clear();
|
||||||
|
|
||||||
|
for (auto& pack : srcPacks) {
|
||||||
|
if (pack.dependencies.empty())
|
||||||
|
continue;
|
||||||
ContentLoader loader(&pack);
|
ContentLoader loader(&pack);
|
||||||
loader.load(&contentBuilder);
|
loader.load(&contentBuilder);
|
||||||
resRoots.push_back(pack.folder);
|
resRoots.push_back(pack.folder);
|
||||||
|
addPack(pack, srcPacks, contentPacks);
|
||||||
}
|
}
|
||||||
|
for (auto& pack : srcPacks) {
|
||||||
|
if (!pack.dependencies.empty())
|
||||||
|
continue;
|
||||||
|
ContentLoader loader(&pack);
|
||||||
|
loader.load(&contentBuilder);
|
||||||
|
resRoots.push_back(pack.folder);
|
||||||
|
addPack(pack, srcPacks, contentPacks);
|
||||||
|
}
|
||||||
|
|
||||||
content.reset(contentBuilder.build());
|
content.reset(contentBuilder.build());
|
||||||
resPaths.reset(new ResPaths(resdir, resRoots));
|
resPaths.reset(new ResPaths(resdir, resRoots));
|
||||||
|
|
||||||
@@ -163,13 +207,12 @@ void Engine::loadContent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assets->extend(*new_assets.get());
|
assets->extend(*new_assets.get());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadWorldContent(const fs::path& folder) {
|
void Engine::loadWorldContent(const fs::path& folder) {
|
||||||
contentPacks.clear();
|
contentPacks.clear();
|
||||||
auto packNames = ContentPack::worldPacksList(folder);
|
auto packNames = ContentPack::worldPacksList(folder);
|
||||||
|
std::cout << folder << " " << packNames.size() << std::endl;
|
||||||
ContentPack::readPacks(paths, contentPacks, packNames, folder);
|
ContentPack::readPacks(paths, contentPacks, packNames, folder);
|
||||||
loadContent();
|
loadContent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -401,7 +401,6 @@ void create_new_world_panel(Engine* engine, PagesControl* menu) {
|
|||||||
std::cout << "world seed: " << seed << std::endl;
|
std::cout << "world seed: " << seed << std::endl;
|
||||||
|
|
||||||
auto folder = paths->getWorldsFolder()/fs::u8path(nameutf8);
|
auto folder = paths->getWorldsFolder()/fs::u8path(nameutf8);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
engine->loadAllPacks();
|
engine->loadAllPacks();
|
||||||
engine->loadContent();
|
engine->loadContent();
|
||||||
|
|||||||
Reference in New Issue
Block a user