[godot] Add spine-godot to formatting script.

This commit is contained in:
Mario Zechner 2022-04-06 10:04:17 +02:00
parent e0e3bb9f93
commit 8b892dc58a
7 changed files with 64 additions and 62 deletions

View File

@ -25,7 +25,9 @@ spotless {
'spine-sfml/**/*.cpp',
'spine-sfml/**/*.h',
'spine-ue4/**/*.cpp',
'spine-ue4/**/*.h'
'spine-ue4/**/*.h',
'spine-godot/godot/modules/spine_godot/*.cpp',
'spine-godot/godot/modules/spine_godot/*.h'
clangFormat("13.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
}

View File

@ -953,8 +953,8 @@ spSkeletonData *spSkeletonJson_readSkeletonDataFile(spSkeletonJson *self, const
static int string_starts_with(const char *str, const char *needle) {
int lenStr, lenNeedle, i;
if (!str) return 0;
lenStr = (int)strlen(str);
lenNeedle = (int)strlen(needle);
lenStr = (int) strlen(str);
lenNeedle = (int) strlen(needle);
if (lenStr < lenNeedle) return 0;
for (i = 0; i < lenNeedle; i++) {
if (str[i] != needle[i]) return 0;

View File

@ -78,7 +78,7 @@ public:
};
class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {
GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader);
GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader);
public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
@ -88,7 +88,7 @@ public:
};
class SpineAtlasResourceFormatSaver : public ResourceFormatSaver {
GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver);
GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver);
public:
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;

View File

@ -74,7 +74,7 @@ public:
};
class SpineBinaryResourceImportPlugin : public EditorImportPlugin {
GDCLASS(SpineBinaryResourceImportPlugin, EditorImportPlugin);
GDCLASS(SpineBinaryResourceImportPlugin, EditorImportPlugin);
public:
String get_importer_name() const override { return "spine.skel"; }

View File

@ -99,7 +99,7 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *atlas, const String &json
spine::SkeletonData *skeletonData = NULL;
if (!json.empty()) {
spine::SkeletonJson skeletonJson(atlas);
skeletonData = skeletonJson.readSkeletonData(json.utf8());
skeletonData = skeletonJson.readSkeletonData(json.utf8());
if (!skeletonData) {
print_error(String("Error while loading skeleton data: ") + get_path());
print_error(String("Error message: ") + skeletonJson.getError().buffer());

View File

@ -33,67 +33,67 @@ void SpineSkeletonFileResource::_bind_methods() {
}
Error SpineSkeletonFileResource::load_from_file(const String &p_path) {
Error err;
Error err;
if(p_path.ends_with("spjson"))
json = FileAccess::get_file_as_string(p_path, &err);
else
binary = FileAccess::get_file_as_array(p_path, &err);
return err;
if (p_path.ends_with("spjson"))
json = FileAccess::get_file_as_string(p_path, &err);
else
binary = FileAccess::get_file_as_array(p_path, &err);
return err;
}
Error SpineSkeletonFileResource::save_to_file(const String &p_path) {
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err != OK) {
if (file) file->close();
return err;
}
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err != OK) {
if (file) file->close();
return err;
}
if (!is_binary())
file->store_string(json);
else
file->store_buffer(binary.ptr(), binary.size());
file->close();
if (!is_binary())
file->store_string(json);
else
file->store_buffer(binary.ptr(), binary.size());
file->close();
return OK;
return OK;
}
RES SpineSkeletonFileResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
Ref<SpineSkeletonFileResource> skeleton = memnew(SpineSkeletonFileResource);
skeleton->load_from_file(p_path);
Ref<SpineSkeletonFileResource> skeleton = memnew(SpineSkeletonFileResource);
skeleton->load_from_file(p_path);
if (r_error) {
*r_error = OK;
}
return skeleton;
if (r_error) {
*r_error = OK;
}
return skeleton;
}
void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List<String> *r_extensions) const {
r_extensions->push_back("spjson");
r_extensions->push_back("spskel");
r_extensions->push_back("spjson");
r_extensions->push_back("spskel");
}
String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &p_path) const {
return "SpineSkeletonFileResource";
return "SpineSkeletonFileResource";
}
bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &p_type) const {
return p_type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonFileResource");
return p_type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonFileResource");
}
Error SpineSkeletonFileResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<SpineSkeletonFileResource> res = p_resource.get_ref_ptr();
Error error = res->save_to_file(p_path);
return error;
Ref<SpineSkeletonFileResource> res = p_resource.get_ref_ptr();
Error error = res->save_to_file(p_path);
return error;
}
void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (Object::cast_to<SpineSkeletonFileResource>(*p_resource)) {
p_extensions->push_back("spjson");
p_extensions->push_back("spskel");
}
if (Object::cast_to<SpineSkeletonFileResource>(*p_resource)) {
p_extensions->push_back("spjson");
p_extensions->push_back("spskel");
}
}
bool SpineSkeletonFileResourceFormatSaver::recognize(const RES &p_resource) const {
return Object::cast_to<SpineSkeletonFileResource>(*p_resource) != nullptr;
return Object::cast_to<SpineSkeletonFileResource>(*p_resource) != nullptr;
}

View File

@ -35,40 +35,40 @@
#include "core/io/resource_saver.h"
class SpineSkeletonFileResource : public Resource {
GDCLASS(SpineSkeletonFileResource, Resource);
GDCLASS(SpineSkeletonFileResource, Resource);
protected:
static void _bind_methods();
static void _bind_methods();
String json;
Vector<uint8_t> binary;
String json;
Vector<uint8_t> binary;
public:
inline const bool is_binary() { return !binary.empty(); }
inline const Vector<uint8_t> &get_binary() { return binary; }
inline const String &get_json() { return json; }
inline const bool is_binary() { return !binary.empty(); }
inline const Vector<uint8_t> &get_binary() { return binary; }
inline const String &get_json() { return json; }
Error load_from_file(const String &p_path);
Error save_to_file(const String &p_path);
Error load_from_file(const String &p_path);
Error save_to_file(const String &p_path);
};
class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {
GDCLASS(SpineSkeletonFileResourceFormatLoader, 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<String> *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 &p_path, const String &p_original_path, Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *r_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver {
GDCLASS(SpineSkeletonFileResourceFormatSaver, 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<String> *p_extensions) const override;
bool recognize(const RES &p_resource) const override;
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<String> *p_extensions) const override;
bool recognize(const RES &p_resource) const override;
};
#endif //GODOT_SPINESKELETONFILERESOURCE_H
#endif//GODOT_SPINESKELETONFILERESOURCE_H