From 61ae93234e05709687cb8077914ebd66d4bfd129 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Mon, 18 Nov 2024 23:22:31 +0100 Subject: [PATCH] fixed changing root dir --- src/editor/asset_compiler.cpp | 100 ++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/editor/asset_compiler.cpp b/src/editor/asset_compiler.cpp index 7695b456e7..81e6712aba 100644 --- a/src/editor/asset_compiler.cpp +++ b/src/editor/asset_compiler.cpp @@ -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 { @@ -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"); @@ -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(); }