From e06fc3db7dce66d75ea2b0b935dfccd15d1d0e65 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 10 Jun 2022 10:51:57 +0200 Subject: [PATCH 1/5] [funexpected] add DependencyCollectorEditorPlugin --- .../dependency_collector_editor_plugin.cpp | 107 ++++++++++++++++++ .../dependency_collector_editor_plugin.h | 31 +++++ modules/fnxext/register_types.cpp | 2 + 3 files changed, 140 insertions(+) create mode 100644 modules/fnxext/dependency_collector_editor_plugin.cpp create mode 100644 modules/fnxext/dependency_collector_editor_plugin.h diff --git a/modules/fnxext/dependency_collector_editor_plugin.cpp b/modules/fnxext/dependency_collector_editor_plugin.cpp new file mode 100644 index 00000000000..bb72d1fe71d --- /dev/null +++ b/modules/fnxext/dependency_collector_editor_plugin.cpp @@ -0,0 +1,107 @@ +#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(bool p_exist) { + if (collected) { + return; + } + collected = true; + 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); +} + +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("sources_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..71fae19afab --- /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(bool p_exist); + DependencyCollectorEditorPlugin(); +}; + + + +#endif // DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H \ No newline at end of file diff --git a/modules/fnxext/register_types.cpp b/modules/fnxext/register_types.cpp index b3ccb68a020..0352d2da74f 100644 --- a/modules/fnxext/register_types.cpp +++ b/modules/fnxext/register_types.cpp @@ -11,11 +11,13 @@ #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 From 706ee036f3a7dec021c1076d064b0af046890bbe Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 10 Jun 2022 13:47:50 +0200 Subject: [PATCH 2/5] [funexpected] try use filesystem_changed signal instead of sources_changed --- editor/editor_node.cpp | 3 ++- modules/fnxext/dependency_collector_editor_plugin.cpp | 7 +++++-- modules/fnxext/dependency_collector_editor_plugin.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d7efdc5f5a4..7a2c3b33cc4 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -693,7 +693,7 @@ void EditorNode::_resources_changed(const PoolVector &p_resources) { } void EditorNode::_fs_changed() { - + print_line("[dc] EditorNode::_fs_changed"); for (Set::Element *E = file_dialogs.front(); E; E = E->next()) { E->get()->invalidate(); @@ -822,6 +822,7 @@ void EditorNode::_resources_reimported(const Vector &p_resources) { } void EditorNode::_sources_changed(bool p_exist) { + print_line("[dc] EditorNode::_sources_changed"); if (waiting_for_first_scan) { waiting_for_first_scan = false; diff --git a/modules/fnxext/dependency_collector_editor_plugin.cpp b/modules/fnxext/dependency_collector_editor_plugin.cpp index bb72d1fe71d..ec36730def0 100644 --- a/modules/fnxext/dependency_collector_editor_plugin.cpp +++ b/modules/fnxext/dependency_collector_editor_plugin.cpp @@ -41,7 +41,8 @@ void DependencyCollectorEditorPlugin::_bind_methods() { } -void DependencyCollectorEditorPlugin::_collect_dependencies(bool p_exist) { +void DependencyCollectorEditorPlugin::_collect_dependencies() { + print_line(String("[dc] plugin started, scaning =") + Variant(EditorFileSystem::get_singleton()->is_scanning())); if (collected) { return; } @@ -59,6 +60,7 @@ void DependencyCollectorEditorPlugin::_collect_dependencies(bool p_exist) { print_error(String("Invalid file path for collecting dependencies: ") + result_path); } get_tree()->quit(0); + print_line("[dc] plugin done"); } void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory *p_dir, FileAccess *file) { @@ -89,6 +91,7 @@ void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory * } DependencyCollectorEditorPlugin::DependencyCollectorEditorPlugin() { + print_line("[dc] plugin constructor"); collected = false; result_path = ""; first_entry_added = false; @@ -96,7 +99,7 @@ DependencyCollectorEditorPlugin::DependencyCollectorEditorPlugin() { bool collect_required = false; for (List::Element *E = args.front(); E; E = E->next()) { if (E->get() == "--collect-dependencies") { - EditorFileSystem::get_singleton()->connect("sources_changed", this, "_collect_dependencies"); + EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_collect_dependencies"); collect_required = true; } else if (collect_required) { result_path = E->get(); diff --git a/modules/fnxext/dependency_collector_editor_plugin.h b/modules/fnxext/dependency_collector_editor_plugin.h index 71fae19afab..99dc427c6ce 100644 --- a/modules/fnxext/dependency_collector_editor_plugin.h +++ b/modules/fnxext/dependency_collector_editor_plugin.h @@ -22,7 +22,7 @@ class DependencyCollectorEditorPlugin: public EditorPlugin { static void _bind_methods(); public: - void _collect_dependencies(bool p_exist); + void _collect_dependencies(); DependencyCollectorEditorPlugin(); }; From a1e2c5b3a5218f26202794b15f38497e2e77ad3b Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 10 Jun 2022 14:19:22 +0200 Subject: [PATCH 3/5] [funexpected] remove debug prints --- editor/editor_node.cpp | 3 +-- modules/fnxext/dependency_collector_editor_plugin.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 7a2c3b33cc4..d7efdc5f5a4 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -693,7 +693,7 @@ void EditorNode::_resources_changed(const PoolVector &p_resources) { } void EditorNode::_fs_changed() { - print_line("[dc] EditorNode::_fs_changed"); + for (Set::Element *E = file_dialogs.front(); E; E = E->next()) { E->get()->invalidate(); @@ -822,7 +822,6 @@ void EditorNode::_resources_reimported(const Vector &p_resources) { } void EditorNode::_sources_changed(bool p_exist) { - print_line("[dc] EditorNode::_sources_changed"); if (waiting_for_first_scan) { waiting_for_first_scan = false; diff --git a/modules/fnxext/dependency_collector_editor_plugin.cpp b/modules/fnxext/dependency_collector_editor_plugin.cpp index ec36730def0..7d227709287 100644 --- a/modules/fnxext/dependency_collector_editor_plugin.cpp +++ b/modules/fnxext/dependency_collector_editor_plugin.cpp @@ -42,15 +42,17 @@ void DependencyCollectorEditorPlugin::_bind_methods() { } void DependencyCollectorEditorPlugin::_collect_dependencies() { - print_line(String("[dc] plugin started, scaning =") + Variant(EditorFileSystem::get_singleton()->is_scanning())); + 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 + // 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); @@ -60,7 +62,7 @@ void DependencyCollectorEditorPlugin::_collect_dependencies() { print_error(String("Invalid file path for collecting dependencies: ") + result_path); } get_tree()->quit(0); - print_line("[dc] plugin done"); + print_line("[DependencyCollector] done dependency collecting"); } void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory *p_dir, FileAccess *file) { @@ -91,7 +93,6 @@ void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory * } DependencyCollectorEditorPlugin::DependencyCollectorEditorPlugin() { - print_line("[dc] plugin constructor"); collected = false; result_path = ""; first_entry_added = false; From bf2baa3dc5087f039b0c3ff0e34cea535043ca84 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 10 Jun 2022 14:32:23 +0200 Subject: [PATCH 4/5] [funexpected] use spaces as intents --- modules/fnxext/dependency_collector_editor_plugin.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/fnxext/dependency_collector_editor_plugin.cpp b/modules/fnxext/dependency_collector_editor_plugin.cpp index 7d227709287..7b189927194 100644 --- a/modules/fnxext/dependency_collector_editor_plugin.cpp +++ b/modules/fnxext/dependency_collector_editor_plugin.cpp @@ -67,10 +67,10 @@ void DependencyCollectorEditorPlugin::_collect_dependencies() { 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); - } + _populate_deps(p_dir->get_subdir(i), file); + } - for (int i = 0; i < p_dir->get_file_count(); i++) { + for (int i = 0; i < p_dir->get_file_count(); i++) { String path = p_dir->get_file_path(i); if (first_entry_added) { @@ -89,7 +89,7 @@ void DependencyCollectorEditorPlugin::_populate_deps(EditorFileSystemDirectory * file->store_string("\""); } file->store_string("\n]"); - } + } } DependencyCollectorEditorPlugin::DependencyCollectorEditorPlugin() { From d3f4b9d9904c9b970842ed7995e5f706e87c1bc3 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 17 Jun 2022 13:33:41 +0200 Subject: [PATCH 5/5] [funexpected.engine_internals] initial implementation --- modules/fnxext/engine_internals.cpp | 17 +++++++++++++++++ modules/fnxext/engine_internals.h | 17 +++++++++++++++++ modules/fnxext/register_types.cpp | 6 ++++++ modules/fnxext/zip_tool.cpp | 2 ++ 4 files changed, 42 insertions(+) create mode 100644 modules/fnxext/engine_internals.cpp create mode 100644 modules/fnxext/engine_internals.h 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 0352d2da74f..4b593f3236b 100644 --- a/modules/fnxext/register_types.cpp +++ b/modules/fnxext/register_types.cpp @@ -1,12 +1,15 @@ #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 @@ -27,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