Skip to content

Commit

Permalink
fixed changing root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Nov 18, 2024
1 parent bfbb4c9 commit 61ae932
Showing 1 changed file with 53 additions and 47 deletions.
100 changes: 53 additions & 47 deletions src/editor/asset_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,63 @@ struct AssetCompilerImpl : AssetCompiler {
, m_resource_compiled(m_allocator)
, m_on_init_load(m_allocator)
{
onBasePathChanged();

Engine& engine = app.getEngine();
ResourceManagerHub& rm = engine.getResourceManager();
rm.setLoadHook(&m_load_hook);
}

~AssetCompilerImpl()
{
m_allocator.deallocate(m_lz4_state);
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (fs.open(".lumix/resources/_resources.txt_tmp", file)) {
file << "resources = [\n";
for (const ResourceItem& ri : m_resources) {
file << "\"" << ri.path << "\",\n";
}
file << "]\n\n";
file << "dependencies = {\n";
for (auto iter : m_dependencies.iterated()) {
file << "\t\"" << iter.key() << "\" = [\n";
for (const Path& p : iter.value()) {
file << "\t\t\"" << p << "\",\n";
}
file << "\t],\n";
}
file << "}\n";

file.close();
fs.deleteFile(".lumix/resources/_resources.txt");
fs.moveFile(".lumix/resources/_resources.txt_tmp", ".lumix/resources/_resources.txt");
}
else {
logError("Could not save .lumix/resources/_resources.txt");
}

ASSERT(m_plugins.empty());
ResourceManagerHub& rm = m_app.getEngine().getResourceManager();
rm.setLoadHook(nullptr);
}

void onBasePathChanged() override {
Engine& engine = m_app.getEngine();
FileSystem& fs = engine.getFileSystem();
const char* base_path = fs.getBasePath();
m_watcher = FileSystemWatcher::create(base_path, m_allocator);
m_watcher->getCallback().bind<&AssetCompilerImpl::onFileChanged>(this);
Path path(base_path, ".lumix/resources");

m_dependencies.clear();
m_resources.clear();


Path path(base_path, ".lumix");
bool success = os::makePath(path.c_str());
if (!success) logError("Could not create ", path);

path.append("/resources");
if (!os::dirExists(path)) {
if (!os::makePath(path.c_str())) logError("Could not create ", path);
else {
Expand All @@ -96,6 +147,7 @@ struct AssetCompilerImpl : AssetCompiler {
}
}
}

os::InputFile file;
if (!file.open(".lumix/resources/_version.bin")) {
logError("Could not open .lumix/resources/_version.bin");
Expand Down Expand Up @@ -134,52 +186,6 @@ struct AssetCompilerImpl : AssetCompiler {
}
}

ResourceManagerHub& rm = engine.getResourceManager();
rm.setLoadHook(&m_load_hook);
}

~AssetCompilerImpl()
{
m_allocator.deallocate(m_lz4_state);
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (fs.open(".lumix/resources/_resources.txt_tmp", file)) {
file << "resources = [\n";
for (const ResourceItem& ri : m_resources) {
file << "\"" << ri.path << "\",\n";
}
file << "]\n\n";
file << "dependencies = {\n";
for (auto iter : m_dependencies.iterated()) {
file << "\t\"" << iter.key() << "\" = [\n";
for (const Path& p : iter.value()) {
file << "\t\t\"" << p << "\",\n";
}
file << "\t],\n";
}
file << "}\n";

file.close();
fs.deleteFile(".lumix/resources/_resources.txt");
fs.moveFile(".lumix/resources/_resources.txt_tmp", ".lumix/resources/_resources.txt");
}
else {
logError("Could not save .lumix/resources/_resources.txt");
}

ASSERT(m_plugins.empty());
ResourceManagerHub& rm = m_app.getEngine().getResourceManager();
rm.setLoadHook(nullptr);
}

void onBasePathChanged() override {
Engine& engine = m_app.getEngine();
FileSystem& fs = engine.getFileSystem();
const char* base_path = fs.getBasePath();
m_watcher = FileSystemWatcher::create(base_path, m_allocator);
m_watcher->getCallback().bind<&AssetCompilerImpl::onFileChanged>(this);
m_dependencies.clear();
m_resources.clear();
fillDB();
}

Expand Down

0 comments on commit 61ae932

Please sign in to comment.