From 5c58111ab3a1c8b9f0ce90960d32da98419d3c94 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 20 Apr 2022 10:48:37 +0200 Subject: [PATCH] [godot] Clean-up SkeletonFileResource --- .../spine_godot/SpineSkeletonFileResource.cpp | 62 +++++++++---------- .../spine_godot/SpineSkeletonFileResource.h | 31 ++++++---- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp index 6109ec651..89b88df84 100644 --- a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp @@ -28,67 +28,63 @@ *****************************************************************************/ #include "SpineSkeletonFileResource.h" +#include "core/os/file_access.h" void SpineSkeletonFileResource::_bind_methods() { } -Error SpineSkeletonFileResource::load_from_file(const String &p_path) { - Error err; - - if (p_path.ends_with("spjson")) - json = FileAccess::get_file_as_string(p_path, &err); +Error SpineSkeletonFileResource::load_from_file(const String &path) { + Error error; + if (path.ends_with("spjson")) + json = FileAccess::get_file_as_string(path, &error); else - binary = FileAccess::get_file_as_array(p_path, &err); - return err; + binary = FileAccess::get_file_as_array(path, &error); + return error; } -Error SpineSkeletonFileResource::save_to_file(const String &p_path) { - Error err; - FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err != OK) { +Error SpineSkeletonFileResource::save_to_file(const String &path) { + Error error; + FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &error); + if (error != OK) { if (file) file->close(); - return err; + return error; } - if (!is_binary()) file->store_string(json); else file->store_buffer(binary.ptr(), binary.size()); file->close(); - return OK; } -RES SpineSkeletonFileResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { - Ref skeleton = memnew(SpineSkeletonFileResource); - skeleton->load_from_file(p_path); - - if (r_error) { - *r_error = OK; - } - return skeleton; +RES SpineSkeletonFileResourceFormatLoader::load(const String &path, const String &original_path, Error *error) { + Ref skeleton_file = memnew(SpineSkeletonFileResource); + skeleton_file->load_from_file(path); + if (error) *error = OK; + return skeleton_file; } -void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List *r_extensions) const { - r_extensions->push_back("spjson"); - r_extensions->push_back("spskel"); +void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List *extensions) const { + extensions->push_back("spjson"); + extensions->push_back("spskel"); } -String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &p_path) const { +String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &path) const { return "SpineSkeletonFileResource"; } -bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &p_type) const { - return p_type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonFileResource"); +bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &type) const { + return type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(type, "SpineSkeletonFileResource"); } -Error SpineSkeletonFileResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref res = p_resource.get_ref_ptr(); - Error error = res->save_to_file(p_path); + +Error SpineSkeletonFileResourceFormatSaver::save(const String &path, const RES &resource, uint32_t flags) { + Ref res = resource.get_ref_ptr(); + Error error = res->save_to_file(path); return error; } -void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (Object::cast_to(*p_resource)) { +void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &resource, List *p_extensions) const { + if (Object::cast_to(*resource)) { p_extensions->push_back("spjson"); p_extensions->push_back("spskel"); } diff --git a/spine-godot/spine_godot/SpineSkeletonFileResource.h b/spine-godot/spine_godot/SpineSkeletonFileResource.h index 56e162ef2..7733c06e4 100644 --- a/spine-godot/spine_godot/SpineSkeletonFileResource.h +++ b/spine-godot/spine_godot/SpineSkeletonFileResource.h @@ -30,7 +30,6 @@ #ifndef GODOT_SPINESKELETONFILERESOURCE_H #define GODOT_SPINESKELETONFILERESOURCE_H -#include "core/variant_parser.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" @@ -44,30 +43,38 @@ protected: Vector binary; public: - inline const bool is_binary() { return !binary.empty(); } - inline const Vector &get_binary() { return binary; } - inline const String &get_json() { return json; } + const bool is_binary() { return !binary.empty(); } - Error load_from_file(const String &p_path); - Error save_to_file(const String &p_path); + const Vector &get_binary() { return binary; } + + const String &get_json() { return json; } + + Error load_from_file(const String &path); + + Error save_to_file(const String &path); }; class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader { GDCLASS(SpineSkeletonFileResourceFormatLoader, ResourceFormatLoader); public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); - virtual void get_recognized_extensions(List *r_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; + virtual RES load(const String &path, const String &original_path, Error *error); + + virtual void get_recognized_extensions(List *extensions) const; + + virtual bool handles_type(const String &type) const; + + virtual String get_resource_type(const String &path) const; }; class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver { GDCLASS(SpineSkeletonFileResourceFormatSaver, ResourceFormatSaver); public: - Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override; - void get_recognized_extensions(const RES &p_resource, List *p_extensions) const override; + Error save(const String &path, const RES &resource, uint32_t flags) override; + + void get_recognized_extensions(const RES &resource, List *p_extensions) const override; + bool recognize(const RES &p_resource) const override; };