From f6950956bdab064cc1e027b93a0ddd0d94dda882 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 19 Feb 2017 23:19:30 -0300 Subject: Editor Export Settings Dialog is completed!! Now on to make some exporters.. --- platform/android/export/export.cpp | 8 +- platform/bb10/export/export.cpp | 10 +- platform/javascript/export/export.cpp | 10 +- platform/osx/export/export.cpp | 10 +- platform/uwp/export/export.cpp | 7 +- platform/windows/export/export.cpp | 9 +- platform/x11/export/export.cpp | 23 +- scene/gui/dialogs.cpp | 4 +- scene/gui/item_list.cpp | 16 + scene/gui/item_list.h | 1 + tools/editor/SCsub | 2 +- tools/editor/editor_export.cpp | 2934 ++++++++++++++++++++ tools/editor/editor_export.h | 281 ++ tools/editor/editor_import_export.cpp | 2572 ----------------- tools/editor/editor_import_export.h | 199 -- tools/editor/editor_node.cpp | 28 +- tools/editor/editor_node.h | 6 +- tools/editor/editor_plugin.h | 2 +- tools/editor/editor_run_native.cpp | 2 +- tools/editor/io_plugins/editor_export_scene.h | 2 +- .../editor/io_plugins/editor_font_import_plugin.h | 2 +- .../io_plugins/editor_translation_import_plugin.h | 2 +- tools/editor/project_export.cpp | 2361 ++++------------ tools/editor/project_export.h | 198 +- tools/editor/property_editor.cpp | 2 +- 25 files changed, 3850 insertions(+), 4841 deletions(-) create mode 100644 tools/editor/editor_export.cpp create mode 100644 tools/editor/editor_export.h delete mode 100644 tools/editor/editor_import_export.cpp delete mode 100644 tools/editor/editor_import_export.h diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 8e1fda74ed..4fc318d4ae 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -29,7 +29,7 @@ #include "version.h" #include "export.h" #include "tools/editor/editor_settings.h" -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "tools/editor/editor_node.h" #include "io/zip_io.h" #include "io/marshalls.h" @@ -1892,9 +1892,11 @@ EditorExportPlatformAndroid::~EditorExportPlatformAndroid() { memdelete(device_thread); } +#endif void register_android_exporter() { +#if 0 String exe_ext=OS::get_singleton()->get_name()=="Windows"?"exe":""; EDITOR_DEF("export/android/adb",""); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/adb",PROPERTY_HINT_GLOBAL_FILE,exe_ext)); @@ -1913,6 +1915,6 @@ void register_android_exporter() { Ref exporter = Ref( memnew(EditorExportPlatformAndroid) ); EditorImportExport::get_singleton()->add_export_platform(exporter); - -} #endif +} + diff --git a/platform/bb10/export/export.cpp b/platform/bb10/export/export.cpp index 3e6dadb094..0a401d3cd8 100644 --- a/platform/bb10/export/export.cpp +++ b/platform/bb10/export/export.cpp @@ -29,7 +29,7 @@ #include "version.h" #include "export.h" #include "tools/editor/editor_settings.h" -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "tools/editor/editor_node.h" #include "io/zip_io.h" #include "io/marshalls.h" @@ -803,9 +803,9 @@ EditorExportPlatformBB10::~EditorExportPlatformBB10() { memdelete(device_thread); } - +#endif void register_bb10_exporter() { - +#if 0 EDITOR_DEF("export/blackberry/host_tools",""); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"export/blackberry/host_tools",PROPERTY_HINT_GLOBAL_DIR)); EDITOR_DEF("export/blackberry/debug_token",""); @@ -824,7 +824,7 @@ void register_bb10_exporter() { Ref exporter = Ref( memnew(EditorExportPlatformBB10) ); EditorImportExport::get_singleton()->add_export_platform(exporter); - +#endif } -#endif + diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index e487383ef4..73ec7bbc54 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -29,7 +29,7 @@ #include "version.h" #include "export.h" #include "tools/editor/editor_settings.h" -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "tools/editor/editor_node.h" #include "io/zip_io.h" #include "io/marshalls.h" @@ -417,14 +417,14 @@ EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() { } - +#endif void register_javascript_exporter() { - Ref exporter = Ref( memnew(EditorExportPlatformJavaScript) ); - EditorImportExport::get_singleton()->add_export_platform(exporter); + //Ref exporter = Ref( memnew(EditorExportPlatformJavaScript) ); + //EditorImportExport::get_singleton()->add_export_platform(exporter); } -#endif + diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 3a97827c16..79103a9b3e 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -29,7 +29,7 @@ #include "version.h" #include "export.h" #include "tools/editor/editor_settings.h" -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "tools/editor/editor_node.h" #include "io/zip_io.h" #include "io/marshalls.h" @@ -536,14 +536,14 @@ EditorExportPlatformOSX::~EditorExportPlatformOSX() { } - +#endif void register_osx_exporter() { - +#if 0 Ref exporter = Ref( memnew(EditorExportPlatformOSX) ); EditorImportExport::get_singleton()->add_export_platform(exporter); - +#endif } -#endif + diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 167a5831cf..112942c324 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -2384,10 +2384,11 @@ EditorExportPlatformUWP::EditorExportPlatformUWP() { EditorExportPlatformUWP::~EditorExportPlatformUWP() {} - +#endif void register_uwp_exporter() { - +#if 0 Ref exporter = Ref(memnew(EditorExportPlatformUWP)); EditorImportExport::get_singleton()->add_export_platform(exporter); -} #endif +} + diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 88d534887b..1c827a93b0 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -28,10 +28,11 @@ /*************************************************************************/ #include "export.h" #include "platform/windows/logo.h" -#include "tools/editor/editor_import_export.h" -#if 0 +#include "tools/editor/editor_export.h" + void register_windows_exporter() { +#if 0 Image img(_windows_logo); Ref logo = memnew( ImageTexture ); logo->create_from_image(img); @@ -48,6 +49,6 @@ void register_windows_exporter() { EditorImportExport::get_singleton()->add_export_platform(exporter); } - -} #endif +} + diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp index 5a4751b387..5c7f98c1f3 100644 --- a/platform/x11/export/export.cpp +++ b/platform/x11/export/export.cpp @@ -28,11 +28,27 @@ /*************************************************************************/ #include "export.h" #include "platform/x11/logo.h" -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "scene/resources/texture.h" -#if 0 + + + void register_x11_exporter() { + Ref platform; + platform.instance(); + + Image img(_x11_logo); + Ref logo; + logo.instance(); + logo->create_from_image(img); + platform->set_logo(logo); + platform->set_name("Linux/X11"); + platform->set_extension(""); + + EditorExport::get_singleton()->add_export_platform(platform); + + #if 0 Image img(_x11_logo); Ref logo = memnew( ImageTexture ); logo->create_from_image(img); @@ -49,5 +65,6 @@ void register_x11_exporter() { EditorImportExport::get_singleton()->add_export_platform(exporter); } + #endif } -#endif + diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 2f97ce2d51..72d3f0e8f8 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -272,7 +272,7 @@ void AcceptDialog::_update_child_rects() { if (!c) continue; - if (c==hbc || c==label || c==get_close_button()) + if (c==hbc || c==label || c==get_close_button() || c->is_set_as_toplevel()) continue; c->set_pos(cpos); @@ -299,7 +299,7 @@ Size2 AcceptDialog::get_minimum_size() const { if (!c) continue; - if (c==hbc || c==label || c==const_cast(this)->get_close_button()) + if (c==hbc || c==label || c==const_cast(this)->get_close_button() || c->is_set_as_toplevel()) continue; Size2 cminsize = c->get_combined_minimum_size(); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 4e10f1d622..d16688407c 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1204,6 +1204,22 @@ int ItemList::get_item_at_pos(const Point2& p_pos, bool p_exact) const { return closest; } +bool ItemList::is_pos_at_end_of_items(const Point2& p_pos) const { + + if (items.empty()) + return true; + + Vector2 pos=p_pos; + Ref bg = get_stylebox("bg"); + pos-=bg->get_offset(); + pos.y+=scroll_bar->get_value(); + + Rect2 endrect = items[items.size()-1].rect_cache; + return (pos.y > endrect.pos.y + endrect.size.y); + +} + + String ItemList::get_tooltip(const Point2& p_pos) const { int closest = get_item_at_pos(p_pos); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index f4a864c782..35ffb1be9c 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -191,6 +191,7 @@ public: virtual String get_tooltip(const Point2& p_pos) const; int get_item_at_pos(const Point2& p_pos,bool p_exact=false) const; + bool is_pos_at_end_of_items(const Point2& p_pos) const; void set_icon_scale(real_t p_scale); real_t get_icon_scale() const; diff --git a/tools/editor/SCsub b/tools/editor/SCsub index 710dac3ea7..76eb65748a 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -137,7 +137,7 @@ if (env["tools"] == "yes"): reg_exporters = 'void register_exporters() {\n' for e in env.platform_exporters: env.editor_sources.append("#platform/" + e + "/export/export.cpp") - reg_exporters += '\t//register_' + e + '_exporter();\n' + reg_exporters += '\tregister_' + e + '_exporter();\n' reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n' reg_exporters += '}\n' f = open("register_exporters.cpp", "wb") diff --git a/tools/editor/editor_export.cpp b/tools/editor/editor_export.cpp new file mode 100644 index 0000000000..599ca6bf6a --- /dev/null +++ b/tools/editor/editor_export.cpp @@ -0,0 +1,2934 @@ +/*************************************************************************/ +/* editor_import_export.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "editor_export.h" +#include "version.h" +#include "script_language.h" +#include "globals.h" +#include "os/file_access.h" +#include "os/dir_access.h" +#include "tools/editor/editor_file_system.h" +#include "io/resource_loader.h" +#include "editor_node.h" +#include "editor_settings.h" +#include "io/config_file.h" +#include "io/resource_saver.h" +#include "io/md5.h" +#include "tools/editor/plugins/script_editor_plugin.h" +#include "io/zip_io.h" + + + + +bool EditorExportPreset::_set(const StringName& p_name, const Variant& p_value) { + + if (values.has(p_name)) { + values[p_name]=p_value; + EditorExport::singleton->save_presets(); + return true; + } + + return false; +} + +bool EditorExportPreset::_get(const StringName& p_name,Variant &r_ret) const{ + + if (values.has(p_name)) { + r_ret=values[p_name]; + return true; + } + + return false; +} +void EditorExportPreset::_get_property_list( List *p_list) const{ + + for (const List::Element *E=properties.front();E;E=E->next()) { + + p_list->push_back(E->get()); + } +} + +Ref EditorExportPreset::get_platform() { + + return platform; +} + +Vector EditorExportPreset::get_files_to_export() const { + + Vector files; + for(Set::Element *E=selected_files.front();E;E=E->next()) { + files.push_back(E->get()); + } + return files; +} + +void EditorExportPreset::set_name(const String& p_name) { + name=p_name; + EditorExport::singleton->save_presets(); + +} + +String EditorExportPreset::get_name() const { + return name; + +} + +void EditorExportPreset::set_runnable(bool p_enable) { + + runnable=p_enable; + EditorExport::singleton->save_presets(); +} + +bool EditorExportPreset::is_runnable() const { + + return runnable; +} + +void EditorExportPreset::set_export_filter(ExportFilter p_filter) { + + export_filter=p_filter; + EditorExport::singleton->save_presets(); + +} + +EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const { + return export_filter; +} + +void EditorExportPreset::set_include_filter(const String& p_include) { + + include_filter=p_include; + EditorExport::singleton->save_presets(); + +} + +String EditorExportPreset::get_include_filter() const { + + return include_filter; +} + +void EditorExportPreset::set_exclude_filter(const String& p_exclude) { + + exclude_filter=p_exclude; + EditorExport::singleton->save_presets(); +} + +String EditorExportPreset::get_exclude_filter() const { + + return exclude_filter; +} + +void EditorExportPreset::add_export_file(const String& p_path) { + + selected_files.insert(p_path); + EditorExport::singleton->save_presets(); +} + +void EditorExportPreset::remove_export_file(const String& p_path) { + selected_files.erase(p_path); + EditorExport::singleton->save_presets(); +} + +bool EditorExportPreset::has_export_file(const String& p_path) { + + return selected_files.has(p_path); +} + +void EditorExportPreset::add_patch(const String& p_path,int p_at_pos) { + + if (p_at_pos<0) + patches.push_back(p_path); + else + patches.insert(p_at_pos,p_path); + EditorExport::singleton->save_presets(); +} + +void EditorExportPreset::remove_patch(int p_idx) { + patches.remove(p_idx); + EditorExport::singleton->save_presets(); +} + +void EditorExportPreset::set_patch(int p_index,const String& p_path) { + ERR_FAIL_INDEX(p_index,patches.size()); + patches[p_index]=p_path; + EditorExport::singleton->save_presets(); +} +String EditorExportPreset::get_patch(int p_index) { + + ERR_FAIL_INDEX_V(p_index,patches.size(),String()); + return patches[p_index]; +} + +Vector EditorExportPreset::get_patches() const { + return patches; +} + +EditorExportPreset::EditorExportPreset() { + + export_filter=EXPORT_ALL_RESOURCES; + runnable=false; +} + + +/////////////////////////////////// + +void EditorExportPlatform::gen_debug_flags(Vector &r_flags, int p_flags) { + + String host = EditorSettings::get_singleton()->get("network/debug_host"); + + if (p_flags&DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) + host="localhost"; + + if (p_flags&DEBUG_FLAG_DUMB_CLIENT) { + int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); + String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password"); + r_flags.push_back("-rfs"); + r_flags.push_back(host+":"+itos(port)); + if (passwd!="") { + r_flags.push_back("-rfs_pass"); + r_flags.push_back(passwd); + } + } + + if (p_flags&DEBUG_FLAG_REMOTE_DEBUG) { + + r_flags.push_back("-rdebug"); + + r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + + List breakpoints; + ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); + + + if (breakpoints.size()) { + + r_flags.push_back("-bp"); + String bpoints; + for(const List::Element *E=breakpoints.front();E;E=E->next()) { + + bpoints+=E->get().replace(" ","%20"); + if (E->next()) + bpoints+=","; + } + + r_flags.push_back(bpoints); + } + + } + + if (p_flags&DEBUG_FLAG_VIEW_COLLISONS) { + + r_flags.push_back("-debugcol"); + } + + if (p_flags&DEBUG_FLAG_VIEW_NAVIGATION) { + + r_flags.push_back("-debugnav"); + } +} + +Error EditorExportPlatform::_save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { + + return OK; +} + +Error EditorExportPlatform::_save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { + + + String path=p_path.replace_first("res://",""); + + ZipData *zd = (ZipData*)p_userdata; + + zipFile zip=(zipFile)zd->zip; + + zipOpenNewFileInZip(zip, + path.utf8().get_data(), + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + zipWriteInFileInZip(zip,p_data.ptr(),p_data.size()); + zipCloseFileInZip(zip); + + zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); + zd->count++; + return OK; +} + +String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { + + String user_file = EditorSettings::get_singleton()->get_settings_path() + +"/templates/"+template_file_name; + String system_file=OS::get_singleton()->get_installed_templates_path(); + bool has_system_path=(system_file!=""); + system_file+=template_file_name; + + // Prefer user file + if (FileAccess::exists(user_file)) { + return user_file; + } + + // Now check system file + if (has_system_path) { + if (FileAccess::exists(system_file)) { + return system_file; + } + } + + // Not found + if (err) { + *err+="No export template found at \""+user_file+"\""; + if (has_system_path) + *err+="\n or \""+system_file+"\"."; + else + *err+="."; + } + return ""; +} + +Ref EditorExportPlatform::create_preset() { + + Ref preset; + preset.instance(); + preset->platform=Ref(this); + + List options; + get_export_options(&options); + + for (List::Element *E=options.front();E;E=E->next()) { + + preset->properties.push_back(E->get().option); + preset->values[E->get().option.name]=E->get().default_value; + } + + return preset; + +} + +Error EditorExportPlatform::export_project_files(const Ref& p_preset,EditorExportSaveFunction p_func, void* p_udata) { + + return OK; +} + +Error EditorExportPlatform::save_pack(const Ref& p_preset,FileAccess *p_where) { + + return OK; +} + +Error EditorExportPlatform::save_zip(const Ref& p_preset,const String& p_path) { + + return OK; +} + +EditorExportPlatform::EditorExportPlatform() { + + +} + + +//// + +EditorExport *EditorExport::singleton=NULL; + + +void EditorExport::_save() { + + + Ref config; + config.instance(); + for(int i=0;i preset = export_presets[i]; + String section="preset."+itos(i); + + config->set_value(section,"name",preset->get_name()); + config->set_value(section,"platform",preset->get_platform()->get_name()); + config->set_value(section,"runnable",preset->is_runnable()); + bool save_files=false; + switch(preset->get_export_filter()) { + case EditorExportPreset::EXPORT_ALL_RESOURCES: { + config->set_value(section,"export_filter","all_resources"); + } break; + case EditorExportPreset::EXPORT_SELECTED_SCENES: { + config->set_value(section,"export_filter","scenes"); + save_files=true; + } break; + case EditorExportPreset::EXPORT_SELECTED_RESOURCES: { + config->set_value(section,"export_filter","resources"); + save_files=true; + } break; + case EditorExportPreset::EXPORT_ALL_FILES: { + config->set_value(section,"export_filter","all_files"); + } break; + + } + + if (save_files) { + Vector export_files = preset->get_files_to_export(); + config->set_value(section,"export_files",export_files); + } + config->set_value(section,"include_filter",preset->get_include_filter()); + config->set_value(section,"exclude_filter",preset->get_exclude_filter()); + config->set_value(section,"patch_list",preset->get_patches()); + + String option_section="preset."+itos(i)+".options"; + + for (const List::Element *E=preset->get_properties().front();E;E=E->next()) { + config->set_value(option_section,E->get().name,preset->get(E->get().name)); + } + } + + config->save("res://export_presets.cfg"); + + print_line("saved ok"); + +} + + +void EditorExport::save_presets() { + + print_line("save presets"); + if (block_save) + return; + save_timer->start(); +} + +void EditorExport::_bind_methods() { + + ClassDB::bind_method("_save",&EditorExport::_save); +} + +void EditorExport::add_export_platform(const Ref& p_platform) { + + export_platforms.push_back(p_platform); +} + +int EditorExport::get_export_platform_count() { + + return export_platforms.size(); +} + +Ref EditorExport::get_export_platform(int p_idx) { + + ERR_FAIL_INDEX_V(p_idx,export_platforms.size(),Ref()); + + return export_platforms[p_idx]; +} + + +void EditorExport::add_export_preset(const Ref& p_preset,int p_at_pos) { + + if (p_at_pos<0) + export_presets.push_back(p_preset); + else + export_presets.insert(p_at_pos,p_preset); + + +} + +int EditorExport::get_export_preset_count() const { + + return export_presets.size(); +} + +Ref EditorExport::get_export_preset(int p_idx) { + + ERR_FAIL_INDEX_V( p_idx, export_presets.size(),Ref() ); + return export_presets[p_idx]; +} + +void EditorExport::remove_export_preset(int p_idx) { + + export_presets.remove(p_idx); +} + +void EditorExport::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + load_config(); + } +} + +void EditorExport::load_config() { + + Ref config; + config.instance(); + Error err = config->load("res://export_presets.cfg"); + if (err!=OK) + return; + + block_save=true; + + int index=0; + while(true) { + + String section = "preset."+itos(index); + if (!config->has_section(section)) + break; + + String platform=config->get_value(section,"platform"); + + Ref preset; + + for(int i=0;iget_name()==platform) { + preset = export_platforms[i]->create_preset(); + break; + } + } + + if (!preset.is_valid()) { + index++; + ERR_CONTINUE(!preset.is_valid()); + } + + preset->set_name( config->get_value(section,"name") ); + preset->set_runnable( config->get_value(section,"runnable") ); + + String export_filter = config->get_value(section,"export_filter"); + + bool get_files=false; + + if (export_filter=="all_resources") { + preset->set_export_filter(EditorExportPreset::EXPORT_ALL_RESOURCES); + } else if (export_filter=="scenes") { + preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_SCENES); + get_files=true; + } else if (export_filter=="resources") { + preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_RESOURCES); + get_files=true; + } else if (export_filter=="all_files") { + preset->set_export_filter(EditorExportPreset::EXPORT_ALL_FILES); + } + + if (get_files) { + + Vector files = config->get_value(section,"export_files"); + + for(int i=0;iadd_export_file(files[i]); + } + } + + preset->set_include_filter( config->get_value(section,"include_filter") ); + preset->set_exclude_filter( config->get_value(section,"exclude_filter") ); + + + Vector patch_list = config->get_value(section,"patch_list"); + + for(int i=0;iadd_patch(patch_list[i]); + } + + String option_section="preset."+itos(index)+".options"; + + List options; + + config->get_section_keys(option_section,&options); + + for (List::Element *E=options.front();E;E=E->next()) { + + Variant value = config->get_value(option_section,E->get()); + + preset->set(E->get(),value); + } + + add_export_preset(preset); + index++; + } + + block_save=false; + +} + + + +EditorExport::EditorExport() { + + save_timer = memnew( Timer ); + add_child(save_timer); + save_timer->set_wait_time(0.8); + save_timer->set_one_shot(true); + save_timer->connect("timeout",this,"_save"); + block_save=false; + + singleton=this; +} + +EditorExport::~EditorExport() { + + +} + + +////////// + +void EditorExportPlatformPC::get_preset_features(const Ref& p_preset,List* r_features) { + + if (p_preset->get("texture_format/s3tc")) { + r_features->push_back("s3tc"); + } + if (p_preset->get("texture_format/etc")) { + r_features->push_back("etc"); + } + if (p_preset->get("texture_format/etc2")) { + r_features->push_back("etc2"); + } +} + +void EditorExportPlatformPC::get_export_options(List *r_options) { + + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/s3tc"),true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/etc"),false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"texture_format/etc2"),false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL,"binary_format/64_bits"),true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING,"custom_template/release",PROPERTY_HINT_GLOBAL_FILE),"")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING,"custom_template/debug",PROPERTY_HINT_GLOBAL_FILE),"")); +} + +String EditorExportPlatformPC::get_name() const { + + return name; +} +Ref EditorExportPlatformPC::get_logo() const { + + return logo; +} + +bool EditorExportPlatformPC::can_export(String *r_error) const { + return true; +} + +String EditorExportPlatformPC::get_binary_extension() const { + return extension; +} + +Error EditorExportPlatformPC::export_project(const Ref& p_preset,const String& p_path,int p_flags) { + + return OK; +} + +void EditorExportPlatformPC::set_extension(const String& p_extension) { + extension=p_extension; +} + +void EditorExportPlatformPC::set_name(const String& p_name) { + name=p_name; +} + +void EditorExportPlatformPC::set_logo(const Ref& p_logo) { + logo=p_logo; +} + +EditorExportPlatformPC::EditorExportPlatformPC() { + +} + +//////// + +#if 0 +#include "version.h" +#include "script_language.h" +#include "globals.h" +#include "os/file_access.h" +#include "os/dir_access.h" +#include "tools/editor/editor_file_system.h" +#include "io/resource_loader.h" +#include "editor_node.h" +#include "editor_settings.h" +#include "io/config_file.h" +#include "io/resource_saver.h" +#include "io/md5.h" +#include "io_plugins/editor_texture_import_plugin.h" +#include "tools/editor/plugins/script_editor_plugin.h" +#include "io/zip_io.h" + + +String EditorImportPlugin::validate_source_path(const String& p_path) { + + String gp = GlobalConfig::get_singleton()->globalize_path(p_path); + String rp = GlobalConfig::get_singleton()->get_resource_path(); + if (!rp.ends_with("/")) + rp+="/"; + + return rp.path_to_file(gp); +} + +String EditorImportPlugin::expand_source_path(const String& p_path) { + + if (p_path.is_rel_path()) { + return GlobalConfig::get_singleton()->get_resource_path().plus_file(p_path).simplify_path(); + } else { + return p_path; + } +} + + +String EditorImportPlugin::_validate_source_path(const String& p_path) { + + return validate_source_path(p_path); +} + +String EditorImportPlugin::_expand_source_path(const String& p_path) { + + return expand_source_path(p_path); +} + +void EditorImportPlugin::_bind_methods() { + + + ClassDB::bind_method(D_METHOD("validate_source_path","path"),&EditorImportPlugin::_validate_source_path); + ClassDB::bind_method(D_METHOD("expand_source_path","path"),&EditorImportPlugin::_expand_source_path); + + ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_name")); + ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_visible_name")); + ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_dialog",PropertyInfo(Variant::STRING,"from"))); + ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::INT,"import",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"from",PROPERTY_HINT_RESOURCE_TYPE,"ResourceImportMetadata"))); + ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::POOL_BYTE_ARRAY,"custom_export",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform"))); + ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_from_drop",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::STRING,"dest_path"))); + ClassDB::add_virtual_method(get_class_static(),MethodInfo("reimport_multiple_files",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"))); + ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::BOOL,"can_reimport_multiple_files")); + + //BIND_VMETHOD( mi ); +} + +String EditorImportPlugin::get_name() const { + + if (get_script_instance() && get_script_instance()->has_method("get_name")) { + return get_script_instance()->call("get_name"); + } + + ERR_FAIL_V(""); +} + +String EditorImportPlugin::get_visible_name() const { + + if (get_script_instance() && get_script_instance()->has_method("get_visible_name")) { + return get_script_instance()->call("get_visible_name"); + } + + ERR_FAIL_V(""); +} + + +void EditorImportPlugin::import_dialog(const String& p_from) { + + if (get_script_instance() && get_script_instance()->has_method("import_dialog")) { + get_script_instance()->call("import_dialog",p_from); + return; + } + + ERR_FAIL(); + +} + +Error EditorImportPlugin::import(const String& p_path, const Ref& p_from) { + + if (get_script_instance() && get_script_instance()->has_method("import")) { + return Error(get_script_instance()->call("import",p_path,p_from).operator int()); + } + + ERR_FAIL_V(ERR_UNAVAILABLE); +} + +Vector EditorImportPlugin::custom_export(const String& p_path, const Ref &p_platform) { + + if (get_script_instance() && get_script_instance()->has_method("custom_export")) { + get_script_instance()->call("custom_export",p_path,p_platform); + } + + return Vector(); +} + +bool EditorImportPlugin::can_reimport_multiple_files() const { + + if (get_script_instance() && get_script_instance()->has_method("can_reimport_multiple_files")) { + return get_script_instance()->call("can_reimport_multiple_files"); + } + + return false; +} +void EditorImportPlugin::reimport_multiple_files(const Vector& p_list) { + + if (get_script_instance() && get_script_instance()->has_method("reimport_multiple_files")) { + get_script_instance()->call("reimport_multiple_files",p_list); + } + +} + +void EditorImportPlugin::import_from_drop(const Vector& p_drop, const String &p_dest_path) { + + if (get_script_instance() && get_script_instance()->has_method("import_from_drop")) { + get_script_instance()->call("import_from_drop",p_drop,p_dest_path); + } + +} + +EditorImportPlugin::EditorImportPlugin() { + + +} + +///////////////////////////////////////////////////////////////////////////////////////////////////// + + +void EditorExportPlugin::_bind_methods() { + + MethodInfo mi = MethodInfo("custom_export:Variant",PropertyInfo(Variant::STRING,"name"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform")); + mi.return_val.type=Variant::POOL_BYTE_ARRAY; + + BIND_VMETHOD( mi ); +} + + +Vector EditorExportPlugin::custom_export(String& p_path,const Ref &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(); + if (d.get_type()==Variant::POOL_BYTE_ARRAY) + return d; + + ERR_FAIL_COND_V(d.get_type()!=Variant::DICTIONARY,Vector()); + Dictionary dict=d; + ERR_FAIL_COND_V(!dict.has("name"),Vector()); + ERR_FAIL_COND_V(!dict.has("data"),Vector()); + p_path=dict["name"]; + return dict["data"]; + } + + return Vector(); + +} + + +EditorExportPlugin::EditorExportPlugin() { + + +} + +///////////////////////////////////////////////////////////////////////////////////////////////////// + + + +static void _add_to_list(EditorFileSystemDirectory *p_efsd,Set& r_list) { + + for(int i=0;iget_subdir_count();i++) { + + _add_to_list(p_efsd->get_subdir(i),r_list); + } + + for(int i=0;iget_file_count();i++) { + r_list.insert(p_efsd->get_file_path(i)); + } +} + + +struct __EESortDepCmp { + + _FORCE_INLINE_ bool operator()(const StringName& p_l,const StringName& p_r) const { + return p_l.operator String() < p_r.operator String(); + } +}; + + + + +static void _edit_files_with_filter(DirAccess *da,const List& p_filters,Set& r_list,bool exclude) { + + + List files; + List dirs; + + da->list_dir_begin(); + + String f = da->get_next(); + while(f!="") { + + print_line("HOHO: "+f); + if (da->current_is_dir()) + dirs.push_back(f); + else + files.push_back(f); + + f=da->get_next(); + } + + String r = da->get_current_dir().replace("\\","/"); + if (!r.ends_with("/")) + r+="/"; + + print_line("AT: "+r); + + for(List::Element *E=files.front();E;E=E->next()) { + String fullpath=r+E->get(); + for(const List::Element *F=p_filters.front();F;F=F->next()) { + + if (fullpath.matchn(F->get())) { + String act = TTR("Added:")+" "; + + if (!exclude) { + r_list.insert(fullpath); + } else { + act = TTR("Removed:")+" "; + r_list.erase(fullpath); + } + + + print_line(act+fullpath); + } + } + } + + da->list_dir_end(); + + for(List::Element *E=dirs.front();E;E=E->next()) { + if (E->get().begins_with(".")) + continue; + da->change_dir(E->get()); + _edit_files_with_filter(da,p_filters,r_list,exclude); + da->change_dir(".."); + } + +} + +static void _edit_filter_list(Set& r_list,const String& p_filter,bool exclude) { + + if (p_filter=="") + return; + Vector split = p_filter.split(","); + List filters; + for(int i=0;i& r_list,const String& p_filter) { + _edit_filter_list(r_list,p_filter,false); +} + +static void _remove_filter_from_list(Set& r_list,const String& p_filter) { + _edit_filter_list(r_list,p_filter,true); +} + +bool EditorExportPlatform::_set(const StringName& p_name, const Variant& p_value) { + + String n = p_name; + + if (n=="debug/debugging_enabled") { + set_debugging_enabled(p_value); + } else { + return false; + } + + return true; + +} + +bool EditorExportPlatform::_get(const StringName& p_name,Variant &r_ret) const { + + String n = p_name; + + if (n=="debug/debugging_enabled") { + r_ret=is_debugging_enabled(); + } else { + return false; + } + + return true; + +} + +void EditorExportPlatform::_get_property_list( List *p_list) const { + + p_list->push_front( PropertyInfo( Variant::BOOL, "debug/debugging_enabled")); +} + +Vector EditorExportPlatform::get_exported_file_default(String& p_fname) const { + + FileAccess *f = FileAccess::open(p_fname,FileAccess::READ); + ERR_FAIL_COND_V(!f,Vector()); + Vector ret; + ret.resize(f->get_len()); + int rbs = f->get_buffer(ret.ptr(),ret.size()); + memdelete(f); + return ret; +} + +Vector EditorExportPlatform::get_exported_file(String& p_fname) const { + + Ref ep=EditorImportExport::get_singleton()->get_export_platform(get_name()); + + for(int i=0;iget_export_plugin_count();i++) { + + Vector data = EditorImportExport::get_singleton()->get_export_plugin(i)->custom_export(p_fname,ep); + if (data.size()) + return data; + + } + + + return get_exported_file_default(p_fname); + + +} + +Vector EditorExportPlatform::get_dependencies(bool p_bundles) const { + + + Set exported; + + if (FileAccess::exists("res://godot.cfg")) + exported.insert("res://godot.cfg"); + + if (EditorImportExport::get_singleton()->get_export_filter()!=EditorImportExport::EXPORT_SELECTED) { + + String filter; + if (EditorImportExport::get_singleton()->get_export_filter()==EditorImportExport::EXPORT_ALL) { + _add_filter_to_list(exported,"*"); + } else { + _add_to_list(EditorFileSystem::get_singleton()->get_filesystem(),exported); + String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); + if (cf!="") + cf+=","; + cf+="*.flags"; + _add_filter_to_list(exported,cf); + + cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude(); + _remove_filter_from_list(exported,cf); + } + + + } else { + + + Map > remapped_paths; + + Set scene_extensions; + Set resource_extensions; + + { + + List l; + /* + SceneLoader::get_recognized_extensions(&l); + for(List::Element *E=l.front();E;E=E->next()) { + scene_extensions.insert(E->get()); + } + */ + ResourceLoader::get_recognized_extensions_for_type("",&l); + for(List::Element *E=l.front();E;E=E->next()) { + + resource_extensions.insert(E->get()); + } + } + + + List toexport; + + EditorImportExport::get_singleton()->get_export_file_list(&toexport); + + print_line("TO EXPORT: "+itos(toexport.size())); + + + for (List::Element *E=toexport.front();E;E=E->next()) { + + print_line("DEP: "+String(E->get())); + exported.insert(E->get()); + if (p_bundles && EditorImportExport::get_singleton()->get_export_file_action(E->get())==EditorImportExport::ACTION_BUNDLE) { + print_line("NO BECAUSE OF BUNDLE!"); + continue; //no dependencies needed to be copied + } + + List testsubs; + testsubs.push_back(E->get()); + + while(testsubs.size()) { + //recursive subdep search! + List deplist; + ResourceLoader::get_dependencies(testsubs.front()->get(),&deplist); + testsubs.pop_front(); + + List subdeps; + + for (List::Element *F=deplist.front();F;F=F->next()) { + + StringName dep = F->get(); + + if (exported.has(dep) || EditorImportExport::get_singleton()->get_export_file_action(dep)!=EditorImportExport::ACTION_NONE) + continue; //dependency added or to be added + print_line(" SUBDEP: "+String(dep)); + + exported.insert(dep); + testsubs.push_back(dep); + } + } + } + String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); + if (cf!="") + cf+=","; + cf+="*.flags"; + _add_filter_to_list(exported,cf); + + cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude(); + _remove_filter_from_list(exported,cf); + + + } + + Vector ret; + ret.resize(exported.size()); + + + int idx=0; + for(Set::Element *E=exported.front();E;E=E->next()) { + + ret[idx++]=E->get(); + + } + + SortArray sort; //some platforms work better if this is sorted + sort.sort(ret.ptr(),ret.size()); + + return ret; + +} + +String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { + String user_file = EditorSettings::get_singleton()->get_settings_path() + +"/templates/"+template_file_name; + String system_file=OS::get_singleton()->get_installed_templates_path(); + bool has_system_path=(system_file!=""); + system_file+=template_file_name; + + // Prefer user file + if (FileAccess::exists(user_file)) { + return user_file; + } + + // Now check system file + if (has_system_path) { + if (FileAccess::exists(system_file)) { + return system_file; + } + } + + // Not found + if (err) { + *err+="No export template found at \""+user_file+"\""; + if (has_system_path) + *err+="\n or \""+system_file+"\"."; + else + *err+="."; + } + return ""; +} + +bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const { + return find_export_template(template_file_name,err)!=""; +} + +/////////////////////////////////////// + + + +bool EditorExportPlatform::is_debugging_enabled() const { + + return debugging_enabled; +} + +void EditorExportPlatform::set_debugging_enabled(bool p_enabled) { + + debugging_enabled = p_enabled; +} + +bool EditorExportPlatformPC::_set(const StringName& p_name, const Variant& p_value) { + + String n = p_name; + + if (n=="custom_binary/release") { + + custom_release_binary=p_value; + } else if (n=="custom_binary/debug") { + + custom_debug_binary=p_value; + } else if (n=="resources/pack_mode") { + + export_mode=ExportMode(int(p_value)); + } else if (n=="resources/bundle_dependencies_(for_optical_disc)") { + + bundle=p_value; + } else if (n=="binary/64_bits") { + + use64=p_value; + } else + return false; + + return true; + +} + +bool EditorExportPlatformPC::_get(const StringName& p_name,Variant &r_ret) const { + + String n = p_name; + + if (n=="custom_binary/release") { + + r_ret=custom_release_binary; + } else if (n=="custom_binary/debug") { + + r_ret=custom_debug_binary; + } else if (n=="resources/pack_mode") { + + r_ret=export_mode; + } else if (n=="resources/bundle_dependencies_(for_optical_disc)") { + + r_ret=bundle; + } else if (n=="binary/64_bits") { + + r_ret=use64; + } else + return false; + + return true; + +} + +void EditorExportPlatformPC::_get_property_list( List *p_list) const { + + p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/debug", PROPERTY_HINT_GLOBAL_FILE,binary_extension)); + p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/release", PROPERTY_HINT_GLOBAL_FILE,binary_extension)); + p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Pack into executable,Pack into binary file (.pck),Pack into archive file (.zip)")); + p_list->push_back( PropertyInfo( Variant::BOOL, "resources/bundle_dependencies_(for_optical_disc)")); + p_list->push_back( PropertyInfo( Variant::BOOL, "binary/64_bits")); +} + + + +static void _exp_add_dep(Map > &deps,const StringName& p_path) { + + + if (deps.has(p_path)) + return; //already done + + deps.insert(p_path,List()); + + List &deplist=deps[p_path]; + Set depset; + + List dl; + ResourceLoader::get_dependencies(p_path,&dl); + + //added in order so child dependencies are always added bfore parent dependencies + for (List::Element *E=dl.front();E;E=E->next()) { + + + if (!deps.has(E->get())) + _exp_add_dep(deps,E->get()); + + for(List::Element *F=deps[E->get()].front();F;F=F->next()) { + + + if (!depset.has(F->get())) { + depset.insert(F->get()); + deplist.push_back(F->get()); + } + } + + if (!depset.has(E->get())) { + depset.insert(E->get()); + deplist.push_back(E->get()); + } + + } +} + + + +Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles) { + +/* ALL FILES AND DEPENDENCIES */ + + Vector files=get_dependencies(p_make_bundles); + + Map > deps; + + if (false) { + for(int i=0;i groups; + + EditorImportExport::get_singleton()->image_export_get_groups(&groups); + + Map remap_files; + Set saved; + + int counter=0; + + for(List::Element *E=groups.front();E;E=E->next()) { + + if (!EditorImportExport::get_singleton()->image_export_group_get_make_atlas(E->get())) + continue; //uninterested, only process for atlas! + + List atlas_images; + EditorImportExport::get_singleton()->image_export_get_images_in_group(E->get(),&atlas_images); + atlas_images.sort_custom(); + + for (List::Element *F=atlas_images.front();F;) { + + List::Element *N=F->next(); + + if (!FileAccess::exists(F->get())) { + atlas_images.erase(F); + } + + F=N; + + } + + if (atlas_images.size()<=1) + continue; + + int group_format=0; + float group_lossy_quality=EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(E->get()); + int group_shrink=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get()); + group_shrink*=EditorImportExport::get_singleton()->get_export_image_shrink(); + + switch(EditorImportExport::get_singleton()->image_export_group_get_image_action(E->get())) { + case EditorImportExport::IMAGE_ACTION_KEEP: + case EditorImportExport::IMAGE_ACTION_NONE: { + + switch(EditorImportExport::get_singleton()->get_export_image_action()) { + case EditorImportExport::IMAGE_ACTION_NONE: { + + group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS; //? + + } break; //use default + case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: { + group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY; + } break; //use default + case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: { + group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM; + } break; //use default + } + + group_lossy_quality=EditorImportExport::get_singleton()->get_export_image_quality(); + + } break; //use default + case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: { + group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY; + } break; //use default + case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: { + group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM; + } break; //use default + } + + String image_listD_METHOD5; + + { + MD5_CTX ctx; + MD5Init(&ctx); + for (List::Element *F=atlas_images.front();F;F=F->next()) { + + String p = F->get(); + MD5Update(&ctx,(unsigned char*)p.utf8().get_data(),p.utf8().length()); + + } + + MD5Final(&ctx); + image_listD_METHOD5=String::md5(ctx.digest); + } + //ok see if cached + String md5; + bool atlas_valid=true; + String atlas_name; + + { + MD5_CTX ctx; + MD5Init(&ctx); + String path = GlobalConfig::get_singleton()->get_resource_path()+"::"+String(E->get())+"::"+get_name(); + MD5Update(&ctx,(unsigned char*)path.utf8().get_data(),path.utf8().length()); + MD5Final(&ctx); + md5 = String::md5(ctx.digest); + } + + FileAccess *f=NULL; + + if (!FileAccess::exists(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5)) { + print_line("NO MD5 INVALID"); + atlas_valid=false; + } + + if (atlas_valid) + f=FileAccess::open(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5,FileAccess::READ); + + if (atlas_valid) { + //compare options + /*Dictionary options; + options.parse_json(f->get_line()); + if (!options.has("lossy_quality") || float(options["lossy_quality"])!=group_lossy_quality) + atlas_valid=false; + else if (!options.has("shrink") || int(options["shrink"])!=group_shrink) + atlas_valid=false; + else if (!options.has("image_format") || int(options["image_format"])!=group_format) + atlas_valid=false; + + if (!atlas_valid) + print_line("JSON INVALID"); +*/ + } + + + if (atlas_valid) { + //check md5 of list of image /names/ + if (f->get_line().strip_edges()!=image_listD_METHOD5) { + atlas_valid=false; + print_line("IMAGE MD5 INVALID!"); + } + + } + + Vector rects; + bool resave_deps=false; + + if (atlas_valid) { + + //check if images were not modified + for (List::Element *F=atlas_images.front();F;F=F->next()) { + + Vector slices = f->get_line().strip_edges().split("::"); + + if (slices.size()!=10) { + atlas_valid=false; + print_line("CANT SLICE IN 10"); + break; + } + uint64_t mod_time = slices[0].to_int64(); + uint64_t file_mod_time = FileAccess::get_modified_time(F->get()); + if (mod_time!=file_mod_time) { + + String imageD_METHOD5 = slices[1]; + String fileD_METHOD5 = FileAccess::getD_METHOD5(F->get()); + + if (imageD_METHOD5!=fileD_METHOD5) { + atlas_valid=false; + print_line("IMAGE INVALID "+slices[0]); + break; + } else { + resave_deps=true; + } + } + + if (atlas_valid) { + //push back region and margin + rects.push_back(Rect2(slices[2].to_float(),slices[3].to_float(),slices[4].to_float(),slices[5].to_float())); + rects.push_back(Rect2(slices[6].to_float(),slices[7].to_float(),slices[8].to_float(),slices[9].to_float())); + } + } + + } + + if (f) { + memdelete(f); + f=NULL; + } + + print_line("ATLAS VALID? "+itos(atlas_valid)+" RESAVE DEPS? "+itos(resave_deps)); + if (!atlas_valid) { + rects.clear(); + //oh well, atlas is not valid. need to make new one.... + + String dst_file = EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex"; + Ref imd = memnew( ResourceImportMetadata ); + //imd->set_editor(); + + + for (List::Element *F=atlas_images.front();F;F=F->next()) { + + imd->add_source(EditorImportPlugin::validate_source_path(F->get()),FileAccess::getD_METHOD5(F->get())); + + } + + + imd->set_option("format",group_format); + + + int flags=0; + + if (GlobalConfig::get_singleton()->get("image_loader/filter")) + flags|=EditorTextureImportPlugin::IMAGE_FLAG_FILTER; + if (!GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps")) + flags|=EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS; + if (!GlobalConfig::get_singleton()->get("image_loader/repeat")) + flags|=EditorTextureImportPlugin::IMAGE_FLAG_REPEAT; + + flags|=EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA; + + imd->set_option("flags",flags); + imd->set_option("quality",group_lossy_quality); + imd->set_option("atlas",true); + imd->set_option("crop",true); + imd->set_option("shrink",group_shrink); + + + + Ref plugin = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture"); + Error err = plugin->import2(dst_file,imd,get_image_compression(),true); + if (err) { + + EditorNode::add_io_error(TTR("Error saving atlas:")+" "+dst_file.get_file()); + return ERR_CANT_CREATE; + } + + ERR_FAIL_COND_V(imd->get_option("rects")==Variant(),ERR_BUG); + + Array r_rects=imd->get_option("rects"); + rects.resize(r_rects.size()); + for(int i=0;iget_settings_path()+"/tmp/atlas-"+md5,FileAccess::WRITE); + Dictionary options; + options["lossy_quality"]=group_lossy_quality; + options["shrink"]=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get()); + options["image_format"]=group_format; + //f->store_line(options.to_json()); + f->store_line(image_listD_METHOD5); + } + + //go through all ATEX files + + { + Ref atlas = memnew( ImageTexture ); //fake atlas! + String atlas_path="res://atlas-"+md5+".tex"; + atlas->set_path(atlas_path); + int idx=0; + for (List::Element *F=atlas_images.front();F;F=F->next()) { + + String p = F->get(); + Ref atex = memnew(AtlasTexture); + atex->set_atlas(atlas); + Rect2 region=rects[idx++]; + Rect2 margin=rects[idx++]; + atex->set_region(region); + atex->set_margin(margin); + + String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpatlas.atex"; + Error err = ResourceSaver::save(path,atex); + if (err!=OK) { + EditorNode::add_io_error(TTR("Could not save atlas subtexture:")+" "+path); + return ERR_CANT_CREATE; + } + Vector data = FileAccess::get_file_as_array(path); + String dst_path = F->get().operator String().get_basename()+".atex"; + err = p_func(p_udata,dst_path,data,counter++,files.size()); + saved.insert(dst_path); + if (err) + return err; + + if (f) { + //recreating deps.. + String depline; + //depline=String(F->get())+"::"+itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::getD_METHOD5(F->get()); name unneccesary by top md5 + depline=itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::getD_METHOD5(F->get()); + depline+="::"+itos(region.pos.x)+"::"+itos(region.pos.y)+"::"+itos(region.size.x)+"::"+itos(region.size.y); + depline+="::"+itos(margin.pos.x)+"::"+itos(margin.pos.y)+"::"+itos(margin.size.x)+"::"+itos(margin.size.y); + f->store_line(depline); + } + + remap_files[F->get()]=dst_path; + } + + Vector atlas_data = FileAccess::get_file_as_array(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex"); + Error err = p_func(p_udata,atlas_path,atlas_data,counter,files.size()); + saved.insert(atlas_path); + if (err) + return err; + + } + + + if (f) { + memdelete(f); + } + + } + + + StringName engine_cfg="res://godot.cfg"; + StringName boot_splash; + { + String splash=GlobalConfig::get_singleton()->get("application/boot_splash"); //avoid splash from being converted + splash=splash.strip_edges(); + if (splash!=String()) { + if (!splash.begins_with("res://")) + splash="res://"+splash; + splash=splash.simplify_path(); + boot_splash=splash; + } + } + StringName custom_cursor; + { + String splash=GlobalConfig::get_singleton()->get("display/custom_mouse_cursor"); //avoid splash from being converted + splash=splash.strip_edges(); + if (splash!=String()) { + if (!splash.begins_with("res://")) + splash="res://"+splash; + splash=splash.simplify_path(); + custom_cursor=splash; + } + } + + + + + for(int i=0;i buf; + + if (src==boot_splash || src==custom_cursor) + buf = get_exported_file_default(src); //bootsplash must be kept if used + else + buf = get_exported_file(src); + + ERR_CONTINUE( saved.has(src) ); + + Error err = p_func(p_udata,src,buf,counter++,files.size()); + if (err) + return err; + + saved.insert(src); + if (src!=String(files[i])) + remap_files[files[i]]=src; + + } + + + { + + //make binary godot.cfg config + Map custom; + + + if (remap_files.size()) { + Vector remapsprop; + for(Map::Element *E=remap_files.front();E;E=E->next()) { + print_line("REMAP: "+String(E->key())+" -> "+E->get()); + remapsprop.push_back(E->key()); + remapsprop.push_back(E->get()); + } + + custom["remap/all"]=remapsprop; + } + + //add presaved dependencies + for(Map >::Element *E=deps.front();E;E=E->next()) { + + if (E->get().size()==0) + continue; //no deps + String key; + Vector deps; + //if bundle continue (when bundles supported obviously) + + if (remap_files.has(E->key())) { + key=remap_files[E->key()]; + } else { + key=E->key(); + } + + deps.resize(E->get().size()); + int i=0; + + for(List::Element *F=E->get().front();F;F=F->next()) { + deps[i++]=F->get(); + print_line(" -"+String(F->get())); + } + + NodePath prop(deps,true,String()); //seems best to use this for performance + + custom["deps/"+key.md5_text()]=prop; + + } + + String remap_file="godot.cfb"; + String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+remap_file; + GlobalConfig::get_singleton()->save_custom(engine_cfb,custom); + Vector data = FileAccess::get_file_as_array(engine_cfb); + + Error err = p_func(p_udata,"res://"+remap_file,data,counter,files.size()); + if (err) + return err; + + } + + return OK; +} + +static int _get_pad(int p_alignment, int p_n) { + + int rest = p_n % p_alignment; + int pad = 0; + if (rest > 0) { + pad = p_alignment - rest; + }; + + return pad; +}; + +void EditorExportPlatform::gen_export_flags(Vector &r_flags, int p_flags) { + + String host = EditorSettings::get_singleton()->get("network/debug_host"); + + if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST) + host="localhost"; + + if (p_flags&EXPORT_DUMB_CLIENT) { + int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); + String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password"); + r_flags.push_back("-rfs"); + r_flags.push_back(host+":"+itos(port)); + if (passwd!="") { + r_flags.push_back("-rfs_pass"); + r_flags.push_back(passwd); + } + } + + if (p_flags&EXPORT_REMOTE_DEBUG) { + + r_flags.push_back("-rdebug"); + + r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + + List breakpoints; + ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); + + + if (breakpoints.size()) { + + r_flags.push_back("-bp"); + String bpoints; + for(const List::Element *E=breakpoints.front();E;E=E->next()) { + + bpoints+=E->get().replace(" ","%20"); + if (E->next()) + bpoints+=","; + } + + r_flags.push_back(bpoints); + } + + } + + if (p_flags&EXPORT_VIEW_COLLISONS) { + + r_flags.push_back("-debugcol"); + } + + if (p_flags&EXPORT_VIEW_NAVIGATION) { + + r_flags.push_back("-debugnav"); + } + + +} + +Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { + + + PackData *pd = (PackData*)p_userdata; + + CharString cs=p_path.utf8(); + pd->f->store_32(cs.length()); + pd->f->store_buffer((uint8_t*)cs.get_data(),cs.length()); + TempData td; + td.pos=pd->f->get_pos(); + td.ofs=pd->ftmp->get_pos(); + td.size=p_data.size(); + pd->file_ofs.push_back(td); + pd->f->store_64(0); //ofs + pd->f->store_64(0); //size + { + MD5_CTX ctx; + MD5Init(&ctx); + MD5Update(&ctx,(unsigned char*)p_data.ptr(),p_data.size()); + MD5Final(&ctx); + pd->f->store_buffer(ctx.digest,16); + } + pd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); + pd->count++; + pd->ftmp->store_buffer(p_data.ptr(),p_data.size()); + if (pd->alignment > 1) { + + int pad = _get_pad(pd->alignment, pd->ftmp->get_pos()); + for (int i=0; iftmp->store_8(0); + }; + }; + return OK; + +} + +Error EditorExportPlatform::save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { + + + String path=p_path.replace_first("res://",""); + + ZipData *zd = (ZipData*)p_userdata; + + zipFile zip=(zipFile)zd->zip; + + zipOpenNewFileInZip(zip, + path.utf8().get_data(), + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + zipWriteInFileInZip(zip,p_data.ptr(),p_data.size()); + zipCloseFileInZip(zip); + + zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); + zd->count++; + return OK; + +} + +Error EditorExportPlatform::save_zip(const String& p_path, bool p_make_bundles) { + + EditorProgress ep("savezip",TTR("Packing"),102); + + //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); + + FileAccess *src_f; + zlib_filefunc_def io = zipio_create_io_from_file(&src_f); + zipFile zip=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io); + + ZipData zd; + zd.count=0; + zd.ep=&ep; + zd.zip=zip; + + + Error err = export_project_files(save_zip_file,&zd,p_make_bundles); + + zipClose(zip,NULL); + + return err; +} + +Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles, int p_alignment) { + + EditorProgress ep("savepack",TTR("Packing"),102); + + String tmppath = EditorSettings::get_singleton()->get_settings_path()+"/tmp/packtmp"; + FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); + uint64_t ofs_begin = dst->get_pos(); + + dst->store_32(0x43504447); //GDPK + dst->store_32(0); //pack version + dst->store_32(VERSION_MAJOR); + dst->store_32(VERSION_MINOR); + dst->store_32(0); //hmph + for(int i=0;i<16;i++) { + //reserved + dst->store_32(0); + } + + size_t fcountpos = dst->get_pos(); + dst->store_32(0); + + PackData pd; + pd.ep=&ep; + pd.f=dst; + pd.ftmp=tmp; + pd.count=0; + pd.alignment = p_alignment; + Error err = export_project_files(save_pack_file,&pd,p_make_bundles); + memdelete(tmp); + if (err) + return err; + + if (p_alignment > 1) { + int pad = _get_pad(p_alignment, dst->get_pos()); + for (int i=0; istore_8(0); + }; + }; + + size_t ofsplus = dst->get_pos(); + //append file + + tmp = FileAccess::open(tmppath,FileAccess::READ); + + ERR_FAIL_COND_V(!tmp,ERR_CANT_OPEN;) + const int bufsize=16384; + uint8_t buf[bufsize]; + + while(true) { + + int got = tmp->get_buffer(buf,bufsize); + if (got<=0) + break; + dst->store_buffer(buf,got); + } + + memdelete(tmp); + + dst->store_64(dst->get_pos()-ofs_begin); + dst->store_32(0x43504447); //GDPK + + //fix offsets + + dst->seek(fcountpos); + dst->store_32(pd.count); + for(int i=0;iseek(pd.file_ofs[i].pos); + dst->store_64(pd.file_ofs[i].ofs+ofsplus); + dst->store_64(pd.file_ofs[i].size); + } + + return OK; +} + +EditorExportPlatform::EditorExportPlatform() { + + debugging_enabled = true; +} + +Error EditorExportPlatformPC::export_project(const String& p_path, bool p_debug, int p_flags) { + + + + EditorProgress ep("export",vformat(TTR("Exporting for %s"),get_name()),102); + + const int BUFSIZE = 32768; + + + + ep.step(TTR("Setting Up.."),0); + + String exe_path=""; + + if (p_debug) + exe_path=custom_debug_binary; + else + exe_path=custom_release_binary; + + if (exe_path=="") { + String fname; + if (use64) { + if (p_debug) + fname=debug_binary64; + else + fname=release_binary64; + } else { + if (p_debug) + fname=debug_binary32; + else + fname=release_binary32; + } + String err=""; + exe_path=find_export_template(fname,&err); + if (exe_path=="") { + EditorNode::add_io_error(err); + return ERR_FILE_CANT_READ; + } + } + + FileAccess *src_exe=FileAccess::open(exe_path,FileAccess::READ); + if (!src_exe) { + + EditorNode::add_io_error("Couldn't read source executable at:\n "+exe_path); + return ERR_FILE_CANT_READ; + } + + FileAccess *dst=FileAccess::open(p_path,FileAccess::WRITE); + if (!dst) { + + EditorNode::add_io_error("Can't copy executable file to:\n "+p_path); + return ERR_FILE_CANT_WRITE; + } + + uint8_t buff[32768]; + + while(true) { + + int c = src_exe->get_buffer(buff,BUFSIZE); + if (c>0) { + + dst->store_buffer(buff,c); + } else { + break; + } + } + + String dstfile = p_path.replace_first("res://","").replace("\\","/"); + if (export_mode!=EXPORT_EXE) { + + String dstfile_extension=export_mode==EXPORT_ZIP?".zip":".pck"; + if (dstfile.find("/")!=-1) + dstfile=dstfile.get_base_dir()+"/data"+dstfile_extension; + else + dstfile="data"+dstfile_extension; + if (export_mode==EXPORT_PACK) { + + memdelete(dst); + + dst=FileAccess::open(dstfile,FileAccess::WRITE); + if (!dst) { + + EditorNode::add_io_error("Can't write data pack to:\n "+p_path); + return ERR_FILE_CANT_WRITE; + } + } + } + + + + memdelete(src_exe); + + Error err = export_mode==EXPORT_ZIP?save_zip(dstfile,bundle):save_pack(dst,bundle); + memdelete(dst); + return err; +} + +void EditorExportPlatformPC::set_binary_extension(const String& p_extension) { + + binary_extension=p_extension; +} + +bool EditorExportPlatformPC::can_export(String *r_error) const { + + String err; + bool valid=true; + + if (use64 && (!exists_export_template(debug_binary64) || !exists_export_template(release_binary64))) { + valid=false; + err="No 64 bits export templates found.\nDownload and install export templates.\n"; + } + + if (!use64 && (!exists_export_template(debug_binary32) || !exists_export_template(release_binary32))) { + valid=false; + err="No 32 bits export templates found.\nDownload and install export templates.\n"; + } + + if(custom_debug_binary=="" && custom_release_binary=="") { + if (r_error) *r_error=err; + return valid; + } + + bool dvalid = true; + bool rvalid = true; + + if(!FileAccess::exists(custom_debug_binary)) { + dvalid = false; + err = "Custom debug binary not found.\n"; + } + + if(!FileAccess::exists(custom_release_binary)) { + rvalid = false; + err = "Custom release binary not found.\n"; + } + + if (dvalid || rvalid) + valid = true; + else + valid = false; + + if (r_error) + *r_error=err; + return valid; +} + + +EditorExportPlatformPC::EditorExportPlatformPC() { + + export_mode=EXPORT_PACK; + use64=true; +} + + + + + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + + +EditorImportExport* EditorImportExport::singleton=NULL; + +void EditorImportExport::add_import_plugin(const Ref& p_plugin) { + + // Need to make sure the name is unique if we are going to lookup by it + ERR_FAIL_COND(by_idx.has(p_plugin->get_name())); + + by_idx[ p_plugin->get_name() ]=plugins.size(); + plugins.push_back(p_plugin); +} + +void EditorImportExport::remove_import_plugin(const Ref& p_plugin) { + + String plugin_name = p_plugin->get_name(); + + // Keep the indices the same + // Find the index of the target plugin + ERR_FAIL_COND(!by_idx.has(plugin_name)); + int idx = by_idx[plugin_name]; + int last_idx = plugins.size() - 1; + + // Swap the last plugin and the target one + SWAP(plugins[idx], plugins[last_idx]); + + // Update the index of the old last one + by_idx[plugins[idx]->get_name()] = idx; + + // Remove the target plugin's by_idx entry + by_idx.erase(plugin_name); + + // Erase the plugin + plugins.remove(last_idx); +} + +int EditorImportExport::get_import_plugin_count() const{ + + return plugins.size(); +} +Ref EditorImportExport::get_import_plugin(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,plugins.size(),Ref()); + return plugins[p_idx]; + +} + + + +Ref EditorImportExport::get_import_plugin_by_name(const String& p_string) const{ + + ERR_FAIL_COND_V( !by_idx.has(p_string), Ref()); + return plugins[ by_idx[p_string] ]; +} + +void EditorImportExport::add_export_plugin(const Ref& p_plugin) { + + ERR_FAIL_COND( p_plugin.is_null() ); + + export_plugins.push_back(p_plugin); +} + +void EditorImportExport::remove_export_plugin(const Ref& p_plugin) { + + ERR_FAIL_COND( p_plugin.is_null() ); + export_plugins.erase(p_plugin); +} + +int EditorImportExport::get_export_plugin_count() const{ + + return export_plugins.size(); +} +Ref EditorImportExport::get_export_plugin(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,export_plugins.size(),Ref()); + return export_plugins[p_idx]; +} + +void EditorImportExport::set_export_file_action(const StringName& p_file, FileAction p_action) { + + if (p_action==ACTION_NONE) { + + files.erase(p_file); + } else { + + files[p_file]=p_action; + } + +} + +EditorImportExport::FileAction EditorImportExport::get_export_file_action(const StringName& p_file) const{ + + + if (files.has(p_file)) + return files[p_file]; + + + return ACTION_NONE; +} + +void EditorImportExport::get_export_file_list(List *p_files){ + + + for (Map::Element *E=files.front();E;E=E->next()) { + + p_files->push_back(E->key()); + } + +} + +void EditorImportExport::add_export_platform(const Ref& p_export) { + + exporters[p_export->get_name()]=p_export; +} + + +void EditorImportExport::get_export_platforms(List *r_platforms) { + + for (Map >::Element *E=exporters.front();E;E=E->next()) { + + r_platforms->push_back(E->key()); + } +} + +Ref EditorImportExport::get_export_platform(const StringName& p_platform) { + + if (exporters.has(p_platform)) { + return exporters[p_platform]; + } else { + return Ref(); + } +} + + +bool EditorImportExport::poll_export_platforms() { + + bool changed=false; + for (Map >::Element *E=exporters.front();E;E=E->next()) { + + if (E->get()->poll_devices()) + changed=true; + } + + return changed; + +} + +void EditorImportExport::set_export_filter(ExportFilter p_enable) { + + export_filter=p_enable; +} + +EditorImportExport::ExportFilter EditorImportExport::get_export_filter() const{ + + return export_filter; +} + +void EditorImportExport::set_export_custom_filter(const String& p_custom_filter){ + export_custom_filter=p_custom_filter; +} +void EditorImportExport::set_export_custom_filter_exclude(const String& p_custom_filter){ + export_custom_filter_exclude=p_custom_filter; +} +String EditorImportExport::get_export_custom_filter() const{ + return export_custom_filter; +} +String EditorImportExport::get_export_custom_filter_exclude() const{ + return export_custom_filter_exclude; +} + +void EditorImportExport::set_export_image_action(ImageAction p_action) { + + image_action=p_action; +} + +EditorImportExport::ImageAction EditorImportExport::get_export_image_action() const{ + + return image_action; +} + +void EditorImportExport::set_export_image_shrink(float p_shrink) { + + image_shrink=p_shrink; +} + +float EditorImportExport::get_export_image_shrink() const{ + + return image_shrink; +} + + +void EditorImportExport::set_export_image_quality(float p_quality){ + + image_action_compress_quality=p_quality; +} + +float EditorImportExport::get_export_image_quality() const{ + + return image_action_compress_quality; +} + +void EditorImportExport::image_export_group_create(const StringName& p_name) { + + ERR_FAIL_COND(image_groups.has(p_name)); + ImageGroup ig; + ig.action=IMAGE_ACTION_NONE; //default + ig.make_atlas=false; + ig.shrink=1; + ig.lossy_quality=0.7; + image_groups[p_name]=ig; + + +} + + +bool EditorImportExport::image_export_has_group(const StringName& p_name) const { + + return image_groups.has(p_name); +} +void EditorImportExport::image_export_get_groups(List *r_name) const { + + for (Map::Element *E=image_groups.front();E;E=E->next()) { + + r_name->push_back(E->key()); + } +} + +void EditorImportExport::image_export_group_remove(const StringName& p_name){ + + ERR_FAIL_COND(!image_groups.has(p_name)); + image_groups.erase(p_name); +} +void EditorImportExport::image_export_group_set_image_action(const StringName& p_export_group,ImageAction p_action){ + + ERR_FAIL_COND(!image_groups.has(p_export_group)); + image_groups[p_export_group].action=p_action; + +} +EditorImportExport::ImageAction EditorImportExport::image_export_group_get_image_action(const StringName& p_export_group) const{ + + ERR_FAIL_COND_V(!image_groups.has(p_export_group),IMAGE_ACTION_NONE); + return image_groups[p_export_group].action; + +} +void EditorImportExport::image_export_group_set_make_atlas(const StringName& p_export_group,bool p_make){ + + ERR_FAIL_COND(!image_groups.has(p_export_group)); + image_groups[p_export_group].make_atlas=p_make; + +} +bool EditorImportExport::image_export_group_get_make_atlas(const StringName& p_export_group) const{ + + ERR_FAIL_COND_V(!image_groups.has(p_export_group),false); + return image_groups[p_export_group].make_atlas; + +} +void EditorImportExport::image_export_group_set_shrink(const StringName& p_export_group,float p_amount){ + ERR_FAIL_COND(!image_groups.has(p_export_group)); + image_groups[p_export_group].shrink=p_amount; + +} +float EditorImportExport::image_export_group_get_shrink(const StringName& p_export_group) const{ + + ERR_FAIL_COND_V(!image_groups.has(p_export_group),1); + return image_groups[p_export_group].shrink; + +} + +void EditorImportExport::image_export_group_set_lossy_quality(const StringName& p_export_group,float p_amount){ + ERR_FAIL_COND(!image_groups.has(p_export_group)); + image_groups[p_export_group].lossy_quality=p_amount; + +} +float EditorImportExport::image_export_group_get_lossy_quality(const StringName& p_export_group) const{ + + ERR_FAIL_COND_V(!image_groups.has(p_export_group),1); + return image_groups[p_export_group].lossy_quality; + +} + +StringName EditorImportExport::image_get_export_group(const StringName& p_image) const { + + if (image_group_files.has(p_image)) + return image_group_files[p_image]; + else + return StringName(); + +} + +void EditorImportExport::image_add_to_export_group(const StringName& p_image,const StringName& p_export_group) { + + + bool emptygroup = String(p_export_group)==String(); + ERR_FAIL_COND(!emptygroup && !image_groups.has(p_export_group)); + + if (emptygroup) + image_group_files.erase(p_image); + else + image_group_files[p_image]=p_export_group; +} + +void EditorImportExport::image_export_get_images_in_group(const StringName& p_group,List *r_images) const { + + for (Map::Element *E=image_group_files.front();E;E=E->next()) { + + if (p_group==E->get()) + r_images->push_back(E->key()); + } +} + +void EditorImportExport::set_convert_text_scenes(bool p_convert) { + + convert_text_scenes=p_convert; +} + +bool EditorImportExport::get_convert_text_scenes() const{ + + return convert_text_scenes; +} + + +void EditorImportExport::load_config() { + + Ref cf = memnew( ConfigFile ); + + Error err = cf->load("res://export.cfg"); + if (err!=OK) + return; //no export config to be loaded! + + + export_custom_filter=cf->get_value("export_filter","filter"); + export_custom_filter_exclude=cf->get_value("export_filter","filter_exclude"); + String t=cf->get_value("export_filter","type"); + if (t=="selected") + export_filter=EXPORT_SELECTED; + else if (t=="resources") + export_filter=EXPORT_RESOURCES; + else if (t=="all") + export_filter=EXPORT_ALL; + + if (cf->has_section("convert_images")) { + + String ci = "convert_images"; + String action = cf->get_value(ci,"action"); + if (action=="none") + image_action=IMAGE_ACTION_NONE; + else if (action=="compress_ram") + image_action=IMAGE_ACTION_COMPRESS_RAM; + else if (action=="compress_disk") + image_action=IMAGE_ACTION_COMPRESS_DISK; + + image_action_compress_quality = cf->get_value(ci,"compress_quality"); + if (cf->has_section_key(ci,"shrink")) + image_shrink = cf->get_value(ci,"shrink"); + else + image_shrink=1; + String formats=cf->get_value(ci,"formats"); + Vector f = formats.split(","); + image_formats.clear(); + for(int i=0;ihas_section("convert_scenes")) { + + convert_text_scenes = cf->get_value("convert_scenes","convert_text_scenes"); + } + + + if (cf->has_section("export_filter_files")) { + + + String eff = "export_filter_files"; + List k; + cf->get_section_keys(eff,&k); + for(List::Element *E=k.front();E;E=E->next()) { + + String val = cf->get_value(eff,E->get()); + if (val=="copy") { + files[E->get()]=ACTION_COPY; + } else if (val=="bundle") { + files[E->get()]=ACTION_BUNDLE; + } + } + } + + List sect; + + cf->get_sections(§); + + for(List::Element *E=sect.front();E;E=E->next()) { + + String s = E->get(); + if (!s.begins_with("platform:")) + continue; + String p = s.substr(s.find(":")+1,s.length()); + + if (!exporters.has(p)) + continue; + + Ref ep = exporters[p]; + if (!ep.is_valid()) { + continue; + } + List keys; + cf->get_section_keys(s,&keys); + for(List::Element *F=keys.front();F;F=F->next()) { + ep->set(F->get(),cf->get_value(s,F->get())); + } + } + + //save image groups + + if (cf->has_section("image_groups")) { + + sect.clear(); + cf->get_section_keys("image_groups",§); + for(List::Element *E=sect.front();E;E=E->next()) { + + Dictionary d = cf->get_value("image_groups",E->get()); + ImageGroup g; + g.action=IMAGE_ACTION_NONE; + g.make_atlas=false; + g.lossy_quality=0.7; + g.shrink=1; + + if (d.has("action")) { + String action=d["action"]; + if (action=="compress_ram") + g.action=IMAGE_ACTION_COMPRESS_RAM; + else if (action=="compress_disk") + g.action=IMAGE_ACTION_COMPRESS_DISK; + else if (action=="keep") + g.action=IMAGE_ACTION_KEEP; + } + + if (d.has("atlas")) + g.make_atlas=d["atlas"]; + if (d.has("lossy_quality")) + g.lossy_quality=d["lossy_quality"]; + if (d.has("shrink")) { + + g.shrink=d["shrink"]; + g.shrink=CLAMP(g.shrink,1,8); + } + + image_groups[E->get()]=g; + + } + + if (cf->has_section_key("image_group_files","files")) { + + Vector sa=cf->get_value("image_group_files","files"); + if (sa.size()%2==0) { + for(int i=0;ihas_section("script")) { + + if (cf->has_section_key("script","action")) { + + String action = cf->get_value("script","action"); + if (action=="compile") + script_action=SCRIPT_ACTION_COMPILE; + else if (action=="encrypt") + script_action=SCRIPT_ACTION_ENCRYPT; + else + script_action=SCRIPT_ACTION_NONE; + + } + + if (cf->has_section_key("script","encrypt_key")) { + + script_key = cf->get_value("script","encrypt_key"); + } + } + + if (cf->has_section("convert_samples")) { + + if (cf->has_section_key("convert_samples","action")) { + String action = cf->get_value("convert_samples","action"); + if (action=="none") { + sample_action=SAMPLE_ACTION_NONE; + } else if (action=="compress_ram") { + sample_action=SAMPLE_ACTION_COMPRESS_RAM; + } + } + + if (cf->has_section_key("convert_samples","max_hz")) + sample_action_max_hz=cf->get_value("convert_samples","max_hz"); + + if (cf->has_section_key("convert_samples","trim")) + sample_action_trim=cf->get_value("convert_samples","trim"); + } + + + +} + + + + + +void EditorImportExport::save_config() { + + Ref cf = memnew( ConfigFile ); + + switch(export_filter) { + case EXPORT_SELECTED: cf->set_value("export_filter","type","selected"); break; + case EXPORT_RESOURCES: cf->set_value("export_filter","type","resources"); break; + case EXPORT_ALL: cf->set_value("export_filter","type","all"); break; + } + + cf->set_value("export_filter","filter",export_custom_filter); + cf->set_value("export_filter", "filter_exclude",export_custom_filter_exclude); + + String file_action_section = "export_filter_files"; + + for (Map::Element *E=files.front();E;E=E->next()) { + + String f=E->key(); + String a; + switch (E->get()) { + case ACTION_NONE: {} + case ACTION_COPY: a="copy"; break; + case ACTION_BUNDLE: a="bundle"; break; + } + + cf->set_value(file_action_section,f,a); + } + + + for (Map >::Element *E=exporters.front();E;E=E->next()) { + + String pname = "platform:"+String(E->key()); + + Ref ep = E->get(); + + List pl; + ep->get_property_list(&pl); + + for (List::Element *F=pl.front();F;F=F->next()) { + + cf->set_value(pname,F->get().name,ep->get(F->get().name)); + } + + } + + switch(image_action) { + case IMAGE_ACTION_NONE: cf->set_value("convert_images","action","none"); break; + case IMAGE_ACTION_COMPRESS_RAM: cf->set_value("convert_images","action","compress_ram"); break; + case IMAGE_ACTION_COMPRESS_DISK: cf->set_value("convert_images","action","compress_disk"); break; + } + + cf->set_value("convert_images","shrink",image_shrink); + cf->set_value("convert_images","compress_quality",image_action_compress_quality); + + String formats; + for(Set::Element *E=image_formats.front();E;E=E->next()) { + + if (E!=image_formats.front()) + formats+=","; + formats+=E->get(); + } + + cf->set_value("convert_images","formats",formats); + + //save image groups + + for(Map::Element *E=image_groups.front();E;E=E->next()) { + + Dictionary d; + switch(E->get().action) { + case IMAGE_ACTION_NONE: d["action"]="default"; break; + case IMAGE_ACTION_COMPRESS_RAM: d["action"]="compress_ram"; break; + case IMAGE_ACTION_COMPRESS_DISK: d["action"]="compress_disk"; break; + case IMAGE_ACTION_KEEP: d["action"]="keep"; break; + } + + + d["atlas"]=E->get().make_atlas; + d["shrink"]=E->get().shrink; + d["lossy_quality"]=E->get().lossy_quality; + cf->set_value("image_groups",E->key(),d); + + } + + if (image_groups.size() && image_group_files.size()){ + + Vector igfkeys; + igfkeys.resize(image_group_files.size()); + int idx=0; + for (Map::Element *E=image_group_files.front();E;E=E->next()) { + igfkeys[idx++]=E->key(); + } + igfkeys.sort(); + + Vector igfsave; + igfsave.resize(image_group_files.size()*2); + idx=0; + for (int i=0;iset_value("image_group_files","files",igfsave); + } + + switch(script_action) { + case SCRIPT_ACTION_NONE: cf->set_value("script","action","none"); break; + case SCRIPT_ACTION_COMPILE: cf->set_value("script","action","compile"); break; + case SCRIPT_ACTION_ENCRYPT: cf->set_value("script","action","encrypt"); break; + } + + cf->set_value("convert_scenes","convert_text_scenes",convert_text_scenes); + + cf->set_value("script","encrypt_key",script_key); + + switch(sample_action) { + case SAMPLE_ACTION_NONE: cf->set_value("convert_samples","action","none"); break; + case SAMPLE_ACTION_COMPRESS_RAM: cf->set_value("convert_samples","action","compress_ram"); break; + } + + cf->set_value("convert_samples","max_hz",sample_action_max_hz); + cf->set_value("convert_samples","trim",sample_action_trim); + + cf->save("res://export.cfg"); + +} + + +void EditorImportExport::script_set_action(ScriptAction p_action) { + + script_action=p_action; +} + +EditorImportExport::ScriptAction EditorImportExport::script_get_action() const{ + + return script_action; +} + +void EditorImportExport::script_set_encryption_key(const String& p_key){ + + script_key=p_key; +} +String EditorImportExport::script_get_encryption_key() const{ + + return script_key; +} + + +void EditorImportExport::sample_set_action(SampleAction p_action) { + + sample_action=p_action; +} + +EditorImportExport::SampleAction EditorImportExport::sample_get_action() const{ + + return sample_action; +} + +void EditorImportExport::sample_set_max_hz(int p_hz){ + + sample_action_max_hz=p_hz; +} +int EditorImportExport::sample_get_max_hz() const{ + + return sample_action_max_hz; +} + +void EditorImportExport::sample_set_trim(bool p_trim){ + + sample_action_trim=p_trim; +} +bool EditorImportExport::sample_get_trim() const{ + + return sample_action_trim; +} + +PoolVector EditorImportExport::_get_export_file_list() { + + PoolVector fl; + for (Map::Element *E=files.front();E;E=E->next()) { + + fl.push_back(E->key()); + } + + return fl; +} + +PoolVector EditorImportExport::_get_export_platforms() { + + PoolVector ep; + for (Map >::Element *E=exporters.front();E;E=E->next()) { + + ep.push_back(E->key()); + } + + return ep; + +} + +void EditorImportExport::_bind_methods() { + + ClassDB::bind_method(D_METHOD("add_import_plugin","plugin:EditorImportPlugin"),&EditorImportExport::add_import_plugin); + ClassDB::bind_method(D_METHOD("remove_import_plugin","plugin:EditorImportPlugin"),&EditorImportExport::remove_import_plugin); + ClassDB::bind_method(D_METHOD("get_import_plugin_count"),&EditorImportExport::get_import_plugin_count); + ClassDB::bind_method(D_METHOD("get_import_plugin:EditorImportPlugin","idx"),&EditorImportExport::get_import_plugin); + ClassDB::bind_method(D_METHOD("get_import_plugin_by_name:EditorImportPlugin","name"),&EditorImportExport::get_import_plugin_by_name); + + ClassDB::bind_method(D_METHOD("add_export_plugin","plugin:EditorExportPlugin"),&EditorImportExport::add_export_plugin); + ClassDB::bind_method(D_METHOD("remove_export_plugin","plugin:EditorExportPlugin"),&EditorImportExport::remove_export_plugin); + ClassDB::bind_method(D_METHOD("get_export_plugin_count"),&EditorImportExport::get_export_plugin_count); + ClassDB::bind_method(D_METHOD("get_export_plugin:EditorExportPlugin","idx"),&EditorImportExport::get_export_plugin); + + ClassDB::bind_method(D_METHOD("set_export_file_action","file","action"),&EditorImportExport::set_export_file_action); + ClassDB::bind_method(D_METHOD("get_export_file_action","file"),&EditorImportExport::get_export_file_action); + ClassDB::bind_method(D_METHOD("get_export_file_list"),&EditorImportExport::_get_export_file_list); + + ClassDB::bind_method(D_METHOD("add_export_platform","platform:EditorExportplatform"),&EditorImportExport::add_export_platform); + //ClassDB::bind_method(D_METHOD("remove_export_platform","platform:EditorExportplatform"),&EditorImportExport::add_export_platform); + ClassDB::bind_method(D_METHOD("get_export_platform:EditorExportPlatform","name"),&EditorImportExport::get_export_platform); + ClassDB::bind_method(D_METHOD("get_export_platforms"),&EditorImportExport::_get_export_platforms); + + ClassDB::bind_method(D_METHOD("set_export_filter","filter"),&EditorImportExport::set_export_filter); + ClassDB::bind_method(D_METHOD("get_export_filter"),&EditorImportExport::get_export_filter); + + ClassDB::bind_method(D_METHOD("set_export_custom_filter","filter"),&EditorImportExport::set_export_custom_filter); + ClassDB::bind_method(D_METHOD("get_export_custom_filter"),&EditorImportExport::get_export_custom_filter); + + ClassDB::bind_method(D_METHOD("set_export_custom_filter_exclude","filter_exclude"),&EditorImportExport::set_export_custom_filter_exclude); + ClassDB::bind_method(D_METHOD("get_export_custom_filter_exclude"),&EditorImportExport::get_export_custom_filter_exclude); + + + ClassDB::bind_method(D_METHOD("image_export_group_create"),&EditorImportExport::image_export_group_create); + ClassDB::bind_method(D_METHOD("image_export_group_remove"),&EditorImportExport::image_export_group_remove); + ClassDB::bind_method(D_METHOD("image_export_group_set_image_action"),&EditorImportExport::image_export_group_set_image_action); + ClassDB::bind_method(D_METHOD("image_export_group_set_make_atlas"),&EditorImportExport::image_export_group_set_make_atlas); + ClassDB::bind_method(D_METHOD("image_export_group_set_shrink"),&EditorImportExport::image_export_group_set_shrink); + ClassDB::bind_method(D_METHOD("image_export_group_get_image_action"),&EditorImportExport::image_export_group_get_image_action); + ClassDB::bind_method(D_METHOD("image_export_group_get_make_atlas"),&EditorImportExport::image_export_group_get_make_atlas); + ClassDB::bind_method(D_METHOD("image_export_group_get_shrink"),&EditorImportExport::image_export_group_get_shrink); + ClassDB::bind_method(D_METHOD("image_add_to_export_group"),&EditorImportExport::image_add_to_export_group); + ClassDB::bind_method(D_METHOD("script_set_action"),&EditorImportExport::script_set_action); + ClassDB::bind_method(D_METHOD("script_set_encryption_key"),&EditorImportExport::script_set_encryption_key); + ClassDB::bind_method(D_METHOD("script_get_action"),&EditorImportExport::script_get_action); + ClassDB::bind_method(D_METHOD("script_get_encryption_key"),&EditorImportExport::script_get_encryption_key); + + + + BIND_CONSTANT( ACTION_NONE ); + BIND_CONSTANT( ACTION_COPY ); + BIND_CONSTANT( ACTION_BUNDLE ); + + BIND_CONSTANT( EXPORT_SELECTED ); + BIND_CONSTANT( EXPORT_RESOURCES ); + BIND_CONSTANT( EXPORT_ALL ); + + BIND_CONSTANT( IMAGE_ACTION_NONE ); + BIND_CONSTANT( IMAGE_ACTION_COMPRESS_DISK ); + BIND_CONSTANT( IMAGE_ACTION_COMPRESS_RAM ); + BIND_CONSTANT( IMAGE_ACTION_KEEP ); + + BIND_CONSTANT( SCRIPT_ACTION_NONE ); + BIND_CONSTANT( SCRIPT_ACTION_COMPILE ); + BIND_CONSTANT( SCRIPT_ACTION_ENCRYPT ); +}; + + + +EditorImportExport::EditorImportExport() { + + export_filter=EXPORT_RESOURCES; + singleton=this; + image_action=IMAGE_ACTION_NONE; + image_action_compress_quality=0.7; + image_formats.insert("png"); + image_shrink=1; + + + script_action=SCRIPT_ACTION_COMPILE; + + sample_action=SAMPLE_ACTION_NONE; + sample_action_max_hz=44100; + sample_action_trim=false; + + convert_text_scenes=true; + +} + + + +EditorImportExport::~EditorImportExport() { + + + +} +#endif diff --git a/tools/editor/editor_export.h b/tools/editor/editor_export.h new file mode 100644 index 0000000000..1aa4f103ec --- /dev/null +++ b/tools/editor/editor_export.h @@ -0,0 +1,281 @@ +/*************************************************************************/ +/* editor_import_export.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef EDITOR_EXPORT_H +#define EDITOR_EXPORT_H + + + +#include "resource.h" +#include "scene/main/node.h" +#include "scene/resources/texture.h" +#include "scene/main/timer.h" + +class EditorProgress; +class FileAccess; +class EditorExportPlatform; + +class EditorExportPreset : public Reference { + + GDCLASS( EditorExportPreset,Reference ) +public: + enum ExportFilter { + EXPORT_ALL_RESOURCES, + EXPORT_SELECTED_SCENES, + EXPORT_SELECTED_RESOURCES, + EXPORT_ALL_FILES, + }; + +private: + + Ref platform; + ExportFilter export_filter; + String include_filter; + String exclude_filter; + + String exporter; + Set selected_files; + bool runnable; + + Vector patches; + +friend class EditorExport; +friend class EditorExportPlatform; + + List properties; + Map values; + + String name; +protected: + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List *p_list) const; + +public: + + Ref get_platform(); + bool has(const StringName& p_property) const { return values.has(p_property); } + + Vector get_files_to_export() const; + + void add_export_file(const String& p_path); + void remove_export_file(const String& p_path); + bool has_export_file(const String& p_path); + + void set_name(const String& p_name); + String get_name() const; + + void set_runnable(bool p_enable); + bool is_runnable() const; + + void set_export_filter(ExportFilter p_filter); + ExportFilter get_export_filter() const; + + void set_include_filter(const String& p_include); + String get_include_filter() const; + + void set_exclude_filter(const String& p_exclude); + String get_exclude_filter() const; + + void add_patch(const String& p_path,int p_at_pos=-1); + void set_patch(int p_index,const String& p_path); + String get_patch(int p_index); + void remove_patch(int p_idx); + Vector get_patches() const; + + const List& get_properties() const { return properties; } + + EditorExportPreset(); +}; + + +class EditorExportPlatform : public Reference { + + GDCLASS( EditorExportPlatform,Reference ) + +public: + + typedef Error (*EditorExportSaveFunction)(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); + +private: + + struct SavedData { + + String path; + uint64_t ofs; + uint64_t size; + }; + + struct PackData { + + FileAccess *f; + Vector file_ofs; + EditorProgress *ep; + }; + + struct ZipData { + + void* zip; + EditorProgress *ep; + int count; + + }; + + void gen_debug_flags(Vector &r_flags, int p_flags); + static Error _save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); + static Error _save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); + + +protected: + + virtual void get_preset_features(const Ref& p_preset,List *r_features)=0; + String find_export_template(String template_file_name, String *err=NULL) const; + +public: + + + struct ExportOption { + PropertyInfo option; + Variant default_value; + + ExportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; } + ExportOption() {} + }; + + virtual Ref create_preset(); + + virtual void get_export_options(List *r_options)=0; + virtual String get_name() const =0; + virtual Ref get_logo() const =0; + + + Error export_project_files(const Ref& p_preset,EditorExportSaveFunction p_func, void* p_udata); + + Error save_pack(const Ref& p_preset,FileAccess *p_where); + Error save_zip(const Ref& p_preset,const String& p_path); + + + virtual bool poll_devices() { return false; } + virtual int get_device_count() const { return 0; } + virtual String get_device_name(int p_device) const { return ""; } + virtual String get_device_info(int p_device) const { return ""; } + + enum DebugFlags { + DEBUG_FLAG_DUMB_CLIENT=1, + DEBUG_FLAG_REMOTE_DEBUG=2, + DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST=4, + DEBUG_FLAG_VIEW_COLLISONS=8, + DEBUG_FLAG_VIEW_NAVIGATION=16, + }; + + virtual Error run(int p_device,int p_debug_flags) { return OK; } + + virtual bool can_export(String *r_error=NULL) const=0; + + virtual String get_binary_extension() const=0; + virtual Error export_project(const Ref& p_preset,const String& p_path,int p_flags=0)=0; + + EditorExportPlatform(); +}; + + +class EditorExport : public Node { + GDCLASS(EditorExport,Node); + + Vector > export_platforms; + Vector > export_presets; + + Timer *save_timer; + bool block_save; + + static EditorExport *singleton; + + void _save(); +protected: + +friend class EditorExportPreset; + void save_presets(); + + void _notification(int p_what); + static void _bind_methods(); +public: + + static EditorExport * get_singleton() { return singleton; } + + void add_export_platform(const Ref& p_platform); + int get_export_platform_count(); + Ref get_export_platform(int p_idx); + + + void add_export_preset(const Ref& p_preset,int p_at_pos=-1); + int get_export_preset_count() const; + Ref get_export_preset(int p_idx); + void remove_export_preset(int p_idx); + + void load_config(); + + EditorExport(); + ~EditorExport(); +}; + + + + +class EditorExportPlatformPC : public EditorExportPlatform { + + GDCLASS( EditorExportPlatformPC,EditorExportPlatform ) + + Ref logo; + String name; + String extension; + + + +public: + + virtual void get_preset_features(const Ref& p_preset,List* r_features); + + virtual void get_export_options(List *r_options); + + virtual String get_name() const; + virtual Ref get_logo() const; + + virtual bool can_export(String *r_error=NULL) const; + virtual String get_binary_extension() const; + virtual Error export_project(const Ref& p_preset,const String& p_path,int p_flags=0); + + void set_extension(const String& p_extension); + void set_name(const String& p_name); + + void set_logo(const Ref& p_loco); + + EditorExportPlatformPC(); +}; + + +#endif // EDITOR_IMPORT_EXPORT_H diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp deleted file mode 100644 index 5d55de91bd..0000000000 --- a/tools/editor/editor_import_export.cpp +++ /dev/null @@ -1,2572 +0,0 @@ -/*************************************************************************/ -/* editor_import_export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "editor_import_export.h" -#include "version.h" -#include "script_language.h" -#include "globals.h" -#include "os/file_access.h" -#include "os/dir_access.h" -#include "tools/editor/editor_file_system.h" -#include "io/resource_loader.h" -#include "editor_node.h" -#include "editor_settings.h" -#include "io/config_file.h" -#include "io/resource_saver.h" -#include "io/md5.h" -#include "tools/editor/plugins/script_editor_plugin.h" -#include "io/zip_io.h" - - - - -bool EditorExportPreset::_set(const StringName& p_name, const Variant& p_value) { - - if (values.has(p_name)) { - values[p_name]=p_value; - return true; - } - - return false; -} - -bool EditorExportPreset::_get(const StringName& p_name,Variant &r_ret) const{ - - if (values.has(p_name)) { - r_ret=values[p_name]; - return true; - } - - return false; -} -void EditorExportPreset::_get_property_list( List *p_list) const{ - - for (const List::Element *E=properties.front();E;E=E->next()) { - - p_list->push_back(E->get()); - } -} - -Vector EditorExportPreset::get_files_to_export() const { - - return Vector(); -} - - -EditorExportPreset::EditorExportPreset() { - - -} - - -/////////////////////////////////// - -void EditorExportPlatform::gen_debug_flags(Vector &r_flags, int p_flags) { - - String host = EditorSettings::get_singleton()->get("network/debug_host"); - - if (p_flags&DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) - host="localhost"; - - if (p_flags&DEBUG_FLAG_DUMB_CLIENT) { - int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); - String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password"); - r_flags.push_back("-rfs"); - r_flags.push_back(host+":"+itos(port)); - if (passwd!="") { - r_flags.push_back("-rfs_pass"); - r_flags.push_back(passwd); - } - } - - if (p_flags&DEBUG_FLAG_REMOTE_DEBUG) { - - r_flags.push_back("-rdebug"); - - r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); - - List breakpoints; - ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); - - - if (breakpoints.size()) { - - r_flags.push_back("-bp"); - String bpoints; - for(const List::Element *E=breakpoints.front();E;E=E->next()) { - - bpoints+=E->get().replace(" ","%20"); - if (E->next()) - bpoints+=","; - } - - r_flags.push_back(bpoints); - } - - } - - if (p_flags&DEBUG_FLAG_VIEW_COLLISONS) { - - r_flags.push_back("-debugcol"); - } - - if (p_flags&DEBUG_FLAG_VIEW_NAVIGATION) { - - r_flags.push_back("-debugnav"); - } -} - -Error EditorExportPlatform::_save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { - - -} - -Error EditorExportPlatform::_save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { - - - String path=p_path.replace_first("res://",""); - - ZipData *zd = (ZipData*)p_userdata; - - zipFile zip=(zipFile)zd->zip; - - zipOpenNewFileInZip(zip, - path.utf8().get_data(), - NULL, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - - zipWriteInFileInZip(zip,p_data.ptr(),p_data.size()); - zipCloseFileInZip(zip); - - zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); - zd->count++; - return OK; -} - -String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { - - String user_file = EditorSettings::get_singleton()->get_settings_path() - +"/templates/"+template_file_name; - String system_file=OS::get_singleton()->get_installed_templates_path(); - bool has_system_path=(system_file!=""); - system_file+=template_file_name; - - // Prefer user file - if (FileAccess::exists(user_file)) { - return user_file; - } - - // Now check system file - if (has_system_path) { - if (FileAccess::exists(system_file)) { - return system_file; - } - } - - // Not found - if (err) { - *err+="No export template found at \""+user_file+"\""; - if (has_system_path) - *err+="\n or \""+system_file+"\"."; - else - *err+="."; - } - return ""; -} - - -Error EditorExportPlatform::export_project_files(const Ref& p_preset,EditorExportSaveFunction p_func, void* p_udata) { - - return OK; -} - -Error EditorExportPlatform::save_pack(const Ref& p_preset,FileAccess *p_where) { - - return OK; -} - -Error EditorExportPlatform::save_zip(const Ref& p_preset,const String& p_path) { - - return OK; -} - -EditorExportPlatform::EditorExportPlatform() { - - -} - - -//// - -void EditorExport::add_export_platform(const Ref& p_platform) { - - export_platforms.push_back(p_platform); -} - -int EditorExport::get_export_platform_count() { - - return export_platforms.size(); -} - -Ref EditorExport::get_export_platform(int p_idx) { - - ERR_FAIL_INDEX_V(p_idx,export_platforms.size(),Ref()); - - return export_platforms[p_idx]; -} - - -void EditorExport::add_export_preset(const Ref& p_preset,int p_at_pos) { - - if (p_at_pos<0) - export_presets.push_back(p_preset); - else - export_presets.insert(p_at_pos,p_preset); - - -} - -int EditorExport::get_export_preset_count() const { - - return export_presets.size(); -} - -Ref EditorExport::get_export_preset(int p_idx) { - - ERR_FAIL_INDEX_V( p_idx, export_presets.size(),Ref() ); - return export_presets[p_idx]; -} - -void EditorExport::remove_export_preset(int p_idx) { - - export_presets.remove(p_idx); -} - -void EditorExport::load_config() { - - -} - -void EditorExport::save_config() { - -} - -EditorExport::EditorExport() { - - -} - -EditorExport::~EditorExport() { - - -} - -//////// - -#if 0 -#include "version.h" -#include "script_language.h" -#include "globals.h" -#include "os/file_access.h" -#include "os/dir_access.h" -#include "tools/editor/editor_file_system.h" -#include "io/resource_loader.h" -#include "editor_node.h" -#include "editor_settings.h" -#include "io/config_file.h" -#include "io/resource_saver.h" -#include "io/md5.h" -#include "io_plugins/editor_texture_import_plugin.h" -#include "tools/editor/plugins/script_editor_plugin.h" -#include "io/zip_io.h" - - -String EditorImportPlugin::validate_source_path(const String& p_path) { - - String gp = GlobalConfig::get_singleton()->globalize_path(p_path); - String rp = GlobalConfig::get_singleton()->get_resource_path(); - if (!rp.ends_with("/")) - rp+="/"; - - return rp.path_to_file(gp); -} - -String EditorImportPlugin::expand_source_path(const String& p_path) { - - if (p_path.is_rel_path()) { - return GlobalConfig::get_singleton()->get_resource_path().plus_file(p_path).simplify_path(); - } else { - return p_path; - } -} - - -String EditorImportPlugin::_validate_source_path(const String& p_path) { - - return validate_source_path(p_path); -} - -String EditorImportPlugin::_expand_source_path(const String& p_path) { - - return expand_source_path(p_path); -} - -void EditorImportPlugin::_bind_methods() { - - - ClassDB::bind_method(D_METHOD("validate_source_path","path"),&EditorImportPlugin::_validate_source_path); - ClassDB::bind_method(D_METHOD("expand_source_path","path"),&EditorImportPlugin::_expand_source_path); - - ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_name")); - ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_visible_name")); - ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_dialog",PropertyInfo(Variant::STRING,"from"))); - ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::INT,"import",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"from",PROPERTY_HINT_RESOURCE_TYPE,"ResourceImportMetadata"))); - ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::POOL_BYTE_ARRAY,"custom_export",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform"))); - ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_from_drop",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::STRING,"dest_path"))); - ClassDB::add_virtual_method(get_class_static(),MethodInfo("reimport_multiple_files",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"))); - ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::BOOL,"can_reimport_multiple_files")); - - //BIND_VMETHOD( mi ); -} - -String EditorImportPlugin::get_name() const { - - if (get_script_instance() && get_script_instance()->has_method("get_name")) { - return get_script_instance()->call("get_name"); - } - - ERR_FAIL_V(""); -} - -String EditorImportPlugin::get_visible_name() const { - - if (get_script_instance() && get_script_instance()->has_method("get_visible_name")) { - return get_script_instance()->call("get_visible_name"); - } - - ERR_FAIL_V(""); -} - - -void EditorImportPlugin::import_dialog(const String& p_from) { - - if (get_script_instance() && get_script_instance()->has_method("import_dialog")) { - get_script_instance()->call("import_dialog",p_from); - return; - } - - ERR_FAIL(); - -} - -Error EditorImportPlugin::import(const String& p_path, const Ref& p_from) { - - if (get_script_instance() && get_script_instance()->has_method("import")) { - return Error(get_script_instance()->call("import",p_path,p_from).operator int()); - } - - ERR_FAIL_V(ERR_UNAVAILABLE); -} - -Vector EditorImportPlugin::custom_export(const String& p_path, const Ref &p_platform) { - - if (get_script_instance() && get_script_instance()->has_method("custom_export")) { - get_script_instance()->call("custom_export",p_path,p_platform); - } - - return Vector(); -} - -bool EditorImportPlugin::can_reimport_multiple_files() const { - - if (get_script_instance() && get_script_instance()->has_method("can_reimport_multiple_files")) { - return get_script_instance()->call("can_reimport_multiple_files"); - } - - return false; -} -void EditorImportPlugin::reimport_multiple_files(const Vector& p_list) { - - if (get_script_instance() && get_script_instance()->has_method("reimport_multiple_files")) { - get_script_instance()->call("reimport_multiple_files",p_list); - } - -} - -void EditorImportPlugin::import_from_drop(const Vector& p_drop, const String &p_dest_path) { - - if (get_script_instance() && get_script_instance()->has_method("import_from_drop")) { - get_script_instance()->call("import_from_drop",p_drop,p_dest_path); - } - -} - -EditorImportPlugin::EditorImportPlugin() { - - -} - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - -void EditorExportPlugin::_bind_methods() { - - MethodInfo mi = MethodInfo("custom_export:Variant",PropertyInfo(Variant::STRING,"name"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform")); - mi.return_val.type=Variant::POOL_BYTE_ARRAY; - - BIND_VMETHOD( mi ); -} - - -Vector EditorExportPlugin::custom_export(String& p_path,const Ref &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(); - if (d.get_type()==Variant::POOL_BYTE_ARRAY) - return d; - - ERR_FAIL_COND_V(d.get_type()!=Variant::DICTIONARY,Vector()); - Dictionary dict=d; - ERR_FAIL_COND_V(!dict.has("name"),Vector()); - ERR_FAIL_COND_V(!dict.has("data"),Vector()); - p_path=dict["name"]; - return dict["data"]; - } - - return Vector(); - -} - - -EditorExportPlugin::EditorExportPlugin() { - - -} - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - - -static void _add_to_list(EditorFileSystemDirectory *p_efsd,Set& r_list) { - - for(int i=0;iget_subdir_count();i++) { - - _add_to_list(p_efsd->get_subdir(i),r_list); - } - - for(int i=0;iget_file_count();i++) { - r_list.insert(p_efsd->get_file_path(i)); - } -} - - -struct __EESortDepCmp { - - _FORCE_INLINE_ bool operator()(const StringName& p_l,const StringName& p_r) const { - return p_l.operator String() < p_r.operator String(); - } -}; - - - - -static void _edit_files_with_filter(DirAccess *da,const List& p_filters,Set& r_list,bool exclude) { - - - List files; - List dirs; - - da->list_dir_begin(); - - String f = da->get_next(); - while(f!="") { - - print_line("HOHO: "+f); - if (da->current_is_dir()) - dirs.push_back(f); - else - files.push_back(f); - - f=da->get_next(); - } - - String r = da->get_current_dir().replace("\\","/"); - if (!r.ends_with("/")) - r+="/"; - - print_line("AT: "+r); - - for(List::Element *E=files.front();E;E=E->next()) { - String fullpath=r+E->get(); - for(const List::Element *F=p_filters.front();F;F=F->next()) { - - if (fullpath.matchn(F->get())) { - String act = TTR("Added:")+" "; - - if (!exclude) { - r_list.insert(fullpath); - } else { - act = TTR("Removed:")+" "; - r_list.erase(fullpath); - } - - - print_line(act+fullpath); - } - } - } - - da->list_dir_end(); - - for(List::Element *E=dirs.front();E;E=E->next()) { - if (E->get().begins_with(".")) - continue; - da->change_dir(E->get()); - _edit_files_with_filter(da,p_filters,r_list,exclude); - da->change_dir(".."); - } - -} - -static void _edit_filter_list(Set& r_list,const String& p_filter,bool exclude) { - - if (p_filter=="") - return; - Vector split = p_filter.split(","); - List filters; - for(int i=0;i& r_list,const String& p_filter) { - _edit_filter_list(r_list,p_filter,false); -} - -static void _remove_filter_from_list(Set& r_list,const String& p_filter) { - _edit_filter_list(r_list,p_filter,true); -} - -bool EditorExportPlatform::_set(const StringName& p_name, const Variant& p_value) { - - String n = p_name; - - if (n=="debug/debugging_enabled") { - set_debugging_enabled(p_value); - } else { - return false; - } - - return true; - -} - -bool EditorExportPlatform::_get(const StringName& p_name,Variant &r_ret) const { - - String n = p_name; - - if (n=="debug/debugging_enabled") { - r_ret=is_debugging_enabled(); - } else { - return false; - } - - return true; - -} - -void EditorExportPlatform::_get_property_list( List *p_list) const { - - p_list->push_front( PropertyInfo( Variant::BOOL, "debug/debugging_enabled")); -} - -Vector EditorExportPlatform::get_exported_file_default(String& p_fname) const { - - FileAccess *f = FileAccess::open(p_fname,FileAccess::READ); - ERR_FAIL_COND_V(!f,Vector()); - Vector ret; - ret.resize(f->get_len()); - int rbs = f->get_buffer(ret.ptr(),ret.size()); - memdelete(f); - return ret; -} - -Vector EditorExportPlatform::get_exported_file(String& p_fname) const { - - Ref ep=EditorImportExport::get_singleton()->get_export_platform(get_name()); - - for(int i=0;iget_export_plugin_count();i++) { - - Vector data = EditorImportExport::get_singleton()->get_export_plugin(i)->custom_export(p_fname,ep); - if (data.size()) - return data; - - } - - - return get_exported_file_default(p_fname); - - -} - -Vector EditorExportPlatform::get_dependencies(bool p_bundles) const { - - - Set exported; - - if (FileAccess::exists("res://godot.cfg")) - exported.insert("res://godot.cfg"); - - if (EditorImportExport::get_singleton()->get_export_filter()!=EditorImportExport::EXPORT_SELECTED) { - - String filter; - if (EditorImportExport::get_singleton()->get_export_filter()==EditorImportExport::EXPORT_ALL) { - _add_filter_to_list(exported,"*"); - } else { - _add_to_list(EditorFileSystem::get_singleton()->get_filesystem(),exported); - String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); - if (cf!="") - cf+=","; - cf+="*.flags"; - _add_filter_to_list(exported,cf); - - cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude(); - _remove_filter_from_list(exported,cf); - } - - - } else { - - - Map > remapped_paths; - - Set scene_extensions; - Set resource_extensions; - - { - - List l; - /* - SceneLoader::get_recognized_extensions(&l); - for(List::Element *E=l.front();E;E=E->next()) { - scene_extensions.insert(E->get()); - } - */ - ResourceLoader::get_recognized_extensions_for_type("",&l); - for(List::Element *E=l.front();E;E=E->next()) { - - resource_extensions.insert(E->get()); - } - } - - - List toexport; - - EditorImportExport::get_singleton()->get_export_file_list(&toexport); - - print_line("TO EXPORT: "+itos(toexport.size())); - - - for (List::Element *E=toexport.front();E;E=E->next()) { - - print_line("DEP: "+String(E->get())); - exported.insert(E->get()); - if (p_bundles && EditorImportExport::get_singleton()->get_export_file_action(E->get())==EditorImportExport::ACTION_BUNDLE) { - print_line("NO BECAUSE OF BUNDLE!"); - continue; //no dependencies needed to be copied - } - - List testsubs; - testsubs.push_back(E->get()); - - while(testsubs.size()) { - //recursive subdep search! - List deplist; - ResourceLoader::get_dependencies(testsubs.front()->get(),&deplist); - testsubs.pop_front(); - - List subdeps; - - for (List::Element *F=deplist.front();F;F=F->next()) { - - StringName dep = F->get(); - - if (exported.has(dep) || EditorImportExport::get_singleton()->get_export_file_action(dep)!=EditorImportExport::ACTION_NONE) - continue; //dependency added or to be added - print_line(" SUBDEP: "+String(dep)); - - exported.insert(dep); - testsubs.push_back(dep); - } - } - } - String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); - if (cf!="") - cf+=","; - cf+="*.flags"; - _add_filter_to_list(exported,cf); - - cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude(); - _remove_filter_from_list(exported,cf); - - - } - - Vector ret; - ret.resize(exported.size()); - - - int idx=0; - for(Set::Element *E=exported.front();E;E=E->next()) { - - ret[idx++]=E->get(); - - } - - SortArray sort; //some platforms work better if this is sorted - sort.sort(ret.ptr(),ret.size()); - - return ret; - -} - -String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { - String user_file = EditorSettings::get_singleton()->get_settings_path() - +"/templates/"+template_file_name; - String system_file=OS::get_singleton()->get_installed_templates_path(); - bool has_system_path=(system_file!=""); - system_file+=template_file_name; - - // Prefer user file - if (FileAccess::exists(user_file)) { - return user_file; - } - - // Now check system file - if (has_system_path) { - if (FileAccess::exists(system_file)) { - return system_file; - } - } - - // Not found - if (err) { - *err+="No export template found at \""+user_file+"\""; - if (has_system_path) - *err+="\n or \""+system_file+"\"."; - else - *err+="."; - } - return ""; -} - -bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const { - return find_export_template(template_file_name,err)!=""; -} - -/////////////////////////////////////// - - - -bool EditorExportPlatform::is_debugging_enabled() const { - - return debugging_enabled; -} - -void EditorExportPlatform::set_debugging_enabled(bool p_enabled) { - - debugging_enabled = p_enabled; -} - -bool EditorExportPlatformPC::_set(const StringName& p_name, const Variant& p_value) { - - String n = p_name; - - if (n=="custom_binary/release") { - - custom_release_binary=p_value; - } else if (n=="custom_binary/debug") { - - custom_debug_binary=p_value; - } else if (n=="resources/pack_mode") { - - export_mode=ExportMode(int(p_value)); - } else if (n=="resources/bundle_dependencies_(for_optical_disc)") { - - bundle=p_value; - } else if (n=="binary/64_bits") { - - use64=p_value; - } else - return false; - - return true; - -} - -bool EditorExportPlatformPC::_get(const StringName& p_name,Variant &r_ret) const { - - String n = p_name; - - if (n=="custom_binary/release") { - - r_ret=custom_release_binary; - } else if (n=="custom_binary/debug") { - - r_ret=custom_debug_binary; - } else if (n=="resources/pack_mode") { - - r_ret=export_mode; - } else if (n=="resources/bundle_dependencies_(for_optical_disc)") { - - r_ret=bundle; - } else if (n=="binary/64_bits") { - - r_ret=use64; - } else - return false; - - return true; - -} - -void EditorExportPlatformPC::_get_property_list( List *p_list) const { - - p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/debug", PROPERTY_HINT_GLOBAL_FILE,binary_extension)); - p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/release", PROPERTY_HINT_GLOBAL_FILE,binary_extension)); - p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Pack into executable,Pack into binary file (.pck),Pack into archive file (.zip)")); - p_list->push_back( PropertyInfo( Variant::BOOL, "resources/bundle_dependencies_(for_optical_disc)")); - p_list->push_back( PropertyInfo( Variant::BOOL, "binary/64_bits")); -} - - - -static void _exp_add_dep(Map > &deps,const StringName& p_path) { - - - if (deps.has(p_path)) - return; //already done - - deps.insert(p_path,List()); - - List &deplist=deps[p_path]; - Set depset; - - List dl; - ResourceLoader::get_dependencies(p_path,&dl); - - //added in order so child dependencies are always added bfore parent dependencies - for (List::Element *E=dl.front();E;E=E->next()) { - - - if (!deps.has(E->get())) - _exp_add_dep(deps,E->get()); - - for(List::Element *F=deps[E->get()].front();F;F=F->next()) { - - - if (!depset.has(F->get())) { - depset.insert(F->get()); - deplist.push_back(F->get()); - } - } - - if (!depset.has(E->get())) { - depset.insert(E->get()); - deplist.push_back(E->get()); - } - - } -} - - - -Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles) { - -/* ALL FILES AND DEPENDENCIES */ - - Vector files=get_dependencies(p_make_bundles); - - Map > deps; - - if (false) { - for(int i=0;i groups; - - EditorImportExport::get_singleton()->image_export_get_groups(&groups); - - Map remap_files; - Set saved; - - int counter=0; - - for(List::Element *E=groups.front();E;E=E->next()) { - - if (!EditorImportExport::get_singleton()->image_export_group_get_make_atlas(E->get())) - continue; //uninterested, only process for atlas! - - List atlas_images; - EditorImportExport::get_singleton()->image_export_get_images_in_group(E->get(),&atlas_images); - atlas_images.sort_custom(); - - for (List::Element *F=atlas_images.front();F;) { - - List::Element *N=F->next(); - - if (!FileAccess::exists(F->get())) { - atlas_images.erase(F); - } - - F=N; - - } - - if (atlas_images.size()<=1) - continue; - - int group_format=0; - float group_lossy_quality=EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(E->get()); - int group_shrink=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get()); - group_shrink*=EditorImportExport::get_singleton()->get_export_image_shrink(); - - switch(EditorImportExport::get_singleton()->image_export_group_get_image_action(E->get())) { - case EditorImportExport::IMAGE_ACTION_KEEP: - case EditorImportExport::IMAGE_ACTION_NONE: { - - switch(EditorImportExport::get_singleton()->get_export_image_action()) { - case EditorImportExport::IMAGE_ACTION_NONE: { - - group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS; //? - - } break; //use default - case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: { - group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY; - } break; //use default - case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: { - group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM; - } break; //use default - } - - group_lossy_quality=EditorImportExport::get_singleton()->get_export_image_quality(); - - } break; //use default - case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: { - group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY; - } break; //use default - case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: { - group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM; - } break; //use default - } - - String image_listD_METHOD5; - - { - MD5_CTX ctx; - MD5Init(&ctx); - for (List::Element *F=atlas_images.front();F;F=F->next()) { - - String p = F->get(); - MD5Update(&ctx,(unsigned char*)p.utf8().get_data(),p.utf8().length()); - - } - - MD5Final(&ctx); - image_listD_METHOD5=String::md5(ctx.digest); - } - //ok see if cached - String md5; - bool atlas_valid=true; - String atlas_name; - - { - MD5_CTX ctx; - MD5Init(&ctx); - String path = GlobalConfig::get_singleton()->get_resource_path()+"::"+String(E->get())+"::"+get_name(); - MD5Update(&ctx,(unsigned char*)path.utf8().get_data(),path.utf8().length()); - MD5Final(&ctx); - md5 = String::md5(ctx.digest); - } - - FileAccess *f=NULL; - - if (!FileAccess::exists(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5)) { - print_line("NO MD5 INVALID"); - atlas_valid=false; - } - - if (atlas_valid) - f=FileAccess::open(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5,FileAccess::READ); - - if (atlas_valid) { - //compare options - /*Dictionary options; - options.parse_json(f->get_line()); - if (!options.has("lossy_quality") || float(options["lossy_quality"])!=group_lossy_quality) - atlas_valid=false; - else if (!options.has("shrink") || int(options["shrink"])!=group_shrink) - atlas_valid=false; - else if (!options.has("image_format") || int(options["image_format"])!=group_format) - atlas_valid=false; - - if (!atlas_valid) - print_line("JSON INVALID"); -*/ - } - - - if (atlas_valid) { - //check md5 of list of image /names/ - if (f->get_line().strip_edges()!=image_listD_METHOD5) { - atlas_valid=false; - print_line("IMAGE MD5 INVALID!"); - } - - } - - Vector rects; - bool resave_deps=false; - - if (atlas_valid) { - - //check if images were not modified - for (List::Element *F=atlas_images.front();F;F=F->next()) { - - Vector slices = f->get_line().strip_edges().split("::"); - - if (slices.size()!=10) { - atlas_valid=false; - print_line("CANT SLICE IN 10"); - break; - } - uint64_t mod_time = slices[0].to_int64(); - uint64_t file_mod_time = FileAccess::get_modified_time(F->get()); - if (mod_time!=file_mod_time) { - - String imageD_METHOD5 = slices[1]; - String fileD_METHOD5 = FileAccess::getD_METHOD5(F->get()); - - if (imageD_METHOD5!=fileD_METHOD5) { - atlas_valid=false; - print_line("IMAGE INVALID "+slices[0]); - break; - } else { - resave_deps=true; - } - } - - if (atlas_valid) { - //push back region and margin - rects.push_back(Rect2(slices[2].to_float(),slices[3].to_float(),slices[4].to_float(),slices[5].to_float())); - rects.push_back(Rect2(slices[6].to_float(),slices[7].to_float(),slices[8].to_float(),slices[9].to_float())); - } - } - - } - - if (f) { - memdelete(f); - f=NULL; - } - - print_line("ATLAS VALID? "+itos(atlas_valid)+" RESAVE DEPS? "+itos(resave_deps)); - if (!atlas_valid) { - rects.clear(); - //oh well, atlas is not valid. need to make new one.... - - String dst_file = EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex"; - Ref imd = memnew( ResourceImportMetadata ); - //imd->set_editor(); - - - for (List::Element *F=atlas_images.front();F;F=F->next()) { - - imd->add_source(EditorImportPlugin::validate_source_path(F->get()),FileAccess::getD_METHOD5(F->get())); - - } - - - imd->set_option("format",group_format); - - - int flags=0; - - if (GlobalConfig::get_singleton()->get("image_loader/filter")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_FILTER; - if (!GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS; - if (!GlobalConfig::get_singleton()->get("image_loader/repeat")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_REPEAT; - - flags|=EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA; - - imd->set_option("flags",flags); - imd->set_option("quality",group_lossy_quality); - imd->set_option("atlas",true); - imd->set_option("crop",true); - imd->set_option("shrink",group_shrink); - - - - Ref plugin = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture"); - Error err = plugin->import2(dst_file,imd,get_image_compression(),true); - if (err) { - - EditorNode::add_io_error(TTR("Error saving atlas:")+" "+dst_file.get_file()); - return ERR_CANT_CREATE; - } - - ERR_FAIL_COND_V(imd->get_option("rects")==Variant(),ERR_BUG); - - Array r_rects=imd->get_option("rects"); - rects.resize(r_rects.size()); - for(int i=0;iget_settings_path()+"/tmp/atlas-"+md5,FileAccess::WRITE); - Dictionary options; - options["lossy_quality"]=group_lossy_quality; - options["shrink"]=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get()); - options["image_format"]=group_format; - //f->store_line(options.to_json()); - f->store_line(image_listD_METHOD5); - } - - //go through all ATEX files - - { - Ref atlas = memnew( ImageTexture ); //fake atlas! - String atlas_path="res://atlas-"+md5+".tex"; - atlas->set_path(atlas_path); - int idx=0; - for (List::Element *F=atlas_images.front();F;F=F->next()) { - - String p = F->get(); - Ref atex = memnew(AtlasTexture); - atex->set_atlas(atlas); - Rect2 region=rects[idx++]; - Rect2 margin=rects[idx++]; - atex->set_region(region); - atex->set_margin(margin); - - String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpatlas.atex"; - Error err = ResourceSaver::save(path,atex); - if (err!=OK) { - EditorNode::add_io_error(TTR("Could not save atlas subtexture:")+" "+path); - return ERR_CANT_CREATE; - } - Vector data = FileAccess::get_file_as_array(path); - String dst_path = F->get().operator String().get_basename()+".atex"; - err = p_func(p_udata,dst_path,data,counter++,files.size()); - saved.insert(dst_path); - if (err) - return err; - - if (f) { - //recreating deps.. - String depline; - //depline=String(F->get())+"::"+itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::getD_METHOD5(F->get()); name unneccesary by top md5 - depline=itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::getD_METHOD5(F->get()); - depline+="::"+itos(region.pos.x)+"::"+itos(region.pos.y)+"::"+itos(region.size.x)+"::"+itos(region.size.y); - depline+="::"+itos(margin.pos.x)+"::"+itos(margin.pos.y)+"::"+itos(margin.size.x)+"::"+itos(margin.size.y); - f->store_line(depline); - } - - remap_files[F->get()]=dst_path; - } - - Vector atlas_data = FileAccess::get_file_as_array(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex"); - Error err = p_func(p_udata,atlas_path,atlas_data,counter,files.size()); - saved.insert(atlas_path); - if (err) - return err; - - } - - - if (f) { - memdelete(f); - } - - } - - - StringName engine_cfg="res://godot.cfg"; - StringName boot_splash; - { - String splash=GlobalConfig::get_singleton()->get("application/boot_splash"); //avoid splash from being converted - splash=splash.strip_edges(); - if (splash!=String()) { - if (!splash.begins_with("res://")) - splash="res://"+splash; - splash=splash.simplify_path(); - boot_splash=splash; - } - } - StringName custom_cursor; - { - String splash=GlobalConfig::get_singleton()->get("display/custom_mouse_cursor"); //avoid splash from being converted - splash=splash.strip_edges(); - if (splash!=String()) { - if (!splash.begins_with("res://")) - splash="res://"+splash; - splash=splash.simplify_path(); - custom_cursor=splash; - } - } - - - - - for(int i=0;i buf; - - if (src==boot_splash || src==custom_cursor) - buf = get_exported_file_default(src); //bootsplash must be kept if used - else - buf = get_exported_file(src); - - ERR_CONTINUE( saved.has(src) ); - - Error err = p_func(p_udata,src,buf,counter++,files.size()); - if (err) - return err; - - saved.insert(src); - if (src!=String(files[i])) - remap_files[files[i]]=src; - - } - - - { - - //make binary godot.cfg config - Map custom; - - - if (remap_files.size()) { - Vector remapsprop; - for(Map::Element *E=remap_files.front();E;E=E->next()) { - print_line("REMAP: "+String(E->key())+" -> "+E->get()); - remapsprop.push_back(E->key()); - remapsprop.push_back(E->get()); - } - - custom["remap/all"]=remapsprop; - } - - //add presaved dependencies - for(Map >::Element *E=deps.front();E;E=E->next()) { - - if (E->get().size()==0) - continue; //no deps - String key; - Vector deps; - //if bundle continue (when bundles supported obviously) - - if (remap_files.has(E->key())) { - key=remap_files[E->key()]; - } else { - key=E->key(); - } - - deps.resize(E->get().size()); - int i=0; - - for(List::Element *F=E->get().front();F;F=F->next()) { - deps[i++]=F->get(); - print_line(" -"+String(F->get())); - } - - NodePath prop(deps,true,String()); //seems best to use this for performance - - custom["deps/"+key.md5_text()]=prop; - - } - - String remap_file="godot.cfb"; - String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+remap_file; - GlobalConfig::get_singleton()->save_custom(engine_cfb,custom); - Vector data = FileAccess::get_file_as_array(engine_cfb); - - Error err = p_func(p_udata,"res://"+remap_file,data,counter,files.size()); - if (err) - return err; - - } - - return OK; -} - -static int _get_pad(int p_alignment, int p_n) { - - int rest = p_n % p_alignment; - int pad = 0; - if (rest > 0) { - pad = p_alignment - rest; - }; - - return pad; -}; - -void EditorExportPlatform::gen_export_flags(Vector &r_flags, int p_flags) { - - String host = EditorSettings::get_singleton()->get("network/debug_host"); - - if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST) - host="localhost"; - - if (p_flags&EXPORT_DUMB_CLIENT) { - int port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); - String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password"); - r_flags.push_back("-rfs"); - r_flags.push_back(host+":"+itos(port)); - if (passwd!="") { - r_flags.push_back("-rfs_pass"); - r_flags.push_back(passwd); - } - } - - if (p_flags&EXPORT_REMOTE_DEBUG) { - - r_flags.push_back("-rdebug"); - - r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); - - List breakpoints; - ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); - - - if (breakpoints.size()) { - - r_flags.push_back("-bp"); - String bpoints; - for(const List::Element *E=breakpoints.front();E;E=E->next()) { - - bpoints+=E->get().replace(" ","%20"); - if (E->next()) - bpoints+=","; - } - - r_flags.push_back(bpoints); - } - - } - - if (p_flags&EXPORT_VIEW_COLLISONS) { - - r_flags.push_back("-debugcol"); - } - - if (p_flags&EXPORT_VIEW_NAVIGATION) { - - r_flags.push_back("-debugnav"); - } - - -} - -Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { - - - PackData *pd = (PackData*)p_userdata; - - CharString cs=p_path.utf8(); - pd->f->store_32(cs.length()); - pd->f->store_buffer((uint8_t*)cs.get_data(),cs.length()); - TempData td; - td.pos=pd->f->get_pos(); - td.ofs=pd->ftmp->get_pos(); - td.size=p_data.size(); - pd->file_ofs.push_back(td); - pd->f->store_64(0); //ofs - pd->f->store_64(0); //size - { - MD5_CTX ctx; - MD5Init(&ctx); - MD5Update(&ctx,(unsigned char*)p_data.ptr(),p_data.size()); - MD5Final(&ctx); - pd->f->store_buffer(ctx.digest,16); - } - pd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); - pd->count++; - pd->ftmp->store_buffer(p_data.ptr(),p_data.size()); - if (pd->alignment > 1) { - - int pad = _get_pad(pd->alignment, pd->ftmp->get_pos()); - for (int i=0; iftmp->store_8(0); - }; - }; - return OK; - -} - -Error EditorExportPlatform::save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total) { - - - String path=p_path.replace_first("res://",""); - - ZipData *zd = (ZipData*)p_userdata; - - zipFile zip=(zipFile)zd->zip; - - zipOpenNewFileInZip(zip, - path.utf8().get_data(), - NULL, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - - zipWriteInFileInZip(zip,p_data.ptr(),p_data.size()); - zipCloseFileInZip(zip); - - zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false); - zd->count++; - return OK; - -} - -Error EditorExportPlatform::save_zip(const String& p_path, bool p_make_bundles) { - - EditorProgress ep("savezip",TTR("Packing"),102); - - //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); - - FileAccess *src_f; - zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - zipFile zip=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io); - - ZipData zd; - zd.count=0; - zd.ep=&ep; - zd.zip=zip; - - - Error err = export_project_files(save_zip_file,&zd,p_make_bundles); - - zipClose(zip,NULL); - - return err; -} - -Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles, int p_alignment) { - - EditorProgress ep("savepack",TTR("Packing"),102); - - String tmppath = EditorSettings::get_singleton()->get_settings_path()+"/tmp/packtmp"; - FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); - uint64_t ofs_begin = dst->get_pos(); - - dst->store_32(0x43504447); //GDPK - dst->store_32(0); //pack version - dst->store_32(VERSION_MAJOR); - dst->store_32(VERSION_MINOR); - dst->store_32(0); //hmph - for(int i=0;i<16;i++) { - //reserved - dst->store_32(0); - } - - size_t fcountpos = dst->get_pos(); - dst->store_32(0); - - PackData pd; - pd.ep=&ep; - pd.f=dst; - pd.ftmp=tmp; - pd.count=0; - pd.alignment = p_alignment; - Error err = export_project_files(save_pack_file,&pd,p_make_bundles); - memdelete(tmp); - if (err) - return err; - - if (p_alignment > 1) { - int pad = _get_pad(p_alignment, dst->get_pos()); - for (int i=0; istore_8(0); - }; - }; - - size_t ofsplus = dst->get_pos(); - //append file - - tmp = FileAccess::open(tmppath,FileAccess::READ); - - ERR_FAIL_COND_V(!tmp,ERR_CANT_OPEN;) - const int bufsize=16384; - uint8_t buf[bufsize]; - - while(true) { - - int got = tmp->get_buffer(buf,bufsize); - if (got<=0) - break; - dst->store_buffer(buf,got); - } - - memdelete(tmp); - - dst->store_64(dst->get_pos()-ofs_begin); - dst->store_32(0x43504447); //GDPK - - //fix offsets - - dst->seek(fcountpos); - dst->store_32(pd.count); - for(int i=0;iseek(pd.file_ofs[i].pos); - dst->store_64(pd.file_ofs[i].ofs+ofsplus); - dst->store_64(pd.file_ofs[i].size); - } - - return OK; -} - -EditorExportPlatform::EditorExportPlatform() { - - debugging_enabled = true; -} - -Error EditorExportPlatformPC::export_project(const String& p_path, bool p_debug, int p_flags) { - - - - EditorProgress ep("export",vformat(TTR("Exporting for %s"),get_name()),102); - - const int BUFSIZE = 32768; - - - - ep.step(TTR("Setting Up.."),0); - - String exe_path=""; - - if (p_debug) - exe_path=custom_debug_binary; - else - exe_path=custom_release_binary; - - if (exe_path=="") { - String fname; - if (use64) { - if (p_debug) - fname=debug_binary64; - else - fname=release_binary64; - } else { - if (p_debug) - fname=debug_binary32; - else - fname=release_binary32; - } - String err=""; - exe_path=find_export_template(fname,&err); - if (exe_path=="") { - EditorNode::add_io_error(err); - return ERR_FILE_CANT_READ; - } - } - - FileAccess *src_exe=FileAccess::open(exe_path,FileAccess::READ); - if (!src_exe) { - - EditorNode::add_io_error("Couldn't read source executable at:\n "+exe_path); - return ERR_FILE_CANT_READ; - } - - FileAccess *dst=FileAccess::open(p_path,FileAccess::WRITE); - if (!dst) { - - EditorNode::add_io_error("Can't copy executable file to:\n "+p_path); - return ERR_FILE_CANT_WRITE; - } - - uint8_t buff[32768]; - - while(true) { - - int c = src_exe->get_buffer(buff,BUFSIZE); - if (c>0) { - - dst->store_buffer(buff,c); - } else { - break; - } - } - - String dstfile = p_path.replace_first("res://","").replace("\\","/"); - if (export_mode!=EXPORT_EXE) { - - String dstfile_extension=export_mode==EXPORT_ZIP?".zip":".pck"; - if (dstfile.find("/")!=-1) - dstfile=dstfile.get_base_dir()+"/data"+dstfile_extension; - else - dstfile="data"+dstfile_extension; - if (export_mode==EXPORT_PACK) { - - memdelete(dst); - - dst=FileAccess::open(dstfile,FileAccess::WRITE); - if (!dst) { - - EditorNode::add_io_error("Can't write data pack to:\n "+p_path); - return ERR_FILE_CANT_WRITE; - } - } - } - - - - memdelete(src_exe); - - Error err = export_mode==EXPORT_ZIP?save_zip(dstfile,bundle):save_pack(dst,bundle); - memdelete(dst); - return err; -} - -void EditorExportPlatformPC::set_binary_extension(const String& p_extension) { - - binary_extension=p_extension; -} - -bool EditorExportPlatformPC::can_export(String *r_error) const { - - String err; - bool valid=true; - - if (use64 && (!exists_export_template(debug_binary64) || !exists_export_template(release_binary64))) { - valid=false; - err="No 64 bits export templates found.\nDownload and install export templates.\n"; - } - - if (!use64 && (!exists_export_template(debug_binary32) || !exists_export_template(release_binary32))) { - valid=false; - err="No 32 bits export templates found.\nDownload and install export templates.\n"; - } - - if(custom_debug_binary=="" && custom_release_binary=="") { - if (r_error) *r_error=err; - return valid; - } - - bool dvalid = true; - bool rvalid = true; - - if(!FileAccess::exists(custom_debug_binary)) { - dvalid = false; - err = "Custom debug binary not found.\n"; - } - - if(!FileAccess::exists(custom_release_binary)) { - rvalid = false; - err = "Custom release binary not found.\n"; - } - - if (dvalid || rvalid) - valid = true; - else - valid = false; - - if (r_error) - *r_error=err; - return valid; -} - - -EditorExportPlatformPC::EditorExportPlatformPC() { - - export_mode=EXPORT_PACK; - use64=true; -} - - - - - - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////// - - -EditorImportExport* EditorImportExport::singleton=NULL; - -void EditorImportExport::add_import_plugin(const Ref& p_plugin) { - - // Need to make sure the name is unique if we are going to lookup by it - ERR_FAIL_COND(by_idx.has(p_plugin->get_name())); - - by_idx[ p_plugin->get_name() ]=plugins.size(); - plugins.push_back(p_plugin); -} - -void EditorImportExport::remove_import_plugin(const Ref& p_plugin) { - - String plugin_name = p_plugin->get_name(); - - // Keep the indices the same - // Find the index of the target plugin - ERR_FAIL_COND(!by_idx.has(plugin_name)); - int idx = by_idx[plugin_name]; - int last_idx = plugins.size() - 1; - - // Swap the last plugin and the target one - SWAP(plugins[idx], plugins[last_idx]); - - // Update the index of the old last one - by_idx[plugins[idx]->get_name()] = idx; - - // Remove the target plugin's by_idx entry - by_idx.erase(plugin_name); - - // Erase the plugin - plugins.remove(last_idx); -} - -int EditorImportExport::get_import_plugin_count() const{ - - return plugins.size(); -} -Ref EditorImportExport::get_import_plugin(int p_idx) const{ - - ERR_FAIL_INDEX_V(p_idx,plugins.size(),Ref()); - return plugins[p_idx]; - -} - - - -Ref EditorImportExport::get_import_plugin_by_name(const String& p_string) const{ - - ERR_FAIL_COND_V( !by_idx.has(p_string), Ref()); - return plugins[ by_idx[p_string] ]; -} - -void EditorImportExport::add_export_plugin(const Ref& p_plugin) { - - ERR_FAIL_COND( p_plugin.is_null() ); - - export_plugins.push_back(p_plugin); -} - -void EditorImportExport::remove_export_plugin(const Ref& p_plugin) { - - ERR_FAIL_COND( p_plugin.is_null() ); - export_plugins.erase(p_plugin); -} - -int EditorImportExport::get_export_plugin_count() const{ - - return export_plugins.size(); -} -Ref EditorImportExport::get_export_plugin(int p_idx) const{ - - ERR_FAIL_INDEX_V(p_idx,export_plugins.size(),Ref()); - return export_plugins[p_idx]; -} - -void EditorImportExport::set_export_file_action(const StringName& p_file, FileAction p_action) { - - if (p_action==ACTION_NONE) { - - files.erase(p_file); - } else { - - files[p_file]=p_action; - } - -} - -EditorImportExport::FileAction EditorImportExport::get_export_file_action(const StringName& p_file) const{ - - - if (files.has(p_file)) - return files[p_file]; - - - return ACTION_NONE; -} - -void EditorImportExport::get_export_file_list(List *p_files){ - - - for (Map::Element *E=files.front();E;E=E->next()) { - - p_files->push_back(E->key()); - } - -} - -void EditorImportExport::add_export_platform(const Ref& p_export) { - - exporters[p_export->get_name()]=p_export; -} - - -void EditorImportExport::get_export_platforms(List *r_platforms) { - - for (Map >::Element *E=exporters.front();E;E=E->next()) { - - r_platforms->push_back(E->key()); - } -} - -Ref EditorImportExport::get_export_platform(const StringName& p_platform) { - - if (exporters.has(p_platform)) { - return exporters[p_platform]; - } else { - return Ref(); - } -} - - -bool EditorImportExport::poll_export_platforms() { - - bool changed=false; - for (Map >::Element *E=exporters.front();E;E=E->next()) { - - if (E->get()->poll_devices()) - changed=true; - } - - return changed; - -} - -void EditorImportExport::set_export_filter(ExportFilter p_enable) { - - export_filter=p_enable; -} - -EditorImportExport::ExportFilter EditorImportExport::get_export_filter() const{ - - return export_filter; -} - -void EditorImportExport::set_export_custom_filter(const String& p_custom_filter){ - export_custom_filter=p_custom_filter; -} -void EditorImportExport::set_export_custom_filter_exclude(const String& p_custom_filter){ - export_custom_filter_exclude=p_custom_filter; -} -String EditorImportExport::get_export_custom_filter() const{ - return export_custom_filter; -} -String EditorImportExport::get_export_custom_filter_exclude() const{ - return export_custom_filter_exclude; -} - -void EditorImportExport::set_export_image_action(ImageAction p_action) { - - image_action=p_action; -} - -EditorImportExport::ImageAction EditorImportExport::get_export_image_action() const{ - - return image_action; -} - -void EditorImportExport::set_export_image_shrink(float p_shrink) { - - image_shrink=p_shrink; -} - -float EditorImportExport::get_export_image_shrink() const{ - - return image_shrink; -} - - -void EditorImportExport::set_export_image_quality(float p_quality){ - - image_action_compress_quality=p_quality; -} - -float EditorImportExport::get_export_image_quality() const{ - - return image_action_compress_quality; -} - -void EditorImportExport::image_export_group_create(const StringName& p_name) { - - ERR_FAIL_COND(image_groups.has(p_name)); - ImageGroup ig; - ig.action=IMAGE_ACTION_NONE; //default - ig.make_atlas=false; - ig.shrink=1; - ig.lossy_quality=0.7; - image_groups[p_name]=ig; - - -} - - -bool EditorImportExport::image_export_has_group(const StringName& p_name) const { - - return image_groups.has(p_name); -} -void EditorImportExport::image_export_get_groups(List *r_name) const { - - for (Map::Element *E=image_groups.front();E;E=E->next()) { - - r_name->push_back(E->key()); - } -} - -void EditorImportExport::image_export_group_remove(const StringName& p_name){ - - ERR_FAIL_COND(!image_groups.has(p_name)); - image_groups.erase(p_name); -} -void EditorImportExport::image_export_group_set_image_action(const StringName& p_export_group,ImageAction p_action){ - - ERR_FAIL_COND(!image_groups.has(p_export_group)); - image_groups[p_export_group].action=p_action; - -} -EditorImportExport::ImageAction EditorImportExport::image_export_group_get_image_action(const StringName& p_export_group) const{ - - ERR_FAIL_COND_V(!image_groups.has(p_export_group),IMAGE_ACTION_NONE); - return image_groups[p_export_group].action; - -} -void EditorImportExport::image_export_group_set_make_atlas(const StringName& p_export_group,bool p_make){ - - ERR_FAIL_COND(!image_groups.has(p_export_group)); - image_groups[p_export_group].make_atlas=p_make; - -} -bool EditorImportExport::image_export_group_get_make_atlas(const StringName& p_export_group) const{ - - ERR_FAIL_COND_V(!image_groups.has(p_export_group),false); - return image_groups[p_export_group].make_atlas; - -} -void EditorImportExport::image_export_group_set_shrink(const StringName& p_export_group,float p_amount){ - ERR_FAIL_COND(!image_groups.has(p_export_group)); - image_groups[p_export_group].shrink=p_amount; - -} -float EditorImportExport::image_export_group_get_shrink(const StringName& p_export_group) const{ - - ERR_FAIL_COND_V(!image_groups.has(p_export_group),1); - return image_groups[p_export_group].shrink; - -} - -void EditorImportExport::image_export_group_set_lossy_quality(const StringName& p_export_group,float p_amount){ - ERR_FAIL_COND(!image_groups.has(p_export_group)); - image_groups[p_export_group].lossy_quality=p_amount; - -} -float EditorImportExport::image_export_group_get_lossy_quality(const StringName& p_export_group) const{ - - ERR_FAIL_COND_V(!image_groups.has(p_export_group),1); - return image_groups[p_export_group].lossy_quality; - -} - -StringName EditorImportExport::image_get_export_group(const StringName& p_image) const { - - if (image_group_files.has(p_image)) - return image_group_files[p_image]; - else - return StringName(); - -} - -void EditorImportExport::image_add_to_export_group(const StringName& p_image,const StringName& p_export_group) { - - - bool emptygroup = String(p_export_group)==String(); - ERR_FAIL_COND(!emptygroup && !image_groups.has(p_export_group)); - - if (emptygroup) - image_group_files.erase(p_image); - else - image_group_files[p_image]=p_export_group; -} - -void EditorImportExport::image_export_get_images_in_group(const StringName& p_group,List *r_images) const { - - for (Map::Element *E=image_group_files.front();E;E=E->next()) { - - if (p_group==E->get()) - r_images->push_back(E->key()); - } -} - -void EditorImportExport::set_convert_text_scenes(bool p_convert) { - - convert_text_scenes=p_convert; -} - -bool EditorImportExport::get_convert_text_scenes() const{ - - return convert_text_scenes; -} - - -void EditorImportExport::load_config() { - - Ref cf = memnew( ConfigFile ); - - Error err = cf->load("res://export.cfg"); - if (err!=OK) - return; //no export config to be loaded! - - - export_custom_filter=cf->get_value("export_filter","filter"); - export_custom_filter_exclude=cf->get_value("export_filter","filter_exclude"); - String t=cf->get_value("export_filter","type"); - if (t=="selected") - export_filter=EXPORT_SELECTED; - else if (t=="resources") - export_filter=EXPORT_RESOURCES; - else if (t=="all") - export_filter=EXPORT_ALL; - - if (cf->has_section("convert_images")) { - - String ci = "convert_images"; - String action = cf->get_value(ci,"action"); - if (action=="none") - image_action=IMAGE_ACTION_NONE; - else if (action=="compress_ram") - image_action=IMAGE_ACTION_COMPRESS_RAM; - else if (action=="compress_disk") - image_action=IMAGE_ACTION_COMPRESS_DISK; - - image_action_compress_quality = cf->get_value(ci,"compress_quality"); - if (cf->has_section_key(ci,"shrink")) - image_shrink = cf->get_value(ci,"shrink"); - else - image_shrink=1; - String formats=cf->get_value(ci,"formats"); - Vector f = formats.split(","); - image_formats.clear(); - for(int i=0;ihas_section("convert_scenes")) { - - convert_text_scenes = cf->get_value("convert_scenes","convert_text_scenes"); - } - - - if (cf->has_section("export_filter_files")) { - - - String eff = "export_filter_files"; - List k; - cf->get_section_keys(eff,&k); - for(List::Element *E=k.front();E;E=E->next()) { - - String val = cf->get_value(eff,E->get()); - if (val=="copy") { - files[E->get()]=ACTION_COPY; - } else if (val=="bundle") { - files[E->get()]=ACTION_BUNDLE; - } - } - } - - List sect; - - cf->get_sections(§); - - for(List::Element *E=sect.front();E;E=E->next()) { - - String s = E->get(); - if (!s.begins_with("platform:")) - continue; - String p = s.substr(s.find(":")+1,s.length()); - - if (!exporters.has(p)) - continue; - - Ref ep = exporters[p]; - if (!ep.is_valid()) { - continue; - } - List keys; - cf->get_section_keys(s,&keys); - for(List::Element *F=keys.front();F;F=F->next()) { - ep->set(F->get(),cf->get_value(s,F->get())); - } - } - - //save image groups - - if (cf->has_section("image_groups")) { - - sect.clear(); - cf->get_section_keys("image_groups",§); - for(List::Element *E=sect.front();E;E=E->next()) { - - Dictionary d = cf->get_value("image_groups",E->get()); - ImageGroup g; - g.action=IMAGE_ACTION_NONE; - g.make_atlas=false; - g.lossy_quality=0.7; - g.shrink=1; - - if (d.has("action")) { - String action=d["action"]; - if (action=="compress_ram") - g.action=IMAGE_ACTION_COMPRESS_RAM; - else if (action=="compress_disk") - g.action=IMAGE_ACTION_COMPRESS_DISK; - else if (action=="keep") - g.action=IMAGE_ACTION_KEEP; - } - - if (d.has("atlas")) - g.make_atlas=d["atlas"]; - if (d.has("lossy_quality")) - g.lossy_quality=d["lossy_quality"]; - if (d.has("shrink")) { - - g.shrink=d["shrink"]; - g.shrink=CLAMP(g.shrink,1,8); - } - - image_groups[E->get()]=g; - - } - - if (cf->has_section_key("image_group_files","files")) { - - Vector sa=cf->get_value("image_group_files","files"); - if (sa.size()%2==0) { - for(int i=0;ihas_section("script")) { - - if (cf->has_section_key("script","action")) { - - String action = cf->get_value("script","action"); - if (action=="compile") - script_action=SCRIPT_ACTION_COMPILE; - else if (action=="encrypt") - script_action=SCRIPT_ACTION_ENCRYPT; - else - script_action=SCRIPT_ACTION_NONE; - - } - - if (cf->has_section_key("script","encrypt_key")) { - - script_key = cf->get_value("script","encrypt_key"); - } - } - - if (cf->has_section("convert_samples")) { - - if (cf->has_section_key("convert_samples","action")) { - String action = cf->get_value("convert_samples","action"); - if (action=="none") { - sample_action=SAMPLE_ACTION_NONE; - } else if (action=="compress_ram") { - sample_action=SAMPLE_ACTION_COMPRESS_RAM; - } - } - - if (cf->has_section_key("convert_samples","max_hz")) - sample_action_max_hz=cf->get_value("convert_samples","max_hz"); - - if (cf->has_section_key("convert_samples","trim")) - sample_action_trim=cf->get_value("convert_samples","trim"); - } - - - -} - - - - - -void EditorImportExport::save_config() { - - Ref cf = memnew( ConfigFile ); - - switch(export_filter) { - case EXPORT_SELECTED: cf->set_value("export_filter","type","selected"); break; - case EXPORT_RESOURCES: cf->set_value("export_filter","type","resources"); break; - case EXPORT_ALL: cf->set_value("export_filter","type","all"); break; - } - - cf->set_value("export_filter","filter",export_custom_filter); - cf->set_value("export_filter", "filter_exclude",export_custom_filter_exclude); - - String file_action_section = "export_filter_files"; - - for (Map::Element *E=files.front();E;E=E->next()) { - - String f=E->key(); - String a; - switch (E->get()) { - case ACTION_NONE: {} - case ACTION_COPY: a="copy"; break; - case ACTION_BUNDLE: a="bundle"; break; - } - - cf->set_value(file_action_section,f,a); - } - - - for (Map >::Element *E=exporters.front();E;E=E->next()) { - - String pname = "platform:"+String(E->key()); - - Ref ep = E->get(); - - List pl; - ep->get_property_list(&pl); - - for (List::Element *F=pl.front();F;F=F->next()) { - - cf->set_value(pname,F->get().name,ep->get(F->get().name)); - } - - } - - switch(image_action) { - case IMAGE_ACTION_NONE: cf->set_value("convert_images","action","none"); break; - case IMAGE_ACTION_COMPRESS_RAM: cf->set_value("convert_images","action","compress_ram"); break; - case IMAGE_ACTION_COMPRESS_DISK: cf->set_value("convert_images","action","compress_disk"); break; - } - - cf->set_value("convert_images","shrink",image_shrink); - cf->set_value("convert_images","compress_quality",image_action_compress_quality); - - String formats; - for(Set::Element *E=image_formats.front();E;E=E->next()) { - - if (E!=image_formats.front()) - formats+=","; - formats+=E->get(); - } - - cf->set_value("convert_images","formats",formats); - - //save image groups - - for(Map::Element *E=image_groups.front();E;E=E->next()) { - - Dictionary d; - switch(E->get().action) { - case IMAGE_ACTION_NONE: d["action"]="default"; break; - case IMAGE_ACTION_COMPRESS_RAM: d["action"]="compress_ram"; break; - case IMAGE_ACTION_COMPRESS_DISK: d["action"]="compress_disk"; break; - case IMAGE_ACTION_KEEP: d["action"]="keep"; break; - } - - - d["atlas"]=E->get().make_atlas; - d["shrink"]=E->get().shrink; - d["lossy_quality"]=E->get().lossy_quality; - cf->set_value("image_groups",E->key(),d); - - } - - if (image_groups.size() && image_group_files.size()){ - - Vector igfkeys; - igfkeys.resize(image_group_files.size()); - int idx=0; - for (Map::Element *E=image_group_files.front();E;E=E->next()) { - igfkeys[idx++]=E->key(); - } - igfkeys.sort(); - - Vector igfsave; - igfsave.resize(image_group_files.size()*2); - idx=0; - for (int i=0;iset_value("image_group_files","files",igfsave); - } - - switch(script_action) { - case SCRIPT_ACTION_NONE: cf->set_value("script","action","none"); break; - case SCRIPT_ACTION_COMPILE: cf->set_value("script","action","compile"); break; - case SCRIPT_ACTION_ENCRYPT: cf->set_value("script","action","encrypt"); break; - } - - cf->set_value("convert_scenes","convert_text_scenes",convert_text_scenes); - - cf->set_value("script","encrypt_key",script_key); - - switch(sample_action) { - case SAMPLE_ACTION_NONE: cf->set_value("convert_samples","action","none"); break; - case SAMPLE_ACTION_COMPRESS_RAM: cf->set_value("convert_samples","action","compress_ram"); break; - } - - cf->set_value("convert_samples","max_hz",sample_action_max_hz); - cf->set_value("convert_samples","trim",sample_action_trim); - - cf->save("res://export.cfg"); - -} - - -void EditorImportExport::script_set_action(ScriptAction p_action) { - - script_action=p_action; -} - -EditorImportExport::ScriptAction EditorImportExport::script_get_action() const{ - - return script_action; -} - -void EditorImportExport::script_set_encryption_key(const String& p_key){ - - script_key=p_key; -} -String EditorImportExport::script_get_encryption_key() const{ - - return script_key; -} - - -void EditorImportExport::sample_set_action(SampleAction p_action) { - - sample_action=p_action; -} - -EditorImportExport::SampleAction EditorImportExport::sample_get_action() const{ - - return sample_action; -} - -void EditorImportExport::sample_set_max_hz(int p_hz){ - - sample_action_max_hz=p_hz; -} -int EditorImportExport::sample_get_max_hz() const{ - - return sample_action_max_hz; -} - -void EditorImportExport::sample_set_trim(bool p_trim){ - - sample_action_trim=p_trim; -} -bool EditorImportExport::sample_get_trim() const{ - - return sample_action_trim; -} - -PoolVector EditorImportExport::_get_export_file_list() { - - PoolVector fl; - for (Map::Element *E=files.front();E;E=E->next()) { - - fl.push_back(E->key()); - } - - return fl; -} - -PoolVector EditorImportExport::_get_export_platforms() { - - PoolVector ep; - for (Map >::Element *E=exporters.front();E;E=E->next()) { - - ep.push_back(E->key()); - } - - return ep; - -} - -void EditorImportExport::_bind_methods() { - - ClassDB::bind_method(D_METHOD("add_import_plugin","plugin:EditorImportPlugin"),&EditorImportExport::add_import_plugin); - ClassDB::bind_method(D_METHOD("remove_import_plugin","plugin:EditorImportPlugin"),&EditorImportExport::remove_import_plugin); - ClassDB::bind_method(D_METHOD("get_import_plugin_count"),&EditorImportExport::get_import_plugin_count); - ClassDB::bind_method(D_METHOD("get_import_plugin:EditorImportPlugin","idx"),&EditorImportExport::get_import_plugin); - ClassDB::bind_method(D_METHOD("get_import_plugin_by_name:EditorImportPlugin","name"),&EditorImportExport::get_import_plugin_by_name); - - ClassDB::bind_method(D_METHOD("add_export_plugin","plugin:EditorExportPlugin"),&EditorImportExport::add_export_plugin); - ClassDB::bind_method(D_METHOD("remove_export_plugin","plugin:EditorExportPlugin"),&EditorImportExport::remove_export_plugin); - ClassDB::bind_method(D_METHOD("get_export_plugin_count"),&EditorImportExport::get_export_plugin_count); - ClassDB::bind_method(D_METHOD("get_export_plugin:EditorExportPlugin","idx"),&EditorImportExport::get_export_plugin); - - ClassDB::bind_method(D_METHOD("set_export_file_action","file","action"),&EditorImportExport::set_export_file_action); - ClassDB::bind_method(D_METHOD("get_export_file_action","file"),&EditorImportExport::get_export_file_action); - ClassDB::bind_method(D_METHOD("get_export_file_list"),&EditorImportExport::_get_export_file_list); - - ClassDB::bind_method(D_METHOD("add_export_platform","platform:EditorExportplatform"),&EditorImportExport::add_export_platform); - //ClassDB::bind_method(D_METHOD("remove_export_platform","platform:EditorExportplatform"),&EditorImportExport::add_export_platform); - ClassDB::bind_method(D_METHOD("get_export_platform:EditorExportPlatform","name"),&EditorImportExport::get_export_platform); - ClassDB::bind_method(D_METHOD("get_export_platforms"),&EditorImportExport::_get_export_platforms); - - ClassDB::bind_method(D_METHOD("set_export_filter","filter"),&EditorImportExport::set_export_filter); - ClassDB::bind_method(D_METHOD("get_export_filter"),&EditorImportExport::get_export_filter); - - ClassDB::bind_method(D_METHOD("set_export_custom_filter","filter"),&EditorImportExport::set_export_custom_filter); - ClassDB::bind_method(D_METHOD("get_export_custom_filter"),&EditorImportExport::get_export_custom_filter); - - ClassDB::bind_method(D_METHOD("set_export_custom_filter_exclude","filter_exclude"),&EditorImportExport::set_export_custom_filter_exclude); - ClassDB::bind_method(D_METHOD("get_export_custom_filter_exclude"),&EditorImportExport::get_export_custom_filter_exclude); - - - ClassDB::bind_method(D_METHOD("image_export_group_create"),&EditorImportExport::image_export_group_create); - ClassDB::bind_method(D_METHOD("image_export_group_remove"),&EditorImportExport::image_export_group_remove); - ClassDB::bind_method(D_METHOD("image_export_group_set_image_action"),&EditorImportExport::image_export_group_set_image_action); - ClassDB::bind_method(D_METHOD("image_export_group_set_make_atlas"),&EditorImportExport::image_export_group_set_make_atlas); - ClassDB::bind_method(D_METHOD("image_export_group_set_shrink"),&EditorImportExport::image_export_group_set_shrink); - ClassDB::bind_method(D_METHOD("image_export_group_get_image_action"),&EditorImportExport::image_export_group_get_image_action); - ClassDB::bind_method(D_METHOD("image_export_group_get_make_atlas"),&EditorImportExport::image_export_group_get_make_atlas); - ClassDB::bind_method(D_METHOD("image_export_group_get_shrink"),&EditorImportExport::image_export_group_get_shrink); - ClassDB::bind_method(D_METHOD("image_add_to_export_group"),&EditorImportExport::image_add_to_export_group); - ClassDB::bind_method(D_METHOD("script_set_action"),&EditorImportExport::script_set_action); - ClassDB::bind_method(D_METHOD("script_set_encryption_key"),&EditorImportExport::script_set_encryption_key); - ClassDB::bind_method(D_METHOD("script_get_action"),&EditorImportExport::script_get_action); - ClassDB::bind_method(D_METHOD("script_get_encryption_key"),&EditorImportExport::script_get_encryption_key); - - - - BIND_CONSTANT( ACTION_NONE ); - BIND_CONSTANT( ACTION_COPY ); - BIND_CONSTANT( ACTION_BUNDLE ); - - BIND_CONSTANT( EXPORT_SELECTED ); - BIND_CONSTANT( EXPORT_RESOURCES ); - BIND_CONSTANT( EXPORT_ALL ); - - BIND_CONSTANT( IMAGE_ACTION_NONE ); - BIND_CONSTANT( IMAGE_ACTION_COMPRESS_DISK ); - BIND_CONSTANT( IMAGE_ACTION_COMPRESS_RAM ); - BIND_CONSTANT( IMAGE_ACTION_KEEP ); - - BIND_CONSTANT( SCRIPT_ACTION_NONE ); - BIND_CONSTANT( SCRIPT_ACTION_COMPILE ); - BIND_CONSTANT( SCRIPT_ACTION_ENCRYPT ); -}; - - - -EditorImportExport::EditorImportExport() { - - export_filter=EXPORT_RESOURCES; - singleton=this; - image_action=IMAGE_ACTION_NONE; - image_action_compress_quality=0.7; - image_formats.insert("png"); - image_shrink=1; - - - script_action=SCRIPT_ACTION_COMPILE; - - sample_action=SAMPLE_ACTION_NONE; - sample_action_max_hz=44100; - sample_action_trim=false; - - convert_text_scenes=true; - -} - - - -EditorImportExport::~EditorImportExport() { - - - -} -#endif diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h deleted file mode 100644 index 364ac612a8..0000000000 --- a/tools/editor/editor_import_export.h +++ /dev/null @@ -1,199 +0,0 @@ -/*************************************************************************/ -/* editor_import_export.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EDITOR_IMPORT_EXPORT_H -#define EDITOR_IMPORT_EXPORT_H - - - -#include "resource.h" -#include "scene/main/node.h" -#include "scene/resources/texture.h" - -class EditorProgress; -class FileAccess; - -class EditorExportPreset : public Reference { - - GDCLASS( EditorExportPreset,Reference ) -public: - enum ExportFilter { - EXPORT_RESOURCES, - EXPORT_SELECTED, - EXPORT_ALL, - }; - -private: - - ExportFilter export_filter; - String exporter; - Set selected_files; - bool debug; - -friend class EditorExport; - - List properties; - Map values; - -protected: - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List *p_list) const; - -public: - - Vector get_files_to_export() const; - - - EditorExportPreset(); -}; - - -class EditorExportPlatform : public Reference { - - GDCLASS( EditorExportPlatform,Reference ) - -public: - - typedef Error (*EditorExportSaveFunction)(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); - -private: - - struct SavedData { - - String path; - uint64_t ofs; - uint64_t size; - }; - - struct PackData { - - FileAccess *f; - Vector file_ofs; - EditorProgress *ep; - }; - - struct ZipData { - - void* zip; - EditorProgress *ep; - int count; - - }; - - void gen_debug_flags(Vector &r_flags, int p_flags); - static Error _save_pack_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); - static Error _save_zip_file(void *p_userdata,const String& p_path, const Vector& p_data,int p_file,int p_total); - - -protected: - - virtual void get_preset_features(const Ref& p_preset,List r_features)=0; - String find_export_template(String template_file_name, String *err=NULL) const; - -public: - - - struct ExportOption { - PropertyInfo option; - Variant default_value; - - ExportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; } - ExportOption() {} - }; - - virtual void get_export_options(ExportOption *r_options)=0; - virtual Ref create_preset()=0; - virtual String get_name() const =0; - virtual Ref get_logo() const =0; - - - Error export_project_files(const Ref& p_preset,EditorExportSaveFunction p_func, void* p_udata); - - Error save_pack(const Ref& p_preset,FileAccess *p_where); - Error save_zip(const Ref& p_preset,const String& p_path); - - - virtual bool poll_devices() { return false; } - virtual int get_device_count() const { return 0; } - virtual String get_device_name(int p_device) const { return ""; } - virtual String get_device_info(int p_device) const { return ""; } - - enum DebugFlags { - DEBUG_FLAG_DUMB_CLIENT=1, - DEBUG_FLAG_REMOTE_DEBUG=2, - DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST=4, - DEBUG_FLAG_VIEW_COLLISONS=8, - DEBUG_FLAG_VIEW_NAVIGATION=16, - }; - - virtual Error run(int p_device,int p_debug_flags) { return OK; } - - virtual bool can_export(String *r_error=NULL) const=0; - - virtual String get_binary_extension() const=0; - virtual Error export_project(const Ref& p_preset,const String& p_path,int p_flags=0)=0; - - EditorExportPlatform(); -}; - - -class EditorExport : public Node { - GDCLASS(EditorExport,Node); - - Vector > export_platforms; - Vector > export_presets; - - static EditorExport *singleton; - -protected: - - - static void _bind_methods(); -public: - - void add_export_platform(const Ref& p_platform); - int get_export_platform_count(); - Ref get_export_platform(int p_idx); - - - void add_export_preset(const Ref& p_preset,int p_at_pos=-1); - int get_export_preset_count() const; - Ref get_export_preset(int p_idx); - void remove_export_preset(int p_idx); - - void load_config(); - void save_config(); - - EditorExport(); - ~EditorExport(); -}; - - - -#endif // EDITOR_IMPORT_EXPORT_H diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index da9138e5d9..f6e2d5f954 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -2209,25 +2209,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { case FILE_EXPORT_PROJECT: { - //project_export_settings->popup_export(); - /* - String target = export_db->get_current_platform(); - Ref exporter = export_db->get_exporter(target); - if (exporter.is_null()) { - accept->set_text("No exporter for platform '"+target+"' yet."); - accept->popup_centered(Size2(300,70)); - return; - } - - String extension = exporter->get_binary_extension(); - print_line("for target: "+target+" extension: "+extension); - file_export_password->set_editable( exporter->requieres_password(file_export_check->is_pressed())); - - file_export->clear_filters(); - if (extension!="") { - file_export->add_filter("*."+extension); - } - file_export->popup_centered_ratio();*/ + project_export->popup_export(); } break; case FILE_EXPORT_MESH_LIBRARY: { @@ -5236,6 +5218,9 @@ EditorNode::EditorNode() { EditorFileDialog::register_func=_editor_file_dialog_register; EditorFileDialog::unregister_func=_editor_file_dialog_unregister; + editor_export = memnew( EditorExport ); + add_child(editor_export); + register_exporters(); @@ -6156,8 +6141,8 @@ EditorNode::EditorNode() { //gui_base->add_child(optimized_save); //optimized_save->connect("confirmed",this,"_save_optimized"); - //project_export = memnew( ProjectExport(&editor_data) ); - //gui_base->add_child(project_export); + project_export = memnew( ProjectExportDialog ); + gui_base->add_child(project_export); //project_export_settings = memnew( ProjectExportDialog(this) ); //gui_base->add_child(project_export_settings); @@ -6302,6 +6287,7 @@ EditorNode::EditorNode() { + add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) ); add_editor_plugin( memnew( SpatialEditorPlugin(this) ) ); diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index 7ac2760a5c..41c1012ff0 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -73,7 +73,7 @@ #include "tools/editor/quick_open.h" #include "tools/editor/project_export.h" #include "tools/editor/editor_sub_scene.h" -#include "editor_import_export.h" +#include "editor_export.h" #include "editor_reimport_dialog.h" #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_name_dialog.h" @@ -365,7 +365,7 @@ private: String _tmp_import_path; - EditorImportExport *editor_import_export; + EditorExport *editor_export; Object *current; @@ -395,7 +395,7 @@ private: EditorRun editor_run; EditorSelection *editor_selection; // ProjectExport *project_export; -// ProjectExportDialog *project_export_settings; + ProjectExportDialog *project_export; EditorResourcePreview *resource_preview; EditorFileServer *file_server; diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index cf998dd55b..13d8ab0343 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -43,7 +43,7 @@ class EditorNode; class Spatial; class Camera; class EditorSelection; -class EditorImportExport; +class EditorExport; class EditorSettings; class SpatialEditorGizmo; class EditorImportPlugin; diff --git a/tools/editor/editor_run_native.cpp b/tools/editor/editor_run_native.cpp index 25cb41befc..60a9f53b94 100644 --- a/tools/editor/editor_run_native.cpp +++ b/tools/editor/editor_run_native.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "editor_run_native.h" -#include "editor_import_export.h" +#include "editor_export.h" void EditorRunNative::_notification(int p_what) { diff --git a/tools/editor/io_plugins/editor_export_scene.h b/tools/editor/io_plugins/editor_export_scene.h index 191029bd84..c067e835a3 100644 --- a/tools/editor/io_plugins/editor_export_scene.h +++ b/tools/editor/io_plugins/editor_export_scene.h @@ -29,7 +29,7 @@ #ifndef EDITOR_EXPORT_SCENE_H #define EDITOR_EXPORT_SCENE_H -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #if 0 class EditorSceneExportPlugin : public EditorExportPlugin { diff --git a/tools/editor/io_plugins/editor_font_import_plugin.h b/tools/editor/io_plugins/editor_font_import_plugin.h index a5b265736f..bed1463aeb 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.h +++ b/tools/editor/io_plugins/editor_font_import_plugin.h @@ -29,7 +29,7 @@ #ifndef EDITOR_FONT_IMPORT_PLUGIN_H #define EDITOR_FONT_IMPORT_PLUGIN_H -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "scene/resources/font.h" #if 0 class EditorNode; diff --git a/tools/editor/io_plugins/editor_translation_import_plugin.h b/tools/editor/io_plugins/editor_translation_import_plugin.h index 4884ea71c5..22065599b9 100644 --- a/tools/editor/io_plugins/editor_translation_import_plugin.h +++ b/tools/editor/io_plugins/editor_translation_import_plugin.h @@ -29,7 +29,7 @@ #ifndef EDITOR_TRANSLATION_IMPORT_PLUGIN_H #define EDITOR_TRANSLATION_IMPORT_PLUGIN_H -#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_export.h" #include "scene/resources/font.h" #if 0 class EditorNode; diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp index c760e45025..86324f1cac 100644 --- a/tools/editor/project_export.cpp +++ b/tools/editor/project_export.cpp @@ -27,7 +27,6 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "project_export.h" -#if 0 #include "os/dir_access.h" #include "os/file_access.h" #include "globals.h" @@ -37,6 +36,7 @@ #include "scene/gui/box_container.h" #include "scene/gui/tab_container.h" #include "scene/gui/scroll_container.h" +#include "scene/gui/margin_container.h" #include "editor_data.h" #include "io/image_loader.h" #include "compressed_translation.h" @@ -44,2087 +44,738 @@ #include "io_plugins/editor_texture_import_plugin.h" #include "editor_settings.h" -const char *ProjectExportDialog::da_string[ProjectExportDialog::ACTION_MAX]={ - "", - "Copy", - "Bundle" -}; - -bool ProjectExportDialog::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { - - TreeItem *item = tree->create_item(p_parent); - item->set_text(0,p_dir->get_name()+"/"); - item->set_icon(0,get_icon("Folder","EditorIcons")); - - - bool has_items=false; - - for(int i=0;iget_subdir_count();i++) { - - if (_create_tree(item,p_dir->get_subdir(i))) - has_items=true; - } - - //int cc = p_options.get_slice_count(","); - - for (int i=0;iget_file_count();i++) { - - TreeItem *fitem = tree->create_item(item); - //fitem->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); - //fitem->set_editable(0,true); - //fitem->set_checked(0,isfave); - fitem->set_text(0,p_dir->get_file(i)); - String path = p_dir->get_file_path(i); - fitem->set_tooltip(0,path); - fitem->set_metadata(0,path); - Ref icon = get_icon( (has_icon(p_dir->get_file_type(i),ei)?p_dir->get_file_type(i):ot),ei); - fitem->set_icon(0,icon); - - fitem->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); - fitem->set_range_config(1,0,2,1); - fitem->set_text(1,expopt); - fitem->set_editable(1,true); - - EditorImportExport::FileAction fa = EditorImportExport::get_singleton()->get_export_file_action(path); - fitem->set_range(1,fa); - - has_items=true; - - } - - if (!has_items) { - - memdelete(item); - return false; +void ProjectExportDialog::_notification(int p_what) { + if (p_what==NOTIFICATION_READY) { + delete_preset->set_icon(get_icon("Del","EditorIcons")); } - - return true; } -void ProjectExportDialog::_tree_changed() { - - TreeItem *t=tree->get_selected(); - if (!t) - return; - - String selected = t->get_metadata(0); - - EditorImportExport::get_singleton()->set_export_file_action(selected,EditorImportExport::FileAction(int(t->get_range(1)))); - _save_export_cfg(); - - //editor->save_import_export(true); - //EditorImportDB::get_singleton()->save_settings(); - -} - void ProjectExportDialog::popup_export() { - popup_centered_ratio(); - if (pending_update_tree) { - _update_tree(); - _update_group_tree(); - pending_update_tree=false; - } -} -void ProjectExportDialog::_update_tree() { + add_preset->get_popup()->clear(); + for(int i=0;iget_export_platform_count();i++) { + Ref plat = EditorExport::get_singleton()->get_export_platform(i); + add_preset->get_popup()->add_icon_item(plat->get_logo(),plat->get_name()); - updating_tree=true; - tree->clear(); - EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_filesystem(); - - if (efsd) { - _create_tree(NULL,efsd); } - updating_tree=false; + _update_presets(); + popup_centered_ratio(); } +void ProjectExportDialog::_add_preset(int p_platform) { + Ref preset = EditorExport::get_singleton()->get_export_platform(p_platform)->create_preset(); + ERR_FAIL_COND(!preset.is_valid()); + String name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name(); + bool make_runnable=true; + int attempt=1; + while(true) { -void ProjectExportDialog::_update_platform() { - - _validate_platform(); - TreeItem *selected = platforms->get_selected(); - if (!selected) - return; - - String platform = selected->get_metadata(0); - Ref exporter = EditorImportExport::get_singleton()->get_export_platform(platform); - platform_options->edit( exporter.ptr() ); -} - -void ProjectExportDialog::_platform_selected() { + bool valid=true; - String p =platforms->get_selected()->get_metadata(0); - _update_platform(); - //editor->save_import_export(); - //EditorFileSystem::get_singleton()->scan(); + for(int i=0;iget_export_preset_count();i++) { + Ref p = EditorExport::get_singleton()->get_export_preset(i); + if (p->get_platform()==preset->get_platform() && p->is_runnable()) { + make_runnable=false; + } + if (p->get_name()==name) { + valid=false; + break; + } -} + } -void ProjectExportDialog::_scan_finished() { + if (valid) + break; -/* print_line("**********SCAN DONEEE********"); - print_line("**********SCAN DONEEE********"); - print_line("**********SCAN DONEEE********"); - print_line("**********SCAN DONEEE********");*/ + attempt++; + name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name()+" "+itos(attempt); - if (!is_visible_in_tree()) { - pending_update_tree=true; - return; } - _update_tree(); - _update_group_tree(); + preset->set_name(name); + if (make_runnable) + preset->set_runnable(make_runnable); + EditorExport::get_singleton()->add_export_preset(preset); + _update_presets(); + _edit_preset(EditorExport::get_singleton()->get_export_preset_count()-1); + } -void ProjectExportDialog::_rescan() { - EditorFileSystem::get_singleton()->scan(); +void ProjectExportDialog::_update_presets() { -} + updating=true; -void ProjectExportDialog::_update_exporter() { + Ref current; + if (presets->get_current()>=0 && presets->get_current()get_item_count()) + current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + int current_idx=-1; + presets->clear(); + for(int i=0;iget_export_preset_count();i++) { + Ref preset = EditorExport::get_singleton()->get_export_preset(i); + if (preset==current) { + current_idx=i; + } -} + String name = preset->get_name(); + if (preset->is_runnable()) + name+=" ("+TTR("Runnable")+")"; + presets->add_item(name,preset->get_platform()->get_logo()); + } + if (current_idx!=-1) { + presets->select(current_idx); + //_edit_preset(current_idx); + } -void ProjectExportDialog::_save_export_cfg() { + updating=false; - EditorImportExport::get_singleton()->save_config(); } -void ProjectExportDialog::_prop_edited(String what) { +void ProjectExportDialog::_edit_preset(int p_index) { - _save_export_cfg(); + if (p_index<0 || p_index>=presets->get_item_count()) { + name->set_text(""); + name->set_editable(false); + runnable->set_disabled(true); + parameters->edit(NULL); + delete_preset->set_disabled(true); + sections->hide(); + patches->clear(); + return; + } - _validate_platform(); -} + Ref current = EditorExport::get_singleton()->get_export_preset(p_index); + ERR_FAIL_COND(current.is_null()); -void ProjectExportDialog::_filters_edited(String what) { - EditorImportExport::get_singleton()->set_export_custom_filter(what); - _save_export_cfg(); -} + updating=true; -void ProjectExportDialog::_filters_exclude_edited(String what) { - EditorImportExport::get_singleton()->set_export_custom_filter_exclude(what); - _save_export_cfg(); -} + presets->select(p_index); + sections->show(); + + name->set_editable(true); + delete_preset->set_disabled(false); + name->set_text(current->get_name()); + runnable->set_disabled(false); + runnable->set_pressed(current->is_runnable()); + parameters->edit(current.ptr()); + + export_filter->select(current->get_export_filter()); + include_filters->set_text(current->get_include_filter()); + exclude_filters->set_text(current->get_exclude_filter()); + + + patches->clear(); + TreeItem *patch_root = patches->create_item(); + Vector patchlist = current->get_patches(); + for(int i=0;icreate_item(patch_root); + patch->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); + String file = patchlist[i].get_file(); + patch->set_editable(0,true); + patch->set_text(0,file.get_file().replace("*","")); + if (file.ends_with("*")) + patch->set_checked(0,true); + patch->set_tooltip(0,patchlist[i]); + patch->set_metadata(0,i); + patch->add_button(0,get_icon("Del","EditorIcons"),0); + patch->add_button(0,get_icon("folder","FileDialog"),1); + } + + TreeItem *patch_add = patches->create_item(patch_root); + patch_add->set_metadata(0,patchlist.size()); + if (patchlist.size()==0) + patch_add->set_text(0,"Add initial export.."); + else + patch_add->set_text(0,"Add previous patches.."); -void ProjectExportDialog::_quality_edited(float what) { + patch_add->add_button(0,get_icon("folder","FileDialog"),1); - EditorImportExport::get_singleton()->set_export_image_quality(what); - _save_export_cfg(); -} + _fill_resource_tree(); -void ProjectExportDialog::_shrink_edited(float what) { + updating=false; - EditorImportExport::get_singleton()->set_export_image_shrink(what); - _save_export_cfg(); } -void ProjectExportDialog::_image_export_edited(int what) { +void ProjectExportDialog::_patch_button_pressed(Object* p_item,int p_column,int p_id) { - EditorImportExport::get_singleton()->set_export_image_action(EditorImportExport::ImageAction(what)); - _save_export_cfg(); -} -void ProjectExportDialog::_format_toggled() { + TreeItem *ti = (TreeItem*)p_item; - EditorImportExport::get_singleton()->get_image_formats().clear(); + patch_index=ti->get_metadata(0); - for(int i=0;iis_checked(0)) - EditorImportExport::get_singleton()->get_image_formats().insert( formats[i]->get_text(0)); + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); + if (p_id==0) { + Vector patches = current->get_patches(); + ERR_FAIL_INDEX(patch_index,patches.size()); + patch_erase->set_text(vformat(TTR("Delete patch '"+patches[patch_index].get_file()+"' from list?"))); + patch_erase->popup_centered_minsize(); + } else { + patch_dialog->popup_centered_ratio(); } - _save_export_cfg(); } +void ProjectExportDialog::_patch_edited() { -void ProjectExportDialog::_script_edited(Variant v) { - - if (updating_script) + TreeItem *item = patches->get_edited(); + if (!item) return; - updating_script=true; - EditorNode::get_undo_redo()->create_action(TTR("Edit Script Options")); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"script_set_action",script_mode->get_selected()); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"script_set_action",EditorImportExport::get_singleton()->script_get_action()); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"script_set_encryption_key",script_key->get_text()); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"script_set_encryption_key",EditorImportExport::get_singleton()->script_get_encryption_key()); - EditorNode::get_undo_redo()->add_do_method(this,"_update_script"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_script"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->commit_action(); - updating_script=false; - - -} - -void ProjectExportDialog::_sample_convert_edited(int what) { - EditorImportExport::get_singleton()->sample_set_action( EditorImportExport::SampleAction(sample_mode->get_selected())); - EditorImportExport::get_singleton()->sample_set_max_hz( sample_max_hz->get_value() ); - EditorImportExport::get_singleton()->sample_set_trim( sample_trim->is_pressed() ); - _save_export_cfg(); - -} - -void ProjectExportDialog::_notification(int p_what) { - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { + int index = item->get_metadata(0); + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); - CenterContainer *cc = memnew( CenterContainer ); - TextureRect *tf = memnew( TextureRect); - tf->set_texture(get_icon("ErrorSign","EditorIcons")); - cc->add_child(tf); - plat_errors->add_child(cc); - platform_error_string->raise(); + Vector patches = current->get_patches(); - TreeItem *root = platforms->create_item(NULL); - List ep; - EditorImportExport::get_singleton()->get_export_platforms(&ep); - ep.sort_custom(); + ERR_FAIL_INDEX(index,patches.size()); - for(List::Element *E=ep.front();E;E=E->next()) { + String patch = patches[index].replace("*",""); - - Ref eep = EditorImportExport::get_singleton()->get_export_platform(E->get()); - TreeItem *p = platforms->create_item(root); - p->set_text(0,eep->get_name()); - p->set_icon(0,eep->get_logo()); - p->set_metadata(0,eep->get_name()); - if (eep->get_name()==OS::get_singleton()->get_name()) - p->select(0); - - } - - EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_scan_finished"); - //_rescan(); - _update_platform(); - export_mode->select( EditorImportExport::get_singleton()->get_export_filter() ); - convert_text_scenes->set_pressed( EditorImportExport::get_singleton()->get_convert_text_scenes() ); - filters->set_text( EditorImportExport::get_singleton()->get_export_custom_filter() ); - filters_exclude->set_text( EditorImportExport::get_singleton()->get_export_custom_filter_exclude() ); - if (EditorImportExport::get_singleton()->get_export_filter()!=EditorImportExport::EXPORT_SELECTED) - tree_vb->hide(); - else - tree_vb->show(); - - image_action->select(EditorImportExport::get_singleton()->get_export_image_action()); - image_quality->set_value(EditorImportExport::get_singleton()->get_export_image_quality()); - image_shrink->set_value(EditorImportExport::get_singleton()->get_export_image_shrink()); - _update_script(); - - - image_quality->connect("value_changed",this,"_quality_edited"); - image_shrink->connect("value_changed",this,"_shrink_edited"); - image_action->connect("item_selected",this,"_image_export_edited"); - - script_mode->connect("item_selected",this,"_script_edited"); - script_key->connect("text_changed",this,"_script_edited"); - - for(int i=0;iget_image_formats().has(formats[i]->get_text(0))) - formats[i]->set_checked(0,true); - } - image_formats->connect("item_edited",this,"_format_toggled"); - group_add->set_icon(get_icon("Add","EditorIcons")); - //group_del->set_icon(get_icon("Del","EditorIcons")); - - _update_group_list(); - _update_group(); - _update_group_tree(); - - sample_mode->select( EditorImportExport::get_singleton()->sample_get_action() ); - sample_max_hz->set_value( EditorImportExport::get_singleton()->sample_get_max_hz() ); - sample_trim->set_pressed( EditorImportExport::get_singleton()->sample_get_trim() ); - - sample_mode->connect("item_selected",this,"_sample_convert_edited"); - sample_max_hz->connect("value_changed",this,"_sample_convert_edited"); - sample_trim->connect("toggled",this,"_sample_convert_edited"); - - - } break; - case NOTIFICATION_EXIT_TREE: { - - } break; - case MainLoop::NOTIFICATION_WM_FOCUS_IN: { - //something may have changed - _validate_platform(); - - } break; - case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible_in_tree()) - _validate_platform(); - - } break; - case NOTIFICATION_PROCESS: { - - } break; + if (item->is_checked(0)) { + patch+="*"; } -} + current->set_patch(index,patch); -void ProjectExportDialog::_validate_platform() { - get_ok()->set_disabled(true); - button_export->set_disabled(true); - TreeItem *selected = platforms->get_selected(); - plat_errors->hide(); - if (!selected) { - return; - } +} - String platform = selected->get_metadata(0); - Ref exporter = EditorImportExport::get_singleton()->get_export_platform(platform); - if (!exporter.is_valid()) { - return; - } +void ProjectExportDialog::_patch_selected(const String& p_path) { - String err; - if (!exporter->can_export(&err)) { - Vector items = err.strip_edges().split("\n"); - err=""; - for(int i=0;i current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); - platform_error_string->set_text(err); - plat_errors->show(); - return; - } + Vector patches = current->get_patches(); - List pl; - EditorFileSystem::get_singleton()->get_changed_sources(&pl); + if (patch_index >=patches.size()) { - if (false && pl.size()) { - if (pl.size()==1) - platform_error_string->set_text(" -One Resource is pending re-import."); - else - platform_error_string->set_text(" "+itos(pl.size())+" Resources are pending re-import."); + current->add_patch(GlobalConfig::get_singleton()->get_resource_path().path_to(p_path)+"*"); + } else { + String enabled = patches[patch_index].ends_with("*") ? String("*") : String(); + current->set_patch(patch_index,GlobalConfig::get_singleton()->get_resource_path().path_to(p_path)+enabled); - plat_errors->show(); - return; } - get_ok()->set_disabled(false); - button_export->set_disabled(false); + _edit_preset(presets->get_current()); } -void ProjectExportDialog::_export_mode_changed(int p_idx) { - - if (EditorImportExport::get_singleton()->get_export_filter()==p_idx) - return; - EditorImportExport::get_singleton()->set_export_filter(EditorImportExport::ExportFilter(p_idx)); +void ProjectExportDialog::_patch_deleted() { - if (p_idx!=EditorImportExport::EXPORT_SELECTED) - tree_vb->hide(); - else - tree_vb->show(); + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); - EditorImportExport::get_singleton()->set_convert_text_scenes( convert_text_scenes->is_pressed() ); + Vector patches = current->get_patches(); + if (patch_index remove_patch(patch_index); + _edit_preset(presets->get_current()); + } } -void ProjectExportDialog::_export_action(const String& p_file) { +void ProjectExportDialog::_runnable_pressed() { - String location = GlobalConfig::get_singleton()->globalize_path(p_file).get_base_dir().replace("\\","/"); + if (updating) + return; - while(true) { + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); - print_line("TESTING: "+location.plus_file("godot.cfg")); - if (FileAccess::exists(location.plus_file("godot.cfg"))) { + if (runnable->is_pressed()) { - error->set_text(TTR("Please export outside the project folder!")); - error->popup_centered_minsize(); - return; + for(int i=0;iget_export_preset_count();i++) { + Ref p = EditorExport::get_singleton()->get_export_preset(i); + if (p->get_platform()==current->get_platform()) { + p->set_runnable(current==p); + } } - String nl = (location+"/..").simplify_path(); - if (nl.find("/")==location.find_last("/")) - break; - location=nl; - } - - /* Checked if the export location is outside the project directory, - * now will check if a file name has been entered */ - if (p_file.ends_with("/")) { - - error->set_text("Please enter a file name!"); - error->popup_centered_minsize(); - return; - } - - TreeItem *selected = platforms->get_selected(); - if (!selected) - return; + } else { - String platform = selected->get_metadata(0); - bool debugging_enabled = EditorImportExport::get_singleton()->get_export_platform(platform)->is_debugging_enabled(); - Error err = export_platform(platform,p_file,debugging_enabled,file_export_password->get_text(),false); - if (err!=OK) { - error->set_text(TTR("Error exporting project!")); - error->popup_centered_minsize(); + current->set_runnable(false); } + _update_presets(); } -void ProjectExportDialog::_export_action_pck(const String& p_file) { +void ProjectExportDialog::_name_changed(const String& p_string) { - TreeItem *selected = platforms->get_selected(); - if (!selected) - return; - - Ref exporter = EditorImportExport::get_singleton()->get_export_platform(selected->get_metadata(0)); - if (exporter.is_null()) { - ERR_PRINT("Invalid platform for export of PCK"); + if (updating) return; - } - if (p_file.ends_with(".pck")) { - FileAccess *f = FileAccess::open(p_file,FileAccess::WRITE); - if (!f) { - error->set_text(TTR("Error writing the project PCK!")); - error->popup_centered_minsize(); - } - ERR_FAIL_COND(!f); - - Error err = exporter->save_pack(f,false); - memdelete(f); + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + ERR_FAIL_COND(current.is_null()); - if (err!=OK) { - error->set_text(TTR("Error exporting project!")); - error->popup_centered_minsize(); - return; - } - } else if (p_file.ends_with(".zip")) { + current->set_name(p_string); + _update_presets(); - Error err = exporter->save_zip(p_file,false); - if (err!=OK) { - error->set_text(TTR("Error exporting project!")); - error->popup_centered_minsize(); - return; - } - } } +void ProjectExportDialog::_delete_preset() { -Error ProjectExportDialog::export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password, bool p_quit_after) { - - Ref exporter = EditorImportExport::get_singleton()->get_export_platform(p_platform); - if (exporter.is_null()) { - ERR_PRINT("Invalid platform for export"); - - List platforms; - EditorImportExport::get_singleton()->get_export_platforms(&platforms); - print_line("Valid export plaftorms are:"); - for (List::Element *E=platforms.front();E;E=E->next()) - print_line(" \""+E->get()+"\""); - - if (p_quit_after) { - OS::get_singleton()->set_exit_code(255); - get_tree()->quit(); - } - - return ERR_INVALID_PARAMETER; - } - Error err = exporter->export_project(p_path,p_debug); - if (err!=OK) { - error->set_text(TTR("Error exporting project!")); - error->popup_centered_minsize(); - ERR_PRINT("Exporting failed!"); - if (p_quit_after) { - OS::get_singleton()->set_exit_code(255); - get_tree()->quit(); - } - return ERR_CANT_CREATE; - } else { - if (p_quit_after) { - get_tree()->quit(); - } - } + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + if (current.is_null()) + return; - return OK; + delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"),current->get_name())); + delete_confirm->popup_centered_minsize(); } -void ProjectExportDialog::ok_pressed() { - //export pck - pck_export->popup_centered_ratio(); +void ProjectExportDialog::_delete_preset_confirm() { + int idx = presets->get_current(); + parameters->edit(NULL);//to avoid crash + EditorExport::get_singleton()->remove_export_preset(idx); + _update_presets(); + _edit_preset(-1); } -void ProjectExportDialog::custom_action(const String&) { - //real export - - TreeItem *selected = platforms->get_selected(); - if (!selected) - return; - String platform = selected->get_metadata(0); - Ref exporter = EditorImportExport::get_singleton()->get_export_platform(platform); - if (exporter.is_null()) { - error->set_text(vformat(TTR("No exporter for platform '%s' yet."),platform)); - error->popup_centered_minsize(); - return; - } +Variant ProjectExportDialog::get_drag_data_fw(const Point2& p_point,Control* p_from) { - if (platform.to_lower()=="android" && _check_android_setting(exporter)==false){ - // not filled all field for Android release - return; - } + if (p_from==presets) { + int pos = presets->get_item_at_pos(p_point,true); - String extension = exporter->get_binary_extension(); + if (pos>=0) { + Dictionary d; + d["type"]="export_preset"; + d["preset"]=pos; - file_export_password->set_editable( exporter->requires_password(exporter->is_debugging_enabled()) ); + HBoxContainer *drag = memnew( HBoxContainer); + TextureRect *tr = memnew(TextureRect); + tr->set_texture(presets->get_item_icon(pos)); + drag->add_child(tr); + Label *label = memnew( Label ); + label->set_text(presets->get_item_text(pos)); + drag->add_child(label); - file_export->clear_filters(); - if (extension!="") { - file_export->add_filter("*."+extension); - } - file_export->popup_centered_ratio(); + set_drag_preview(drag); + return d; -} + } + } else if (p_from==patches) { -LineEdit* ProjectExportDialog::_create_keystore_input(Control* container, const String& p_label, const String& name) { + TreeItem *item = patches->get_item_at_pos(p_point); - HBoxContainer* hb=memnew(HBoxContainer); - Label* lb=memnew(Label); - LineEdit* input=memnew(LineEdit); + if (item && item->get_cell_mode(0)==TreeItem::CELL_MODE_CHECK) { - lb->set_text(p_label); - lb->set_custom_minimum_size(Size2(140*EDSCALE,0)); - lb->set_align(Label::ALIGN_RIGHT); + int metadata = item->get_metadata(0); + Dictionary d; + d["type"]="export_patch"; + d["patch"]=metadata; - input->set_custom_minimum_size(Size2(170*EDSCALE,0)); - input->set_name(name); + Label *label = memnew( Label ); + label->set_text(item->get_text(0)); + set_drag_preview(label); - hb->add_constant_override("separation", 10*EDSCALE); - hb->add_child(lb); - hb->add_child(input); - container->add_child(hb); + return d; + } - return input; + } + return Variant(); } -void ProjectExportDialog::_create_android_keystore_window() { - - keystore_file_dialog = memnew( EditorFileDialog ); - add_child(keystore_file_dialog); - keystore_file_dialog->set_mode(EditorFileDialog::MODE_OPEN_DIR); - keystore_file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - keystore_file_dialog->set_current_dir( "res://" ); - - keystore_file_dialog->set_title(TTR("Target Path:")); - keystore_file_dialog->connect("dir_selected", this,"_keystore_dir_selected"); - - keystore_create_dialog=memnew(ConfirmationDialog); - VBoxContainer* vb=memnew(VBoxContainer); - vb->set_size(Size2(340*EDSCALE,0)); - keystore_create_dialog->set_title(TTR("Create Android keystore")); - - _create_keystore_input(vb, TTR("Full name"), "name"); - _create_keystore_input(vb, TTR("Organizational unit"), "unit"); - _create_keystore_input(vb, TTR("Organization"), "org"); - _create_keystore_input(vb, TTR("City"), "city"); - _create_keystore_input(vb, TTR("State"), "state"); - _create_keystore_input(vb, TTR("2 letter country code"), "code"); - _create_keystore_input(vb, TTR("User alias"), "alias"); - LineEdit* pass=_create_keystore_input(vb, TTR("Password"), "pass"); - pass->set_placeholder(TTR("at least 6 characters")); - _create_keystore_input(vb, TTR("File name"), "file"); - - Label* lb_path=memnew(Label); - LineEdit* path=memnew(LineEdit); - Button* btn=memnew(Button); - HBoxContainer* hb=memnew(HBoxContainer); - - lb_path->set_text(TTR("Path : (better to save outside of project)")); - path->set_h_size_flags(SIZE_EXPAND_FILL); - path->set_name("path"); - btn->set_text(" .. "); - btn->connect("pressed", keystore_file_dialog, "popup_centered_ratio"); - - vb->add_spacer(); - vb->add_child(lb_path); - hb->add_child(path); - hb->add_child(btn); - vb->add_child(hb); - - keystore_create_dialog->add_child(vb); - //keystore_create_dialog->set_child_rect(vb); - add_child(keystore_create_dialog); - - keystore_create_dialog->connect("confirmed", this, "_create_android_keystore"); - path->connect("text_changed", this, "_check_keystore_path"); - - confirm_keystore = memnew(ConfirmationDialog); - confirm_keystore->connect("confirmed", keystore_create_dialog, "popup_centered_minsize"); - add_child(confirm_keystore); +bool ProjectExportDialog::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ -} + if (p_from==presets) { + Dictionary d = p_data; + if (!d.has("type") || String(d["type"])!="export_preset") + return false; -void ProjectExportDialog::_keystore_dir_selected(const String& path) { - LineEdit* edit=keystore_create_dialog->find_node("path", true, false)->cast_to(); - edit->set_text(path.simplify_path()); + if (presets->get_item_at_pos(p_point,true)<0 && !presets->is_pos_at_end_of_items(p_point)) + return false; + } else if (p_from==patches) { -} + Dictionary d = p_data; + if (!d.has("type") || String(d["type"])!="export_patch") + return false; -void ProjectExportDialog::_keystore_created() { + patches->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); - if (error->is_connected("popup_hide", this, "_keystore_created")){ - error->disconnect("popup_hide", this, "_keystore_created"); - } - custom_action("export_pck"); + TreeItem *item = patches->get_item_at_pos(p_point); -} + if (!item) { -void ProjectExportDialog::_check_keystore_path(const String& path) { + return false; + } - LineEdit* edit=keystore_create_dialog->find_node("path", true, false)->cast_to(); - bool exists = DirAccess::exists(path); - if (!exists) { - edit->add_color_override("font_color", Color(1,0,0,1)); - } else { - edit->add_color_override("font_color", Color(0,1,0,1)); } + return true; } -void ProjectExportDialog::_create_android_keystore() { - - Vector names=String("name,unit,org,city,state,code,alias,pass").split(","); - String path=keystore_create_dialog->find_node("path", true, false)->cast_to()->get_text(); - String file=keystore_create_dialog->find_node("file", true, false)->cast_to()->get_text(); - - if (file.ends_with(".keystore")==false) { - file+=".keystore"; - } - String fullpath=path.plus_file(file); - String info="CN=$name, OU=$unit, O=$org, L=$city, S=$state, C=$code"; - Dictionary dic; - - for (int i=0;ifind_node(names[i], true, false)->cast_to(); - dic[names[i]]=edit->get_text(); - info=info.replace("$"+names[i], edit->get_text()); - } - - String jarsigner=EditorSettings::get_singleton()->get("export/android/jarsigner"); - String keytool=jarsigner.get_base_dir().plus_file("keytool"); - String os_name=OS::get_singleton()->get_name(); - if (os_name.to_lower()=="windows") { - keytool+=".exe"; - } - - bool exist=FileAccess::exists(keytool); - if (!exist) { - error->set_text("Can't find 'keytool'"); - error->popup_centered_minsize(); - return; - } - - List args; - args.push_back("-genkey"); - args.push_back("-v"); - args.push_back("-keystore"); - args.push_back(fullpath); - args.push_back("-alias"); - args.push_back(dic["alias"]); - args.push_back("-storepass"); - args.push_back(dic["pass"]); - args.push_back("-keypass"); - args.push_back(dic["pass"]); - args.push_back("-keyalg"); - args.push_back("RSA"); - args.push_back("-keysize"); - args.push_back("2048"); - args.push_back("-validity"); - args.push_back("10000"); - args.push_back("-dname"); - args.push_back(info); - int retval; - OS::get_singleton()->execute(keytool,args,true,NULL,NULL,&retval); - - if (retval==0) { // success - platform_options->_edit_set("keystore/release", fullpath); - platform_options->_edit_set("keystore/release_user", dic["alias"]); - platform_options->_edit_set("keystore/release_password", dic["pass"]); - - error->set_text("Android keystore created at \n"+fullpath); - error->connect("popup_hide", this, "_keystore_created"); - error->popup_centered_minsize(); - } else { // fail - error->set_text("Fail to create android keystore at \n"+fullpath); - error->popup_centered_minsize(); - } - -} +void ProjectExportDialog::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ -bool ProjectExportDialog::_check_android_setting(const Ref& exporter) { + if (p_from==presets) { + Dictionary d=p_data; + int from_pos = d["preset"]; - bool is_debugging = exporter->get("debug/debugging_enabled"); - String release = exporter->get("keystore/release"); - String user = exporter->get("keystore/release_user"); - String password = exporter->get("keystore/release_password"); + int to_pos=-1; - if (!is_debugging && (release=="" || user=="" || password=="")){ - if (release==""){ - confirm_keystore->set_text(TTR("Release keystore is not set.\nDo you want to create one?")); - confirm_keystore->popup_centered_minsize(); - } else { - error->set_text(TTR("Fill Keystore/Release User and Release Password")); - error->popup_centered_minsize(); + if (presets->get_item_at_pos(p_point,true)>=0) { + to_pos = presets->get_item_at_pos(p_point,true); } - return false; - } - - return true; - -} - -void ProjectExportDialog::_group_selected() { + if (to_pos==-1 && !presets->is_pos_at_end_of_items(p_point)) + return; - _update_group(); //? + if (to_pos==from_pos) + return; + else if (to_pos>from_pos) { + to_pos--; + } - _update_group_tree(); -} -String ProjectExportDialog::_get_selected_group() { + Ref preset = EditorExport::get_singleton()->get_export_preset(from_pos); + EditorExport::get_singleton()->remove_export_preset(from_pos); + EditorExport::get_singleton()->add_export_preset(preset,to_pos); - TreeItem *sel = groups->get_selected(); - if (!sel) - return String(); + _update_presets(); + if (to_pos>=0) + _edit_preset(to_pos); + else + _edit_preset(presets->get_item_count()-1); + } else if (p_from==patches) { - return sel->get_text(0); + Dictionary d = p_data; + if (!d.has("type") || String(d["type"])!="export_patch") + return; + int from_pos = d["patch"]; -} + TreeItem *item = patches->get_item_at_pos(p_point); + if (!item) + return; -void ProjectExportDialog::_update_group_list() { + int to_pos = item->get_cell_mode(0)==TreeItem::CELL_MODE_CHECK ? int(item->get_metadata(0)) : -1; - String current = _get_selected_group(); + if (to_pos==from_pos) + return; + else if (to_pos>from_pos) { + to_pos--; + } - groups->clear(); - List grouplist; - EditorImportExport::get_singleton()->image_export_get_groups(&grouplist); - grouplist.sort_custom(); + Ref preset = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + String patch = preset->get_patch(from_pos); + preset->remove_patch(from_pos); + preset->add_patch(patch,to_pos); - TreeItem *r = groups->create_item(); - for (List::Element *E=grouplist.front();E;E=E->next()) { + _edit_preset(presets->get_current()); - TreeItem *ti = groups->create_item(r); - ti->set_text(0,E->get()); - ti->add_button(0,get_icon("Remove","EditorIcons")); - if (E->get()==current) { - ti->select(0); - } } - _update_group(); } -void ProjectExportDialog::_select_group(const String& p_by_name) { +void ProjectExportDialog::_export_type_changed(int p_which) { - TreeItem *c = groups->get_root(); - if (!c) + if (updating) return; - c=c->get_children(); - if (!c) + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + if (current.is_null()) return; - while(c) { + current->set_export_filter(EditorExportPreset::ExportFilter(p_which)); + updating=true; + _fill_resource_tree(); + updating=false; - if (c->get_text(0)==p_by_name) { - c->select(0); - _update_group(); - return; - } - c=c->get_next(); - } } -void ProjectExportDialog::_update_group() { +void ProjectExportDialog::_filter_changed(const String& p_filter) { if (updating) return; - updating=true; + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + if (current.is_null()) + return; - if (_get_selected_group()=="") { - group_options->hide(); - //group_del->set_disabled(true); - - } else { - group_options->show(); - //group_del->set_disabled(false); - StringName name = _get_selected_group(); - group_image_action->select(EditorImportExport::get_singleton()->image_export_group_get_image_action(name)); - group_atlas->set_pressed(EditorImportExport::get_singleton()->image_export_group_get_make_atlas(name)); - group_shrink->set_value(EditorImportExport::get_singleton()->image_export_group_get_shrink(name)); - group_lossy_quality->set_value(EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(name)); - if (group_atlas->is_pressed()) - atlas_preview->show(); - else - atlas_preview->hide(); + current->set_include_filter(include_filters->get_text()); + current->set_exclude_filter(exclude_filters->get_text()); - } - _update_group_tree(); - updating=false; +} +void ProjectExportDialog::_fill_resource_tree() { -} + include_files->clear(); + include_label->hide(); + include_margin->hide(); -bool ProjectExportDialog::_update_group_treef(TreeItem *p_parent,EditorFileSystemDirectory *p_dir,const Set& p_extensions,const String& p_groups,const Map& p_group_index) { + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + if (current.is_null()) + return; - TreeItem *ti = group_images->create_item(p_parent); - ti->set_text(0,p_dir->get_name()+"/"); - bool has_child=false; - for(int i=0;iget_subdir_count();i++) { + EditorExportPreset::ExportFilter f = current->get_export_filter(); - if (_update_group_treef(ti,p_dir->get_subdir(i),p_extensions,p_groups,p_group_index)) { - has_child=true; - } + if (f==EditorExportPreset::EXPORT_ALL_RESOURCES || f==EditorExportPreset::EXPORT_ALL_FILES) { + return; } - String filter=group_images_filter->get_text(); - StringName current_group = _get_selected_group(); - String check_text=TTR("Include"); + include_label->show(); + include_margin->show(); - for(int i=0;iget_file_count();i++) { + TreeItem *root = include_files->create_item(); - String fname = p_dir->get_file(i); - if (p_extensions.has(fname.to_lower().get_extension())) { - String path = p_dir->get_file_path(i); - if (filter!=String() && path.find(filter)==-1) - continue; + _fill_tree(EditorFileSystem::get_singleton()->get_filesystem(),root,current,f==EditorExportPreset::EXPORT_SELECTED_SCENES); - has_child=true; - TreeItem *file = group_images->create_item(ti); - file->set_text(0,fname); +} - StringName g = EditorImportExport::get_singleton()->image_get_export_group(path); - if (current_group==g || g==StringName()) { +bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir,TreeItem *p_item,Ref ¤t,bool p_only_scenes) { - file->set_cell_mode(1,TreeItem::CELL_MODE_CHECK); - file->set_text(1,check_text); - file->set_editable(1,true); - file->set_checked(1,current_group==g); - } else { + p_item->set_icon(0,get_icon("folder","FileDialog")); + p_item->set_text(0,p_dir->get_name()+"/"); - file->set_text(1,g); - file->set_editable(1,false); - file->set_selectable(1,false); - } + bool used=false; + for(int i=0;iget_subdir_count();i++) { - file->set_metadata(0,path); + TreeItem *subdir = include_files->create_item(p_item); + if (_fill_tree(p_dir->get_subdir(i),subdir,current,p_only_scenes)==false) { + memdelete(subdir); + } else { + used=true; } } - if (!has_child) { - memdelete(ti); - return false; - } - - return true; - -} -void ProjectExportDialog::_update_group_tree() { - if (updating) - return; - group_images->clear(); + for(int i=0;iget_file_count();i++) { - if (_get_selected_group()=="") - return; + String type = p_dir->get_file_type(i); + if (p_only_scenes && type!="PackedScene") + continue; - updating=true; - print_line("****UGT"); - List img_extensions; - ImageLoader::get_recognized_extensions(&img_extensions); - Set extensions; - for(List::Element *E=img_extensions.front();E;E=E->next()) { + TreeItem *file = include_files->create_item(p_item); + file->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); + file->set_text(0,p_dir->get_file(i)); - extensions.insert(E->get()); - } + Ref tex; + if (has_icon(type,editor_icons)) { + tex = get_icon(type,editor_icons); + } else { + tex = get_icon("Object",editor_icons); + } - List grouplist; - EditorImportExport::get_singleton()->image_export_get_groups(&grouplist); - grouplist.sort_custom(); - Map group_index; - group_index[StringName()]=0; - int idx=1; - String groupenum="--"; - for(List::Element *E=grouplist.front();E;E=E->next()) { - - group_index[E->get()]=idx++; - groupenum+=","+String(E->get()); - } + String path = p_dir->get_file_path(i); - updating=false; + file->set_icon(0,tex); + file->set_editable(0,true); + file->set_checked(0,current->has_export_file(path)); + file->set_metadata(0,path); + used=true; - _update_group_treef(NULL,EditorFileSystem::get_singleton()->get_filesystem(),extensions,groupenum,group_index); + } + return used; } -void ProjectExportDialog::_group_changed(Variant v) { +void ProjectExportDialog::_tree_changed() { if (updating) return; - if (_get_selected_group()=="") - return; - updating=true; - StringName name = _get_selected_group(); - EditorNode::get_undo_redo()->create_action(TTR("Change Image Group")); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_set_image_action",name,group_image_action->get_selected()); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_set_make_atlas",name,group_atlas->is_pressed()); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_set_shrink",name,group_shrink->get_value()); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_set_lossy_quality",name,group_lossy_quality->get_value()); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_image_action",name,EditorImportExport::get_singleton()->image_export_group_get_image_action(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_make_atlas",name,EditorImportExport::get_singleton()->image_export_group_get_make_atlas(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_shrink",name,EditorImportExport::get_singleton()->image_export_group_get_shrink(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_lossy_quality",name,EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(name)); - EditorNode::get_undo_redo()->add_do_method(this,"_update_group"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->commit_action(); - updating=false; - // update atlas preview button - _update_group(); -} -void ProjectExportDialog::_group_item_edited() { + Ref current = EditorExport::get_singleton()->get_export_preset(presets->get_current()); + if (current.is_null()) + return; - TreeItem *item = group_images->get_edited(); + TreeItem *item = include_files->get_edited(); if (!item) return; - if (_get_selected_group()==String()) - return; - StringName path = item->get_metadata(0); - String group; - if (item->is_checked(1)) { - group=_get_selected_group(); - } else { - group=String(); - } + String path = item->get_metadata(0); + bool added = item->is_checked(0); - print_line("changed "+path+" to group: "+group); - EditorNode::get_undo_redo()->create_action(TTR("Change Image Group")); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_add_to_export_group",path,group); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_add_to_export_group",path,EditorImportExport::get_singleton()->image_get_export_group(path)); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->commit_action(); + if (added) { + current->add_export_file(path); + } else { + current->remove_export_file(path); + } } -void ProjectExportDialog::_group_add() { +void ProjectExportDialog::_bind_methods() { - String name = group_new_name->get_text(); + ClassDB::bind_method("_add_preset",&ProjectExportDialog::_add_preset); + ClassDB::bind_method("_edit_preset",&ProjectExportDialog::_edit_preset); + ClassDB::bind_method("_runnable_pressed",&ProjectExportDialog::_runnable_pressed); + ClassDB::bind_method("_name_changed",&ProjectExportDialog::_name_changed); + ClassDB::bind_method("_delete_preset",&ProjectExportDialog::_delete_preset); + ClassDB::bind_method("_delete_preset_confirm",&ProjectExportDialog::_delete_preset_confirm); + ClassDB::bind_method("get_drag_data_fw",&ProjectExportDialog::get_drag_data_fw); + ClassDB::bind_method("can_drop_data_fw",&ProjectExportDialog::can_drop_data_fw); + ClassDB::bind_method("drop_data_fw",&ProjectExportDialog::drop_data_fw); + ClassDB::bind_method("_export_type_changed",&ProjectExportDialog::_export_type_changed); + ClassDB::bind_method("_filter_changed",&ProjectExportDialog::_filter_changed); + ClassDB::bind_method("_tree_changed",&ProjectExportDialog::_tree_changed); + ClassDB::bind_method("_patch_button_pressed",&ProjectExportDialog::_patch_button_pressed); + ClassDB::bind_method("_patch_selected",&ProjectExportDialog::_patch_selected); + ClassDB::bind_method("_patch_deleted",&ProjectExportDialog::_patch_deleted); + ClassDB::bind_method("_patch_edited",&ProjectExportDialog::_patch_edited); + + + + +} +ProjectExportDialog::ProjectExportDialog() { + + HBoxContainer *hbox = memnew( HBoxContainer ); + add_child(hbox); + + VBoxContainer *preset_vb = memnew( VBoxContainer ); + preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hbox->add_child(preset_vb); + + HBoxContainer *preset_hb = memnew( HBoxContainer ); + preset_hb->add_child(memnew(Label(TTR("Presets")))); + preset_hb->add_spacer(); + preset_vb->add_child(preset_hb); + + add_preset = memnew( MenuButton ); + add_preset->set_text(TTR("Add..")); + add_preset->get_popup()->connect("index_pressed",this,"_add_preset"); + preset_hb->add_child(add_preset); + MarginContainer *mc = memnew( MarginContainer ); + preset_vb->add_child(mc); + mc->set_v_size_flags(SIZE_EXPAND_FILL); + presets = memnew( ItemList ); + presets->set_drag_forwarding(this); + mc->add_child(presets); + presets->connect("item_selected",this,"_edit_preset"); + delete_preset = memnew( ToolButton ); + preset_hb->add_child(delete_preset); + delete_preset->connect("pressed",this,"_delete_preset"); + + VBoxContainer *settings_vb = memnew( VBoxContainer ); + settings_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hbox->add_child(settings_vb); + + name = memnew(LineEdit); + settings_vb->add_margin_child(TTR("Name:"),name); + name->connect("text_changed",this,"_name_changed"); + runnable = memnew(CheckButton); + runnable->set_text(TTR("Runnable")); + runnable->connect("pressed",this,"_runnable_pressed"); + settings_vb->add_child(runnable); + + sections = memnew (TabContainer ); + settings_vb->add_child(sections); + sections->set_v_size_flags(SIZE_EXPAND_FILL); + + parameters = memnew (PropertyEditor ); + sections->add_child(parameters); + parameters->set_name(TTR("Options")); + parameters->hide_top_label(); + parameters->set_v_size_flags(SIZE_EXPAND_FILL); + parameters->set_hide_script(true); + + VBoxContainer *resources_vb = memnew( VBoxContainer ); + sections->add_child(resources_vb); + resources_vb->set_name(TTR("Resources")); + + export_filter = memnew( OptionButton ); + export_filter->add_item(TTR("Export all resources in the project")); + export_filter->add_item(TTR("Export selected scenes (and dependencies)")); + export_filter->add_item(TTR("Export selected resources (and dependencies)")); + export_filter->add_item(TTR("Export all files in the project directory")); + resources_vb->add_margin_child(TTR("Export Mode:"),export_filter); + export_filter->connect("item_selected",this,"_export_type_changed"); + + include_label = memnew( Label ); + include_label->set_text(TTR("Resources to export:")); + resources_vb->add_child(include_label); + include_margin = memnew( MarginContainer ); + include_margin->set_v_size_flags(SIZE_EXPAND_FILL); + resources_vb->add_child(include_margin); + + include_files = memnew(Tree); + include_margin->add_child(include_files); + include_files->connect("item_edited",this,"_tree_changed"); + + include_filters = memnew( LineEdit ); + resources_vb->add_margin_child(TTR("Filters to export non-resource files (comma separated, e.g: *.json, *.txt)"),include_filters); + include_filters->connect("text_changed",this,"_filter_changed"); + + exclude_filters = memnew( LineEdit ); + resources_vb->add_margin_child(TTR("Filters to exclude files from project (comma separated, e.g: *.json, *.txt)"),exclude_filters); + exclude_filters->connect("text_changed",this,"_filter_changed"); + + VBoxContainer *patch_vb = memnew( VBoxContainer ); + sections->add_child(patch_vb); + patch_vb->set_name(TTR("Patches")); + + patches = memnew( Tree ); + patch_vb->add_child(patches); + patches->set_v_size_flags(SIZE_EXPAND_FILL); + patches->set_hide_root(true); + patches->connect("button_pressed",this,"_patch_button_pressed"); + patches->connect("item_edited",this,"_patch_edited"); + patches->set_drag_forwarding(this); + patches->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); + + HBoxContainer *patches_hb = memnew( HBoxContainer ); + patch_vb->add_child(patches_hb); + patches_hb->add_spacer(); + patch_export = memnew( Button ); + patch_export->set_text(TTR("Make Patch")); + patches_hb->add_child(patch_export); + patches_hb->add_spacer(); + + patch_dialog = memnew( FileDialog ); + patch_dialog->add_filter("*.pck ; Pack File"); + patch_dialog->set_mode(FileDialog::MODE_OPEN_FILE); + patch_dialog->connect("file_selected",this,"_patch_selected"); + add_child(patch_dialog); + + patch_erase = memnew( ConfirmationDialog ); + patch_erase->get_ok()->set_text(TTR("Delete")); + patch_erase->connect("confirmed",this,"_patch_deleted"); + add_child(patch_erase); + + + //disable by default + name->set_editable(false); + runnable->set_disabled(true); + delete_preset->set_disabled(true); + sections->hide(); + parameters->edit(NULL); + + delete_confirm = memnew( ConfirmationDialog ); + add_child(delete_confirm); + delete_confirm->get_ok()->set_text(TTR("Delete")); + delete_confirm->connect("confirmed",this,"_delete_preset_confirm"); - if (name=="") { - group_new_name_error->show(); - group_new_name_error->set_text(TTR("Group name can't be empty!")); - return; - } - if (name.find("/")!=-1 || name.find(":")!=-1 || name.find(",")!=-1 || name.find("-")!=-1) { - group_new_name_error->set_text(TTR("Invalid character in group name!")); - group_new_name_error->show(); - return; - } + updating=false; - if (EditorImportExport::get_singleton()->image_export_has_group(name)) { - group_new_name_error->set_text(TTR("Group name already exists!")); - group_new_name_error->show(); - return; - } - group_new_name_error->hide(); + get_ok()->set_text("Export PCK/Zip"); + add_button("Export Project",!OS::get_singleton()->get_swap_ok_cancel(),"export"); - String current=_get_selected_group(); - - - EditorNode::get_undo_redo()->create_action(TTR("Add Image Group")); - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_create",name); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_remove",name); - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_list"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_list"); - EditorNode::get_undo_redo()->add_do_method(this,"_select_group",name); - if (current!="") - EditorNode::get_undo_redo()->add_undo_method(this,"_select_group",current); - - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - - EditorNode::get_undo_redo()->commit_action(); - -} - - -void ProjectExportDialog::_group_del(Object *p_item, int p_column, int p_button){ - - TreeItem *item = p_item->cast_to(); - if (!item) - return; - String name = item->get_text(0); - - EditorNode::get_undo_redo()->create_action(TTR("Delete Image Group")); - List images_used; - EditorImportExport::get_singleton()->image_export_get_images_in_group(name,&images_used); - for (List::Element*E=images_used.front();E;E=E->next()) { - - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),StringName()); - - } - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_export_group_remove",name); - - - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_create",name); - for (List::Element*E=images_used.front();E;E=E->next()) { - - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),name); - - } - - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_image_action",name,EditorImportExport::get_singleton()->image_export_group_get_image_action(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_make_atlas",name,EditorImportExport::get_singleton()->image_export_group_get_make_atlas(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_shrink",name,EditorImportExport::get_singleton()->image_export_group_get_shrink(name)); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_export_group_set_lossy_quality",name,EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(name)); - - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_list"); - EditorNode::get_undo_redo()->add_do_method(this,"_update_group"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_list"); - EditorNode::get_undo_redo()->add_undo_method(this,"_select_group",name); - - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->commit_action(); - -} - -void ProjectExportDialog::_group_select_all() { - - - String group = _get_selected_group(); - if (group=="") - return; - - TreeItem *item = group_images->get_root(); - if (!item) - return; - - List items; - while(item) { - - if (item->get_cell_mode(1)==TreeItem::CELL_MODE_CHECK && !item->is_checked(1)) - items.push_back(item->get_metadata(0)); - item=item->get_next_visible(); - } - - - if (items.size()==0) - return; - - EditorNode::get_undo_redo()->create_action(TTR("Select All")); - - for (List::Element *E=items.front();E;E=E->next()) { - - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),group); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),String()); - - } - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - - EditorNode::get_undo_redo()->commit_action(); - -} - -void ProjectExportDialog::_group_select_none(){ - - String group = _get_selected_group(); - if (group=="") - return; - - TreeItem *item = group_images->get_root(); - if (!item) - return; - - List items; - while(item) { - - if (item->get_cell_mode(1)==TreeItem::CELL_MODE_CHECK && item->is_checked(1)) - items.push_back(item->get_metadata(0)); - item=item->get_next_visible(); - } - - - if (items.size()==0) - return; - - EditorNode::get_undo_redo()->create_action(TTR("Select All")); - - for (List::Element *E=items.front();E;E=E->next()) { - - EditorNode::get_undo_redo()->add_do_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),String()); - EditorNode::get_undo_redo()->add_undo_method(EditorImportExport::get_singleton(),"image_add_to_export_group",E->get(),group); - - } - EditorNode::get_undo_redo()->add_do_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_undo_method(this,"_update_group_tree"); - EditorNode::get_undo_redo()->add_do_method(this,"_save_export_cfg"); - EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); - - EditorNode::get_undo_redo()->commit_action(); - -} - -void ProjectExportDialog::_group_atlas_preview() { - - StringName group = _get_selected_group(); - if (!group) - return; - - atlas_preview_frame->set_texture(Ref()); //clear previous - - List images; - EditorImportExport::get_singleton()->image_export_get_images_in_group(group,&images); - images.sort_custom(); - - String dst_file = EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-preview.tex"; - Ref imd = memnew( ResourceImportMetadata ); - //imd->set_editor(); - - for (List::Element *F=images.front();F;F=F->next()) { - - imd->add_source(EditorImportPlugin::validate_source_path(F->get())); - } - - - int flags=0; - - if (GlobalConfig::get_singleton()->get("image_loader/filter")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_FILTER; - if (!GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS; - if (!GlobalConfig::get_singleton()->get("image_loader/repeat")) - flags|=EditorTextureImportPlugin::IMAGE_FLAG_REPEAT; - - flags|=EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA; - - imd->set_option("format",EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS); - imd->set_option("flags",flags); - imd->set_option("quality",0.7); - imd->set_option("atlas",true); - imd->set_option("crop",true); - - Ref plugin = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture"); - Error err = plugin->import2(dst_file,imd,EditorExportPlatform::IMAGE_COMPRESSION_NONE,true); - if (err) { - - EditorNode::add_io_error(TTR("Error saving atlas:")+" "+dst_file.get_file()); - return; - } - - Ref tex = ResourceLoader::load(dst_file); - atlas_preview_frame->set_texture(tex); //clear previous - atlas_preview_dialog->set_title(TTR("Atlas Preview")+" ("+itos(tex->get_width())+"x"+itos(tex->get_height())+")"); - atlas_preview_dialog->popup_centered_ratio(0.9); - -} - -void ProjectExportDialog::_update_script() { - - if (updating_script) - return; - updating_script=true; - script_mode->select(EditorImportExport::get_singleton()->script_get_action()); - script_key->set_text(EditorImportExport::get_singleton()->script_get_encryption_key()); - updating_script=false; - -} - -void ProjectExportDialog::_image_filter_changed(String) { - - _update_group_tree(); -} - -void ProjectExportDialog::_bind_methods() { - - - ClassDB::bind_method(D_METHOD("_rescan"),&ProjectExportDialog::_rescan); - ClassDB::bind_method(D_METHOD("_tree_changed"),&ProjectExportDialog::_tree_changed); - ClassDB::bind_method(D_METHOD("_scan_finished"),&ProjectExportDialog::_scan_finished); - ClassDB::bind_method(D_METHOD("_platform_selected"),&ProjectExportDialog::_platform_selected); - ClassDB::bind_method(D_METHOD("_prop_edited"),&ProjectExportDialog::_prop_edited); - ClassDB::bind_method(D_METHOD("_export_mode_changed"),&ProjectExportDialog::_export_mode_changed); - ClassDB::bind_method(D_METHOD("_filters_edited"),&ProjectExportDialog::_filters_edited); - ClassDB::bind_method(D_METHOD("_filters_exclude_edited"),&ProjectExportDialog::_filters_exclude_edited); - ClassDB::bind_method(D_METHOD("_export_action"),&ProjectExportDialog::_export_action); - ClassDB::bind_method(D_METHOD("_export_action_pck"),&ProjectExportDialog::_export_action_pck); - ClassDB::bind_method(D_METHOD("_quality_edited"),&ProjectExportDialog::_quality_edited); - ClassDB::bind_method(D_METHOD("_shrink_edited"),&ProjectExportDialog::_shrink_edited); - ClassDB::bind_method(D_METHOD("_image_export_edited"),&ProjectExportDialog::_image_export_edited); - ClassDB::bind_method(D_METHOD("_format_toggled"),&ProjectExportDialog::_format_toggled); - ClassDB::bind_method(D_METHOD("_group_changed"),&ProjectExportDialog::_group_changed); - ClassDB::bind_method(D_METHOD("_group_add"),&ProjectExportDialog::_group_add); - ClassDB::bind_method(D_METHOD("_group_del"),&ProjectExportDialog::_group_del); - ClassDB::bind_method(D_METHOD("_group_selected"),&ProjectExportDialog::_group_selected); - ClassDB::bind_method(D_METHOD("_update_group"),&ProjectExportDialog::_update_group); - ClassDB::bind_method(D_METHOD("_update_group_list"),&ProjectExportDialog::_update_group_list); - ClassDB::bind_method(D_METHOD("_select_group"),&ProjectExportDialog::_select_group); - ClassDB::bind_method(D_METHOD("_update_group_tree"),&ProjectExportDialog::_update_group_tree); - ClassDB::bind_method(D_METHOD("_group_item_edited"),&ProjectExportDialog::_group_item_edited); - ClassDB::bind_method(D_METHOD("_save_export_cfg"),&ProjectExportDialog::_save_export_cfg); - ClassDB::bind_method(D_METHOD("_image_filter_changed"),&ProjectExportDialog::_image_filter_changed); - ClassDB::bind_method(D_METHOD("_group_atlas_preview"),&ProjectExportDialog::_group_atlas_preview); - ClassDB::bind_method(D_METHOD("_group_select_all"),&ProjectExportDialog::_group_select_all); - ClassDB::bind_method(D_METHOD("_group_select_none"),&ProjectExportDialog::_group_select_none); - ClassDB::bind_method(D_METHOD("_script_edited"),&ProjectExportDialog::_script_edited); - ClassDB::bind_method(D_METHOD("_update_script"),&ProjectExportDialog::_update_script); - ClassDB::bind_method(D_METHOD("_sample_convert_edited"),&ProjectExportDialog::_sample_convert_edited); - - - ClassDB::bind_method(D_METHOD("export_platform"),&ProjectExportDialog::export_platform); - ClassDB::bind_method(D_METHOD("_create_android_keystore"),&ProjectExportDialog::_create_android_keystore); - ClassDB::bind_method(D_METHOD("_check_keystore_path"),&ProjectExportDialog::_check_keystore_path); - ClassDB::bind_method(D_METHOD("_keystore_dir_selected"),&ProjectExportDialog::_keystore_dir_selected); - ClassDB::bind_method(D_METHOD("_keystore_created"),&ProjectExportDialog::_keystore_created); - - - //ADD_SIGNAL(MethodInfo("instance")); - //ADD_SIGNAL(MethodInfo("open")); - -} - - -ProjectExportDialog::ProjectExportDialog(EditorNode *p_editor) { - - editor=p_editor; - set_title(TTR("Project Export Settings")); - - sections = memnew( TabContainer ); - add_child(sections); - //set_child_rect(sections); - - VBoxContainer *pvbox = memnew( VBoxContainer ); - sections->add_child(pvbox); - pvbox->set_name(TTR("Target")); - - HBoxContainer *phbox = memnew( HBoxContainer ); - pvbox->add_child(phbox); - phbox->set_v_size_flags(SIZE_EXPAND_FILL); - - plat_errors = memnew( HBoxContainer ); - pvbox->add_child(plat_errors); - platform_error_string = memnew( Label ); - platform_error_string->set_h_size_flags(SIZE_EXPAND_FILL); - plat_errors->add_child(platform_error_string); - - VBoxContainer *vb = memnew( VBoxContainer ); - vb->set_h_size_flags(SIZE_EXPAND_FILL); - vb->set_v_size_flags(SIZE_EXPAND_FILL); - phbox->add_child(vb); - platforms = memnew( Tree ); - platforms->set_hide_root(true); - vb->add_margin_child(TTR("Export to Platform"),platforms,true); - - platforms->connect("cell_selected",this,"_platform_selected"); - - - vb = memnew(VBoxContainer ); - phbox->add_child(vb); - vb->set_h_size_flags(SIZE_EXPAND_FILL); - vb->set_v_size_flags(SIZE_EXPAND_FILL); - platform_options = memnew( PropertyEditor() ); - platform_options->hide_top_label(); - vb->add_margin_child(TTR("Options"),platform_options,true); - platform_options->connect("property_edited",this,"_prop_edited"); - - - - ////////////////// - - vb = memnew( VBoxContainer ); - vb->set_name(TTR("Resources")); - sections->add_child(vb); - - export_mode = memnew( OptionButton ); - export_mode->add_item(TTR("Export selected resources (including dependencies).")); - export_mode->add_item(TTR("Export all resources in the project.")); - export_mode->add_item(TTR("Export all files in the project directory.")); - export_mode->connect("item_selected",this,"_export_mode_changed"); - - vb->add_margin_child(TTR("Export Mode:"),export_mode); - - - - tree_vb = memnew( VBoxContainer ); - vb->add_child(tree_vb); - tree_vb->set_v_size_flags(SIZE_EXPAND_FILL); - - tree = memnew( Tree ); - tree_vb->add_margin_child(TTR("Resources to Export:"),tree,true); - - tree->set_v_size_flags(SIZE_EXPAND_FILL); - tree->connect("item_edited",this,"_tree_changed"); - tree->set_columns(2); - tree->set_column_titles_visible(true); - tree->set_column_title(0,TTR("File")); - tree->set_column_title(1,TTR("Action")); - tree->set_column_expand(1,false); - tree->set_column_min_width(1,90); - - filters = memnew( LineEdit ); - vb->add_margin_child(TTR("Filters to export non-resource files (comma-separated, e.g.: *.json, *.txt):"),filters); - filters->connect("text_changed",this,"_filters_edited"); - filters_exclude = memnew( LineEdit ); - vb->add_margin_child(TTR("Filters to exclude from export (comma-separated, e.g.: *.json, *.txt):"),filters_exclude); - filters_exclude->connect("text_changed",this,"_filters_exclude_edited"); - - convert_text_scenes = memnew( CheckButton ); - convert_text_scenes->set_text(TTR("Convert text scenes to binary on export.")); - vb->add_child(convert_text_scenes); - convert_text_scenes->connect("toggled",this,"_export_mode_changed"); - - image_vb = memnew( VBoxContainer ); - image_vb->set_name(TTR("Images")); - image_action = memnew( OptionButton ); - image_action->add_item(TTR("Keep Original")); - image_action->add_item(TTR("Compress for Disk (Lossy, WebP)")); - image_action->add_item(TTR("Compress for RAM (BC/PVRTC/ETC)")); - image_vb->add_margin_child(TTR("Convert Images (*.png):"),image_action); - HBoxContainer *qhb = memnew( HBoxContainer ); - image_quality = memnew( HSlider ); - qhb->add_child(image_quality); - image_quality->set_h_size_flags(SIZE_EXPAND_FILL); - SpinBox *qspin = memnew( SpinBox ); - image_quality->share(qspin); - qhb->add_child(qspin); - image_quality->set_min(0); - image_quality->set_max(1); - image_quality->set_step(0.01); - image_vb->add_margin_child(TTR("Compress for Disk (Lossy) Quality:"),qhb); - image_shrink = memnew( SpinBox ); - image_shrink->set_min(1); - image_shrink->set_max(8); - image_shrink->set_step(0.1); - image_vb->add_margin_child(TTR("Shrink All Images:"),image_shrink); - sections->add_child(image_vb); - - image_formats=memnew(Tree); - image_formats->set_hide_root(true); - TreeItem *root = image_formats->create_item(NULL); - List fmts; - ImageLoader::get_recognized_extensions(&fmts); - for(List::Element *E=fmts.front();E;E=E->next()) { - - TreeItem *fmt = image_formats->create_item(root); - fmt->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); - fmt->set_text(0,E->get()); - fmt->set_editable(0,true); - formats.push_back(fmt); - } - image_vb->add_margin_child(TTR("Compress Formats:")+" ",image_formats,true); - - /// groups - HBoxContainer *group_hb = memnew( HBoxContainer ); - group_hb->set_name(TTR("Image Groups")); - sections->add_child(group_hb); - VBoxContainer *group_vb_left = memnew( VBoxContainer); - group_hb->add_child(group_vb_left); - - VBoxContainer *gvb = memnew(VBoxContainer); - HBoxContainer *ghb = memnew(HBoxContainer); - gvb->add_child(ghb); - - group_new_name = memnew( LineEdit ); - group_new_name->set_h_size_flags(SIZE_EXPAND_FILL); - ghb->add_child(group_new_name); - - group_add = memnew(ToolButton); - group_add->connect("pressed",this,"_group_add"); - ghb->add_child(group_add); - - group_new_name_error = memnew( Label ); - group_new_name_error->add_color_override("font_color",Color(1,0.4,0.4)); - gvb->add_child(group_new_name_error); - group_new_name_error->hide(); - - groups=memnew(Tree); - groups->set_v_size_flags(SIZE_EXPAND_FILL); - groups->connect("cell_selected",this,"_group_selected",varray(),CONNECT_DEFERRED); - groups->connect("button_pressed",this,"_group_del",varray(),CONNECT_DEFERRED); - groups->set_hide_root(true); - gvb->add_child(groups); - - group_vb_left->add_margin_child(TTR("Groups:"),gvb,true); - //group_vb_left->add_child( memnew( HSeparator)); - group_options = memnew(VBoxContainer); - group_vb_left->add_child(group_options); - - - group_image_action = memnew(OptionButton); - group_image_action->add_item(TTR("Default")); - group_image_action->add_item(TTR("Compress Disk")); - group_image_action->add_item(TTR("Compress RAM")); - group_image_action->add_item(TTR("Keep Original")); - group_options->add_margin_child(TTR("Compress Mode:"),group_image_action); - group_image_action->connect("item_selected",this,"_group_changed"); - - group_lossy_quality = memnew( HSlider ); - group_lossy_quality->set_min(0.1); - group_lossy_quality->set_max(1.0); - group_lossy_quality->set_step(0.01); - group_lossy_quality->set_value(0.7); - group_lossy_quality->connect("value_changed",this,"_quality_edited"); - - HBoxContainer *gqhb = memnew( HBoxContainer ); - SpinBox *gqspin = memnew( SpinBox ); - group_lossy_quality->share(gqspin); - group_lossy_quality->set_h_size_flags(SIZE_EXPAND_FILL); - gqhb->add_child(group_lossy_quality); - gqhb->add_child(gqspin); - group_options->add_margin_child(TTR("Lossy Quality:"),gqhb); - - group_atlas = memnew(CheckButton); - group_atlas->set_pressed(true); - group_options->add_margin_child(TTR("Atlas:"),group_atlas); - group_atlas->connect("toggled",this,"_group_changed"); - - group_shrink = memnew(SpinBox); - group_shrink->set_min(1); - group_shrink->set_max(8); - group_shrink->set_value(1); - group_shrink->set_step(0.001); - group_options->add_margin_child(TTR("Shrink By:"),group_shrink); - group_shrink->connect("value_changed",this,"_group_changed"); - - atlas_preview = memnew( Button ); - atlas_preview->set_text(TTR("Preview Atlas")); - group_options->add_child(atlas_preview); - atlas_preview->show(); - atlas_preview->connect("pressed",this,"_group_atlas_preview"); - Control *ec = memnew(Control ); - ec->set_custom_minimum_size(Size2(150,1)); - gvb->add_child(ec); - - VBoxContainer *group_vb_right = memnew( VBoxContainer ); - group_hb->add_child(group_vb_right); - group_vb_right->set_h_size_flags(SIZE_EXPAND_FILL); - - HBoxContainer *filter_hb = memnew (HBoxContainer); - - group_images_filter = memnew( LineEdit ); - group_vb_right->add_margin_child(TTR("Image Filter:"),filter_hb); - filter_hb->add_child(group_images_filter); - group_images_filter->set_h_size_flags(SIZE_EXPAND_FILL); - group_images_filter->connect("text_changed",this,"_image_filter_changed"); - group_images = memnew( Tree ); - group_images->set_v_size_flags(SIZE_EXPAND_FILL); - group_vb_right->add_margin_child(TTR("Images:"),group_images,true); - - Button *filt_select_all = memnew( Button ); - filt_select_all->set_text(TTR("Select All")); - filter_hb->add_child(filt_select_all); - filt_select_all->connect("pressed",this,"_group_select_all"); - - Button *filt_select_none = memnew( Button ); - filt_select_none->set_text(TTR("Select None")); - filter_hb->add_child(filt_select_none); - filt_select_none->connect("pressed",this,"_group_select_none"); - - atlas_preview_dialog = memnew( AcceptDialog ); - ScrollContainer *scroll = memnew( ScrollContainer ); - atlas_preview_dialog->add_child(scroll); - //atlas_preview_dialog->set_child_rect(scroll); - atlas_preview_frame = memnew( TextureRect ); - scroll->add_child(atlas_preview_frame); - add_child(atlas_preview_dialog); - - - group_images->set_hide_root(true); - group_images->set_columns(2); - group_images->set_column_expand(0,true); - group_images->set_column_expand(1,false); - group_images->set_column_min_width(1,100); - group_images->set_column_titles_visible(true); - group_images->set_column_title(0,TTR("Images")); - group_images->set_column_title(1,TTR("Group")); - group_images->connect("item_edited",this,"_group_item_edited",varray(),CONNECT_DEFERRED); - -/* SpinBox *group_shrink; - CheckButton *group_atlas; - OptionButton *group_image_action;*/ - - -/* progress = memnew( Label ); - add_child(progress); - progress->set_area_as_parent_rect(); - progress->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,25); - progress->hide(); - progress->set_align(Label::ALIGN_CENTER);*/ - -/* - button_reload = memnew( Button ); - button_reload->set_pos(Point2(3,2)); - button_reload->set_size(Point2(20,5)); - button_reload->set_flat(true); - //add_child(button_reload); - button_reload->connect("pressed",this,"_rescan"); - hbc->add_child(button_reload); -*/ - - - sample_vbox = memnew( VBoxContainer ); - sample_vbox->set_name(TTR("Samples")); - sections->add_child(sample_vbox); - sample_mode = memnew( OptionButton ); - sample_vbox->add_margin_child(TTR("Sample Conversion Mode: (.wav files):"),sample_mode); - sample_mode->add_item(TTR("Keep")); - sample_mode->add_item(TTR("Compress (RAM - IMA-ADPCM)")); - sample_max_hz = memnew( SpinBox ); - sample_max_hz->set_max(192000); - sample_max_hz->set_min(8000); - sample_vbox->add_margin_child(TTR("Sampling Rate Limit (Hz):"),sample_max_hz); - sample_trim = memnew( CheckButton ); - sample_trim->set_text(TTR("Trim")); - sample_vbox->add_margin_child(TTR("Trailing Silence:"),sample_trim); - - script_vbox = memnew( VBoxContainer ); - script_vbox->set_name(TTR("Script")); - sections->add_child(script_vbox); - script_mode = memnew( OptionButton ); - script_vbox->add_margin_child(TTR("Script Export Mode:"),script_mode); - script_mode->add_item(TTR("Text")); - script_mode->add_item(TTR("Compiled")); - script_mode->add_item(TTR("Encrypted (Provide Key Below)")); - script_key = memnew( LineEdit ); - script_vbox->add_margin_child(TTR("Script Encryption Key (256-bits as hex):"),script_key); - - - - updating=false; - - error = memnew( AcceptDialog ); - add_child(error); - - confirm = memnew( ConfirmationDialog ); - add_child(confirm); - confirm->connect("confirmed",this,"_confirmed"); - - get_ok()->set_text(TTR("Export PCK/Zip")); - - - expopt="--,Export,Bundle"; - - file_export = memnew( EditorFileDialog ); - add_child(file_export); - file_export->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - file_export->set_current_dir( EditorSettings::get_singleton()->get("filesystem/directories/default_project_export_path") ); - - file_export->set_title(TTR("Export Project")); - file_export->connect("file_selected", this,"_export_action"); - - file_export_password = memnew( LineEdit ); - file_export_password->set_secret(true); - file_export_password->set_editable(false); - file_export->get_vbox()->add_margin_child(TTR("Password:"),file_export_password); - - pck_export = memnew( EditorFileDialog ); - pck_export->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - pck_export->set_current_dir( EditorSettings::get_singleton()->get("filesystem/directories/default_project_export_path") ); - pck_export->set_title(TTR("Export Project PCK")); - pck_export->connect("file_selected", this,"_export_action_pck"); - pck_export->add_filter("*.pck ; Data Pack"); - pck_export->add_filter("*.zip ; Zip"); - add_child(pck_export); - - button_export = add_button(TTR("Export.."),!OS::get_singleton()->get_swap_ok_cancel(),"export_pck"); - updating_script=false; - - ei="EditorIcons"; - ot="Object"; - pending_update_tree=true; - - _create_android_keystore_window(); + editor_icons = "EditorIcons"; } - ProjectExportDialog::~ProjectExportDialog() { } - -void ProjectExport::popup_export() { - - Set presets; - presets.insert("default"); - - List pi; - GlobalConfig::get_singleton()->get_property_list(&pi); - export_preset->clear(); - - for (List::Element *E=pi.front();E;E=E->next()) { - - if (!E->get().name.begins_with("export_presets/")) - continue; - presets.insert(E->get().name.get_slice("/",1)); - } - - for(Set::Element *E=presets.front();E;E=E->next()) { - - export_preset->add_item(E->get()); - } - - - - popup_centered(Size2(300,100)); - - - -} -Error ProjectExport::export_project(const String& p_preset) { - - return OK; - -#if 0 - - String selected=p_preset; - - PoolVector preset_settings = GlobalConfig::get_singleton()->get("export_presets/"+selected); - String preset_path=GlobalConfig::get_singleton()->get("export_presets_path/"+selected); - if (preset_path=="") { - - error->set_text("Export path empty, see export options"); - error->popup_centered_minsize(Size2(300,100)); - ERR_FAIL_V(ERR_INVALID_DATA); - } - - int pc=preset_settings.size(); - - DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (d->change_dir(preset_path)!=OK) { - - memdelete(d); - error->set_text("Can't access to export path:\n "+preset_path); - error->popup_centered_minsize(Size2(300,100)); - ERR_FAIL_V(ERR_INVALID_DATA); - } - - if (pc==0) { - memdelete(d); - return OK; - } - if (pc%3 != 0 ) { - memdelete(d); - error->set_text("Corrupted export data.."); - error->popup_centered_minsize(Size2(300,100)); - ERR_EXPLAIN("Corrupted export data..."); - ERR_FAIL_V(ERR_INVALID_DATA); - } - - Map export_action; - - - Map > remapped_paths; - - Set scene_extensions; - Set resource_extensions; - - { - - List l; - /* - SceneLoader::get_recognized_extensions(&l); - for(List::Element *E=l.front();E;E=E->next()) { - - scene_extensions.insert(E->get()); - } - */ - ResourceLoader::get_recognized_extensions_for_type("",&l); - for(List::Element *E=l.front();E;E=E->next()) { - - resource_extensions.insert(E->get()); - } - } - - Vector names = GlobalConfig::get_singleton()->get_optimizer_presets(); - - //prepare base paths - - for(int i=0;i=0) { - export_action[name].action=idx; - export_action[name].depaction=dep_idx; - } - - } - - - Set bundle_exceptions; - for (Map::Element *E=export_action.front();E;E=E->next()) { - bundle_exceptions.insert(E->key()); - } - - - { - - // find dependencies and add them to export - - Map dependencies; - - for (Map::Element *E=export_action.front();E;E=E->next()) { - - ProjectExportSettings::ItemData &id=E->get(); - - if (id.depaction!=ProjectExportSettings::DA_COPY && id.depaction!=ProjectExportSettings::DA_OPTIMIZE) - continue; //no copy or optimize, go on - List deplist; - ResourceLoader::get_dependencies(E->key(),&deplist); - - while (deplist.size()) { - - String dependency = deplist.front()->get(); - deplist.pop_front(); - if (export_action.has(dependency)) - continue; //taged to export, will not override - if (dependencies.has(dependency)) { - - if (id.action <= dependencies[dependency].action ) - continue; - } - - ProjectExportSettings::ItemData depid; - if (id.depaction==ProjectExportSettings::DA_COPY || id.action==ProjectExportSettings::DA_COPY) - depid.action=ProjectExportSettings::DA_COPY; - else if (id.depaction==ProjectExportSettings::DA_OPTIMIZE) - depid.action=id.action; - depid.depaction=0; - - dependencies[dependency]=depid; - - ResourceLoader::get_dependencies(dependency,&deplist); - } - - - } - - for (Map::Element *E=dependencies.front();E;E=E->next()) { - export_action[E->key()]=E->get(); - } - } - - - - int idx=0; - for (Map::Element *E=export_action.front();E;E=E->next(),idx++) { - - - String path=E->key(); - if (E->get().action==0) - continue; //nothing to do here - String preset; - if (E->get().action==1) - preset=""; - else - preset=names[E->get().action-2]; - - print_line("Exporting "+itos(idx)+"/"+itos(export_action.size())+": "+path); - - String base_dir = GlobalConfig::get_singleton()->localize_path(path.get_base_dir()).replace("\\","/").replace("res://",""); - DirAccess *da=DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - String cwd = d->get_current_dir(); - da->change_dir(cwd); - print_line("base dir: "+base_dir); - String remap_platform="all"; - - for(int j=0;jchange_dir(p)!=OK) { - - Error err = da->make_dir(p); - if (err!=OK) { - memdelete(da); - memdelete(d); - ERR_EXPLAIN("Cannot make dir: "+cwd+"/"+p); - ERR_FAIL_V(ERR_CANT_CREATE); - } - - if (da->change_dir(p)!=OK) { - - memdelete(da); - memdelete(d); - ERR_EXPLAIN("Cannot change to dir: "+cwd+"/"+p); - ERR_FAIL_V(ERR_CANT_CREATE); - } - - } - - cwd=da->get_current_dir(); - } - - memdelete(da); - //cwd is the target dir - - String source_file; - - print_line("Exporting: "+source_file); - bool delete_source=false; - if (preset=="") { - //just copy! - - source_file=path; - delete_source=false; - } else { - - delete_source=true; - //create an optimized source file - - if (!GlobalConfig::get_singleton()->has("optimizer_presets/"+preset)) { - memdelete(d); - ERR_EXPLAIN("Unknown optimizer preset: "+preset); - ERR_FAIL_V(ERR_INVALID_DATA); - } - - - Dictionary dc = GlobalConfig::get_singleton()->get("optimizer_presets/"+preset); - - ERR_FAIL_COND_V(!dc.has("__type__"),ERR_INVALID_DATA); - String type=dc["__type__"]; - - Ref saver; - - for(int i=0;iget_optimized_saver_count();i++) { - - if (editor_data->get_optimized_saver(i)->get_target_name()==type) { - saver=editor_data->get_optimized_saver(i); - } - } - - if (saver.is_null()) { - memdelete(d); - ERR_EXPLAIN("Preset '"+preset+"' references nonexistent saver: "+type); - ERR_FAIL_COND_V(saver.is_null(),ERR_INVALID_DATA); - } - - List keys; - dc.get_key_list(&keys); - - saver->clear(); - - for(List::Element *E=keys.front();E;E=E->next()) { - - saver->set(E->get(),dc[E->get()]); - } - - - remap_platform=saver->get_target_platform(); - if (remap_platform=="") - remap_platform="all"; - - - if (resource_extensions.has(path.extension().to_lower())) { - - uint32_t flags=0; - - /* - if (saver->is_bundle_scenes_enabled()) - flags|=Reso::FLAG_BUNDLE_INSTANCED_SCENES; - */ - saver->set_bundle_exceptions(NULL); - if (E->get().depaction>=ProjectExportSettings::DA_BUNDLE) { - flags|=ResourceSaver::FLAG_BUNDLE_RESOURCES; - if (E->get().depaction==ProjectExportSettings::DA_BUNDLE) - saver->set_bundle_exceptions(&bundle_exceptions); - - } - - if (saver->is_remove_editor_data_enabled()) - flags|=ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; - if (saver->is_big_endian_data_enabled()) - flags|=ResourceSaver::FLAG_SAVE_BIG_ENDIAN; - - RES res = ResourceLoader::load(path); - - if (res.is_null()) { - - memdelete(d); - ERR_EXPLAIN("Error loading resource to optimize: "+path); - ERR_FAIL_V(ERR_INVALID_DATA); - } - - if (saver->is_compress_translations_enabled() && res->get_type()=="Translation") { - - Ref ct = Ref( memnew( PHashTranslation ) ); - ct->generate(res); - res=ct; - } - - - //dst_file=path.get_file(); - //dst_file = cwd+"/"+dst_file.substr(0,dst_file.length()-dst_file.extension().length())+"opt.scn"; - - //String write_file = path.substr(0,path.length()-path.extension().length())+"optimized.res"; - String write_file = path+".opt.res"; - - - print_line("DST RES FILE: "+write_file); - Error err = ResourceSaver::save(write_file,res,flags,saver); - if (err) { - memdelete(d); - ERR_EXPLAIN("Error saving optimized resource: "+write_file); - ERR_FAIL_COND_V(err,ERR_CANT_OPEN); - } - source_file=write_file; - //project_settings->add_remapped_path(src_scene,path,platform); - - } - - - } - - String dst_file; - dst_file=cwd+"/"+source_file.get_file(); - print_line("copying from: "+source_file); - print_line("copying to: "+dst_file); - Error err = d->copy(source_file,dst_file); - - if (delete_source) - d->remove(source_file); - - if (err) { - - - ERR_EXPLAIN("Error copying from: "+source_file+" to "+dst_file+"."); - ERR_FAIL_COND_V(err,err); - } - - String src_remap=path; - String dst_remap=source_file; - print_line("remap from: "+src_remap); - print_line("remap to: "+dst_remap); - if (src_remap!=dst_remap) { - - - remapped_paths[remap_platform][src_remap]=dst_remap; - } - - //do the copy man... - - } - - Map added_settings; - - - for (Map >::Element *E=remapped_paths.front();E;E=E->next()) { - - String platform=E->key(); - PoolVector remaps; - for(Map::Element *F=E->get().front();F;F=F->next() ) { - - remaps.push_back(F->key()); - remaps.push_back(F->get()); - } - - - - //added_settings["remap/"+platform]=remaps;` - added_settings["remap/"+platform]=Variant(remaps).operator Array(); - } - - String engine_cfg_path=d->get_current_dir()+"/godot.cfg"; - print_line("enginecfg: "+engine_cfg_path); - GlobalConfig::get_singleton()->save_custom(engine_cfg_path,added_settings); - - memdelete(d); - return OK; -#endif -} - -ProjectExport::ProjectExport(EditorData* p_data) { - - editor_data=p_data; - VBoxContainer *vbc = memnew( VBoxContainer ); - add_child(vbc); - //set_child_rect(vbc); - set_title(TTR("Project Export")); - label = memnew( Label ); - label->set_text(TTR("Export Preset:")); - vbc->add_child(label); - export_preset = memnew (OptionButton); - vbc->add_child(export_preset); - get_ok()->set_text(TTR("Export")); - set_hide_on_ok(false); - error = memnew( AcceptDialog ); - add_child(error); - - -} -#endif diff --git a/tools/editor/project_export.h b/tools/editor/project_export.h index c528a23121..715d3c3e68 100644 --- a/tools/editor/project_export.h +++ b/tools/editor/project_export.h @@ -35,6 +35,7 @@ #include "scene/gui/label.h" #include "tools/editor/editor_file_dialog.h" #include "scene/gui/button.h" +#include "scene/gui/file_dialog.h" #include "scene/gui/dialogs.h" #include "scene/gui/tab_container.h" #include "os/dir_access.h" @@ -44,167 +45,77 @@ #include "scene/gui/slider.h" #include "tools/editor/editor_file_system.h" #include "property_editor.h" -#include "editor_import_export.h" +#include "editor_export.h" + -#if 0 class EditorNode; class ProjectExportDialog : public ConfirmationDialog { GDCLASS( ProjectExportDialog, ConfirmationDialog ); -public: - enum ExportAction { - ACTION_NONE, - ACTION_COPY, - ACTION_BUNDLE, - ACTION_MAX - - }; - - static const char *da_string[ACTION_MAX]; - private: - EditorNode *editor; - String expopt; - TabContainer *sections; - bool updating_tree; - bool pending_update_tree; - AcceptDialog *error; - ConfirmationDialog *confirm; - ConfirmationDialog *confirm_keystore; - Button *button_reload; - LineEdit *filters, *filters_exclude; - HBoxContainer *plat_errors; - Label *platform_error_string; + MenuButton *add_preset; + Button *delete_preset; + ItemList *presets; - StringName ei; - StringName ot; + LineEdit *name; + PropertyEditor *parameters; + CheckButton *runnable; - Tree * tree; EditorFileDialog *pck_export; EditorFileDialog *file_export; - LineEdit *file_export_password; Button *button_export; - String _delete_attempt; - bool updating; - void _tree_changed(); - void _update_tree(); - - bool _create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir); - void _rescan(); - //void _confirmed(); - void _scan_finished(); - - void _validate_platform(); - /////////////////// - - Tree * platforms; - PropertyEditor *platform_options; - - OptionButton *export_mode; - CheckButton *convert_text_scenes; - VBoxContainer *tree_vb; - - VBoxContainer *image_vb; - OptionButton *image_action; - HSlider *image_quality; - SpinBox *image_shrink; - Tree *image_formats; - Vector formats; - - LineEdit *group_new_name; - HSlider *group_lossy_quality; - Label *group_new_name_error; - VBoxContainer *group_options; - Tree *groups; - SpinBox *group_shrink; - CheckButton *group_atlas; - OptionButton *group_image_action; - Button *group_add; - Tree *group_images; - LineEdit *group_images_filter; - Button *atlas_preview; - - - AcceptDialog *atlas_preview_dialog; - TextureRect *atlas_preview_frame; - - - VBoxContainer *script_vbox; - OptionButton *script_mode; - LineEdit *script_key; - - VBoxContainer *sample_vbox; - OptionButton *sample_mode; - SpinBox *sample_max_hz; - CheckButton *sample_trim; + ConfirmationDialog *delete_confirm; - ConfirmationDialog* keystore_create_dialog; - EditorFileDialog* keystore_file_dialog; + OptionButton *export_filter; + LineEdit *include_filters; + LineEdit *exclude_filters; + Tree *include_files; + Label* include_label; + MarginContainer *include_margin; - void _export_mode_changed(int p_idx); - void _prop_edited(String what); + StringName editor_icons; - void _update_platform(); - void _update_exporter(); - void _platform_selected(); + Tree *patches; + Button *patch_export; + int patch_index; + FileDialog *patch_dialog; + ConfirmationDialog *patch_erase; - void _filters_edited(String what); - void _filters_exclude_edited(String what); - void _update_group_tree(); + void _patch_selected(const String& p_path); + void _patch_deleted(); - void _image_filter_changed(String); - bool _update_group_treef(TreeItem *p_parent,EditorFileSystemDirectory *p_dir,const Set& p_extensions,const String& p_groups,const Map& p_group_index); - void _group_item_edited(); - void _group_atlas_preview(); + void _runnable_pressed(); + void _name_changed(const String& p_string); + void _add_preset(int p_platform); + void _edit_preset(int p_index); + void _delete_preset(); + void _delete_preset_confirm(); + void _update_presets(); + void _export_type_changed(int p_which); + void _filter_changed(const String& p_filter); + void _fill_resource_tree(); + bool _fill_tree(EditorFileSystemDirectory *p_dir,TreeItem *p_item,Ref ¤t,bool p_only_scenes); + void _tree_changed(); - void _quality_edited(float what); - void _image_export_edited(int what); - void _shrink_edited(float what); - - void _sample_convert_edited(int what); - - void _update_group_list(); - void _select_group(const String& p_by_name); - - - String _get_selected_group(); - void _update_group(); - void _group_changed(Variant v); - void _group_selected(); - void _group_add(); - void _group_select_all(); - void _group_select_none(); - void _group_del(Object *item,int p_column, int p_button); + void _patch_button_pressed(Object* p_item,int p_column,int p_id); + void _patch_edited(); - bool updating_script; - void _update_script(); - void _script_edited(Variant v); - void _export_action(const String& p_file); - void _export_action_pck(const String& p_file); - void ok_pressed(); - void custom_action(const String&); - LineEdit* _create_keystore_input(Control* container, const String& p_label, const String& name); - void _create_android_keystore_window(); - void _create_android_keystore(); - bool _check_android_setting(const Ref& exporter); - void _check_keystore_path(const String& path); - void _keystore_dir_selected(const String& path); - void _keystore_created(); - void _save_export_cfg(); - void _format_toggled(); + Variant get_drag_data_fw(const Point2& p_point,Control* p_from); + bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; + void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); protected: @@ -212,35 +123,14 @@ protected: static void _bind_methods(); public: - String get_selected_path() const; - - Error export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password,bool p_quit_after=false); - void popup_export(); - ProjectExportDialog(EditorNode *p_editor); + + ProjectExportDialog(); ~ProjectExportDialog(); }; -class EditorData; - -class ProjectExport : public ConfirmationDialog { - GDCLASS( ProjectExport, ConfirmationDialog ); - EditorData *editor_data; - - AcceptDialog *error; - Label *label; - OptionButton *export_preset; -public: - - Error export_project(const String& p_preset); - void popup_export(); - - - ProjectExport(EditorData* p_data); - -}; #endif // PROJECT_EXPORT_SETTINGS_H -#endif + diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index b1528460ea..9fc47b7da4 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -38,7 +38,7 @@ #include "pair.h" #include "scene/scene_string_names.h" #include "editor_settings.h" -#include "editor_import_export.h" +#include "editor_export.h" #include "editor_node.h" #include "multi_node_edit.h" #include "array_property_edit.h" -- cgit v1.2.3