From b466eb09eb98b5eadeb3644062d8149bfc0361b5 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 9 Mar 2024 04:24:05 +0100 Subject: [PATCH] I started some changes I will undo --- scenes/multiple_players_tracker.gd | 1 + scenes/single_peer_tracker.gd | 12 ++++++++++++ scenes/single_peer_tracker.tscn | 6 ++++++ scenes/single_player_tracker.gd | 24 +++++++++++++++++++++++- scenes/single_player_tracker.tscn | 23 ++--------------------- 5 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 scenes/single_peer_tracker.gd create mode 100644 scenes/single_peer_tracker.tscn diff --git a/scenes/multiple_players_tracker.gd b/scenes/multiple_players_tracker.gd index 478030f..e090d57 100644 --- a/scenes/multiple_players_tracker.gd +++ b/scenes/multiple_players_tracker.gd @@ -42,6 +42,7 @@ func find_name(player_name: String) -> SinglePlayerTracker: return tracker return null + ## Create a new [SinglePlayerTracker] for the given peer id, or return the one that already exists. @rpc("authority", "call_local", "reliable") func create(peer_id: int) -> SinglePlayerTracker: diff --git a/scenes/single_peer_tracker.gd b/scenes/single_peer_tracker.gd new file mode 100644 index 0000000..523e8cd --- /dev/null +++ b/scenes/single_peer_tracker.gd @@ -0,0 +1,12 @@ +extends Node +class_name SinglePeerTracker + +## Node representative of a single connected peer. +## +## That specific peer must have authority over this node. +## +## Then, that authority is used to connect to a specific player. + +@rpc("authority", "call_local", "reliable") +func takeover(player: SinglePlayerTracker): + pass diff --git a/scenes/single_peer_tracker.tscn b/scenes/single_peer_tracker.tscn new file mode 100644 index 0000000..a8807c4 --- /dev/null +++ b/scenes/single_peer_tracker.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://gabtrafmbrmn"] + +[ext_resource type="Script" path="res://scenes/single_peer_tracker.gd" id="1_pofmw"] + +[node name="SinglePeerTracker" type="Node"] +script = ExtResource("1_pofmw") diff --git a/scenes/single_player_tracker.gd b/scenes/single_player_tracker.gd index 3b099ba..376bd61 100644 --- a/scenes/single_player_tracker.gd +++ b/scenes/single_player_tracker.gd @@ -1,4 +1,4 @@ -extends MultiplayerSynchronizer +extends Node class_name SinglePlayerTracker ## Node representative of a player connected to the room. @@ -13,3 +13,25 @@ var player_color: Color = Color.WHITE ## Whether this player is currently connected or not. var player_connected: bool = false + +## Change the name of this player. +@rpc("authority", "call_local", "reliable") +func set_player_name(value: String): + player_name = value + +## Change the color of this player. +@rpc("authority", "call_local", "reliable") +func set_player_color(value: Color): + player_color = value + +## Ask the authority for this player to repeat the player's name. +@rpc("any_peer", "call_local", "reliable") +func query_player_name(): + if is_multiplayer_authority(): + set_player_name.rpc(player_name) + +## Ask the authority for this player to repeat the player's color. +@rpc("any_peer", "call_local", "reliable") +func query_player_color(): + if is_multiplayer_authority(): + set_player_color.rpc(player_color) diff --git a/scenes/single_player_tracker.tscn b/scenes/single_player_tracker.tscn index ce11fab..ec5116e 100644 --- a/scenes/single_player_tracker.tscn +++ b/scenes/single_player_tracker.tscn @@ -1,25 +1,6 @@ -[gd_scene load_steps=3 format=3 uid="uid://drccgvtcng3ju"] +[gd_scene load_steps=2 format=3 uid="uid://drccgvtcng3ju"] [ext_resource type="Script" path="res://scenes/single_player_tracker.gd" id="1_jwlkv"] -[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_755wr"] -properties/0/path = NodePath(".:player_connected") -properties/0/spawn = true -properties/0/replication_mode = 2 -properties/1/path = NodePath(".:player_name") -properties/1/spawn = true -properties/1/replication_mode = 2 -properties/2/path = NodePath(".:player_color") -properties/2/spawn = true -properties/2/replication_mode = 2 -properties/3/path = NodePath(".:strokes_per_hole") -properties/3/spawn = true -properties/3/replication_mode = 2 - -[node name="SinglePlayerTracker" type="MultiplayerSynchronizer"] -root_path = NodePath(".") -replication_interval = 1.0 -delta_interval = 0.125 -replication_config = SubResource("SceneReplicationConfig_755wr") -visibility_update_mode = 2 +[node name="SinglePlayerTracker" type="Node"] script = ExtResource("1_jwlkv")