bendn 2022-05-05
commit 315c1ef
-rw-r--r--.gitignore2
-rw-r--r--Chat.gd34
-rw-r--r--WS.gd46
-rw-r--r--WS.tscn87
-rw-r--r--bg.tres4
-rw-r--r--default_env.tres13
-rw-r--r--icon.pngbin0 -> 3498 bytes
-rw-r--r--icon.png.import35
-rw-r--r--project.godot23
-rw-r--r--theme.tres27
-rw-r--r--verdana-bold.ttfbin0 -> 208456 bytes
-rw-r--r--verdana.tres7
12 files changed, 278 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d889656
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.import
+export_presets.cfg
diff --git a/Chat.gd b/Chat.gd
new file mode 100644
index 0000000..57a6080
--- /dev/null
+++ b/Chat.gd
@@ -0,0 +1,34 @@
+extends Control
+
+onready var labels = find_node("labels")
+onready var whoami = find_node("whoami")
+onready var text = find_node("text")
+onready var scroller = find_node("scroller")
+onready var tween = find_node("Tween")
+onready var scrollbar = scroller.get_v_scrollbar()
+
+
+func _ready():
+ text.context_menu_enabled = false
+
+
+func _on_Main_recieved(data):
+ var l = Label.new()
+ l.text = data
+ labels.add_child(l)
+ tween.interpolate_property(
+ scrollbar, "value", scrollbar.value, scrollbar.max_value, .5, Tween.TRANS_BOUNCE
+ )
+ tween.start()
+
+
+func _on_text_entered(t):
+ t = t.strip_edges()
+ if !t:
+ return
+ text.text = ""
+ get_parent().send_packet(whoami.text + ": " + t)
+
+
+func _on_send_pressed():
+ _on_text_entered(text.text)
diff --git a/WS.gd b/WS.gd
new file mode 100644
index 0000000..5559493
--- /dev/null
+++ b/WS.gd
@@ -0,0 +1,46 @@
+extends Node
+
+var ws = null
+
+signal recieved(data)
+
+
+func _ready():
+ ws = WebSocketClient.new()
+ ws.connect("connection_established", self, "_connection_established")
+ ws.connect("connection_closed", self, "_connection_closed")
+ ws.connect("connection_error", self, "_connection_error")
+
+ var url = "https://chat-server-gd.herokuapp.com/"
+ print("Connecting to " + url)
+ ws.connect_to_url(url)
+
+
+func _connection_established(protocol):
+ print("Connection established with protocol: ", protocol)
+
+
+func _connection_closed(_err):
+ print("Connection closed")
+
+
+func _connection_error():
+ print("Connection error")
+
+
+func _process(_delta):
+ if (
+ ws.get_connection_status() == ws.CONNECTION_CONNECTING
+ || ws.get_connection_status() == ws.CONNECTION_CONNECTED
+ ):
+ ws.poll()
+ if ws.get_peer(1).is_connected_to_host():
+ if ws.get_peer(1).get_available_packet_count() > 0:
+ var text = ws.get_peer(1).get_var()
+ emit_signal("recieved", text.value)
+ print("recieved %s" % text.value)
+
+
+func send_packet(variant: String):
+ if ws.get_peer(1).is_connected_to_host():
+ ws.get_peer(1).put_var(variant)
diff --git a/WS.tscn b/WS.tscn
new file mode 100644
index 0000000..dbc11e5
--- /dev/null
+++ b/WS.tscn
@@ -0,0 +1,87 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://WS.gd" type="Script" id=1]
+[ext_resource path="res://Chat.gd" type="Script" id=2]
+[ext_resource path="res://theme.tres" type="Theme" id=3]
+
+[node name="Main" type="Node"]
+script = ExtResource( 1 )
+
+[node name="Chat" type="Control" parent="."]
+anchor_right = 1.0
+anchor_bottom = 1.0
+theme = ExtResource( 3 )
+script = ExtResource( 2 )
+
+[node name="v" type="VBoxContainer" parent="Chat"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+margin_left = 32.0
+margin_top = 64.0
+margin_right = -32.0
+margin_bottom = -60.0
+custom_constants/separation = 0
+
+[node name="h" type="HBoxContainer" parent="Chat/v"]
+margin_right = 960.0
+margin_bottom = 38.0
+
+[node name="whoami" type="LineEdit" parent="Chat/v/h"]
+margin_right = 200.0
+margin_bottom = 38.0
+rect_min_size = Vector2( 200, 0 )
+text = "whoami"
+max_length = 30
+expand_to_text_length = true
+placeholder_text = "whoami"
+caret_blink = true
+caret_blink_speed = 0.5
+
+[node name="Label" type="Label" parent="Chat/v/h"]
+margin_left = 204.0
+margin_right = 324.0
+margin_bottom = 38.0
+text = "room 2"
+
+[node name="p" type="Panel" parent="Chat/v"]
+margin_top = 38.0
+margin_right = 960.0
+margin_bottom = 438.0
+rect_min_size = Vector2( 896, 400 )
+
+[node name="scroller" type="ScrollContainer" parent="Chat/v/p"]
+margin_right = 896.0
+margin_bottom = 400.0
+rect_min_size = Vector2( 0, 400 )
+
+[node name="labels" type="VBoxContainer" parent="Chat/v/p/scroller"]
+
+[node name="h2" type="HBoxContainer" parent="Chat/v"]
+margin_top = 438.0
+margin_right = 960.0
+margin_bottom = 476.0
+custom_constants/separation = 0
+
+[node name="text" type="LineEdit" parent="Chat/v/h2"]
+margin_right = 800.0
+margin_bottom = 38.0
+rect_min_size = Vector2( 800, 0 )
+max_length = 27
+placeholder_text = "send message"
+caret_blink = true
+caret_blink_speed = 0.5
+
+[node name="send" type="Button" parent="Chat/v/h2"]
+margin_left = 800.0
+margin_right = 960.0
+margin_bottom = 38.0
+focus_mode = 0
+size_flags_horizontal = 3
+enabled_focus_mode = 0
+text = "send"
+
+[node name="Tween" type="Tween" parent="Chat"]
+
+[connection signal="recieved" from="." to="Chat" method="_on_Main_recieved"]
+[connection signal="text_entered" from="Chat/v/h2/text" to="Chat" method="_on_text_entered"]
+[connection signal="pressed" from="Chat/v/h2/send" to="Chat" method="_on_send_pressed"]
diff --git a/bg.tres b/bg.tres
new file mode 100644
index 0000000..448a5ad
--- /dev/null
+++ b/bg.tres
@@ -0,0 +1,4 @@
+[gd_resource type="StyleBoxFlat" format=2]
+
+[resource]
+bg_color = Color( 0.180392, 0.180392, 0.180392, 1 )
diff --git a/default_env.tres b/default_env.tres
new file mode 100644
index 0000000..d37b59d
--- /dev/null
+++ b/default_env.tres
@@ -0,0 +1,13 @@
+[gd_resource type="Environment" load_steps=2 format=2]
+
+[sub_resource type="ProceduralSky" id=1]
+sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
+sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
+sky_curve = 0.25
+ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
+ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
+ground_curve = 0.01
+
+[resource]
+background_mode = 2
+background_sky = SubResource( 1 )
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..a0b64ee
--- /dev/null
+++ b/icon.png
Binary files differ
diff --git a/icon.png.import b/icon.png.import
new file mode 100644
index 0000000..a4c02e6
--- /dev/null
+++ b/icon.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/project.godot b/project.godot
new file mode 100644
index 0000000..70ae54f
--- /dev/null
+++ b/project.godot
@@ -0,0 +1,23 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=4
+
+_global_script_classes=[ ]
+_global_script_class_icons={
+}
+
+[application]
+
+config/name="gd-com-websocket-basic"
+run/main_scene="res://WS.tscn"
+config/icon="res://icon.png"
+
+[rendering]
+
+environment/default_environment="res://default_env.tres"
diff --git a/theme.tres b/theme.tres
new file mode 100644
index 0000000..48e0503
--- /dev/null
+++ b/theme.tres
@@ -0,0 +1,27 @@
+[gd_resource type="Theme" load_steps=7 format=2]
+
+[ext_resource path="res://bg.tres" type="StyleBox" id=1]
+[ext_resource path="res://verdana.tres" type="DynamicFont" id=2]
+
+[sub_resource type="StyleBoxFlat" id=4]
+bg_color = Color( 0.196078, 0.309804, 0.396078, 1 )
+
+[sub_resource type="StyleBoxFlat" id=1]
+bg_color = Color( 0.145098, 0.117647, 0.117647, 1 )
+
+[sub_resource type="StyleBoxFlat" id=2]
+bg_color = Color( 0.117647, 0.117647, 0.117647, 1 )
+
+[sub_resource type="StyleBoxEmpty" id=3]
+
+[resource]
+default_font = ExtResource( 2 )
+Button/styles/focus = SubResource( 4 )
+Button/styles/hover = SubResource( 4 )
+Button/styles/normal = ExtResource( 1 )
+Button/styles/pressed = SubResource( 4 )
+LineEdit/colors/font_color = Color( 1, 1, 1, 1 )
+LineEdit/styles/focus = SubResource( 1 )
+LineEdit/styles/normal = SubResource( 2 )
+Panel/styles/panel = ExtResource( 1 )
+VScrollBar/styles/scroll = SubResource( 3 )
diff --git a/verdana-bold.ttf b/verdana-bold.ttf
new file mode 100644
index 0000000..e54bccd
--- /dev/null
+++ b/verdana-bold.ttf
Binary files differ
diff --git a/verdana.tres b/verdana.tres
new file mode 100644
index 0000000..d8abd0f
--- /dev/null
+++ b/verdana.tres
@@ -0,0 +1,7 @@
+[gd_resource type="DynamicFont" load_steps=2 format=2]
+
+[ext_resource path="res://verdana-bold.ttf" type="DynamicFontData" id=1]
+
+[resource]
+size = 30
+font_data = ExtResource( 1 )