Skip to content

Commit 5e07aa3

Browse files
authored
Add files via upload
1 parent 5c39794 commit 5e07aa3

File tree

11 files changed

+155
-86
lines changed

11 files changed

+155
-86
lines changed

Connection.tscn

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://sw0x55mw6x86"]
1+
[gd_scene load_steps=7 format=4 uid="uid://sw0x55mw6x86"]
22

33
[ext_resource type="Script" uid="uid://bkvt4c8aiypuj" path="res://connection.gd" id="1_n3v31"]
44
[ext_resource type="FontVariation" uid="uid://bbbowwhyjq3j8" path="res://fonts/kc_fonts_regular.tres" id="2_gipfx"]
5+
[ext_resource type="StyleBox" uid="uid://dbvlytgdphl8o" path="res://button_normal.tres" id="3_8dcmy"]
6+
[ext_resource type="TileSet" uid="uid://yu8us2sunv2v" path="res://ui_tileset.tres" id="3_miogf"]
7+
[ext_resource type="StyleBox" uid="uid://b5ik4wnedffx1" path="res://button_hover.tres" id="4_go0sp"]
58

69
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_gipfx"]
710

@@ -10,23 +13,38 @@ script = ExtResource("1_n3v31")
1013

1114
[node name="Status_BG" type="Panel" parent="."]
1215
texture_filter = 1
13-
offset_left = 973.0
14-
offset_top = 664.0
15-
offset_right = 1261.0
16-
offset_bottom = 716.0
16+
offset_right = 288.0
17+
offset_bottom = 52.0
1718
theme_override_styles/panel = SubResource("StyleBoxEmpty_gipfx")
1819

1920
[node name="Status" type="Label" parent="Status_BG"]
2021
z_index = 1
2122
texture_filter = 1
2223
layout_mode = 0
23-
offset_left = 4.0
24-
offset_top = 22.0
25-
offset_right = 292.0
26-
offset_bottom = 54.0
24+
offset_left = 1.0
25+
offset_right = 879.0
26+
offset_bottom = 17.0
2727
theme_override_colors/font_color = Color(1, 1, 1, 1)
2828
theme_override_fonts/font = ExtResource("2_gipfx")
2929
theme_override_font_sizes/font_size = 12
3030
horizontal_alignment = 1
3131
vertical_alignment = 1
3232
autowrap_mode = 1
33+
34+
[node name="ReconnectButton" type="Button" parent="Status_BG"]
35+
layout_mode = 0
36+
offset_left = 339.0
37+
offset_top = 317.0
38+
offset_right = 557.0
39+
offset_bottom = 375.0
40+
theme_override_fonts/font = ExtResource("2_gipfx")
41+
theme_override_font_sizes/font_size = 36
42+
theme_override_styles/normal = ExtResource("3_8dcmy")
43+
theme_override_styles/pressed = ExtResource("4_go0sp")
44+
theme_override_styles/hover = ExtResource("4_go0sp")
45+
text = "Reconnect"
46+
47+
[node name="TileMapLayer" type="TileMapLayer" parent="Status_BG/ReconnectButton"]
48+
position = Vector2(13, 13)
49+
tile_map_data = PackedByteArray("AAD/////AQAAAAAAAAAAAP//AQABAAAAAAABAP//AQABAAAAAAACAP//AQABAAAAAAADAP//AQABAAAAAAAEAP//AQABAAAAAAAFAP//AQABAAAAAAAGAP//AQADAAAAAAD//wAAAQAAAAEAAAAGAAAAAQAAAAEAAAD//wEAAQAAAAIAAAAGAAEAAQADAAIAAAAAAAEAAQABAAAAAAABAAEAAQABAAAAAAACAAEAAQABAAAAAAADAAEAAQABAAAAAAAEAAEAAQABAAAAAAAFAAEAAQABAAAAAAA=")
50+
tile_set = ExtResource("3_miogf")

Containers.tscn

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
[gd_scene load_steps=15 format=4 uid="uid://47siqdrbmm5y"]
1+
[gd_scene load_steps=13 format=4 uid="uid://47siqdrbmm5y"]
22

33
[ext_resource type="Script" uid="uid://dh5p1h1ow0a8g" path="res://containers.gd" id="1_aqjdc"]
4+
[ext_resource type="StyleBox" uid="uid://dbvlytgdphl8o" path="res://button_normal.tres" id="5_labx1"]
5+
[ext_resource type="StyleBox" uid="uid://b5ik4wnedffx1" path="res://button_hover.tres" id="6_2t56i"]
46
[ext_resource type="FontVariation" uid="uid://bbbowwhyjq3j8" path="res://fonts/kc_fonts_regular.tres" id="6_jsvej"]
57
[ext_resource type="Script" uid="uid://ccuqqlwx5pgei" path="res://backpack.gd" id="7_q7mms"]
68
[ext_resource type="Texture2D" uid="uid://cju0nqelwrivj" path="res://assets/ui_frame.png" id="7_yq0kq"]
@@ -35,14 +37,6 @@ texture_region_size = Vector2i(32, 32)
3537
tile_size = Vector2i(32, 32)
3638
sources/1 = SubResource("TileSetAtlasSource_q7mms")
3739

38-
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_yq0kq"]
39-
40-
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_q7mms"]
41-
42-
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_labx1"]
43-
44-
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_2t56i"]
45-
4640
[node name="Containers" type="Node2D"]
4741
script = ExtResource("1_aqjdc")
4842

@@ -82,8 +76,9 @@ offset_right = 317.0
8276
offset_bottom = 27.0
8377
theme_override_fonts/font = ExtResource("6_jsvej")
8478
theme_override_font_sizes/font_size = 18
85-
theme_override_styles/normal = SubResource("StyleBoxEmpty_yq0kq")
86-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_q7mms")
79+
theme_override_styles/normal = ExtResource("5_labx1")
80+
theme_override_styles/pressed = ExtResource("6_2t56i")
81+
theme_override_styles/hover = ExtResource("6_2t56i")
8782
text = "Backpack"
8883
autowrap_trim_flags = 0
8984

@@ -96,8 +91,9 @@ offset_right = 317.0
9691
offset_bottom = 603.0
9792
theme_override_fonts/font = ExtResource("6_jsvej")
9893
theme_override_font_sizes/font_size = 18
99-
theme_override_styles/normal = SubResource("StyleBoxEmpty_labx1")
100-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_2t56i")
94+
theme_override_styles/normal = ExtResource("5_labx1")
95+
theme_override_styles/pressed = ExtResource("6_2t56i")
96+
theme_override_styles/hover = ExtResource("6_2t56i")
10197
text = "Close"
10298
autowrap_trim_flags = 0
10399

@@ -138,8 +134,9 @@ offset_right = 797.0
138134
offset_bottom = 27.0
139135
theme_override_fonts/font = ExtResource("6_jsvej")
140136
theme_override_font_sizes/font_size = 18
141-
theme_override_styles/normal = SubResource("StyleBoxEmpty_yq0kq")
142-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_q7mms")
137+
theme_override_styles/normal = ExtResource("5_labx1")
138+
theme_override_styles/pressed = ExtResource("6_2t56i")
139+
theme_override_styles/hover = ExtResource("6_2t56i")
143140
text = "Score"
144141
autowrap_trim_flags = 0
145142

@@ -152,8 +149,9 @@ offset_right = 797.0
152149
offset_bottom = 283.0
153150
theme_override_fonts/font = ExtResource("6_jsvej")
154151
theme_override_font_sizes/font_size = 18
155-
theme_override_styles/normal = SubResource("StyleBoxEmpty_labx1")
156-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_2t56i")
152+
theme_override_styles/normal = ExtResource("5_labx1")
153+
theme_override_styles/pressed = ExtResource("6_2t56i")
154+
theme_override_styles/hover = ExtResource("6_2t56i")
157155
text = "Close"
158156
autowrap_trim_flags = 0
159157

@@ -194,8 +192,9 @@ offset_right = 794.0
194192
offset_bottom = 251.0
195193
theme_override_fonts/font = ExtResource("6_jsvej")
196194
theme_override_font_sizes/font_size = 18
197-
theme_override_styles/normal = SubResource("StyleBoxEmpty_labx1")
198-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_2t56i")
195+
theme_override_styles/normal = ExtResource("5_labx1")
196+
theme_override_styles/pressed = ExtResource("6_2t56i")
197+
theme_override_styles/hover = ExtResource("6_2t56i")
199198
text = "Close"
200199
autowrap_trim_flags = 0
201200

@@ -208,8 +207,9 @@ offset_right = 797.0
208207
offset_bottom = 27.0
209208
theme_override_fonts/font = ExtResource("6_jsvej")
210209
theme_override_font_sizes/font_size = 18
211-
theme_override_styles/normal = SubResource("StyleBoxEmpty_yq0kq")
212-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_q7mms")
210+
theme_override_styles/normal = ExtResource("5_labx1")
211+
theme_override_styles/pressed = ExtResource("6_2t56i")
212+
theme_override_styles/hover = ExtResource("6_2t56i")
213213
text = "Skills"
214214
autowrap_trim_flags = 0
215215

@@ -249,8 +249,9 @@ offset_right = 794.0
249249
offset_bottom = 250.0
250250
theme_override_fonts/font = ExtResource("6_jsvej")
251251
theme_override_font_sizes/font_size = 18
252-
theme_override_styles/normal = SubResource("StyleBoxEmpty_labx1")
253-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_2t56i")
252+
theme_override_styles/normal = ExtResource("5_labx1")
253+
theme_override_styles/pressed = ExtResource("6_2t56i")
254+
theme_override_styles/hover = ExtResource("6_2t56i")
254255
text = "Close"
255256
autowrap_trim_flags = 0
256257

@@ -263,8 +264,9 @@ offset_right = 797.0
263264
offset_bottom = 27.0
264265
theme_override_fonts/font = ExtResource("6_jsvej")
265266
theme_override_font_sizes/font_size = 18
266-
theme_override_styles/normal = SubResource("StyleBoxEmpty_yq0kq")
267-
theme_override_styles/pressed = SubResource("StyleBoxEmpty_q7mms")
267+
theme_override_styles/normal = ExtResource("5_labx1")
268+
theme_override_styles/pressed = ExtResource("6_2t56i")
269+
theme_override_styles/hover = ExtResource("6_2t56i")
268270
text = "Spells"
269271
autowrap_trim_flags = 0
270272

button_hover.tres

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[gd_resource type="StyleBoxFlat" format=3 uid="uid://b5ik4wnedffx1"]
2+
3+
[resource]
4+
bg_color = Color(0.16206557, 0.1620656, 0.16206548, 1)

button_normal.tres

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[gd_resource type="StyleBoxFlat" format=3 uid="uid://dbvlytgdphl8o"]
2+
3+
[resource]
4+
bg_color = Color(0, 0, 0, 1)

connection.gd

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,100 @@
1-
# connection.gd
21
extends Node
32

43
var official_server_url = "wss://gomud.willowdalemud.com/ws"
54
var catacombs_server_url = "wss://game.kegscatacombs.online/ws"
6-
var socket := WebSocketPeer.new()
75
var websocket_url = official_server_url
6+
var socket := WebSocketPeer.new()
87

9-
# node
108
@onready var status = $Status_BG/Status
9+
@onready var reconnect_button = $Status_BG/ReconnectButton
1110

12-
# signals you can connect to your UI / audio / gmcp handlers ---
1311
signal text_received(text: String)
1412
signal sound_received(path: String, params: Dictionary)
1513
signal GMCP_received(topic: String, data: Variant)
1614

17-
# compiled once
1815
var _re_token := RegEx.new()
1916

2017
func _ready():
21-
_re_token.compile("!!(SOUND|MUSIC|GMCP)\\(([\\s\\S]*?)\\)") # DOTALL via [\\s\\S]
22-
var err = socket.connect_to_url(websocket_url)
23-
print("Connecting to: " + str(websocket_url))
18+
_re_token.compile("!!(SOUND|MUSIC|GMCP)\\(([\\s\\S]*?)\\)")
19+
reconnect_button.connect("pressed", Callable(self, "_on_reconnect_pressed"))
20+
_connect_to_server()
21+
22+
func _connect_to_server():
2423
status.text = "Connecting to: " + str(websocket_url)
24+
print(status.text)
25+
socket = WebSocketPeer.new()
26+
var err = socket.connect_to_url(websocket_url)
2527
if err != OK:
2628
status.text = "Failed to connect..."
27-
print("Failed to connect")
29+
print(status.text)
2830
set_process(false)
2931
else:
32+
set_process(true)
33+
reconnect_button.visible = false
3034
await get_tree().create_timer(2).timeout
3135
status.text = "Connection initiated..."
32-
print("Connection initiated")
36+
print(status.text)
37+
38+
func _on_reconnect_pressed():
39+
status.text = "Reconnecting..."
40+
Global_Status._first_msg = true
41+
print("Reconnecting to server...")
42+
_connect_to_server()
3343

3444
func _process(_delta):
3545
socket.poll()
3646
var state = socket.get_ready_state()
37-
if state == WebSocketPeer.STATE_OPEN and socket.get_available_packet_count() > 0:
38-
var data_received = socket.get_packet().get_string_from_utf8()
39-
if data_received:
40-
var unix_now = Time.get_unix_time_from_system()
41-
status.text = "Data_received: " + str(unix_now)
42-
_parse_and_emit(data_received)
43-
else:
44-
status.text = "Failed to get data: " + data_received
45-
print("Failed to get data: ", data_received)
46-
47-
elif state == WebSocketPeer.STATE_CLOSING or state == WebSocketPeer.STATE_CLOSED:
48-
status.text = "Connection closed..."
49-
print("Connection closed")
50-
set_process(false)
47+
48+
match state:
49+
WebSocketPeer.STATE_OPEN:
50+
if socket.get_available_packet_count() > 0:
51+
var data_received = socket.get_packet().get_string_from_utf8()
52+
if data_received:
53+
var unix_now = Time.get_unix_time_from_system()
54+
status.text = "Data received: " + str(unix_now)
55+
_parse_and_emit(data_received)
56+
else:
57+
status.text = "Failed to get data."
58+
print(status.text)
59+
60+
WebSocketPeer.STATE_CLOSING, WebSocketPeer.STATE_CLOSED:
61+
if reconnect_button.visible == false:
62+
status.text = "Connection closed. Click Reconnect."
63+
reconnect_button.visible = true
64+
print(status.text)
65+
set_process(false)
5166

5267
# ---------- core splitter ----------
5368
func _parse_and_emit(s: String) -> void:
5469
var last := 0
5570
for m in _re_token.search_all(s):
5671
var start = m.get_start()
5772
var stop = m.get_end()
58-
# plain text before the token
5973
if start > last:
6074
var txt := s.substr(last, start - last)
6175
if txt != "":
6276
emit_signal("text_received", txt)
63-
64-
var kind = m.get_string(1) # "SOUND" or "GMCP"
65-
var body = m.get_string(2) # inside the parentheses
66-
67-
if kind == "SOUND":
68-
var snd = _parse_sound(body)
69-
emit_signal("sound_received", snd)
70-
elif kind == "MUSIC":
71-
var musc = _parse_sound(body)
72-
emit_signal("sound_received", musc)
73-
else: # GMCP
74-
var gm = _parse_gmcp(body)
75-
emit_signal("GMCP_received", gm)
77+
78+
var kind = m.get_string(1)
79+
var body = m.get_string(2)
80+
81+
match kind:
82+
"SOUND", "MUSIC":
83+
var snd = _parse_sound(body)
84+
emit_signal("sound_received", snd)
85+
"GMCP":
86+
var gm = _parse_gmcp(body)
87+
emit_signal("GMCP_received", gm)
7688

7789
last = stop
7890

79-
# tail after last token
8091
if last < s.length():
8192
var tail := s.substr(last)
8293
if tail != "":
8394
emit_signal("text_received", tail)
8495

8596
# ---------- SOUND parser ----------
8697
func _parse_sound(body: String) -> Dictionary:
87-
# Example: "static/audio/sound/movement/room-enter.mp3 T=movement V=100"
8898
var parts := body.strip_edges().split(" ", false)
8999
var path := parts[0] if parts.size() > 0 else ""
90100
var params: Dictionary = {}
@@ -99,32 +109,28 @@ func _parse_sound(body: String) -> Dictionary:
99109
params[k] = float(v)
100110
else:
101111
params[k] = v
102-
103112
return {"path": path, "params": params}
104113

105114
# ---------- GMCP parser ----------
106115
func _parse_gmcp(body: String) -> Dictionary:
107-
# Example: "Char.Affects { ...json... }"
108116
var s := body.strip_edges()
109117
var sp := s.find(" ")
110118

111119
var topic := s.substr(0, sp) if sp != -1 else s
112120
var payload := s.substr(sp + 1).strip_edges() if sp != -1 else ""
113-
114121
var data: Variant = payload
122+
115123
if payload.begins_with("{") or payload.begins_with("["):
116124
var j := JSON.new()
117125
if j.parse(payload) == OK:
118-
data = j.data # Dictionary/Array
119-
126+
data = j.data
120127
return {"topic": topic, "data": data}
121128

122-
123129
func send_message(cmd: String):
124130
if socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
125131
status.text = "Cannot send message. Socket not open."
126-
print("Cannot send message. Socket not open.")
132+
print(status.text)
127133
return
128134
socket.send_text(cmd)
129-
status.text = "Sent:" + cmd
130-
print("Sent:", cmd)
135+
status.text = "Sent: " + cmd
136+
print(status.text)

global_status.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extends Node
2+
3+
var _first_msg = true

global_status.gd.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://c06au5roayj0i

main.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ vertical_alignment = 1
120120
position = Vector2(33, 33)
121121

122122
[node name="Connection" parent="." instance=ExtResource("3_lquwl")]
123+
position = Vector2(39, 1)
123124

124125
[node name="Input" parent="." instance=ExtResource("4_1bvp3")]
125126
position = Vector2(81, 656)

project.godot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ run/main_scene="uid://dofvc2ex1xykw"
1515
config/features=PackedStringArray("4.5", "GL Compatibility")
1616
config/icon="res://icon.svg"
1717

18+
[autoload]
19+
20+
Global_Status="*res://global_status.gd"
21+
1822
[display]
1923

2024
window/size/viewport_width=1280

0 commit comments

Comments
 (0)