mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-24 18:51:25 +08:00
[godot] Add spine-godot to formatting script.
This commit is contained in:
parent
e0e3bb9f93
commit
8b892dc58a
@ -25,7 +25,9 @@ spotless {
|
|||||||
'spine-sfml/**/*.cpp',
|
'spine-sfml/**/*.cpp',
|
||||||
'spine-sfml/**/*.h',
|
'spine-sfml/**/*.h',
|
||||||
'spine-ue4/**/*.cpp',
|
'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')
|
clangFormat("13.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -953,8 +953,8 @@ spSkeletonData *spSkeletonJson_readSkeletonDataFile(spSkeletonJson *self, const
|
|||||||
static int string_starts_with(const char *str, const char *needle) {
|
static int string_starts_with(const char *str, const char *needle) {
|
||||||
int lenStr, lenNeedle, i;
|
int lenStr, lenNeedle, i;
|
||||||
if (!str) return 0;
|
if (!str) return 0;
|
||||||
lenStr = (int)strlen(str);
|
lenStr = (int) strlen(str);
|
||||||
lenNeedle = (int)strlen(needle);
|
lenNeedle = (int) strlen(needle);
|
||||||
if (lenStr < lenNeedle) return 0;
|
if (lenStr < lenNeedle) return 0;
|
||||||
for (i = 0; i < lenNeedle; i++) {
|
for (i = 0; i < lenNeedle; i++) {
|
||||||
if (str[i] != needle[i]) return 0;
|
if (str[i] != needle[i]) return 0;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {
|
class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {
|
||||||
GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader);
|
GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
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 {
|
class SpineAtlasResourceFormatSaver : public ResourceFormatSaver {
|
||||||
GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver);
|
GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class SpineBinaryResourceImportPlugin : public EditorImportPlugin {
|
class SpineBinaryResourceImportPlugin : public EditorImportPlugin {
|
||||||
GDCLASS(SpineBinaryResourceImportPlugin, EditorImportPlugin);
|
GDCLASS(SpineBinaryResourceImportPlugin, EditorImportPlugin);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String get_importer_name() const override { return "spine.skel"; }
|
String get_importer_name() const override { return "spine.skel"; }
|
||||||
|
|||||||
@ -99,7 +99,7 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *atlas, const String &json
|
|||||||
spine::SkeletonData *skeletonData = NULL;
|
spine::SkeletonData *skeletonData = NULL;
|
||||||
if (!json.empty()) {
|
if (!json.empty()) {
|
||||||
spine::SkeletonJson skeletonJson(atlas);
|
spine::SkeletonJson skeletonJson(atlas);
|
||||||
skeletonData = skeletonJson.readSkeletonData(json.utf8());
|
skeletonData = skeletonJson.readSkeletonData(json.utf8());
|
||||||
if (!skeletonData) {
|
if (!skeletonData) {
|
||||||
print_error(String("Error while loading skeleton data: ") + get_path());
|
print_error(String("Error while loading skeleton data: ") + get_path());
|
||||||
print_error(String("Error message: ") + skeletonJson.getError().buffer());
|
print_error(String("Error message: ") + skeletonJson.getError().buffer());
|
||||||
|
|||||||
@ -33,67 +33,67 @@ void SpineSkeletonFileResource::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error SpineSkeletonFileResource::load_from_file(const String &p_path) {
|
Error SpineSkeletonFileResource::load_from_file(const String &p_path) {
|
||||||
Error err;
|
Error err;
|
||||||
|
|
||||||
if(p_path.ends_with("spjson"))
|
if (p_path.ends_with("spjson"))
|
||||||
json = FileAccess::get_file_as_string(p_path, &err);
|
json = FileAccess::get_file_as_string(p_path, &err);
|
||||||
else
|
else
|
||||||
binary = FileAccess::get_file_as_array(p_path, &err);
|
binary = FileAccess::get_file_as_array(p_path, &err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error SpineSkeletonFileResource::save_to_file(const String &p_path) {
|
Error SpineSkeletonFileResource::save_to_file(const String &p_path) {
|
||||||
Error err;
|
Error err;
|
||||||
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
if (file) file->close();
|
if (file) file->close();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_binary())
|
if (!is_binary())
|
||||||
file->store_string(json);
|
file->store_string(json);
|
||||||
else
|
else
|
||||||
file->store_buffer(binary.ptr(), binary.size());
|
file->store_buffer(binary.ptr(), binary.size());
|
||||||
file->close();
|
file->close();
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
RES SpineSkeletonFileResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
RES SpineSkeletonFileResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
||||||
Ref<SpineSkeletonFileResource> skeleton = memnew(SpineSkeletonFileResource);
|
Ref<SpineSkeletonFileResource> skeleton = memnew(SpineSkeletonFileResource);
|
||||||
skeleton->load_from_file(p_path);
|
skeleton->load_from_file(p_path);
|
||||||
|
|
||||||
if (r_error) {
|
if (r_error) {
|
||||||
*r_error = OK;
|
*r_error = OK;
|
||||||
}
|
}
|
||||||
return skeleton;
|
return skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List<String> *r_extensions) const {
|
void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List<String> *r_extensions) const {
|
||||||
r_extensions->push_back("spjson");
|
r_extensions->push_back("spjson");
|
||||||
r_extensions->push_back("spskel");
|
r_extensions->push_back("spskel");
|
||||||
}
|
}
|
||||||
|
|
||||||
String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &p_path) const {
|
String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &p_path) const {
|
||||||
return "SpineSkeletonFileResource";
|
return "SpineSkeletonFileResource";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &p_type) const {
|
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) {
|
Error SpineSkeletonFileResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
||||||
Ref<SpineSkeletonFileResource> res = p_resource.get_ref_ptr();
|
Ref<SpineSkeletonFileResource> res = p_resource.get_ref_ptr();
|
||||||
Error error = res->save_to_file(p_path);
|
Error error = res->save_to_file(p_path);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
|
void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
|
||||||
if (Object::cast_to<SpineSkeletonFileResource>(*p_resource)) {
|
if (Object::cast_to<SpineSkeletonFileResource>(*p_resource)) {
|
||||||
p_extensions->push_back("spjson");
|
p_extensions->push_back("spjson");
|
||||||
p_extensions->push_back("spskel");
|
p_extensions->push_back("spskel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpineSkeletonFileResourceFormatSaver::recognize(const RES &p_resource) const {
|
bool SpineSkeletonFileResourceFormatSaver::recognize(const RES &p_resource) const {
|
||||||
return Object::cast_to<SpineSkeletonFileResource>(*p_resource) != nullptr;
|
return Object::cast_to<SpineSkeletonFileResource>(*p_resource) != nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,40 +35,40 @@
|
|||||||
#include "core/io/resource_saver.h"
|
#include "core/io/resource_saver.h"
|
||||||
|
|
||||||
class SpineSkeletonFileResource : public Resource {
|
class SpineSkeletonFileResource : public Resource {
|
||||||
GDCLASS(SpineSkeletonFileResource, Resource);
|
GDCLASS(SpineSkeletonFileResource, Resource);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
String json;
|
String json;
|
||||||
Vector<uint8_t> binary;
|
Vector<uint8_t> binary;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline const bool is_binary() { return !binary.empty(); }
|
inline const bool is_binary() { return !binary.empty(); }
|
||||||
inline const Vector<uint8_t> &get_binary() { return binary; }
|
inline const Vector<uint8_t> &get_binary() { return binary; }
|
||||||
inline const String &get_json() { return json; }
|
inline const String &get_json() { return json; }
|
||||||
|
|
||||||
Error load_from_file(const String &p_path);
|
Error load_from_file(const String &p_path);
|
||||||
Error save_to_file(const String &p_path);
|
Error save_to_file(const String &p_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {
|
class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {
|
||||||
GDCLASS(SpineSkeletonFileResourceFormatLoader, ResourceFormatLoader);
|
GDCLASS(SpineSkeletonFileResourceFormatLoader, ResourceFormatLoader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
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 void get_recognized_extensions(List<String> *r_extensions) const;
|
||||||
virtual bool handles_type(const String &p_type) const;
|
virtual bool handles_type(const String &p_type) const;
|
||||||
virtual String get_resource_type(const String &p_path) const;
|
virtual String get_resource_type(const String &p_path) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver {
|
class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver {
|
||||||
GDCLASS(SpineSkeletonFileResourceFormatSaver, ResourceFormatSaver);
|
GDCLASS(SpineSkeletonFileResourceFormatSaver, ResourceFormatSaver);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) 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;
|
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
|
||||||
bool recognize(const RES &p_resource) const override;
|
bool recognize(const RES &p_resource) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GODOT_SPINESKELETONFILERESOURCE_H
|
#endif//GODOT_SPINESKELETONFILERESOURCE_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user