summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-02-24 09:53:33 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-02-24 09:53:33 -0300
commit4b07eb8deb03ce8c7870d621cd03d04d45f4caaa (patch)
tree3314811f8a347ae60d951163c19d291b46381511 /tools/editor
parent51609ffc04290f8bd1ecbd9cf1639c0cc6368fac (diff)
-moved script to modules
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/editor_import_export.cpp94
-rw-r--r--tools/editor/editor_import_export.h20
-rw-r--r--tools/editor/editor_node.cpp2
-rw-r--r--tools/editor/io_plugins/editor_texture_import_plugin.cpp53
-rw-r--r--tools/editor/io_plugins/editor_texture_import_plugin.h10
5 files changed, 142 insertions, 37 deletions
diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp
index 87d3e17694..22b611fdcc 100644
--- a/tools/editor/editor_import_export.cpp
+++ b/tools/editor/editor_import_export.cpp
@@ -124,6 +124,40 @@ EditorImportPlugin::EditorImportPlugin() {
/////////////////////////////////////////////////////////////////////////////////////////////////////
+void EditorExportPlugin::_bind_methods() {
+
+ BIND_VMETHOD( MethodInfo("custom_export:Dictionary",PropertyInfo(Variant::STRING,"name",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatformPC")) );
+}
+
+
+Vector<uint8_t> EditorExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
+
+ if (get_script_instance()) {
+
+ Variant d = get_script_instance()->call("custom_export",p_path,p_platform);
+ if (d.get_type()==Variant::NIL)
+ return Vector<uint8_t>();
+ ERR_FAIL_COND_V(d.get_type()!=Variant::DICTIONARY,Vector<uint8_t>());
+ Dictionary dict=d;
+ ERR_FAIL_COND_V(!dict.has("name"),Vector<uint8_t>());
+ ERR_FAIL_COND_V(!dict.has("data"),Vector<uint8_t>());
+ p_path=dict["name"];
+ return dict["data"];
+ }
+
+ return Vector<uint8_t>();
+
+}
+
+
+EditorExportPlugin::EditorExportPlugin() {
+
+
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
static void _add_to_list(EditorFileSystemDirectory *p_efsd,Set<StringName>& r_list) {
for(int i=0;i<p_efsd->get_subdir_count();i++) {
@@ -223,48 +257,17 @@ static void _add_filter_to_list(Set<StringName>& r_list,const String& p_filter)
Vector<uint8_t> EditorExportPlatform::get_exported_file(String& p_fname) const {
+ Ref<EditorExportPlatform> ep=EditorImportExport::get_singleton()->get_export_platform(get_name());
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_fname);
+ for(int i=0;i<EditorImportExport::get_singleton()->get_export_plugin_count();i++) {
- if (rimd.is_valid()) {
+ Vector<uint8_t> data = EditorImportExport::get_singleton()->get_export_plugin(i)->custom_export(p_fname,ep);
+ if (data.size())
+ return data;
- if (rimd->get_editor()!="") {
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_fname,EditorImportExport::get_singleton()->get_export_platform(get_name()));
- if (ce.size())
- return ce;
- }
- }
- } else if (EditorImportExport::get_singleton()->image_get_export_group(p_fname)) {
-
-
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture_2d");
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_fname,EditorImportExport::get_singleton()->get_export_platform(get_name()));
- if (ce.size()) {
- p_fname=p_fname.basename()+".tex";
- return ce;
- }
- }
-
- } else if (EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE){
-
- String xt = p_fname.extension().to_lower();
- print_line("TRY FOR: "+p_fname);
- if (EditorImportExport::get_singleton()->get_image_formats().has(xt)) { //should check for more I guess?
-
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture_2d");
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_fname,EditorImportExport::get_singleton()->get_export_platform(get_name()));
- if (ce.size()) {
- p_fname=p_fname.basename()+".tex";
- return ce;
- }
- }
- }
}
+
FileAccess *f = FileAccess::open(p_fname,FileAccess::READ);
ERR_FAIL_COND_V(!f,Vector<uint8_t>());
Vector<uint8_t> ret;
@@ -1061,12 +1064,29 @@ Ref<EditorImportPlugin> EditorImportExport::get_import_plugin(int p_idx) const{
return plugins[p_idx];
}
+
+
+
Ref<EditorImportPlugin> EditorImportExport::get_import_plugin_by_name(const String& p_string) const{
ERR_FAIL_COND_V( !by_idx.has(p_string), Ref<EditorImportPlugin>());
return plugins[ by_idx[p_string] ];
}
+void EditorImportExport::add_export_plugin(const Ref<EditorExportPlugin>& p_plugin) {
+
+ export_plugins.push_back(p_plugin);
+}
+
+int EditorImportExport::get_export_plugin_count() const{
+
+ return export_plugins.size();
+}
+Ref<EditorExportPlugin> EditorImportExport::get_export_plugin(int p_idx) const{
+
+ ERR_FAIL_INDEX_V(p_idx,export_plugins.size(),Ref<EditorExportPlugin>());
+ return export_plugins[p_idx];
+}
void EditorImportExport::set_export_file_action(const StringName& p_file, FileAction p_action) {
diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h
index 1e5e733921..17f2592ad5 100644
--- a/tools/editor/editor_import_export.h
+++ b/tools/editor/editor_import_export.h
@@ -36,6 +36,7 @@
class EditorExportPlatform;
class FileAccess;
class EditorProgress;
+
class EditorImportPlugin : public Reference {
OBJ_TYPE( EditorImportPlugin, Reference);
@@ -59,6 +60,20 @@ public:
EditorImportPlugin();
};
+class EditorExportPlugin : public Reference {
+
+ OBJ_TYPE( EditorExportPlugin, Reference);
+
+protected:
+ static void _bind_methods();
+
+public:
+
+ virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
+
+ EditorExportPlugin();
+};
+
class EditorExportPlatform : public Reference {
OBJ_TYPE( EditorExportPlatform,Reference );
@@ -223,6 +238,7 @@ protected:
int shrink;
};
+ Vector<Ref<EditorExportPlugin> > export_plugins;
Vector<Ref<EditorImportPlugin> > plugins;
Map<String,int> by_idx;
ImageAction image_action;
@@ -249,6 +265,10 @@ public:
Ref<EditorImportPlugin> get_import_plugin(int p_idx) const;
Ref<EditorImportPlugin> get_import_plugin_by_name(const String& p_string) const;
+ void add_export_plugin(const Ref<EditorExportPlugin>& p_plugin);
+ int get_export_plugin_count() const;
+ Ref<EditorExportPlugin> get_export_plugin(int p_idx) const;
+
bool poll_export_platforms();
void set_export_file_action(const StringName& p_export_file, FileAction p_action);
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 33b2e72d62..ae350e3b99 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -4006,10 +4006,12 @@ EditorNode::EditorNode() {
editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this))));
editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this))));
+
for(int i=0;i<editor_import_export->get_import_plugin_count();i++) {
import_menu->get_popup()->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(),IMPORT_PLUGIN_BASE+i);
}
+ editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin)));
add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) );
add_editor_plugin( memnew( SpatialEditorPlugin(this) ) );
diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp
index 2e6e755136..067edee5a0 100644
--- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp
+++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp
@@ -1190,3 +1190,56 @@ EditorTextureImportPlugin::EditorTextureImportPlugin(EditorNode *p_editor, Mode
editor->get_gui_base()->add_child(dialog);
}
+
+////////////////////////////
+
+
+ Vector<uint8_t> EditorTextureExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
+
+ Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
+
+ if (rimd.is_valid()) {
+
+ if (rimd->get_editor()!="") {
+ Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
+ if (pl.is_valid()) {
+ Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
+ if (ce.size())
+ return ce;
+ }
+ }
+ } else if (EditorImportExport::get_singleton()->image_get_export_group(p_path)) {
+
+
+ Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture_2d");
+ if (pl.is_valid()) {
+ Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
+ if (ce.size()) {
+ p_path=p_path.basename()+".tex";
+ return ce;
+ }
+ }
+
+ } else if (EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE){
+
+ String xt = p_path.extension().to_lower();
+ if (EditorImportExport::get_singleton()->get_image_formats().has(xt)) { //should check for more I guess?
+
+ Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture_2d");
+ if (pl.is_valid()) {
+ Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
+ if (ce.size()) {
+ p_path=p_path.basename()+".tex";
+ return ce;
+ }
+ }
+ }
+ }
+
+ return Vector<uint8_t>();
+}
+
+EditorTextureExportPlugin::EditorTextureExportPlugin() {
+
+
+}
diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.h b/tools/editor/io_plugins/editor_texture_import_plugin.h
index 4a9dd6ae9d..b2950a889c 100644
--- a/tools/editor/io_plugins/editor_texture_import_plugin.h
+++ b/tools/editor/io_plugins/editor_texture_import_plugin.h
@@ -106,6 +106,16 @@ public:
};
+class EditorTextureExportPlugin : public EditorExportPlugin {
+
+ OBJ_TYPE( EditorTextureExportPlugin, EditorExportPlugin);
+
+
+public:
+
+ virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
+ EditorTextureExportPlugin();
+};
class EditorImportTextureOptions : public VBoxContainer {
OBJ_TYPE( EditorImportTextureOptions, VBoxContainer );