Chat features
This commit is contained in:
parent
a6adb8b011
commit
3ec9992707
BIN
Assets/star.png
Normal file
BIN
Assets/star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
35
Assets/star.png.import
Normal file
35
Assets/star.png.import
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/star.png-59a17f0ff6ffca9363606061d3940469.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/star.png"
|
||||||
|
dest_files=[ "res://.import/star.png-59a17f0ff6ffca9363606061d3940469.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
|
@ -10,13 +10,43 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="ItemList" type="ItemList" parent="."]
|
[node name="Chat" type="Control" parent="."]
|
||||||
anchor_left = 0.0449219
|
anchor_left = 0.80957
|
||||||
anchor_top = 0.125
|
anchor_top = 0.265
|
||||||
anchor_right = 0.254477
|
anchor_right = 0.80957
|
||||||
anchor_bottom = 0.955
|
anchor_bottom = 0.265
|
||||||
margin_right = -27.584
|
margin_right = 40.0
|
||||||
margin_bottom = -62.0
|
margin_bottom = 40.0
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": true
|
"_edit_use_anchors_": true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="TextEdit" type="TextEdit" parent="Chat"]
|
||||||
|
margin_left = -59.0
|
||||||
|
margin_top = -98.0
|
||||||
|
margin_right = 143.0
|
||||||
|
margin_bottom = 280.0
|
||||||
|
readonly = true
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="LineEdit" type="LineEdit" parent="Chat"]
|
||||||
|
margin_left = -59.0
|
||||||
|
margin_top = 287.0
|
||||||
|
margin_right = 142.0
|
||||||
|
margin_bottom = 316.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CopyBtn" type="Button" parent="."]
|
||||||
|
margin_left = 48.0
|
||||||
|
margin_top = 33.0
|
||||||
|
margin_right = 168.0
|
||||||
|
margin_bottom = 53.0
|
||||||
|
disabled = true
|
||||||
|
text = "Copy Room Code"
|
||||||
|
|
||||||
|
[connection signal="text_entered" from="Chat/LineEdit" to="." method="_on_LineEdit_text_entered"]
|
||||||
|
[connection signal="pressed" from="CopyBtn" to="." method="_on_CopyBtn_pressed"]
|
||||||
|
@ -1,14 +1,36 @@
|
|||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
onready var location = JavaScript.get_interface("location")
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
WebsocketController.connect("hostjoin", self, "_on_hostjoin")
|
WebsocketController.connect("connected", self, "_on_connected")
|
||||||
|
WebsocketController.connect("join_ok", self, "_on_join_ok")
|
||||||
|
WebsocketController.connect("room_code", self, "_on_room_code")
|
||||||
|
WebsocketController.connect("chat", self, "_on_chat")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
WebsocketController.connect_websocket()
|
WebsocketController.connect_websocket()
|
||||||
|
|
||||||
func _on_hostjoin():
|
func _on_connected():
|
||||||
var location = JavaScript.get_interface("location")
|
|
||||||
if location and location.hash != "":
|
if location and location.hash != "":
|
||||||
WebsocketController.join_game(location.hash)
|
WebsocketController.join_game(location.hash.trim_prefix("#"))
|
||||||
else:
|
else:
|
||||||
WebsocketController.host_game()
|
WebsocketController.host_game()
|
||||||
|
|
||||||
|
func _on_room_code(code):
|
||||||
|
location.hash = code
|
||||||
|
$CopyBtn.disabled = false
|
||||||
|
|
||||||
|
func _on_join_ok():
|
||||||
|
$CopyBtn.disabled = false
|
||||||
|
|
||||||
|
func _on_chat(msg):
|
||||||
|
$Chat/TextEdit.text += msg
|
||||||
|
$Chat/TextEdit.text += "\n"
|
||||||
|
|
||||||
|
func _on_CopyBtn_pressed():
|
||||||
|
OS.clipboard = location.href
|
||||||
|
|
||||||
|
func _on_LineEdit_text_entered(text):
|
||||||
|
WebsocketController.chat(text)
|
||||||
|
$Chat/LineEdit.clear()
|
||||||
|
29
Scripts/Message.gd
Normal file
29
Scripts/Message.gd
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
extends Object
|
||||||
|
|
||||||
|
class_name Message
|
||||||
|
|
||||||
|
var command: String
|
||||||
|
var args: Array
|
||||||
|
|
||||||
|
func _init(text: String = ""):
|
||||||
|
if text == "":
|
||||||
|
command = ""
|
||||||
|
args = []
|
||||||
|
return
|
||||||
|
var match_re = RegEx.new();
|
||||||
|
# r"((\\,|[^,])+)"
|
||||||
|
match_re.compile("(\\\\,|[^,])+")
|
||||||
|
|
||||||
|
var radix = text.find(':')
|
||||||
|
command = text.substr(0, radix)
|
||||||
|
var args_raw = text.substr(radix+1)
|
||||||
|
args = []
|
||||||
|
for match_ in match_re.search_all(args_raw):
|
||||||
|
var arg = match_.strings[0].strip_edges().replace("\\,", ",")
|
||||||
|
args.push_back(arg)
|
||||||
|
|
||||||
|
func _to_string():
|
||||||
|
var text = "%s:" % self.command
|
||||||
|
for arg in self.args:
|
||||||
|
text += arg.replace(",", "\\,")
|
||||||
|
return text
|
@ -1,38 +1,56 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var client = WebSocketClient.new()
|
var client = WebSocketClient.new()
|
||||||
var peer
|
var ws
|
||||||
|
|
||||||
signal hostjoin
|
signal connected
|
||||||
|
signal chat
|
||||||
|
signal room_code
|
||||||
|
signal join_ok
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
client.connect("connection_established", self, "_on_connect")
|
client.connect("connection_established", self, "_on_connect")
|
||||||
client.connect("data_received", self, "_on_data")
|
client.connect("data_received", self, "_on_data")
|
||||||
|
|
||||||
func _on_connect(_proto):
|
func _on_connect(_proto):
|
||||||
peer = client.get_peer(1)
|
ws = client.get_peer(1)
|
||||||
peer.set_write_mode(WebSocketPeer.WRITE_MODE_TEXT)
|
ws.set_write_mode(WebSocketPeer.WRITE_MODE_TEXT)
|
||||||
|
emit_signal("connected")
|
||||||
|
|
||||||
func _on_data():
|
func _on_data():
|
||||||
var msg = peer.get_packet().get_string_from_utf8()
|
var msg = Message.new(ws.get_packet().get_string_from_utf8())
|
||||||
var regex = RegEx.new()
|
match msg.command:
|
||||||
regex.compile("([\\w_]+):")
|
"CHAT":
|
||||||
var res = regex.search(msg)
|
emit_signal("chat", msg.args[0])
|
||||||
match res.strings[1]:
|
"ROOM_CODE":
|
||||||
"HOSTJOIN":
|
emit_signal("room_code", msg.args[0])
|
||||||
emit_signal("hostjoin")
|
"JOIN_OK":
|
||||||
|
emit_signal("join_ok")
|
||||||
|
_:
|
||||||
|
print("Unknown command => ", msg)
|
||||||
|
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
client.poll()
|
client.poll()
|
||||||
|
|
||||||
func send_message(message):
|
func send_message(message):
|
||||||
peer.put_packet(message.to_utf8())
|
ws.put_packet(str(message).to_utf8())
|
||||||
|
|
||||||
func connect_websocket():
|
func connect_websocket():
|
||||||
client.connect_to_url(ProjectSettings["global/server_url"]);
|
client.connect_to_url(ProjectSettings["global/server_url"]);
|
||||||
|
|
||||||
func host_game():
|
func host_game():
|
||||||
send_message("HOST:")
|
var msg = Message.new()
|
||||||
|
msg.command = "HOST"
|
||||||
|
send_message(msg)
|
||||||
|
|
||||||
func join_game(hash_):
|
func join_game(hash_):
|
||||||
send_message("JOIN: %s" % hash_)
|
var msg = Message.new()
|
||||||
|
msg.command = "JOIN"
|
||||||
|
msg.args.push_back(hash_)
|
||||||
|
send_message(msg)
|
||||||
|
|
||||||
|
func chat(text):
|
||||||
|
var msg = Message.new()
|
||||||
|
msg.command = "CHAT"
|
||||||
|
msg.args.push_back(text)
|
||||||
|
send_message(msg)
|
||||||
|
@ -23,11 +23,17 @@ _global_script_classes=[ {
|
|||||||
"class": "Hex",
|
"class": "Hex",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://Scripts/Hex.gd"
|
"path": "res://Scripts/Hex.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Object",
|
||||||
|
"class": "Message",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Scripts/Message.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"Board": "",
|
"Board": "",
|
||||||
"Chit": "",
|
"Chit": "",
|
||||||
"Hex": ""
|
"Hex": "",
|
||||||
|
"Message": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
Loading…
Reference in New Issue
Block a user