packs dependencies fix + dofile patch
This commit is contained in:
parent
b14da32867
commit
04293c926d
@ -11,9 +11,6 @@ function is_array(x)
|
||||
return true
|
||||
end
|
||||
|
||||
local __cached_scripts = {}
|
||||
local __cached_results = {}
|
||||
|
||||
-- Get entry-point and filename from `entry-point:filename` path
|
||||
function parse_path(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)
|
||||
end
|
||||
|
||||
local __cached_scripts = {}
|
||||
local __cached_results = {}
|
||||
|
||||
-- Load script with caching
|
||||
--
|
||||
-- path - script path `contentpack:filename`.
|
||||
@ -56,3 +56,20 @@ function sleep(timesec)
|
||||
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
|
||||
|
||||
@ -134,18 +134,62 @@ Engine::~Engine() {
|
||||
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() {
|
||||
auto resdir = paths->getResources();
|
||||
ContentBuilder contentBuilder;
|
||||
setup_definitions(&contentBuilder);
|
||||
paths->setContentPacks(&contentPacks);
|
||||
|
||||
|
||||
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);
|
||||
loader.load(&contentBuilder);
|
||||
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());
|
||||
resPaths.reset(new ResPaths(resdir, resRoots));
|
||||
|
||||
@ -163,13 +207,12 @@ void Engine::loadContent() {
|
||||
}
|
||||
}
|
||||
assets->extend(*new_assets.get());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Engine::loadWorldContent(const fs::path& folder) {
|
||||
contentPacks.clear();
|
||||
auto packNames = ContentPack::worldPacksList(folder);
|
||||
std::cout << folder << " " << packNames.size() << std::endl;
|
||||
ContentPack::readPacks(paths, contentPacks, packNames, folder);
|
||||
loadContent();
|
||||
}
|
||||
|
||||
@ -401,7 +401,6 @@ void create_new_world_panel(Engine* engine, PagesControl* menu) {
|
||||
std::cout << "world seed: " << seed << std::endl;
|
||||
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(nameutf8);
|
||||
|
||||
try {
|
||||
engine->loadAllPacks();
|
||||
engine->loadContent();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user