Re-Added export plugins with a more interesting API, as well as the ability to do path remapping.

Also added ability to tell the exporter that a shared object needs to be bundled in the build.
This commit is contained in:
Juan Linietsky 2017-09-14 19:38:38 -03:00
parent 9488f06e4a
commit d3c1f2a7f6
5 changed files with 179 additions and 28 deletions

View file

@ -476,19 +476,66 @@ void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &
memdelete(da); memdelete(da);
} }
Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata) { void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
ExtraFile ef;
ef.data = p_file;
ef.path = p_path;
ef.remap = p_remap;
extra_files.push_back(ef);
}
void EditorExportPlugin::add_shared_object(const String &p_path) {
shared_objects.push_back(p_path);
}
void EditorExportPlugin::_export_file_script(const String &p_path, const PoolVector<String> &p_features) {
if (get_script_instance()) {
get_script_instance()->call("_export_file", p_path, p_features);
}
}
void EditorExportPlugin::_export_file(const String &p_path, const Set<String> &p_features) {
}
void EditorExportPlugin::skip() {
skipped = true;
}
void EditorExportPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_shared_object", "path"), &EditorExportPlugin::add_shared_object);
ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::POOL_STRING_ARRAY, "features")));
}
EditorExportPlugin::EditorExportPlugin() {
skipped = false;
}
Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
Ref<EditorExportPlatform> platform = p_preset->get_platform(); Ref<EditorExportPlatform> platform = p_preset->get_platform();
List<String> feature_list; List<String> feature_list;
platform->get_preset_features(p_preset, &feature_list); platform->get_preset_features(p_preset, &feature_list);
//figure out features //figure out features
Set<String> features; Set<String> features;
PoolVector<String> features_pv;
for (List<String>::Element *E = feature_list.front(); E; E = E->next()) { for (List<String>::Element *E = feature_list.front(); E; E = E->next()) {
features.insert(E->get()); features.insert(E->get());
features_pv.push_back(E->get());
} }
Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
//figure out paths of files that will be exported //figure out paths of files that will be exported
Set<String> paths; Set<String> paths;
Vector<String> path_remaps;
if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) { if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
//find stuff //find stuff
@ -551,10 +598,43 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
p_func(p_udata, path + ".import", array, idx, total); p_func(p_udata, path + ".import", array, idx, total);
} else { } else {
bool do_export = true;
for (int i = 0; i < export_plugins.size(); i++) {
if (export_plugins[i]->get_script_instance()) { //script based
export_plugins[i]->_export_file_script(path, features_pv);
} else {
export_plugins[i]->_export_file(path, features);
}
if (p_so_func) {
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
}
}
for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total);
if (export_plugins[i]->extra_files[j].remap) {
do_export = false; //if remap, do not
path_remaps.push_back(path);
path_remaps.push_back(export_plugins[i]->extra_files[j].path);
}
}
if (export_plugins[i]->skipped) {
do_export = false;
}
export_plugins[i]->_clear();
if (!do_export)
break; //apologies, not exporting
}
//just store it as it comes //just store it as it comes
if (do_export) {
Vector<uint8_t> array = FileAccess::get_file_as_array(path); Vector<uint8_t> array = FileAccess::get_file_as_array(path);
p_func(p_udata, path, array, idx, total); p_func(p_udata, path, array, idx, total);
} }
}
idx++; idx++;
} }
@ -575,9 +655,14 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
} }
} }
ProjectSettings::CustomMap custom_map;
if (path_remaps.size()) {
custom_map["path_remap/remapped_paths"] = path_remaps;
}
String config_file = "project.binary"; String config_file = "project.binary";
String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file; String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file;
ProjectSettings::get_singleton()->save_custom(engine_cfb, ProjectSettings::CustomMap(), custom_list); ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb); Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
p_func(p_udata, "res://" + config_file, data, idx, total); p_func(p_udata, "res://" + config_file, data, idx, total);
@ -867,6 +952,23 @@ void EditorExport::remove_export_preset(int p_idx) {
export_presets.remove(p_idx); export_presets.remove(p_idx);
} }
void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
if (export_plugins.find(p_plugin) == 1) {
export_plugins.push_back(p_plugin);
}
}
void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
export_plugins.erase(p_plugin);
}
Vector<Ref<EditorExportPlugin> > EditorExport::get_export_plugins() {
return export_plugins;
}
void EditorExport::_notification(int p_what) { void EditorExport::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) { if (p_what == NOTIFICATION_ENTER_TREE) {

View file

@ -124,6 +124,7 @@ class EditorExportPlatform : public Reference {
public: public:
typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total); typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const String &p_path);
private: private:
struct SavedData { struct SavedData {
@ -189,7 +190,7 @@ public:
virtual String get_name() const = 0; virtual String get_name() const = 0;
virtual Ref<Texture> get_logo() const = 0; virtual Ref<Texture> get_logo() const = 0;
Error export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata); Error export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func = NULL);
Error save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path); Error save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path);
Error save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path); Error save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path);
@ -219,11 +220,47 @@ public:
EditorExportPlatform(); EditorExportPlatform();
}; };
class EditorExportPlugin : public Reference {
GDCLASS(EditorExportPlugin, Reference)
friend class EditorExportPlatform;
Vector<String> shared_objects;
struct ExtraFile {
String path;
Vector<uint8_t> data;
bool remap;
};
Vector<ExtraFile> extra_files;
bool skipped;
_FORCE_INLINE_ void _clear() {
shared_objects.clear();
extra_files.clear();
skipped = false;
}
void _export_file_script(const String &p_path, const PoolVector<String> &p_features);
protected:
void add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap);
void add_shared_object(const String &p_path);
void skip();
virtual void _export_file(const String &p_path, const Set<String> &p_features);
static void _bind_methods();
public:
EditorExportPlugin();
};
class EditorExport : public Node { class EditorExport : public Node {
GDCLASS(EditorExport, Node); GDCLASS(EditorExport, Node);
Vector<Ref<EditorExportPlatform> > export_platforms; Vector<Ref<EditorExportPlatform> > export_platforms;
Vector<Ref<EditorExportPreset> > export_presets; Vector<Ref<EditorExportPreset> > export_presets;
Vector<Ref<EditorExportPlugin> > export_plugins;
Timer *save_timer; Timer *save_timer;
bool block_save; bool block_save;
@ -251,6 +288,10 @@ public:
Ref<EditorExportPreset> get_export_preset(int p_idx); Ref<EditorExportPreset> get_export_preset(int p_idx);
void remove_export_preset(int p_idx); void remove_export_preset(int p_idx);
void add_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
void remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin);
Vector<Ref<EditorExportPlugin> > get_export_plugins();
void load_config(); void load_config();
bool poll_export_platforms(); bool poll_export_platforms();

View file

@ -1481,7 +1481,6 @@ void EditorNode::_edit_current() {
if (editable_warning != String()) { if (editable_warning != String()) {
property_editable_warning->show(); //hide by default property_editable_warning->show(); //hide by default
property_editable_warning_dialog->set_text(editable_warning); property_editable_warning_dialog->set_text(editable_warning);
} }
/* Take care of PLUGIN EDITOR */ /* Take care of PLUGIN EDITOR */
@ -3252,9 +3251,9 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<EditorFileSystemDirectory>(); ClassDB::register_class<EditorFileSystemDirectory>();
ClassDB::register_virtual_class<ScriptEditor>(); ClassDB::register_virtual_class<ScriptEditor>();
ClassDB::register_virtual_class<EditorInterface>(); ClassDB::register_virtual_class<EditorInterface>();
ClassDB::register_class<EditorExportPlugin>();
// FIXME: Is this stuff obsolete, or should it be ported to new APIs? // FIXME: Is this stuff obsolete, or should it be ported to new APIs?
//ClassDB::register_class<EditorExportPlugin>();
//ClassDB::register_class<EditorScenePostImport>(); //ClassDB::register_class<EditorScenePostImport>();
//ClassDB::register_type<EditorImportExport>(); //ClassDB::register_type<EditorImportExport>();
} }
@ -4511,8 +4510,6 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method("_toggle_distraction_free_mode", &EditorNode::_toggle_distraction_free_mode); ClassDB::bind_method("_toggle_distraction_free_mode", &EditorNode::_toggle_distraction_free_mode);
ClassDB::bind_method("_property_editable_warning_pressed", &EditorNode::_property_editable_warning_pressed); ClassDB::bind_method("_property_editable_warning_pressed", &EditorNode::_property_editable_warning_pressed);
ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base); ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base);
ClassDB::bind_method(D_METHOD("_bottom_panel_switch"), &EditorNode::_bottom_panel_switch); ClassDB::bind_method(D_METHOD("_bottom_panel_switch"), &EditorNode::_bottom_panel_switch);
@ -5281,7 +5278,6 @@ EditorNode::EditorNode() {
property_editable_warning->hide(); property_editable_warning->hide();
property_editable_warning->connect("pressed", this, "_property_editable_warning_pressed"); property_editable_warning->connect("pressed", this, "_property_editable_warning_pressed");
property_editor = memnew(PropertyEditor); property_editor = memnew(PropertyEditor);
property_editor->set_autoclear(true); property_editor->set_autoclear(true);
property_editor->set_show_categories(true); property_editor->set_show_categories(true);
@ -5302,7 +5298,6 @@ EditorNode::EditorNode() {
dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(import_dock); dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(import_dock);
import_dock->set_name(TTR("Import")); import_dock->set_name(TTR("Import"));
bool use_single_dock_column = (OS::get_singleton()->get_screen_size(OS::get_singleton()->get_current_screen()).x < 1200); bool use_single_dock_column = (OS::get_singleton()->get_screen_size(OS::get_singleton()->get_current_screen()).x < 1200);
node_dock = memnew(NodeDock); node_dock = memnew(NodeDock);

View file

@ -530,6 +530,14 @@ void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importe
EditorFileSystem::get_singleton()->scan(); EditorFileSystem::get_singleton()->scan();
} }
void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
EditorExport::get_singleton()->add_export_plugin(p_exporter);
}
void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
EditorExport::get_singleton()->remove_export_plugin(p_exporter);
}
void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) { if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) {
@ -585,6 +593,8 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout); ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin); ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin);
ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin); ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
ClassDB::bind_method(D_METHOD("add_export_plugin", "exporter"), &EditorPlugin::add_export_plugin);
ClassDB::bind_method(D_METHOD("remove_export_plugin", "exporter"), &EditorPlugin::remove_export_plugin);
ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled); ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface); ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface);

View file

@ -191,6 +191,9 @@ public:
void add_import_plugin(const Ref<EditorImportPlugin> &p_importer); void add_import_plugin(const Ref<EditorImportPlugin> &p_importer);
void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer); void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer);
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
EditorPlugin(); EditorPlugin();
virtual ~EditorPlugin(); virtual ~EditorPlugin();
}; };