From f8db8a3faa30b71dca33ced38be16d3f93f43e8a Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Sun, 19 Mar 2017 00:36:26 +0100 Subject: Bring that Whole New World to the Old Continent too Applies the clang-format style to the 2.1 branch as done for master in 5dbf1809c6e3e905b94b8764e99491e608122261. --- platform/javascript/export/export.cpp | 335 ++++++++++++++++------------------ 1 file changed, 153 insertions(+), 182 deletions(-) (limited to 'platform/javascript/export/export.cpp') diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index b4409e90f..8eb2c42b6 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -26,21 +26,21 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "export.h" -#include "editor/editor_settings.h" #include "editor/editor_import_export.h" #include "editor/editor_node.h" -#include "io/zip_io.h" -#include "io/marshalls.h" +#include "editor/editor_settings.h" #include "globals.h" +#include "io/marshalls.h" +#include "io/zip_io.h" #include "os/file_access.h" #include "os/os.h" #include "platform/javascript/logo.h" #include "string.h" +#include "version.h" class EditorExportPlatformJavaScript : public EditorExportPlatform { - OBJ_TYPE( EditorExportPlatformJavaScript,EditorExportPlatform ); + OBJ_TYPE(EditorExportPlatformJavaScript, EditorExportPlatform); String custom_release_package; String custom_debug_package; @@ -50,7 +50,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { PACK_MULTIPLE_FILES }; - void _fix_html(Vector& p_html, const String& p_name, bool p_debug); + void _fix_html(Vector &p_html, const String &p_name, bool p_debug); PackMode pack_mode; @@ -68,207 +68,194 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { Ref logo; 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; + 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: - virtual String get_name() const { return "HTML5"; } virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_BC; } virtual Ref get_logo() const { return logo; } - - virtual bool poll_devices() { return show_run?true:false;} - virtual int get_device_count() const { return show_run?1:0; }; - virtual String get_device_name(int p_device) const { return "Run in Browser"; } + virtual bool poll_devices() { return show_run ? true : false; } + virtual int get_device_count() const { return show_run ? 1 : 0; }; + virtual String get_device_name(int p_device) const { return "Run in Browser"; } virtual String get_device_info(int p_device) const { return "Run exported HTML in the system's default browser."; } - virtual Error run(int p_device,int p_flags=0); + virtual Error run(int p_device, int p_flags = 0); virtual bool requires_password(bool p_debug) const { return false; } virtual String get_binary_extension() const { return "html"; } - virtual Error export_project(const String& p_path,bool p_debug,int p_flags=0); + virtual Error export_project(const String &p_path, bool p_debug, int p_flags = 0); - virtual bool can_export(String *r_error=NULL) const; + virtual bool can_export(String *r_error = NULL) const; EditorExportPlatformJavaScript(); ~EditorExportPlatformJavaScript(); }; -bool EditorExportPlatformJavaScript::_set(const StringName& p_name, const Variant& p_value) { - - String n=p_name; - - if (n=="custom_package/debug") - custom_debug_package=p_value; - else if (n=="custom_package/release") - custom_release_package=p_value; - else if (n=="browser/enable_run") - show_run=p_value; - else if (n=="options/memory_size") - max_memory=p_value; - else if (n=="html/title") - html_title=p_value; - else if (n=="html/head_include") - html_head_include=p_value; - else if (n=="html/font_family") - html_font_family=p_value; - else if (n=="html/style_include") - html_style_include=p_value; - else if (n=="html/controls_enabled") - html_controls_enabled=p_value; +bool EditorExportPlatformJavaScript::_set(const StringName &p_name, const Variant &p_value) { + + String n = p_name; + + if (n == "custom_package/debug") + custom_debug_package = p_value; + else if (n == "custom_package/release") + custom_release_package = p_value; + else if (n == "browser/enable_run") + show_run = p_value; + else if (n == "options/memory_size") + max_memory = p_value; + else if (n == "html/title") + html_title = p_value; + else if (n == "html/head_include") + html_head_include = p_value; + else if (n == "html/font_family") + html_font_family = p_value; + else if (n == "html/style_include") + html_style_include = p_value; + else if (n == "html/controls_enabled") + html_controls_enabled = p_value; else return false; return true; } -bool EditorExportPlatformJavaScript::_get(const StringName& p_name,Variant &r_ret) const{ - - String n=p_name; - - if (n=="custom_package/debug") - r_ret=custom_debug_package; - else if (n=="custom_package/release") - r_ret=custom_release_package; - else if (n=="browser/enable_run") - r_ret=show_run; - else if (n=="options/memory_size") - r_ret=max_memory; - else if (n=="html/title") - r_ret=html_title; - else if (n=="html/head_include") - r_ret=html_head_include; - else if (n=="html/font_family") - r_ret=html_font_family; - else if (n=="html/style_include") - r_ret=html_style_include; - else if (n=="html/controls_enabled") - r_ret=html_controls_enabled; +bool EditorExportPlatformJavaScript::_get(const StringName &p_name, Variant &r_ret) const { + + String n = p_name; + + if (n == "custom_package/debug") + r_ret = custom_debug_package; + else if (n == "custom_package/release") + r_ret = custom_release_package; + else if (n == "browser/enable_run") + r_ret = show_run; + else if (n == "options/memory_size") + r_ret = max_memory; + else if (n == "html/title") + r_ret = html_title; + else if (n == "html/head_include") + r_ret = html_head_include; + else if (n == "html/font_family") + r_ret = html_font_family; + else if (n == "html/style_include") + r_ret = html_style_include; + else if (n == "html/controls_enabled") + r_ret = html_controls_enabled; else return false; return true; } -void EditorExportPlatformJavaScript::_get_property_list( List *p_list) const{ - - p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE,"zip")); - p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE,"zip")); - p_list->push_back( PropertyInfo( Variant::INT, "options/memory_size",PROPERTY_HINT_ENUM,"32mb,64mb,128mb,256mb,512mb,1024mb")); - p_list->push_back( PropertyInfo( Variant::BOOL, "browser/enable_run")); - p_list->push_back( PropertyInfo( Variant::STRING, "html/title")); - p_list->push_back( PropertyInfo( Variant::STRING, "html/head_include",PROPERTY_HINT_MULTILINE_TEXT)); - p_list->push_back( PropertyInfo( Variant::STRING, "html/font_family")); - p_list->push_back( PropertyInfo( Variant::STRING, "html/style_include",PROPERTY_HINT_MULTILINE_TEXT)); - p_list->push_back( PropertyInfo( Variant::BOOL, "html/controls_enabled")); - +void EditorExportPlatformJavaScript::_get_property_list(List *p_list) const { + + p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip")); + p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip")); + p_list->push_back(PropertyInfo(Variant::INT, "options/memory_size", PROPERTY_HINT_ENUM, "32mb,64mb,128mb,256mb,512mb,1024mb")); + p_list->push_back(PropertyInfo(Variant::BOOL, "browser/enable_run")); + p_list->push_back(PropertyInfo(Variant::STRING, "html/title")); + p_list->push_back(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT)); + p_list->push_back(PropertyInfo(Variant::STRING, "html/font_family")); + p_list->push_back(PropertyInfo(Variant::STRING, "html/style_include", PROPERTY_HINT_MULTILINE_TEXT)); + p_list->push_back(PropertyInfo(Variant::BOOL, "html/controls_enabled")); //p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Copy,Single Exec.,Pack (.pck),Bundles (Optical)")); - } - -void EditorExportPlatformJavaScript::_fix_html(Vector& p_html, const String& p_name, bool p_debug) { - +void EditorExportPlatformJavaScript::_fix_html(Vector &p_html, const String &p_name, bool p_debug) { String str; String strnew; - str.parse_utf8((const char*)p_html.ptr(),p_html.size()); - Vector lines=str.split("\n"); - for(int i=0;i lines = str.split("\n"); + for (int i = 0; i < lines.size(); i++) { String current_line = lines[i]; - current_line = current_line.replace("$GODOT_TMEM",itos((1<<(max_memory+5))*1024*1024)); - current_line = current_line.replace("$GODOT_FS",p_name+"fs.js"); - current_line = current_line.replace("$GODOT_MEM",p_name+".mem"); - current_line = current_line.replace("$GODOT_JS",p_name+".js"); - current_line = current_line.replace("$GODOT_ASM",p_name+".asm.js"); - current_line = current_line.replace("$GODOT_CANVAS_WIDTH",Globals::get_singleton()->get("display/width")); - current_line = current_line.replace("$GODOT_CANVAS_HEIGHT",Globals::get_singleton()->get("display/height")); - current_line = current_line.replace("$GODOT_HEAD_TITLE",!html_title.empty()?html_title:(String) Globals::get_singleton()->get("application/name")); - current_line = current_line.replace("$GODOT_HEAD_INCLUDE",html_head_include); - current_line = current_line.replace("$GODOT_STYLE_FONT_FAMILY",html_font_family); - current_line = current_line.replace("$GODOT_STYLE_INCLUDE",html_style_include); - current_line = current_line.replace("$GODOT_CONTROLS_ENABLED",html_controls_enabled?"true":"false"); - current_line = current_line.replace("$GODOT_DEBUG_ENABLED",p_debug?"true":"false"); - strnew += current_line+"\n"; + current_line = current_line.replace("$GODOT_TMEM", itos((1 << (max_memory + 5)) * 1024 * 1024)); + current_line = current_line.replace("$GODOT_FS", p_name + "fs.js"); + current_line = current_line.replace("$GODOT_MEM", p_name + ".mem"); + current_line = current_line.replace("$GODOT_JS", p_name + ".js"); + current_line = current_line.replace("$GODOT_ASM", p_name + ".asm.js"); + current_line = current_line.replace("$GODOT_CANVAS_WIDTH", Globals::get_singleton()->get("display/width")); + current_line = current_line.replace("$GODOT_CANVAS_HEIGHT", Globals::get_singleton()->get("display/height")); + current_line = current_line.replace("$GODOT_HEAD_TITLE", !html_title.empty() ? html_title : (String)Globals::get_singleton()->get("application/name")); + current_line = current_line.replace("$GODOT_HEAD_INCLUDE", html_head_include); + current_line = current_line.replace("$GODOT_STYLE_FONT_FAMILY", html_font_family); + current_line = current_line.replace("$GODOT_STYLE_INCLUDE", html_style_include); + current_line = current_line.replace("$GODOT_CONTROLS_ENABLED", html_controls_enabled ? "true" : "false"); + current_line = current_line.replace("$GODOT_DEBUG_ENABLED", p_debug ? "true" : "false"); + strnew += current_line + "\n"; } CharString cs = strnew.utf8(); p_html.resize(cs.length()); - for(int i=9;i& html,uint64_t p_data_size) { - +static void _fix_files(Vector &html, uint64_t p_data_size) { String str; String strnew; - str.parse_utf8((const char*)html.ptr(),html.size()); - Vector lines=str.split("\n"); - for(int i=0;i lines = str.split("\n"); + for (int i = 0; i < lines.size(); i++) { + if (lines[i].find("$DPLEN") != -1) { + strnew += lines[i].replace("$DPLEN", itos(p_data_size)); } else { - strnew+=lines[i]+"\n"; + strnew += lines[i] + "\n"; } } CharString cs = strnew.utf8(); html.resize(cs.length()); - for(int i=9;i data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); - unzReadCurrentFile(pkg,data.ptr(),data.size()); + unzReadCurrentFile(pkg, data.ptr(), data.size()); unzCloseCurrentFile(pkg); //write - if (file=="godot.html") { + if (file == "godot.html") { - _fix_html(data,p_path.get_file().basename(), p_debug); - file=p_path.get_file(); + _fix_html(data, p_path.get_file().basename(), p_debug); + file = p_path.get_file(); } - if (file=="godotfs.js") { + if (file == "godotfs.js") { - _fix_files(data,len); - file=p_path.get_file().basename()+"fs.js"; + _fix_files(data, len); + file = p_path.get_file().basename() + "fs.js"; } - if (file=="godot.js") { + if (file == "godot.js") { //_fix_godot(data); - file=p_path.get_file().basename()+".js"; + file = p_path.get_file().basename() + ".js"; } - if (file=="godot.asm.js") { + if (file == "godot.asm.js") { - file=p_path.get_file().basename()+".asm.js"; + file = p_path.get_file().basename() + ".asm.js"; } - if (file=="godot.mem") { + if (file == "godot.mem") { //_fix_godot(data); - file=p_path.get_file().basename()+".mem"; + file = p_path.get_file().basename() + ".mem"; } String dst = p_path.get_base_dir().plus_file(file); - FileAccess *f=FileAccess::open(dst,FileAccess::WRITE); + FileAccess *f = FileAccess::open(dst, FileAccess::WRITE); if (!f) { - EditorNode::add_io_error("Could not create file for writing:\n"+dst); + EditorNode::add_io_error("Could not create file for writing:\n" + dst); unzClose(pkg); return ERR_FILE_CANT_WRITE; } - f->store_buffer(data.ptr(),data.size()); + f->store_buffer(data.ptr(), data.size()); memdelete(f); - ret = unzGoToNextFile(pkg); } - - return OK; - } - Error EditorExportPlatformJavaScript::run(int p_device, int p_flags) { - String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp_export.html"; - Error err = export_project(path,true,p_flags); + String path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp_export.html"; + Error err = export_project(path, true, p_flags); if (err) return err; @@ -368,59 +348,50 @@ Error EditorExportPlatformJavaScript::run(int p_device, int p_flags) { return OK; } - EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() { - show_run=false; - Image img( _javascript_logo ); - logo = Ref( memnew( ImageTexture )); + show_run = false; + Image img(_javascript_logo); + logo = Ref(memnew(ImageTexture)); logo->create_from_image(img); - max_memory=3; - html_title=""; - html_font_family="arial,sans-serif"; - html_controls_enabled=true; - pack_mode=PACK_SINGLE_FILE; + max_memory = 3; + html_title = ""; + html_font_family = "arial,sans-serif"; + html_controls_enabled = true; + pack_mode = PACK_SINGLE_FILE; } bool EditorExportPlatformJavaScript::can_export(String *r_error) const { - - bool valid=true; + bool valid = true; String err; if (!exists_export_template("javascript_debug.zip") || !exists_export_template("javascript_release.zip")) { - valid=false; - err+="No export templates found.\nDownload and install export templates.\n"; + valid = false; + err += "No export templates found.\nDownload and install export templates.\n"; } - if (custom_debug_package!="" && !FileAccess::exists(custom_debug_package)) { - valid=false; - err+="Custom debug package not found.\n"; + if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) { + valid = false; + err += "Custom debug package not found.\n"; } - if (custom_release_package!="" && !FileAccess::exists(custom_release_package)) { - valid=false; - err+="Custom release package not found.\n"; + if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) { + valid = false; + err += "Custom release package not found.\n"; } if (r_error) - *r_error=err; + *r_error = err; return valid; } - EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() { - } - void register_javascript_exporter() { - - Ref exporter = Ref( memnew(EditorExportPlatformJavaScript) ); + Ref exporter = Ref(memnew(EditorExportPlatformJavaScript)); EditorImportExport::get_singleton()->add_export_platform(exporter); - - } - -- cgit v1.2.3-70-g09d2