2020-02-04 16:38:02 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
|
|
const PORT : int = 9374
|
2020-03-01 23:18:15 +00:00
|
|
|
const Arena = preload("res://Scenes/Arena.tscn")
|
2020-02-11 09:59:27 +00:00
|
|
|
var console_output : TextEdit = null
|
2020-03-01 23:18:15 +00:00
|
|
|
var peer : NetworkedMultiplayerENet = null
|
2020-02-04 16:38:02 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
get_tree().connect("connected_to_server", self, "_connected_to_server")
|
|
|
|
get_tree().connect("server_disconnected", self, "_server_disconnected")
|
|
|
|
get_tree().connect("connection_failed", self, "_connection_failed")
|
2020-03-01 23:18:15 +00:00
|
|
|
$Lobby/StartButton.connect("pressed", self, "_on_StartButton_pressed")
|
2020-02-11 09:59:27 +00:00
|
|
|
console_output = $ConsoleOutput
|
|
|
|
|
|
|
|
func _process(delta : float) -> void:
|
|
|
|
if Input.is_action_just_pressed("toggle_console"):
|
|
|
|
self.toggle_console()
|
2020-02-04 16:38:02 +00:00
|
|
|
|
|
|
|
func _connected_to_server() -> void:
|
2020-02-11 09:59:27 +00:00
|
|
|
self.console_print("Connected to server") # Let the server know all about us (eg name)
|
2020-02-04 16:38:02 +00:00
|
|
|
|
|
|
|
func _server_disconnected() -> void:
|
2020-02-11 09:59:27 +00:00
|
|
|
var button : Button = $Lobby/StartButton
|
|
|
|
if button:
|
|
|
|
button.disabled = false
|
|
|
|
else:
|
|
|
|
self.console_print("Tried to re-enable start button, but the start button could not be found")
|
|
|
|
self.console_print("Disconnected from server") # Kick us out the game and bring back the lobby (if applicable)
|
2020-02-04 16:38:02 +00:00
|
|
|
|
|
|
|
func _connection_failed() -> void:
|
2020-02-11 09:59:27 +00:00
|
|
|
var button : Button = $Lobby/StartButton
|
|
|
|
button.disabled = false
|
|
|
|
self.console_print("Connection Error")
|
2020-02-04 16:38:02 +00:00
|
|
|
|
2020-02-11 09:59:27 +00:00
|
|
|
func console_print(text : String) -> void:
|
|
|
|
console_output.text += "\n" + text
|
|
|
|
console_output.cursor_set_line(console_output.get_line_count())
|
|
|
|
print(text)
|
2020-02-04 16:38:02 +00:00
|
|
|
|
2020-02-11 09:59:27 +00:00
|
|
|
func toggle_console() -> bool:
|
|
|
|
console_output.visible = !console_output.visible
|
|
|
|
return console_output.visible
|
2020-02-04 16:38:02 +00:00
|
|
|
|
|
|
|
func _on_StartButton_pressed() -> void:
|
2020-02-11 09:59:27 +00:00
|
|
|
var button : Button = $Lobby/StartButton
|
2020-02-04 16:38:02 +00:00
|
|
|
var ip_addr : String = $Lobby/IPLineEdit.text
|
2020-02-11 09:59:27 +00:00
|
|
|
button.disabled = true
|
2020-03-01 23:18:15 +00:00
|
|
|
peer = NetworkedMultiplayerENet.new()
|
2020-02-04 16:38:02 +00:00
|
|
|
peer.create_client(ip_addr, PORT)
|
|
|
|
get_tree().set_network_peer(peer)
|
2020-03-01 23:18:15 +00:00
|
|
|
|
|
|
|
func arena_ready() -> void:
|
|
|
|
rpc_id(1, 'client_ready', peer.get_unique_id())
|
|
|
|
|
|
|
|
remote func start_game() -> void:
|
|
|
|
$Lobby.queue_free()
|
|
|
|
var arena = Arena.instance()
|
|
|
|
add_child(arena)
|
|
|
|
arena.init()
|
|
|
|
console_print('Starting Game...')
|
|
|
|
|