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