瀏覽代碼

[godot] Fix importers for extension settings

Mario Zechner 11 月之前
父節點
當前提交
6dbed6044f

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

@@ -4,6 +4,7 @@
   "C_Cpp.default.browse.path": [
   "C_Cpp.default.browse.path": [
     "${workspaceFolder}"
     "${workspaceFolder}"
   ],
   ],
+  "C_Cpp.default.defines": ["TOOLS_ENABLED", "SPINE_GODOT_EXTENSION"],
   "dotnet.defaultSolution": "disable",
   "dotnet.defaultSolution": "disable",
   "files.associations": {
   "files.associations": {
     "*.inc": "cpp"
     "*.inc": "cpp"

+ 11 - 6
spine-godot/spine_godot/SpineAtlasResource.cpp

@@ -287,10 +287,14 @@ Error SpineAtlasResource::load_from_file(const String &path) {
 #endif
 #endif
 
 
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
-	JSON json;
-	error = json.parse(json_string);
-	if (error != OK) return error;
-	Variant result = json.get_data();
+	JSON *json = memnew(JSON);
+	error = json->parse(json_string);
+	if (error != OK) {
+		memdelete(json);
+		return error;
+	}
+	Variant result = json->get_data();
+	memdelete(json);
 #else
 #else
 	String error_string;
 	String error_string;
 	int error_line;
 	int error_line;
@@ -337,9 +341,10 @@ Error SpineAtlasResource::save_to_file(const String &path) {
 	content["atlas_data"] = atlas_data;
 	content["atlas_data"] = atlas_data;
 	content["normal_texture_prefix"] = normal_map_prefix;
 	content["normal_texture_prefix"] = normal_map_prefix;
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
-	JSON json;
-	file->store_string(json.stringify(content));
+	JSON *json = memnew(JSON);
+	file->store_string(json->stringify(content));
 	file->flush();
 	file->flush();
+	memdelete(json);
 #else
 #else
 	file->store_string(JSON::print(content));
 	file->store_string(JSON::print(content));
 	file->close();
 	file->close();

+ 12 - 2
spine-godot/spine_godot/SpineEditorPlugin.cpp

@@ -64,8 +64,18 @@ Error SpineAtlasResourceImportPlugin::import(const String &source_file, const St
 	return error;
 	return error;
 }
 }
 
 
-// FIXME get_import_options is not available in godot-cpp
-#ifndef SPINE_GODOT_EXTENSION
+#ifdef SPINE_GODOT_EXTENSION
+TypedArray<Dictionary> SpineAtlasResourceImportPlugin::_get_import_options(const String &p_path, int32_t p_preset_index) const {
+	TypedArray<Dictionary> options;
+	Dictionary dictionary;
+	dictionary["name"] = "normal_map_prefix";
+	dictionary["type"] = Variant::STRING;
+	dictionary["hint_string"] = "String";
+	dictionary["default_value"] = String("n");
+	options.push_back(dictionary);
+	return options;
+}
+#else
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3
 void SpineAtlasResourceImportPlugin::get_import_options(const String &path, List<ImportOption> *options, int preset) const {
 void SpineAtlasResourceImportPlugin::get_import_options(const String &path, List<ImportOption> *options, int preset) const {
 #else
 #else

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

@@ -94,6 +94,8 @@ public:
 
 
 	virtual float _get_priority() const override { return 1; }
 	virtual float _get_priority() const override { return 1; }
 
 
+	TypedArray<Dictionary> _get_import_options(const String &p_path, int32_t p_preset_index) const override;
+
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 
 
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;
@@ -163,6 +165,11 @@ public:
 
 
 	float _get_priority() const override { return 1; }
 	float _get_priority() const override { return 1; }
 
 
+	TypedArray<Dictionary> _get_import_options(const String &p_path, int32_t p_preset_index) const override {
+		TypedArray<Dictionary> options;
+		return options;
+	}
+
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 
 
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;
@@ -232,6 +239,11 @@ public:
 
 
 	float _get_priority() const override { return 1; }
 	float _get_priority() const override { return 1; }
 
 
+	TypedArray<Dictionary> _get_import_options(const String &p_path, int32_t p_preset_index) const override {
+		TypedArray<Dictionary> options;
+		return options;
+	}
+
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 	virtual bool _get_option_visibility(const String &p_path, const StringName &p_option_name, const Dictionary &p_options) const override { return true; };
 
 
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;
 	virtual Error _import(const String &p_source_file, const String &p_save_path, const Dictionary &p_options, const TypedArray<String> &p_platform_variants, const TypedArray<String> &p_gen_files) const override;

+ 0 - 1
spine-godot/spine_godot/register_types.cpp

@@ -192,7 +192,6 @@ void register_spine_godot_types() {
 	ResourceSaver::add_resource_format_saver(skeleton_file_saver);
 	ResourceSaver::add_resource_format_saver(skeleton_file_saver);
 #endif
 #endif
 #endif
 #endif
-	printf(">>>>>>>>>>>>>>>>>>>> fuck\n");
 }
 }
 
 
 #if VERSION_MAJOR > 3
 #if VERSION_MAJOR > 3