Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions modules/fnxext/dependency_collector_editor_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifdef TOOLS_ENABLED

#include "dependency_collector_editor_plugin.h"
#include <core/engine.h>
#include <core/os/os.h>
#include <editor/editor_settings.h>
#include <editor/editor_file_system.h>

// This module allow to collect all project depenencies into single json file.
// Usage:
// godot -e --path <project> --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<String> deps;
ResourceLoader::get_dependencies(path, &deps);
for (List<String>::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<String> args = OS::get_singleton()->get_cmdline_args();
bool collect_required = false;
for (List<String>::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
31 changes: 31 additions & 0 deletions modules/fnxext/dependency_collector_editor_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H
#define DEPENDENCY_COLLECTOR_EDITOR_PLUGIN_H

#include <editor/editor_plugin.h>
#include <editor/editor_file_system.h>
#include <scene/gui/menu_button.h>

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
17 changes: 17 additions & 0 deletions modules/fnxext/engine_internals.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 17 additions & 0 deletions modules/fnxext/engine_internals.h
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions modules/fnxext/register_types.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#ifdef MODULE_FNXEXT_ENABLED

#include <core/class_db.h>
#include <core/engine.h>

#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 <editor/editor_node.h>
#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

Expand All @@ -25,6 +30,9 @@ void register_fnxext_types() {
ClassDB::register_class<MeshLine2D>();
ClassDB::register_class<Future>();
ClassDB::register_class<ZipTool>();
ClassDB::register_class<EngineInternals>();

Engine::get_singleton()->add_singleton(Engine::Singleton("EngineInternals", memnew(EngineInternals)));

#ifdef TOOLS_ENABLED
// Control* gui = EditorNode::get_singleton()->get_gui_base();
Expand Down
2 changes: 2 additions & 0 deletions modules/fnxext/zip_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -43,6 +44,7 @@ Array ZipTool::list_files(const String &p_path) {
unzGoToNextFile(zip);
}
}
unzClose(zip);

return result;
}