From 49f4e7c70f850786558cb0baf3c5d8ac2319163f Mon Sep 17 00:00:00 2001 From: unfa Date: Sun, 22 Aug 2021 01:20:07 +0200 Subject: [PATCH] Added debug display to help figure out syncing player_info between peers --- Game/Main.gd | 17 ++++++++++------- Game/Main.tscn | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Game/Main.gd b/Game/Main.gd index b3f1a99..431b5be 100644 --- a/Game/Main.gd +++ b/Game/Main.gd @@ -61,7 +61,11 @@ class PlayerInfo: #func generate(): - +func _process(delta): + $Label.text = "player_list: \n" + for i in player_list.keys(): + $Label.text += str(i) + str(player_list[i].serialize()) + "\n" + var local_player_info: PlayerInfo #class PlayerList: @@ -131,7 +135,7 @@ func _input(_event) -> void: #@remote func update_player_list(player_list): # self.player_list = player_list -@remote func player_list_update(info): +@remotesync func player_list_update(info): var new_info = PlayerInfo.deserialize(info) var id = get_tree().get_rpc_sender_id() print("Updating player_list wit hnew info: ", new_info) @@ -142,10 +146,8 @@ func _input(_event) -> void: func create_player(id: int, is_local: bool) -> void: var new_player - if player_scene.has_method(&"instance"): - new_player = player_scene.instance() - else: - new_player = player_scene.instantiate() + new_player = player_scene.instantiate() + var spawnpoint = $Map/SpawnPoints.get_children()[randi() % len($Map/SpawnPoints.get_children())] new_player.name = str(id) new_player.global_transform = spawnpoint.global_transform @@ -158,7 +160,8 @@ func create_player(id: int, is_local: bool) -> void: var new_info = PlayerInfo.new() #new_info.generate() local_player_info = new_info - rpc_id(1,&'player_list_update', local_player_info.serialize()) + rpc_id(id, &'player_list_update', local_player_info.serialize()) # send player_info to others + player_list[id] = local_player_info $NetworkTesting/TextEdit.text = local_player_info.name $NetworkTesting/ColorPickerButton.color = local_player_info.color diff --git a/Game/Main.tscn b/Game/Main.tscn index 261a8b0..96151ac 100644 --- a/Game/Main.tscn +++ b/Game/Main.tscn @@ -34,22 +34,22 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1) [node name="NetworkTesting" type="VBoxContainer" parent="."] anchor_left = 1.0 anchor_right = 1.0 -offset_left = -100.0 -offset_bottom = 132.0 +offset_left = -166.0 +offset_bottom = 159.0 script = null __meta__ = { "_edit_use_anchors_": false } [node name="Host" type="Button" parent="NetworkTesting"] -offset_right = 100.0 +offset_right = 166.0 offset_bottom = 29.0 text = "Host" script = null [node name="Connect" type="Button" parent="NetworkTesting"] offset_top = 33.0 -offset_right = 100.0 +offset_right = 166.0 offset_bottom = 62.0 text = "Connect" script = null @@ -59,7 +59,7 @@ __meta__ = { [node name="TextEdit" type="LineEdit" parent="NetworkTesting"] offset_top = 66.0 -offset_right = 100.0 +offset_right = 166.0 offset_bottom = 99.0 rect_min_size = Vector2(100, 30) text = "name" @@ -68,7 +68,7 @@ script = null [node name="ColorPickerButton" type="ColorPickerButton" parent="NetworkTesting"] offset_top = 103.0 -offset_right = 100.0 +offset_right = 166.0 offset_bottom = 132.0 edit_alpha = false script = null @@ -76,6 +76,15 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="Label" type="Label" parent="."] +offset_right = 505.0 +offset_bottom = 238.0 +structured_text_bidi_override_options = [] +script = null +__meta__ = { +"_edit_use_anchors_": false +} + [connection signal="pressed" from="NetworkTesting/Host" to="." method="_on_Host_pressed"] [connection signal="pressed" from="NetworkTesting/Connect" to="." method="_on_Connect_pressed"] [connection signal="text_submitted" from="NetworkTesting/TextEdit" to="." method="_on_TextEdit_text_submitted"]