diff --git a/modules/fnxext/dependency_collector_editor_plugin.cpp b/modules/fnxext/dependency_collector_editor_plugin.cpp new file mode 100644 index 00000000000..7b189927194 --- /dev/null +++ b/modules/fnxext/dependency_collector_editor_plugin.cpp @@ -0,0 +1,111 @@ +#ifdef TOOLS_ENABLED + +#include "dependency_collector_editor_plugin.h" +#include +#include +#include +#include + +// This module allow to collect all project depenencies into single json file. +// Usage: +// godot -e --path --collect-dependencies path/to/result.json +// +// Resulting json format is array of file entry. Each file entry is +// array of strings where first element is file path and the rest is +// its dependencies: +// +// [[ +// "res://ui/onboarding/minigames/geobaord.tscn", +// "res://ui/onboarding/minigames/geoboard.gd", +// "res://ui/onboarding/minigames/board.gd", +// "res://egypt/geoboard/logic/level.tscn" +// ],[ +// "res://ui/onboarding/minigames/geoboard.gd", +// "res://egypt/geoboard/logic/level.gd" +// ],[ +// "res://ui/onboarding/minigames/monkey.gd", +// "res://japan/monkey/logic/bush.tscn", +// "res://japan/monkey/logic/bush.gd", +// "res://japan/monkey/config.gd", +// "res://japan/monkey/logic/textures.gd", +// "res://audio/japan/monkey_eating.ogg", +// "res://audio/japan/monkey_happy.ogg", +// "res://audio/japan/japan_monkey_happy_smile.ogg", +// "res://audio/japan/monkey_itches.ogg" +// ]] + +DependencyCollectorEditorPlugin* DependencyCollectorEditorPlugin::instance = NULL; + +void DependencyCollectorEditorPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("_collect_dependencies"), &DependencyCollectorEditorPlugin::_collect_dependencies); + +} + +void DependencyCollectorEditorPlugin::_collect_dependencies() { + if (EditorFileSystem::get_singleton()->is_scanning()) { + return; + } + if (collected) { + return; + } + collected = true; + print_line("[DependencyCollector] start dependency collecting"); + FileAccess *file = FileAccess::open(result_path, FileAccess::WRITE); + if (file) { + // write json directly to file as it is faster and easier + // then build struct and then serialize json + file->store_string("["); + _populate_deps(EditorFileSystem::get_singleton()->get_filesystem(), file); + file->store_string("]"); + file->close(); + } else { + print_error(String("Invalid file path for collecting dependencies: ") + result_path); + } + get_tree()->quit(0); + print_line("[DependencyCollector] done dependency collecting"); +} + +void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory *p_dir, FileAccess *file) { + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + _populate_deps(p_dir->get_subdir(i), file); + } + + for (int i = 0; i < p_dir->get_file_count(); i++) { + + String path = p_dir->get_file_path(i); + if (first_entry_added) { + file->store_string(","); + } else { + first_entry_added = true; + } + file->store_string("[\n \""); + file->store_string(path); + file->store_string("\""); + List deps; + ResourceLoader::get_dependencies(path, &deps); + for (List::Element *E = deps.front(); E; E = E->next()) { + file->store_string(",\n \""); + file->store_string(E->get()); + file->store_string("\""); + } + file->store_string("\n]"); + } +} + +DependencyCollectorEditorPlugin::DependencyCollectorEditorPlugin() { + collected = false; + result_path = ""; + first_entry_added = false; + List args = OS::get_singleton()->get_cmdline_args(); + bool collect_required = false; + for (List::Element *E = args.front(); E; E = E->next()) { + if (E->get() == "--collect-dependencies") { + EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_collect_dependencies"); + collect_required = true; + } else if (collect_required) { + result_path = E->get(); + break; + } + } +} +#endif \ No newline at end of file diff --git a/modules/fnxext/dependency_collector_editor_plugin.h b/modules/fnxext/dependency_collector_editor_plugin.h new file mode 100644 index 00000000000..99dc427c6ce --- /dev/null +++ b/modules/fnxext/dependency_collector_editor_plugin.h @@ -0,0 +1,31 @@ +#ifndef DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H +#define DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H + +#include +#include +#include + +class DependencyCollectorEditorPlugin: public EditorPlugin { + GDCLASS(DependencyCollectorEditorPlugin, EditorPlugin); + + MenuButton* menu_btn; + Dictionary layers; + + static DependencyCollectorEditorPlugin* instance; + bool first_entry_added; + bool collected; + String result_path; + + void _populate_deps(EditorFileSystemDirectory *p_dir, FileAccess *result); + +protected: + static void _bind_methods(); + +public: + void _collect_dependencies(); + DependencyCollectorEditorPlugin(); +}; + + + +#endif // DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H \ No newline at end of file diff --git a/modules/fnxext/engine_internals.cpp b/modules/fnxext/engine_internals.cpp new file mode 100644 index 00000000000..d2fa6798950 --- /dev/null +++ b/modules/fnxext/engine_internals.cpp @@ -0,0 +1,17 @@ +#include "engine_internals.h" +#include "core/io/resource_loader.h" + +EngineInternals* EngineInternals::singleton = NULL; + +void EngineInternals::_bind_methods() { + ClassDB::bind_method(D_METHOD("add_resource_format_loader", "script_path"), &EngineInternals::add_resource_format_loader); +} + +void EngineInternals::add_resource_format_loader(const String &script_path) { + ResourceLoader::remove_custom_resource_format_loader(script_path); + ResourceLoader::add_custom_resource_format_loader(script_path); +} + +EngineInternals::EngineInternals() { + singleton = this; +} \ No newline at end of file diff --git a/modules/fnxext/engine_internals.h b/modules/fnxext/engine_internals.h new file mode 100644 index 00000000000..e877ebef785 --- /dev/null +++ b/modules/fnxext/engine_internals.h @@ -0,0 +1,17 @@ +#ifndef MODULE_ENGINE_INTERNALS_H +#define MODULE_ENGINE_INTERNALS_H + +#include "core/object.h" + +class EngineInternals: public Object { + GDCLASS(EngineInternals, Object); + static EngineInternals *singleton; + +protected: + static void _bind_methods(); + +public: + void add_resource_format_loader(const String &script_path); + EngineInternals(); +}; +#endif \ No newline at end of file diff --git a/modules/fnxext/register_types.cpp b/modules/fnxext/register_types.cpp index b3ccb68a020..4b593f3236b 100644 --- a/modules/fnxext/register_types.cpp +++ b/modules/fnxext/register_types.cpp @@ -1,21 +1,26 @@ #ifdef MODULE_FNXEXT_ENABLED #include +#include + #include "register_types.h" #include "stylebox_bordered_texture.h" #include "visibility_controller_2d.h" #include "mesh_line_2d.h" #include "future.h" #include "zip_tool.h" +#include "engine_internals.h" #ifdef TOOLS_ENABLED #include #include "canvas_layers_editor_plugin.h" +#include "dependency_collector_editor_plugin.h" #endif #ifdef TOOLS_ENABLED static void _editor_init() { EditorNode::get_singleton()->add_editor_plugin(memnew(CanvasLayersEditorPlugin)); + EditorNode::get_singleton()->add_editor_plugin(memnew(DependencyCollectorEditorPlugin)); } #endif @@ -25,6 +30,9 @@ void register_fnxext_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + + Engine::get_singleton()->add_singleton(Engine::Singleton("EngineInternals", memnew(EngineInternals))); #ifdef TOOLS_ENABLED // Control* gui = EditorNode::get_singleton()->get_gui_base(); diff --git a/modules/fnxext/zip_tool.cpp b/modules/fnxext/zip_tool.cpp index 9d712094568..a968f672377 100644 --- a/modules/fnxext/zip_tool.cpp +++ b/modules/fnxext/zip_tool.cpp @@ -23,6 +23,7 @@ Array ZipTool::list_files(const String &p_path) { unz_global_info64 gi; int err = unzGetGlobalInfo64(zip, &gi); if (err != UNZ_OK) { + unzClose(zip); return result; } @@ -43,6 +44,7 @@ Array ZipTool::list_files(const String &p_path) { unzGoToNextFile(zip); } } + unzClose(zip); return result; } \ No newline at end of file