Ver código fonte

[godot] Fixes for latest Godot 4.0, VS Code settings, tasks, and launch configs.

badlogic 2 anos atrás
pai
commit
35c4294a9c

+ 2 - 0
.gitignore

@@ -181,3 +181,5 @@ spine-ts/spine-ts.zip
 spine-godot/.clang-format
 spine-godot/.clang-format
 
 
 spine-ts/spine-phaser/dist
 spine-ts/spine-phaser/dist
+spine-godot/.cache
+spine-godot/build/compile_commands.json

+ 47 - 0
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"
+        }
+    ]
+}

+ 4 - 0
spine-godot/.vscode/settings.json

@@ -0,0 +1,4 @@
+{
+    "cmake.configureOnOpen": false,
+    "C_Cpp.intelliSenseEngine": "disabled",
+}

+ 35 - 0
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"
+        }
+    ]
+}

+ 1 - 0
spine-godot/build/build.sh

@@ -61,6 +61,7 @@ else
 		target="$target vsproj=yes livepp=$LIVEPP"
 		target="$target vsproj=yes livepp=$LIVEPP"
 	fi
 	fi
 	scons $target compiledb=yes custom_modules="../spine_godot" --jobs=$cpus	
 	scons $target compiledb=yes custom_modules="../spine_godot" --jobs=$cpus	
+	cp compile_commands.json ../build
 	if [ -f "bin/godot.x11.opt.tools.64" ]; then
 	if [ -f "bin/godot.x11.opt.tools.64" ]; then
 		strip bin/godot.x11.opt.tools.64
 		strip bin/godot.x11.opt.tools.64
 		chmod a+x bin/godot.x11.opt.tools.64
 		chmod a+x bin/godot.x11.opt.tools.64

+ 4 - 0
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) {
 char *GodotSpineExtension::_readFile(const spine::String &path, int *length) {
 	Error error;
 	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);
 	auto res = FileAccess::get_file_as_array(String(path.buffer()), &error);
+#endif
 	if (error != OK) {
 	if (error != OK) {
 		if (length) *length = 0;
 		if (length) *length = 0;
 		return NULL;
 		return NULL;

+ 9 - 0
spine-godot/spine_godot/SpineEditorPlugin.cpp

@@ -31,6 +31,7 @@
 #include "SpineEditorPlugin.h"
 #include "SpineEditorPlugin.h"
 #include "SpineAtlasResource.h"
 #include "SpineAtlasResource.h"
 #include "SpineSkeletonFileResource.h"
 #include "SpineSkeletonFileResource.h"
+#include "editor/editor_undo_redo_manager.h"
 
 
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
 Error SpineAtlasResourceImportPlugin::import(const String &source_file, const String &save_path, const HashMap<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) {
 Error SpineAtlasResourceImportPlugin::import(const String &source_file, const String &save_path, const HashMap<StringName, Variant> &options, List<String> *platform_variants, List<String> *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) {
 void SpineEditorPropertyAnimationMix::data_changed(const String &property, const Variant &value, const String &name, bool changing) {
 	auto mix = Object::cast_to<SpineAnimationMix>(get_edited_object()->get(get_edited_property()));
 	auto mix = Object::cast_to<SpineAnimationMix>(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();
 	auto undo_redo = EditorNode::get_undo_redo();
+#endif
 	undo_redo->create_action("Set mix property " + property);
 	undo_redo->create_action("Set mix property " + property);
 	undo_redo->add_do_property(mix, property, value);
 	undo_redo->add_do_property(mix, property, value);
 	undo_redo->add_undo_property(mix, property, mix->get(property));
 	undo_redo->add_undo_property(mix, property, mix->get(property));
@@ -273,7 +278,11 @@ void SpineEditorPropertyAnimationMix::update_property() {
 
 
 	if (container) {
 	if (container) {
 		memdelete(container);
 		memdelete(container);
+#if VERSION_MAJOR > 3
+		SceneTree::get_singleton()->queue_delete(container);
+#else
 		container->queue_delete();
 		container->queue_delete();
+#endif
 		container = nullptr;
 		container = nullptr;
 	}
 	}
 
 

+ 3 - 0
spine-godot/spine_godot/SpineEditorPlugin.h

@@ -32,6 +32,9 @@
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 #include "SpineCommon.h"
 #include "SpineCommon.h"
 #include "SpineSprite.h"
 #include "SpineSprite.h"
+#if VERSION_MAJOR > 3
+#include "editor/import/editor_import_plugin.h"
+#endif
 #include "editor/editor_node.h"
 #include "editor/editor_node.h"
 #include "editor/editor_properties.h"
 #include "editor/editor_properties.h"
 #include "editor/editor_properties_array_dict.h"
 #include "editor/editor_properties_array_dict.h"

+ 4 - 0
spine-godot/spine_godot/SpineSkeletonFileResource.cpp

@@ -122,7 +122,11 @@ Error SpineSkeletonFileResource::load_from_file(const String &path) {
 		if (error != OK) return error;
 		if (error != OK) return error;
 		if (!checkJson(json.utf8())) return ERR_INVALID_DATA;
 		if (!checkJson(json.utf8())) return ERR_INVALID_DATA;
 	} else {
 	} else {
+#if VERSION_MAJOR > 3
+		binary = FileAccess::get_file_as_bytes(path, &error);
+#else
 		binary = FileAccess::get_file_as_array(path, &error);
 		binary = FileAccess::get_file_as_array(path, &error);
+#endif
 		if (error != OK) return error;
 		if (error != OK) return error;
 		if (!checkBinary((const char *) binary.ptr(), binary.size())) return ERR_INVALID_DATA;
 		if (!checkBinary((const char *) binary.ptr(), binary.size())) return ERR_INVALID_DATA;
 	}
 	}

+ 13 - 3
spine-godot/spine_godot/register_types.cpp

@@ -28,6 +28,7 @@
  *****************************************************************************/
  *****************************************************************************/
 
 
 #include "SpineCommon.h"
 #include "SpineCommon.h"
+#include "modules/register_module_types.h"
 #include "register_types.h"
 #include "register_types.h"
 #include "SpineAtlasResource.h"
 #include "SpineAtlasResource.h"
 #include "SpineSkeletonFileResource.h"
 #include "SpineSkeletonFileResource.h"
@@ -70,12 +71,20 @@ static void editor_init_callback() {
 
 
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
 void initialize_spine_godot_module(ModuleInitializationLevel level) {
 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
 #else
 void register_spine_godot_types() {
 void register_spine_godot_types() {
-#endif
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 	EditorNode::add_init_callback(editor_init_callback);
 	EditorNode::add_init_callback(editor_init_callback);
 	GDREGISTER_CLASS(SpineEditorPropertyAnimationMixes);
 	GDREGISTER_CLASS(SpineEditorPropertyAnimationMixes);
+#endif
 #endif
 #endif
 	spine::Bone::setYDown(true);
 	spine::Bone::setYDown(true);
 	GDREGISTER_CLASS(SpineObjectWrapper);
 	GDREGISTER_CLASS(SpineObjectWrapper);
@@ -140,13 +149,14 @@ void register_spine_godot_types() {
 
 
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
 void uninitialize_spine_godot_module(ModuleInitializationLevel level) {
 void uninitialize_spine_godot_module(ModuleInitializationLevel level) {
+	if (level != MODULE_INITIALIZATION_LEVEL_CORE) return;
 #else
 #else
 void unregister_spine_godot_types() {
 void unregister_spine_godot_types() {
 #endif
 #endif
-	ResourceLoader::remove_resource_format_loader(atlas_loader);
+	/*ResourceLoader::remove_resource_format_loader(atlas_loader);
 	ResourceSaver::remove_resource_format_saver(atlas_saver);
 	ResourceSaver::remove_resource_format_saver(atlas_saver);
 	ResourceLoader::remove_resource_format_loader(skeleton_file_loader);
 	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_loader);
 	memdelete(atlas_saver);
 	memdelete(atlas_saver);