Introduced console and bug fixes

pull/1/head
Damien Watson 2020-02-11 10:01:09 +00:00
parent a91e1b4f3c
commit 345044a431
2 changed files with 18 additions and 2 deletions

View File

@ -4,3 +4,11 @@
[node name="RootNode" type="Node"] [node name="RootNode" type="Node"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="ConsoleOutput" type="TextEdit" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
readonly = true
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -5,6 +5,7 @@ const MAX_PLAYERS : int = 2
const PORT : int = 9374 const PORT : int = 9374
var ids = [] var ids = []
var console_output : TextEdit = null
func _ready() -> void: func _ready() -> void:
var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new() var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new()
@ -14,16 +15,23 @@ func _ready() -> void:
get_tree().connect("network_peer_connected", self, "_peer_connected") get_tree().connect("network_peer_connected", self, "_peer_connected")
get_tree().connect("network_peer_disconnected", self, "_peer_disconnected") get_tree().connect("network_peer_disconnected", self, "_peer_disconnected")
console_output = $ConsoleOutput
func console_print(text : String) -> void:
console_output.text += "\n" + text
console_output.cursor_set_line(console_output.get_line_count())
print(text)
func _peer_connected(id : int) -> void: func _peer_connected(id : int) -> void:
if not id: if not id:
return return
ids.append(id) ids.append(id)
print("Player has connected with id " + String(id)) self.console_print("Player has connected with id " + String(id))
# TODO: When we reach max players -> start the game # TODO: When we reach max players -> start the game
func _peer_disconnected(id : int) -> void: func _peer_disconnected(id : int) -> void:
ids.erase(id) ids.erase(id)
print("Player has disconnected with id " + String(id)) self.console_print("Player has disconnected with id " + String(id))
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta): #func _process(delta):