diff options
Diffstat (limited to 'platform/javascript')
-rw-r--r-- | platform/javascript/audio_driver_javascript.cpp | 9 | ||||
-rw-r--r-- | platform/javascript/audio_driver_javascript.h | 1 | ||||
-rw-r--r-- | platform/javascript/export/export.cpp | 4 | ||||
-rw-r--r-- | platform/javascript/os_javascript.cpp | 29 | ||||
-rw-r--r-- | platform/javascript/os_javascript.h | 3 |
5 files changed, 40 insertions, 6 deletions
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index fcfc75280d..16fdc267f3 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -146,6 +146,15 @@ void AudioDriverJavaScript::start() { /* clang-format on */ } +void AudioDriverJavaScript::resume() { + /* clang-format off */ + EM_ASM({ + if (_audioDriver_audioContext.resume) + _audioDriver_audioContext.resume(); + }); + /* clang-format on */ +} + int AudioDriverJavaScript::get_mix_rate() const { /* clang-format off */ diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h index bf7e2bcce6..9dcba02c96 100644 --- a/platform/javascript/audio_driver_javascript.h +++ b/platform/javascript/audio_driver_javascript.h @@ -49,6 +49,7 @@ public: virtual Error init(); virtual void start(); + void resume(); virtual int get_mix_rate() const; virtual SpeakerMode get_speaker_mode() const; virtual void lock(); diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index b3f90b9011..123c6ae645 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -155,7 +155,7 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p if (FileAccess::exists(p_preset->get("custom_template/debug"))) { valid = true; } else { - err += "Custom debug template not found.\n"; + err += TTR("Custom debug template not found.") + "\n"; } } @@ -163,7 +163,7 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p if (FileAccess::exists(p_preset->get("custom_template/release"))) { valid = true; } else { - err += "Custom release template not found.\n"; + err += TTR("Custom release template not found.") + "\n"; } } diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index cc3018716d..e820d07a2a 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -245,6 +245,8 @@ EM_BOOL OS_JavaScript::keydown_callback(int p_event_type, const EmscriptenKeyboa return false; } os->input->parse_input_event(ev); + // Resume audio context after input in case autoplay was denied. + os->audio_driver_javascript.resume(); return true; } @@ -335,6 +337,8 @@ EM_BOOL OS_JavaScript::mouse_button_callback(int p_event_type, const EmscriptenM ev->set_button_mask(mask); os->input->parse_input_event(ev); + // Resume audio context after input in case autoplay was denied. + os->audio_driver_javascript.resume(); // Prevent multi-click text selection and wheel-click scrolling anchor. // Context menu is prevented through contextmenu event. return true; @@ -438,6 +442,9 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s if (texture.is_valid()) { image = texture->get_data(); + if (image.is_valid()) { + image->duplicate(); + } } if (!image.is_valid() && atlas_texture.is_valid()) { @@ -464,6 +471,8 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s ERR_FAIL_COND(!image.is_valid()); + image = image->duplicate(); + if (atlas_texture.is_valid()) image->crop_from_point( atlas_rect.position.x, @@ -663,6 +672,8 @@ EM_BOOL OS_JavaScript::touch_press_callback(int p_event_type, const EmscriptenTo os->input->parse_input_event(ev); } + // Resume audio context after input in case autoplay was denied. + os->audio_driver_javascript.resume(); return true; } @@ -855,8 +866,21 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, video_driver_index = p_video_driver; video_mode = p_desired; - // Can't fulfill fullscreen request during start-up due to browser security. + // fullscreen_change_callback will correct this if the request is successful. video_mode.fullscreen = false; + // Emscripten only attempts fullscreen requests if the user input callback + // was registered through one its own functions, so request manually for + // start-up fullscreen. + if (p_desired.fullscreen) { + /* clang-format off */ + EM_ASM({ + (canvas.requestFullscreen || canvas.msRequestFullscreen || + canvas.mozRequestFullScreen || canvas.mozRequestFullscreen || + canvas.webkitRequestFullscreen + ).call(canvas); + }); + /* clang-format on */ + } /* clang-format off */ if (EM_ASM_INT_V({ return Module.resizeCanvasOnStart })) { /* clang-format on */ @@ -970,7 +994,8 @@ bool OS_JavaScript::main_loop_iterate() { } } - process_joypads(); + if (emscripten_sample_gamepad_data() == EMSCRIPTEN_RESULT_SUCCESS) + process_joypads(); if (just_exited_fullscreen) { if (window_maximized) { diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 64148915a5..a9f9e23463 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -58,6 +58,7 @@ class OS_JavaScript : public OS_Unix { int last_click_button_index; MainLoop *main_loop; + int video_driver_index; AudioDriverJavaScript audio_driver_javascript; bool idb_available; @@ -85,8 +86,6 @@ class OS_JavaScript : public OS_Unix { static void file_access_close_callback(const String &p_file, int p_flags); - int video_driver_index; - protected: virtual int get_current_video_driver() const; |