summaryrefslogtreecommitdiff
path: root/platform/web
diff options
context:
space:
mode:
Diffstat (limited to 'platform/web')
-rw-r--r--platform/web/README.md2
-rw-r--r--platform/web/api/web_tools_editor_plugin.cpp2
-rw-r--r--platform/web/api/web_tools_editor_plugin.h2
-rw-r--r--platform/web/display_server_web.cpp25
-rw-r--r--platform/web/dom_keys.inc56
-rw-r--r--platform/web/export/export_plugin.cpp25
-rw-r--r--platform/web/export/export_plugin.h5
-rw-r--r--platform/web/logo.pngbin1234 -> 0 bytes
-rw-r--r--platform/web/logo.svg1
-rw-r--r--platform/web/os_web.cpp18
-rw-r--r--platform/web/run_icon.pngbin290 -> 0 bytes
-rw-r--r--platform/web/run_icon.svg1
12 files changed, 82 insertions, 55 deletions
diff --git a/platform/web/README.md b/platform/web/README.md
index 1265ca09df..906eb508fe 100644
--- a/platform/web/README.md
+++ b/platform/web/README.md
@@ -10,7 +10,7 @@ this platform such as the html shell (web page).
## Documentation
-- [Compiling for the Web](https://docs.godotengine.org/en/latest/development/compiling/compiling_for_web.html)
+- [Compiling for the Web](https://docs.godotengine.org/en/latest/contributing/development/compiling/compiling_for_web.html)
- Instructions on building this platform port from source.
- [Exporting for the Web](https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_web.html)
- Instructions on using the compiled export templates to export a project.
diff --git a/platform/web/api/web_tools_editor_plugin.cpp b/platform/web/api/web_tools_editor_plugin.cpp
index 7df9555b50..146a48db81 100644
--- a/platform/web/api/web_tools_editor_plugin.cpp
+++ b/platform/web/api/web_tools_editor_plugin.cpp
@@ -57,7 +57,7 @@ WebToolsEditorPlugin::WebToolsEditorPlugin() {
add_tool_menu_item("Download Project Source", callable_mp(this, &WebToolsEditorPlugin::_download_zip));
}
-void WebToolsEditorPlugin::_download_zip(Variant p_v) {
+void WebToolsEditorPlugin::_download_zip() {
if (!Engine::get_singleton() || !Engine::get_singleton()->is_editor_hint()) {
ERR_PRINT("Downloading the project as a ZIP archive is only available in Editor mode.");
return;
diff --git a/platform/web/api/web_tools_editor_plugin.h b/platform/web/api/web_tools_editor_plugin.h
index 72f4950b36..fc74899a58 100644
--- a/platform/web/api/web_tools_editor_plugin.h
+++ b/platform/web/api/web_tools_editor_plugin.h
@@ -41,7 +41,7 @@ class WebToolsEditorPlugin : public EditorPlugin {
private:
void _zip_file(String p_path, String p_base_path, zipFile p_zip);
void _zip_recursive(String p_path, String p_base_path, zipFile p_zip);
- void _download_zip(Variant p_v);
+ void _download_zip();
public:
static void initialize();
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index 7dd0515d3f..d71fd60543 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -121,18 +121,25 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers
// Resume audio context after input in case autoplay was denied.
OS_Web::get_singleton()->resume_audio();
+ char32_t c = 0x00;
+ String unicode = String::utf8(key_event.key);
+ if (unicode.length() == 1) {
+ c = unicode[0];
+ }
+
+ Key keycode = dom_code2godot_scancode(key_event.code, key_event.key, false);
+ Key scancode = dom_code2godot_scancode(key_event.code, key_event.key, true);
+
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_echo(p_repeat);
- ev->set_keycode(dom_code2godot_scancode(key_event.code, key_event.key, false));
- ev->set_physical_keycode(dom_code2godot_scancode(key_event.code, key_event.key, true));
+ ev->set_keycode(fix_keycode(c, keycode));
+ ev->set_physical_keycode(scancode);
+ ev->set_key_label(fix_key_label(c, keycode));
+ ev->set_unicode(fix_unicode(c));
ev->set_pressed(p_pressed);
dom2godot_mod(ev, p_modifiers);
- String unicode = String::utf8(key_event.key);
- if (unicode.length() == 1) {
- ev->set_unicode(unicode[0]);
- }
Input::get_singleton()->parse_input_event(ev);
// Make sure to flush all events so we can call restricted APIs inside the event.
@@ -787,8 +794,10 @@ DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode
RasterizerGLES3::make_current();
} else {
- OS::get_singleton()->alert("Your browser does not seem to support WebGL2. Please update your browser version.",
- "Unable to initialize video driver");
+ OS::get_singleton()->alert(
+ "Your browser seems not to support WebGL 2.\n\n"
+ "If possible, consider updating your browser version and video card drivers.",
+ "Unable to initialize WebGL 2 video driver");
RasterizerDummy::make_current();
}
#else
diff --git a/platform/web/dom_keys.inc b/platform/web/dom_keys.inc
index 5f8d921bfb..e63bd7c69f 100644
--- a/platform/web/dom_keys.inc
+++ b/platform/web/dom_keys.inc
@@ -32,9 +32,9 @@
// See https://w3c.github.io/uievents-code/#code-value-tables
Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], bool p_physical) {
-#define DOM2GODOT(p_str, p_godot_code) \
- if (memcmp((const void *)p_str, (void *)p_code, strlen(p_str) + 1) == 0) { \
- return Key::p_godot_code; \
+#define DOM2GODOT(p_str, p_godot_code) \
+ if (memcmp((const void *)p_str, (void *)(p_physical ? p_key : p_code), strlen(p_str) + 1) == 0) { \
+ return Key::p_godot_code; \
}
// Numpad section.
@@ -70,35 +70,6 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("NumpadStar", KP_MULTIPLY); // or ASTERISK ?
DOM2GODOT("NumpadSubtract", KP_SUBTRACT);
- // Printable ASCII.
- if (!p_physical) {
- uint8_t b0 = (uint8_t)p_key[0];
- uint8_t b1 = (uint8_t)p_key[1];
- uint8_t b2 = (uint8_t)p_key[2];
- if (b1 == 0 && b0 > 0x1F && b0 < 0x7F) { // ASCII.
- if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII.
- b0 -= 32;
- }
- return (Key)b0;
- }
-
-#define _U_2BYTES_MASK 0xE0
-#define _U_2BYTES 0xC0
- // Latin-1 codes.
- if (b2 == 0 && (b0 & _U_2BYTES_MASK) == _U_2BYTES) { // 2-bytes utf8, only known latin.
- uint32_t key = ((b0 & ~_U_2BYTES_MASK) << 6) | (b1 & 0x3F);
- if (key >= 0xA0 && key <= 0xDF) {
- return (Key)key;
- }
- if (key >= 0xE0 && key <= 0xFF) { // Lowercase known latin.
- key -= 0x20;
- return (Key)key;
- }
- }
-#undef _U_2BYTES_MASK
-#undef _U_2BYTES
- }
-
// Alphanumeric section.
DOM2GODOT("Backquote", QUOTELEFT);
DOM2GODOT("Backslash", BACKSLASH);
@@ -162,8 +133,8 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("ControlLeft", CTRL);
DOM2GODOT("ControlRight", CTRL);
DOM2GODOT("Enter", ENTER);
- DOM2GODOT("MetaLeft", SUPER_L);
- DOM2GODOT("MetaRight", SUPER_R);
+ DOM2GODOT("MetaLeft", META);
+ DOM2GODOT("MetaRight", META);
DOM2GODOT("ShiftLeft", SHIFT);
DOM2GODOT("ShiftRight", SHIFT);
DOM2GODOT("Space", SPACE);
@@ -227,6 +198,21 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("AudioVolumeMute", VOLUMEMUTE);
DOM2GODOT("AudioVolumeUp", VOLUMEUP);
//DOM2GODOT("WakeUp", UNKNOWN);
- return Key::UNKNOWN;
+
+ // Printable ASCII.
+ uint8_t b0 = (uint8_t)p_key[0];
+ uint8_t b1 = (uint8_t)p_key[1];
+ if (b0 >= 0x20 && b0 < 0x7F) { // ASCII.
+ if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII.
+ b0 -= 32;
+ }
+ return (Key)b0;
+ } else if (b0 == 0xC2 && b1 == 0xA5) {
+ return Key::YEN;
+ } else if (b0 == 0xC2 && b1 == 0xA7) {
+ return Key::SECTION;
+ }
+
+ return Key::NONE;
#undef DOM2GODOT
}
diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp
index 3e11db6887..d8e04904c7 100644
--- a/platform/web/export/export_plugin.cpp
+++ b/platform/web/export/export_plugin.cpp
@@ -31,7 +31,15 @@
#include "export_plugin.h"
#include "core/config/project_settings.h"
+#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
+#include "platform/web/logo_svg.gen.h"
+#include "platform/web/run_icon_svg.gen.h"
+
+#include "modules/modules_enabled.gen.h" // For svg.
+#ifdef MODULE_SVG_ENABLED
+#include "modules/svg/image_loader_svg.h"
+#endif
Error EditorExportPlatformWeb::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
Ref<FileAccess> io_fa;
@@ -153,7 +161,7 @@ void EditorExportPlatformWeb::_fix_html(Vector<uint8_t> &p_html, const Ref<Edito
const String custom_head_include = p_preset->get("html/head_include");
HashMap<String, String> replaces;
replaces["$GODOT_URL"] = p_name + ".js";
- replaces["$GODOT_PROJECT_NAME"] = ProjectSettings::get_singleton()->get_setting("application/config/name");
+ replaces["$GODOT_PROJECT_NAME"] = GLOBAL_GET("application/config/name");
replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
replaces["$GODOT_CONFIG"] = str_config;
_replace_strings(replaces, p_html);
@@ -193,7 +201,7 @@ Error EditorExportPlatformWeb::_add_manifest_icon(const String &p_path, const St
}
Error EditorExportPlatformWeb::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
- String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
+ String proj_name = GLOBAL_GET("application/config/name");
if (proj_name.is_empty()) {
proj_name = "Godot Game";
}
@@ -651,8 +659,17 @@ EditorExportPlatformWeb::EditorExportPlatformWeb() {
server.instantiate();
server_thread.start(_server_thread_poll, this);
- logo = ImageTexture::create_from_image(memnew(Image(_web_logo)));
- run_icon = ImageTexture::create_from_image(memnew(Image(_web_run_icon)));
+#ifdef MODULE_SVG_ENABLED
+ Ref<Image> img = memnew(Image);
+ const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
+
+ ImageLoaderSVG img_loader;
+ img_loader.create_image_from_string(img, _web_logo_svg, EDSCALE, upsample, false);
+ logo = ImageTexture::create_from_image(img);
+
+ img_loader.create_image_from_string(img, _web_run_icon_svg, EDSCALE, upsample, false);
+ run_icon = ImageTexture::create_from_image(img);
+#endif
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
if (theme.is_valid()) {
diff --git a/platform/web/export/export_plugin.h b/platform/web/export/export_plugin.h
index b85492b66f..e74c945837 100644
--- a/platform/web/export/export_plugin.h
+++ b/platform/web/export/export_plugin.h
@@ -38,11 +38,8 @@
#include "core/io/zip_io.h"
#include "editor/editor_node.h"
#include "editor/export/editor_export_platform.h"
-#include "main/splash.gen.h"
-#include "platform/web/logo.gen.h"
-#include "platform/web/run_icon.gen.h"
-
#include "editor_http_server.h"
+#include "main/splash.gen.h"
class EditorExportPlatformWeb : public EditorExportPlatform {
GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);
diff --git a/platform/web/logo.png b/platform/web/logo.png
deleted file mode 100644
index c046d87dc4..0000000000
--- a/platform/web/logo.png
+++ /dev/null
Binary files differ
diff --git a/platform/web/logo.svg b/platform/web/logo.svg
new file mode 100644
index 0000000000..567b6f3c77
--- /dev/null
+++ b/platform/web/logo.svg
@@ -0,0 +1 @@
+<svg height="32" width="32" xmlns="http://www.w3.org/2000/svg"><path d="M7 5h18v21H7z" fill="#fff"/><path d="M3.143 1 5.48 27.504 15.967 31l10.553-3.496L28.857 1zM23.78 9.565H11.473l.275 3.308h11.759l-.911 9.937-6.556 1.808v.02h-.073l-6.61-1.828-.402-5.076h3.195l.234 2.552 3.583.97 3.595-.97.402-4.165H8.788L7.93 6.37h16.145z" fill="#eb6428"/></svg>
diff --git a/platform/web/os_web.cpp b/platform/web/os_web.cpp
index e12f62f4ad..964bce01da 100644
--- a/platform/web/os_web.cpp
+++ b/platform/web/os_web.cpp
@@ -30,6 +30,7 @@
#include "os_web.h"
+#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
@@ -157,7 +158,22 @@ void OS_Web::vibrate_handheld(int p_duration_ms) {
}
String OS_Web::get_user_data_dir() const {
- return "/userfs";
+ String userfs = "/userfs";
+ String appname = get_safe_dir_name(GLOBAL_GET("application/config/name"));
+ if (!appname.is_empty()) {
+ bool use_custom_dir = GLOBAL_GET("application/config/use_custom_user_dir");
+ if (use_custom_dir) {
+ String custom_dir = get_safe_dir_name(GLOBAL_GET("application/config/custom_user_dir_name"), true);
+ if (custom_dir.is_empty()) {
+ custom_dir = appname;
+ }
+ return userfs.path_join(custom_dir).replace("\\", "/");
+ } else {
+ return userfs.path_join(get_godot_dir_name()).path_join("app_userdata").path_join(appname).replace("\\", "/");
+ }
+ }
+
+ return userfs.path_join(get_godot_dir_name()).path_join("app_userdata").path_join("[unnamed project]");
}
String OS_Web::get_cache_path() const {
diff --git a/platform/web/run_icon.png b/platform/web/run_icon.png
deleted file mode 100644
index 574abb0150..0000000000
--- a/platform/web/run_icon.png
+++ /dev/null
Binary files differ
diff --git a/platform/web/run_icon.svg b/platform/web/run_icon.svg
new file mode 100644
index 0000000000..494f53cb90
--- /dev/null
+++ b/platform/web/run_icon.svg
@@ -0,0 +1 @@
+<svg height="16" width="16" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="M3.143 1 5.48 27.504 15.967 31l10.553-3.496L28.857 1ZM23.78 9.565H11.473l.275 3.308h11.759l-.911 9.937-6.556 1.808v.02h-.073l-6.61-1.828-.402-5.076h3.195l.234 2.552 3.583.97 3.595-.97.402-4.165H8.788L7.93 6.37h16.145Z" fill="#eb6428" style="fill:#e0e0e0;fill-opacity:1" transform="translate(.586 .586) scale(.46337)"/></svg>