Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/AutoTracking.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends Node

const DISABLED_TEXTURE = preload("res://assets/icons/disabled.png");
const TODO_TEXTURE = preload("res://assets/icons/todo.png");
const BLANK_TEXTURE = preload("res://assets/icons/blankTexture.png");
const CHECKED_GREY = Color("282626")
Expand Down Expand Up @@ -124,7 +123,7 @@ enum AUTOTRACKER_STATUS {

var _at_status = AUTOTRACKER_STATUS.DISCONNECTED

onready var status_label = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/VBoxContainer/AutoTrackStatus"
onready var status_label = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer4/AutoTrackStatus"
onready var notes_window = $"/root/Tracker/NotesWindow"

func _ready() -> void:
Expand Down Expand Up @@ -218,7 +217,10 @@ func _on_data():
var connect_data = {'Opcode': "Attach", 'Space': "SNES", 'Operands': [device]}
_client.get_peer(1).put_packet(JSON.print(connect_data).to_utf8())
Events.emit_signal('set_connected_device', device_index)
status_label.text = "Connected to " + device
if (device.length() > 23):
status_label.text = "Connected to " + device.substr(0, 20) + "..."
else:
status_label.text = "Connected to " + device

_at_status = AUTOTRACKER_STATUS.CONNECTED
_timer.start()
Expand Down Expand Up @@ -268,8 +270,13 @@ func process_location_data():
if !(loc == "ParadoxM" or loc == "ParadoxL"):
underworld_node.get_child(0).set_pressed_texture(BLANK_TEXTURE)
underworld_node.get_child(0).set_pressed(true)
Events.emit_signal("coop_send_update", {
"event": "toggle_todo",
"node_path": underworld_node.get_child(0).get_path(),
"is_pressed": true
})
else:
underworld_node.get_child(0).set_pressed_texture(DISABLED_TEXTURE if all_locs_checked else TODO_TEXTURE)
underworld_node.get_child(0).set_pressed_texture(TODO_TEXTURE)
underworld_node.get_child(0).set_pressed(true)
else:
# after loading a save locations on the map get loaded as @loc@[RANDOM NUMBER] instead of just loc
Expand Down
83 changes: 83 additions & 0 deletions src/CoopClient.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
extends Node

# The URL we will connect to

# Our WebSocketClient instance
var _client = WebSocketClient.new()
var connected_to = ""
onready var connect_status = $"/root/Tracker/GUILayer/GUI/CoopClientContainer/CoopClientConnect/Shadow/Container/BG/Control/StatusText"
onready var gui_status = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer2/CoopStatus"
onready var gui_status_container = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer2"
onready var gui_label_container = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer"
const TODO_TEXTURE = preload("res://assets/icons/todo.png");
const CHECKED_GREY = Color("282626")

func _ready():
# Connect base signals to get notified of connection open, close, and errors.
_client.connect("connection_closed", self, "_closed")
_client.connect("connection_error", self, "_closed")
_client.connect("connection_established", self, "_connected")
_client.connect("data_received", self, "_on_data")
Events.connect("coop_send_update", self, "_send_update")
Events.connect("connect_to_coop_server", self, "_on_connect_to_server")

func _on_connect_to_server(websocket_url) -> void:
# Initiate connection to the given URL.
var err = _client.connect_to_url(websocket_url, [])
if err != OK:
connect_status.text = "Unable to connect"
connected_to = websocket_url

func _closed(_was_clean = false):
connect_status.text = "Connection closed"
gui_status.text = "Disconnected"

func _connected(_proto = ""):
connect_status.text = "Connected to " + connected_to
gui_status_container.show()
gui_label_container.show()
if (!Util.coop_server):
gui_status.text = "Connected"

func _send_update(data: Dictionary) -> void:
if _client.get_connected_host() == "":
return
_client.get_peer(1).put_packet(JSON.print(data).to_utf8())

func _on_data():
var pkt = parse_json(_client.get_peer(1).get_packet().get_string_from_utf8())
if typeof(pkt) != TYPE_DICTIONARY:
return
if pkt['event'] == "update_marker":
Events.emit_signal("coop_update_marker", pkt)

elif pkt['event'] == "remove_marker":
Events.emit_signal("coop_remove_marker", pkt.uuid)

elif pkt['event'] == "toggle_todo":
var icon = get_node(pkt['node_path'])
if (icon.get_pressed_texture() != TODO_TEXTURE):
icon.set_pressed_texture(TODO_TEXTURE)
if (icon.get_parent().self_modulate != CHECKED_GREY) and !icon.is_pressed():
icon.set_pressed(pkt['is_pressed'])

elif pkt['event'] == "toggle_button":
var button = get_node(pkt['node_path'])
button.set_pressed(false)
if button.get_parent().self_modulate != CHECKED_GREY && pkt['checked']:
button.get_parent().self_modulate = CHECKED_GREY
elif button.get_parent().self_modulate == CHECKED_GREY && !pkt['checked']:
button.get_parent().self_modulate = Color.white

elif pkt['event'] == "add_location":
var location = get_node(pkt['node_path'])
location.show()
Util.remove_hidden(location)

elif pkt['event'] == "remove_location":
var location = get_node(pkt['node_path'])
location.hide()
Util.add_hidden(location)

func _process(delta):
_client.poll()
68 changes: 68 additions & 0 deletions src/CoopServer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
extends Node

var _server = WebSocketServer.new()
var _clients = {}
var _write_mode = WebSocketPeer.WRITE_MODE_BINARY
var _use_multiplayer = true

onready var server_status = $"/root/Tracker/GUILayer/GUI/CoopServerContainer/CoopServerSettings/Shadow/Container/BG/Control/StatusText"
onready var gui_status = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer2/CoopStatus"
onready var gui_status_container = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer2"
onready var gui_label_container = $"/root/Tracker/GUILayer/GUI/Container/Margin/HSplitContainer/Entrances/Dungeons/MarginContainer/VBoxContainer/HBoxContainer"


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_server.connect("client_connected", self, "_connected")
_server.connect("client_disconnected", self, "_disconnected")
_server.connect("client_close_request", self, "_close_request")
_server.connect("data_received", self, "_on_data")
Events.connect("start_coop_server", self, "_on_start_coop_server")
Events.connect("stop_coop_server", self, "_on_stop_coop_server")


func _on_start_coop_server(port: int) -> void:
server_status.text = "Starting server..."
var ip_address = Util.get_external_ip_address()
var err = _server.listen(port)
if err != OK:
return
server_status.text = "Server started on " + ip_address + ":" + str(port)
Events.emit_signal('connect_to_coop_server', "ws://127.0.0.1:" + str(port))
Events.emit_signal('coop_server_started', ip_address + ":" + str(port))
gui_status.text = "Server Running"
Util.coop_server = true
gui_status_container.show()
gui_label_container.show()

func _on_stop_coop_server() -> void:
server_status.text = "Stopping server..."
_server.stop()
gui_status_container.hide()
gui_label_container.hide()
Events.emit_signal('coop_server_stopped')
Util.coop_server = false
server_status.text = "Server Stopped"
_clients.clear()


func _connected(id, _proto):
_clients[id] = true
if (len(_clients) > 1):
gui_status.text = "Server Running [" + str(len(_clients)-1) + " clients]"

func _close_request(id, _code, _reason):
_clients.erase(id)

func _disconnected(id, _was_clean = false):
_clients.erase(id)

func _on_data(id):
var pkt = _server.get_peer(id).get_packet()
# Broadcast the packet to all clients except the one that sent it.
for client_id in _clients.keys():
if client_id != id:
_server.get_peer(client_id).put_packet(pkt)

func _process(delta):
_server.poll()
16 changes: 16 additions & 0 deletions src/Events.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ signal set_connected_device(device)
# warning-ignore:unused_signal
signal refresh_devices()
# warning-ignore:unused_signal
signal start_coop_server(port)
# warning-ignore:unused_signal
signal stop_coop_server()
# warning-ignore:unused_signal
signal coop_server_started(address)
# warning-ignore:unused_signal
signal coop_server_stopped()
# warning-ignore:unused_signal
signal connect_to_coop_server()
# warning-ignore:unused_signal
signal coop_send_update(data)
# warning-ignore:unused_signal
signal coop_update_marker(data)
# warning-ignore:unused_signal
signal coop_remove_marker(data)
# warning-ignore:unused_signal
signal open_menu()
# warning-ignore:unused_signal
signal undo()
1 change: 0 additions & 1 deletion src/GUI/AutoTrackingSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func _on_devices_discovered(_devices) -> void:
selected_device.add_item(_devices[i], i)

func _on_refresh_devices_pressed() -> void:
print("Refreshing devices")
Events.emit_signal('refresh_devices')

func _on_set_connected_device(_device) -> void:
Expand Down
32 changes: 32 additions & 0 deletions src/GUI/CoopClientConnect.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
extends Control
onready var server_info = $ServerInfo

onready var connect_button = $Connect
onready var close_button = $Close

onready var shadow = $"/root/Tracker/GUILayer/GUI/CoopClientContainer/CoopClientConnect/Shadow"
onready var connect_status = $"/root/Tracker/GUILayer/GUI/CoopClientContainer/CoopClientConnect/Shadow/Container/BG/Control/StatusText"

var regex = RegEx.new()


func _ready() -> void:
Events.connect('set_discovered_devices', self, '_on_devices_discovered')
Events.connect('set_connected_device', self, '_on_set_connected_device')
close_button.connect('pressed', self, '_on_close_pressed')
connect_button.connect('pressed', self, '_on_start_pressed')


func _on_start_pressed() -> void:
var server_address = server_info.text
if server_address == "":
server_address = server_info.placeholder_text
regex.compile("^wss?://[a-zA-Z0-9.-]+:[0-9]+$")
if not regex.search(server_address):
connect_status.text = "Invalid server address"
return
connect_status.text = "Connecting to server..."
Events.emit_signal('connect_to_coop_server', server_address)

func _on_close_pressed() -> void:
shadow.hide()
60 changes: 60 additions & 0 deletions src/GUI/CoopClientConnect.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[gd_scene format=2]

[node name="Control" type="Control"]
process_priority = -1
anchor_right = 0.324
anchor_bottom = 0.283
margin_bottom = 0.149994

[node name="Title" type="Label" parent="."]
margin_left = 128.0
margin_top = 16.0
margin_right = 269.0
margin_bottom = 30.0
text = "Connect to Co-op Server..."
align = 1

[node name="PortTitle" type="Label" parent="."]
margin_left = 19.0
margin_top = 49.0
margin_right = 148.0
margin_bottom = 63.0
rect_pivot_offset = Vector2( 38, 20 )
text = "Server Address (ws(s)://<IP>:<PORT>)"

[node name="Close" type="Button" parent="."]
margin_left = 25.0
margin_top = 202.0
margin_right = 97.0
margin_bottom = 225.0
text = "Close "

[node name="Connect" type="Button" parent="."]
margin_left = 25.0
margin_top = 169.0
margin_right = 97.0
margin_bottom = 192.0
text = "Connect"

[node name="StatusText" type="Label" parent="."]
margin_left = 50.0
margin_top = 143.0
margin_right = 179.0
margin_bottom = 157.0
rect_pivot_offset = Vector2( 38, 20 )
text = "Not Running"

[node name="Status" type="Label" parent="."]
margin_left = 25.0
margin_top = 118.0
margin_right = 73.0
margin_bottom = 132.0
rect_pivot_offset = Vector2( 38, 20 )
text = "Status: "

[node name="ServerInfo" type="LineEdit" parent="."]
margin_left = 30.0
margin_top = 75.0
margin_right = 471.0
margin_bottom = 99.0
placeholder_text = "ws://127.0.0.1:23216"
Loading