diff --git a/.gitignore b/.gitignore index 4cfc577..1c248e5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ bin/ *.dblite *.obj *.os +*.import .DS_Store .vscode \ No newline at end of file diff --git a/addons/tbloader/src/plugin.gd b/addons/tbloader/src/plugin.gd index 6d724da..aa5bb4c 100644 --- a/addons/tbloader/src/plugin.gd +++ b/addons/tbloader/src/plugin.gd @@ -2,13 +2,14 @@ extends EditorPlugin class_name TBPlugin -var map_control: Control = null +var map_control: Control = HBoxContainer.new() var editing_loader: WeakRef = weakref(null) func _enter_tree(): set_icons(true) - map_control = create_map_control() + add_button_to_control("Build Meshes", "build_meshes") + add_button_to_control("Build FGD", "build_fgd") map_control.set_visible(false) add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, map_control) @@ -28,20 +29,21 @@ func _make_visible(visible: bool): func _edit(object): editing_loader = weakref(object) -func create_map_control() -> Control: - var button_build_meshes = Button.new() - button_build_meshes.flat = true - button_build_meshes.text = "Build Meshes" - button_build_meshes.connect("pressed", Callable(self, "build_meshes")) - - var ret = HBoxContainer.new() - ret.add_child(button_build_meshes) - return ret +func add_button_to_control(text, callback): + var button = Button.new() + button.flat = true + button.text = text + button.connect("pressed", Callable(self, callback)) + map_control.add_child(button) func build_meshes(): var loader = editing_loader.get_ref() loader.build_meshes() +func build_fgd(): + var loader = editing_loader.get_ref() + loader.build_fgd() + func set_icons(on): var editor_interface = get_editor_interface() var base_control = editor_interface.get_base_control() diff --git a/godot-cpp b/godot-cpp index 516fad1..f9ccf28 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 516fad14e45d341211121832bb3daa172aebd6e1 +Subproject commit f9ccf28374af9fb93b4f0def4b0b861a185a35e2 diff --git a/src/fgd_gen.cpp b/src/fgd_gen.cpp new file mode 100644 index 0000000..4340c28 --- /dev/null +++ b/src/fgd_gen.cpp @@ -0,0 +1,116 @@ +#include + +#include +#include +#include +#include +#include +#include + +#include + +FGDGen::FGDGen(TBLoader* loader) +{ + m_loader = loader; + this->fgd_properties = std::map>(); + this->fgd_properties["fgd_size"] = [](String size) { + return vformat("size(-%s -%s -%s, %s %s %s)", size, size, size, size, size, size); + }; +} + +FGDGen::~FGDGen() +{ +} + +PackedStringArray FGDGen::find_all_entity_paths_in_dir(String dir_path) { + Ref dir = DirAccess::open(dir_path); + if (dir->get_open_error() != Error::OK) { + UtilityFunctions::print("Error opening directory"); + return PackedStringArray(); + } + + PackedStringArray entity_paths = PackedStringArray(); + for (auto entity_path : dir->get_files()) { + if (entity_path.ends_with(".tscn")) entity_paths.append(entity_path); + } + std::transform(entity_paths.begin(), entity_paths.end(), entity_paths.begin(), [&dir_path, this](String path) { + // return (dir_path + "/" + path).replace(this->m_loader->get_entity_path() + "/", ""); + return (dir_path + "/" + path); + }); + + PackedStringArray subdirs = dir->get_directories(); + if (subdirs.size() > 0) { + for (int i = 0; i < subdirs.size(); i++) { + String subdir_path = dir_path + "/" + subdirs[i]; + PackedStringArray sub_entity_paths = this->find_all_entity_paths_in_dir(subdir_path); + entity_paths.append_array(sub_entity_paths); + } + } + + return entity_paths; +} + +String FGDGen::generate_fgd_for_entity(String entity_path) { + auto resource_loader = ResourceLoader::get_singleton(); + Ref scene = resource_loader->load(entity_path); + Node* instance = scene->instantiate(); + // auto properties = instance->get_property_list(); + Ref