mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-09 08:38:43 +08:00
[godot] Clean-up SpineEditorPlugin.
This commit is contained in:
parent
826e0a7326
commit
00f83a1317
@ -33,47 +33,46 @@
|
||||
#include "SpineAtlasResource.h"
|
||||
#include "SpineSkeletonFileResource.h"
|
||||
|
||||
Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
||||
Ref<SpineAtlasResource> res(memnew(SpineAtlasResource));
|
||||
res->set_normal_texture_prefix(p_options["normal_texture_prefix"]);
|
||||
res->load_from_atlas_file(p_source_file);
|
||||
Error SpineAtlasResourceImportPlugin::import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) {
|
||||
Ref<SpineAtlasResource> atlas(memnew(SpineAtlasResource));
|
||||
atlas->set_normal_texture_prefix(options["normal_map_prefix"]);
|
||||
atlas->load_from_atlas_file(source_file);
|
||||
|
||||
String file_name = vformat("%s.%s", p_save_path, get_save_extension());
|
||||
auto err = ResourceSaver::save(file_name, res);
|
||||
return err;
|
||||
String file_name = vformat("%s.%s", save_path, get_save_extension());
|
||||
auto error = ResourceSaver::save(file_name, atlas);
|
||||
return error;
|
||||
}
|
||||
|
||||
void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *r_options, int p_preset) const {
|
||||
if (p_preset == 0) {
|
||||
void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *options, int preset) const {
|
||||
if (preset == 0) {
|
||||
ImportOption op;
|
||||
op.option.name = "normal_texture_prefix";
|
||||
op.option.name = "normal_map_prefix";
|
||||
op.option.type = Variant::STRING;
|
||||
op.option.hint_string = "String";
|
||||
op.default_value = String("n");
|
||||
r_options->push_back(op);
|
||||
options->push_back(op);
|
||||
}
|
||||
}
|
||||
|
||||
Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
||||
Ref<SpineSkeletonFileResource> res(memnew(SpineSkeletonFileResource));
|
||||
res->load_from_file(p_source_file);
|
||||
Error SpineJsonResourceImportPlugin::import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) {
|
||||
Ref<SpineSkeletonFileResource> skeleton_file_res(memnew(SpineSkeletonFileResource));
|
||||
skeleton_file_res->load_from_file(source_file);
|
||||
|
||||
String file_name = vformat("%s.%s", p_save_path, get_save_extension());
|
||||
auto err = ResourceSaver::save(file_name, res);
|
||||
return err;
|
||||
String file_name = vformat("%s.%s", save_path, get_save_extension());
|
||||
auto error = ResourceSaver::save(file_name, skeleton_file_res);
|
||||
return error;
|
||||
}
|
||||
|
||||
Error SpineBinaryResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
||||
Ref<SpineSkeletonFileResource> res(memnew(SpineSkeletonFileResource));
|
||||
res->load_from_file(p_source_file);
|
||||
Error SpineBinaryResourceImportPlugin::import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) {
|
||||
Ref<SpineSkeletonFileResource> skeleton_file_res(memnew(SpineSkeletonFileResource));
|
||||
skeleton_file_res->load_from_file(source_file);
|
||||
|
||||
String file_name = vformat("%s.%s", p_save_path, get_save_extension());
|
||||
auto err = ResourceSaver::save(file_name, res);
|
||||
return err;
|
||||
String file_name = vformat("%s.%s", save_path, get_save_extension());
|
||||
auto error = ResourceSaver::save(file_name, skeleton_file_res);
|
||||
return error;
|
||||
}
|
||||
|
||||
//=======================| SpineEditorPlugin |============================
|
||||
SpineEditorPlugin::SpineEditorPlugin(EditorNode *p_node) {
|
||||
SpineEditorPlugin::SpineEditorPlugin(EditorNode *node) {
|
||||
add_import_plugin(memnew(SpineAtlasResourceImportPlugin));
|
||||
add_import_plugin(memnew(SpineJsonResourceImportPlugin));
|
||||
add_import_plugin(memnew(SpineBinaryResourceImportPlugin));
|
||||
@ -82,8 +81,8 @@ SpineEditorPlugin::SpineEditorPlugin(EditorNode *p_node) {
|
||||
SpineEditorPlugin::~SpineEditorPlugin() {
|
||||
}
|
||||
|
||||
bool SpineEditorPlugin::handles(Object *p_object) const {
|
||||
return p_object->is_class("SpineSprite");
|
||||
bool SpineEditorPlugin::handles(Object *object) const {
|
||||
return object->is_class("SpineSprite");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -34,43 +34,53 @@
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
class SpineAtlasResourceImportPlugin : public EditorImportPlugin {
|
||||
GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin);
|
||||
GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin)
|
||||
|
||||
public:
|
||||
String get_importer_name() const override { return "spine.atlas"; }
|
||||
|
||||
String get_visible_name() const override { return "Spine Runtime Atlas"; }
|
||||
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("atlas"); }
|
||||
String get_preset_name(int p_idx) const override {
|
||||
if (p_idx == 0) return "Default";
|
||||
else
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
void get_recognized_extensions(List<String> *extensions) const override { extensions->push_back("atlas"); }
|
||||
|
||||
String get_preset_name(int idx) const override { return idx == 0 ? "Default" : "Unknown"; }
|
||||
|
||||
int get_preset_count() const override { return 1; }
|
||||
|
||||
String get_save_extension() const override { return "spatlas"; }
|
||||
|
||||
String get_resource_type() const override { return "SpineAtlasResource"; }
|
||||
void get_import_options(List<ImportOption> *r_options, int p_preset) const override;
|
||||
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override { return true; }
|
||||
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;
|
||||
|
||||
void get_import_options(List<ImportOption> *options, int preset) const override;
|
||||
|
||||
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
|
||||
|
||||
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
|
||||
};
|
||||
|
||||
class SpineJsonResourceImportPlugin : public EditorImportPlugin {
|
||||
GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin);
|
||||
GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin)
|
||||
|
||||
public:
|
||||
String get_importer_name() const override { return "spine.json"; }
|
||||
String get_visible_name() const override { return "Spine Runtime Json"; }
|
||||
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("json"); }
|
||||
String get_preset_name(int p_idx) const override {
|
||||
if (p_idx == 0) return "Default";
|
||||
else
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
String get_visible_name() const override { return "Spine Skeleton Json"; }
|
||||
|
||||
void get_recognized_extensions(List<String> *extensions) const override { extensions->push_back("json"); }
|
||||
|
||||
String get_preset_name(int idx) const override { return idx == 0 ? "Default" : "Unknown"; }
|
||||
|
||||
int get_preset_count() const override { return 1; }
|
||||
|
||||
String get_save_extension() const override { return "spjson"; }
|
||||
|
||||
String get_resource_type() const override { return "SpineSkeletonFileResource"; }
|
||||
void get_import_options(List<ImportOption> *r_options, int p_preset) const override {}
|
||||
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override { return true; }
|
||||
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;
|
||||
|
||||
void get_import_options(List<ImportOption> *options, int preset) const override {}
|
||||
|
||||
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
|
||||
|
||||
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
|
||||
};
|
||||
|
||||
class SpineBinaryResourceImportPlugin : public EditorImportPlugin {
|
||||
@ -78,31 +88,38 @@ class SpineBinaryResourceImportPlugin : public EditorImportPlugin {
|
||||
|
||||
public:
|
||||
String get_importer_name() const override { return "spine.skel"; }
|
||||
String get_visible_name() const override { return "Spine Runtime Binary"; }
|
||||
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("skel"); }
|
||||
String get_preset_name(int p_idx) const override {
|
||||
if (p_idx == 0) return "Default";
|
||||
else
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
String get_visible_name() const override { return "Spine Skeleton Binary"; }
|
||||
|
||||
void get_recognized_extensions(List<String> *extensions) const override { extensions->push_back("skel"); }
|
||||
|
||||
String get_preset_name(int idx) const override { return idx == 0 ? "Default" : "Unknown"; }
|
||||
|
||||
int get_preset_count() const override { return 1; }
|
||||
|
||||
String get_save_extension() const override { return "spskel"; }
|
||||
|
||||
String get_resource_type() const override { return "SpineSkeletonFileResource"; }
|
||||
void get_import_options(List<ImportOption> *r_options, int p_preset) const override {}
|
||||
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override { return true; }
|
||||
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;
|
||||
|
||||
void get_import_options(List<ImportOption> *options, int preset) const override {}
|
||||
|
||||
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
|
||||
|
||||
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
|
||||
};
|
||||
|
||||
class SpineEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(SpineEditorPlugin, EditorPlugin);
|
||||
GDCLASS(SpineEditorPlugin, EditorPlugin)
|
||||
|
||||
public:
|
||||
SpineEditorPlugin(EditorNode *p_node);
|
||||
SpineEditorPlugin(EditorNode *node);
|
||||
~SpineEditorPlugin();
|
||||
|
||||
String get_name() const override { return "SpineEditorPlugin"; }
|
||||
|
||||
bool has_main_screen() const { return false; }
|
||||
bool handles(Object *p_object) const override;
|
||||
|
||||
bool handles(Object *object) const override;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user