diff --git a/.gitignore b/.gitignore index 8bc5fe74a..cee580293 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,5 @@ spine-ts/spine-ts.zip spine-godot/.clang-format spine-ts/spine-phaser/dist +spine-godot/.cache +spine-godot/build/compile_commands.json diff --git a/spine-godot/.vscode/launch.json b/spine-godot/.vscode/launch.json new file mode 100644 index 000000000..6b425359a --- /dev/null +++ b/spine-godot/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "cppvsdbg", + "request": "launch", + "name": "debug scene v4", + "program": "godot/bin/godot.windows.editor.dev.x86_64.exe", + "args": [ + "--path", + "example-v4", + "examples/01-helloworld/helloworld.tscn" + ], + "cwd": "${workspaceFolder}", + "preLaunchTask": "build-v4" + }, + { + "type": "cppvsdbg", + "request": "launch", + "name": "debug editor v4", + "program": "godot/bin/godot.windows.editor.dev.x86_64.exe", + "args": [ + "-e", + "--path", + "example-v4", + ], + "cwd": "${workspaceFolder}", + "preLaunchTask": "build-v4" + }, + { + "type": "cppvsdbg", + "request": "launch", + "name": "debug scene v3", + "program": "godot/bin/godot.windows.editor.dev.x86_64.exe", + "args": [ + "--path", + "example", + "examples/01-helloworld/helloworld.tscn" + ], + "cwd": "${workspaceFolder}", + "preLaunchTask": "build-v3" + } + ] +} \ No newline at end of file diff --git a/spine-godot/.vscode/settings.json b/spine-godot/.vscode/settings.json new file mode 100644 index 000000000..621800919 --- /dev/null +++ b/spine-godot/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "cmake.configureOnOpen": false, + "C_Cpp.intelliSenseEngine": "disabled", +} \ No newline at end of file diff --git a/spine-godot/.vscode/tasks.json b/spine-godot/.vscode/tasks.json new file mode 100644 index 000000000..7daba2cb0 --- /dev/null +++ b/spine-godot/.vscode/tasks.json @@ -0,0 +1,35 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build-v4", + "group": "build", + "type": "shell", + "command": "scons", + "options": { + "cwd": "${workspaceFolder}/godot" + }, + "args": [ + "-j 8", + "dev_build=yes", + "custom_modules=\"${workspaceFolder}/spine_godot" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "build-v3", + "group": "build", + "type": "shell", + "command": "scons", + "options": { + "cwd": "${workspaceFolder}/godot" + }, + "args": [ + "-j 8", + "debug", + "custom_modules=\"${workspaceFolder}/spine_godot" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/spine-godot/build/build.sh b/spine-godot/build/build.sh index 52b231929..2abaed21a 100755 --- a/spine-godot/build/build.sh +++ b/spine-godot/build/build.sh @@ -61,6 +61,7 @@ else target="$target vsproj=yes livepp=$LIVEPP" fi scons $target compiledb=yes custom_modules="../spine_godot" --jobs=$cpus + cp compile_commands.json ../build if [ -f "bin/godot.x11.opt.tools.64" ]; then strip bin/godot.x11.opt.tools.64 chmod a+x bin/godot.x11.opt.tools.64 diff --git a/spine-godot/spine_godot/GodotSpineExtension.cpp b/spine-godot/spine_godot/GodotSpineExtension.cpp index c37b91a3a..877e767aa 100644 --- a/spine-godot/spine_godot/GodotSpineExtension.cpp +++ b/spine-godot/spine_godot/GodotSpineExtension.cpp @@ -61,7 +61,11 @@ void GodotSpineExtension::_free(void *mem, const char *file, int line) { char *GodotSpineExtension::_readFile(const spine::String &path, int *length) { Error error; +#if VERSION_MAJOR > 3 + auto res = FileAccess::get_file_as_bytes(String(path.buffer()), &error); +#else auto res = FileAccess::get_file_as_array(String(path.buffer()), &error); +#endif if (error != OK) { if (length) *length = 0; return NULL; diff --git a/spine-godot/spine_godot/SpineEditorPlugin.cpp b/spine-godot/spine_godot/SpineEditorPlugin.cpp index e5cbeeeb0..4ecdb6594 100644 --- a/spine-godot/spine_godot/SpineEditorPlugin.cpp +++ b/spine-godot/spine_godot/SpineEditorPlugin.cpp @@ -31,6 +31,7 @@ #include "SpineEditorPlugin.h" #include "SpineAtlasResource.h" #include "SpineSkeletonFileResource.h" +#include "editor/editor_undo_redo_manager.h" #if VERSION_MAJOR > 3 Error SpineAtlasResourceImportPlugin::import(const String &source_file, const String &save_path, const HashMap &options, List *platform_variants, List *gen_files, Variant *metadata) { @@ -253,7 +254,11 @@ void SpineEditorPropertyAnimationMix::_bind_methods() { void SpineEditorPropertyAnimationMix::data_changed(const String &property, const Variant &value, const String &name, bool changing) { auto mix = Object::cast_to(get_edited_object()->get(get_edited_property())); +#if VERSION_MAJOR > 3 + auto undo_redo = EditorUndoRedoManager::get_singleton(); +#else auto undo_redo = EditorNode::get_undo_redo(); +#endif undo_redo->create_action("Set mix property " + property); undo_redo->add_do_property(mix, property, value); undo_redo->add_undo_property(mix, property, mix->get(property)); @@ -273,7 +278,11 @@ void SpineEditorPropertyAnimationMix::update_property() { if (container) { memdelete(container); +#if VERSION_MAJOR > 3 + SceneTree::get_singleton()->queue_delete(container); +#else container->queue_delete(); +#endif container = nullptr; } diff --git a/spine-godot/spine_godot/SpineEditorPlugin.h b/spine-godot/spine_godot/SpineEditorPlugin.h index 013a0f23f..38aab3a4f 100644 --- a/spine-godot/spine_godot/SpineEditorPlugin.h +++ b/spine-godot/spine_godot/SpineEditorPlugin.h @@ -32,6 +32,9 @@ #ifdef TOOLS_ENABLED #include "SpineCommon.h" #include "SpineSprite.h" +#if VERSION_MAJOR > 3 +#include "editor/import/editor_import_plugin.h" +#endif #include "editor/editor_node.h" #include "editor/editor_properties.h" #include "editor/editor_properties_array_dict.h" diff --git a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp index afc96925c..07308c9b1 100644 --- a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp @@ -122,7 +122,11 @@ Error SpineSkeletonFileResource::load_from_file(const String &path) { if (error != OK) return error; if (!checkJson(json.utf8())) return ERR_INVALID_DATA; } else { +#if VERSION_MAJOR > 3 + binary = FileAccess::get_file_as_bytes(path, &error); +#else binary = FileAccess::get_file_as_array(path, &error); +#endif if (error != OK) return error; if (!checkBinary((const char *) binary.ptr(), binary.size())) return ERR_INVALID_DATA; } diff --git a/spine-godot/spine_godot/register_types.cpp b/spine-godot/spine_godot/register_types.cpp index 603c87bde..fadc83ba6 100644 --- a/spine-godot/spine_godot/register_types.cpp +++ b/spine-godot/spine_godot/register_types.cpp @@ -28,6 +28,7 @@ *****************************************************************************/ #include "SpineCommon.h" +#include "modules/register_module_types.h" #include "register_types.h" #include "SpineAtlasResource.h" #include "SpineSkeletonFileResource.h" @@ -70,12 +71,20 @@ static void editor_init_callback() { #if VERSION_MAJOR > 3 void initialize_spine_godot_module(ModuleInitializationLevel level) { + if (level == MODULE_INITIALIZATION_LEVEL_EDITOR) { +#ifdef TOOLS_ENABLED + EditorNode::add_init_callback(editor_init_callback); + GDREGISTER_CLASS(SpineEditorPropertyAnimationMixes); + return; +#endif + } + if (level != MODULE_INITIALIZATION_LEVEL_CORE) return; #else void register_spine_godot_types() { -#endif #ifdef TOOLS_ENABLED EditorNode::add_init_callback(editor_init_callback); GDREGISTER_CLASS(SpineEditorPropertyAnimationMixes); +#endif #endif spine::Bone::setYDown(true); GDREGISTER_CLASS(SpineObjectWrapper); @@ -140,13 +149,14 @@ void register_spine_godot_types() { #if VERSION_MAJOR > 3 void uninitialize_spine_godot_module(ModuleInitializationLevel level) { + if (level != MODULE_INITIALIZATION_LEVEL_CORE) return; #else void unregister_spine_godot_types() { #endif - ResourceLoader::remove_resource_format_loader(atlas_loader); + /*ResourceLoader::remove_resource_format_loader(atlas_loader); ResourceSaver::remove_resource_format_saver(atlas_saver); ResourceLoader::remove_resource_format_loader(skeleton_file_loader); - ResourceSaver::remove_resource_format_saver(skeleton_file_saver); + ResourceSaver::remove_resource_format_saver(skeleton_file_saver);*/ /*memdelete(atlas_loader); memdelete(atlas_saver);