extends Control onready var location = JavaScript.get_interface("location") func _init(): 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(): WebsocketController.connect_websocket() func _on_connected(): if location and location.hash != "": WebsocketController.join_game(location.hash.trim_prefix("#")) else: 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()