Skip to content

Commit

Permalink
[godot] Fix importers for extension settings
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Oct 8, 2024
1 parent 14992a5 commit 6dbed60
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions spine-godot/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"C_Cpp.default.browse.path": [
"${workspaceFolder}"
],
"C_Cpp.default.defines": ["TOOLS_ENABLED", "SPINE_GODOT_EXTENSION"],
"dotnet.defaultSolution": "disable",
"files.associations": {
"*.inc": "cpp"
Expand Down
17 changes: 11 additions & 6 deletions spine-godot/spine_godot/SpineAtlasResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ Error SpineAtlasResource::load_from_file(const String &path) {
#endif

#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
String error_string;
int error_line;
Expand Down Expand Up @@ -337,9 +341,10 @@ Error SpineAtlasResource::save_to_file(const String &path) {
content["atlas_data"] = atlas_data;
content["normal_texture_prefix"] = normal_map_prefix;
#if VERSION_MAJOR > 3
JSON json;
file->store_string(json.stringify(content));
JSON *json = memnew(JSON);
file->store_string(json->stringify(content));
file->flush();
memdelete(json);
#else
file->store_string(JSON::print(content));
file->close();
Expand Down
14 changes: 12 additions & 2 deletions spine-godot/spine_godot/SpineEditorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ Error SpineAtlasResourceImportPlugin::import(const String &source_file, const St
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
void SpineAtlasResourceImportPlugin::get_import_options(const String &path, List<ImportOption> *options, int preset) const {
#else
Expand Down
12 changes: 12 additions & 0 deletions spine-godot/spine_godot/SpineEditorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class SpineAtlasResourceImportPlugin : public EditorImportPlugin {

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 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;
Expand Down Expand Up @@ -163,6 +165,11 @@ class SpineJsonResourceImportPlugin : public EditorImportPlugin {

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 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;
Expand Down Expand Up @@ -232,6 +239,11 @@ class SpineBinaryResourceImportPlugin : public EditorImportPlugin {

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 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;
Expand Down
1 change: 0 additions & 1 deletion spine-godot/spine_godot/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ void register_spine_godot_types() {
ResourceSaver::add_resource_format_saver(skeleton_file_saver);
#endif
#endif
printf(">>>>>>>>>>>>>>>>>>>> fuck\n");
}

#if VERSION_MAJOR > 3
Expand Down

0 comments on commit 6dbed60

Please sign in to comment.