commit a70269e9bcde4cdc66115f14c631b0073cdea91e Author: chimchooree Date: Fri Feb 24 21:07:02 2023 -0600 part 1 - connection diff --git a/.import/.gdignore b/.import/.gdignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.import/.gdignore @@ -0,0 +1 @@ + diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 new file mode 100644 index 0000000..5328bc7 --- /dev/null +++ b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 @@ -0,0 +1,3 @@ +source_md5="47313fa4c47a9963fddd764e1ec6e4a8" +dest_md5="26ea799ea0a3da9e753b3ebe822e0570" + diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex new file mode 100644 index 0000000..71f6913 Binary files /dev/null and b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex differ diff --git a/Client.gd b/Client.gd new file mode 100644 index 0000000..ff724fd --- /dev/null +++ b/Client.gd @@ -0,0 +1,41 @@ +extends Node + +export var websocket_url = "ws://127.0.0.1:8080" +var _client = WebSocketClient.new() +onready var UI = $UI +var chat_name + +func join_chat(username): + pass + +func send_message(message): + pass + +sync func receive_message(packet): + pass + +func _ready(): + _client.connect("connection_closed", self, "_closed") + _client.connect("connection_error", self, "_error") + _client.connect("connection_established", self, "_connected") + _client.connect("data_received", self, "_on_data_received") + + var err = _client.connect_to_url(websocket_url) + if err != OK: + print_debug("Unable to connect") + set_process(false) + +func _error(was_clean = false): + print_debug("Error. Clean break? ", was_clean) + +func _closed(was_clean = false): + print_debug("Closed. Clean break? ", was_clean) + +func _connected(protocol = ""): + print_debug("Connected with protocol ", protocol) + +func _on_data_received(): + pass + +func _process(_delta): + _client.poll() diff --git a/Client.tscn b/Client.tscn new file mode 100644 index 0000000..d586707 --- /dev/null +++ b/Client.tscn @@ -0,0 +1,61 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Client.gd" type="Script" id=1] +[ext_resource path="res://UI.gd" type="Script" id=2] + +[node name="Client" type="Node"] +script = ExtResource( 1 ) + +[node name="UI" type="PanelContainer" parent="."] +margin_right = 250.0 +margin_bottom = 600.0 +script = ExtResource( 2 ) + +[node name="VBox" type="VBoxContainer" parent="UI"] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 243.0 +margin_bottom = 593.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Title" type="Label" parent="UI/VBox"] +margin_right = 236.0 +margin_bottom = 14.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +text = "Chatbox" +align = 1 + +[node name="ChatLog" type="TextEdit" parent="UI/VBox"] +margin_top = 18.0 +margin_right = 236.0 +margin_bottom = 530.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +show_line_numbers = true + +[node name="ChatInput" type="LineEdit" parent="UI/VBox"] +margin_top = 534.0 +margin_right = 236.0 +margin_bottom = 558.0 +size_flags_horizontal = 3 +placeholder_text = "Enter your message..." + +[node name="HBox" type="HBoxContainer" parent="UI/VBox"] +margin_top = 562.0 +margin_right = 236.0 +margin_bottom = 586.0 + +[node name="Name" type="LineEdit" parent="UI/VBox/HBox"] +margin_right = 116.0 +margin_bottom = 24.0 +size_flags_horizontal = 3 +placeholder_text = "Username" + +[node name="JoinButton" type="Button" parent="UI/VBox/HBox"] +margin_left = 120.0 +margin_right = 236.0 +margin_bottom = 24.0 +size_flags_horizontal = 3 +text = "Join" diff --git a/UI.gd b/UI.gd new file mode 100644 index 0000000..63d5d1b --- /dev/null +++ b/UI.gd @@ -0,0 +1,21 @@ +extends PanelContainer + +onready var chat_log = $VBox/ChatLog +onready var chat_input = $VBox/ChatInput +onready var join_button = $VBox/HBox/JoinButton +onready var username = $VBox/HBox/Name + +func display_message(packet): # shout, alert, server_message, user_joined, user_left + pass + +func join_chat(): + pass + +func _input(event): + if event is InputEventKey: + if event.pressed and event.scancode == KEY_ENTER: + get_parent().send_message(chat_input.text) + chat_input.text = "" + +func _ready(): + join_button.connect("button_up", self, "join_chat") diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/icon.png 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..4316a25 --- /dev/null +++ b/project.godot @@ -0,0 +1,31 @@ +; 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 + +[application] + +config/name="Chat Client" +run/main_scene="res://Client.tscn" +config/icon="res://icon.png" + +[display] + +window/size/width=250 + +[gui] + +common/drop_mouse_on_gui_input_disabled=true + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres"