feat(web): re-enable web exports

This commit is contained in:
Leroy Hopson 2024-03-30 15:24:32 +13:00 committed by Leroy Hopson
parent fcad5d64b9
commit ff95b60a56
26 changed files with 940 additions and 4887 deletions

View file

@ -8,7 +8,7 @@ var line := ""
var _tput
@onready var terminal = $Terminal
@onready var _has_js: bool = OS.has_feature("JavaScript")
@onready var _has_js: bool = OS.has_feature("web")
func prompt(prompt: String):
@ -42,10 +42,10 @@ func _on_Terminal_key_pressed(_data, event: InputEventKey):
if not event:
return
# For some reason, data String is malformed on HTML5, so only use event.unicode.
# For some reason, data String is malformed on Web, so only use event.unicode.
var data = char(event.unicode)
match event.scancode:
match event.keycode:
KEY_ENTER:
terminal.write("\r\n")
@ -53,22 +53,20 @@ func _on_Terminal_key_pressed(_data, event: InputEventKey):
return emit_signal("exited", 0)
if not _has_js:
var msg := "WebConsole only available in HTML5 build."
var msg := "WebConsole only available in Web build."
push_error(msg)
_tput.setaf(TPut.ANSIColor.red)
terminal.write(msg)
_tput.sgr0()
prompt("\r\n>> ")
else:
# TODO: godot4
pass
# var json = JavaScript.eval("JSON.stringify(%s)" % line, true)
# _tput.setaf(TPut.ANSIColor.magenta)
# terminal.write(str(json))
# _tput.sgr0()
var json = JavaScriptBridge.eval("JSON.stringify(%s)" % line, true)
_tput.setaf(TPut.ANSIColor.magenta)
terminal.write(str(json))
_tput.sgr0()
line = ""
#_tput.srg0()
_tput.sgr0()
prompt("\r\n>> ")
KEY_BACKSPACE:

View file

@ -1,5 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://d3xc4utggdchf"]
[gd_scene load_steps=3 format=3 uid="uid://d3xc4utggdchf"]
[ext_resource type="Theme" uid="uid://0gk8swmcldbg" path="res://addons/godot_xterm/themes/default.tres" id="1_28w8r"]
[ext_resource type="Script" path="res://examples/web_console/web_console.gd" id="3"]
[node name="WebConsole" type="Control"]
@ -9,9 +10,12 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_28w8r")
script = ExtResource("3")
[node name="Terminal" type="Terminal" parent="."]
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]