tarting work on syncronizer node
This commit is contained in:
parent
50f1173373
commit
b9cf3ff9e1
@ -25,6 +25,8 @@ signal user_left_lobby(user_id: int)
|
||||
signal host_left_lobby()
|
||||
signal on_game_started()
|
||||
|
||||
signal property_update_received(node_id: int, property_name: String, value: Variant)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
player_scene = load("res://assets/core/player-controller/scenes/player.tscn") as PackedScene
|
||||
@ -301,6 +303,11 @@ func read_p2p_packet() -> void:
|
||||
print("Received game start packet.")
|
||||
_on_game_started()
|
||||
|
||||
# Property update packet
|
||||
if "message" in readable_data and readable_data["message"] == "property_update":
|
||||
if "node_id" in readable_data and "property_name" in readable_data and "value" in readable_data:
|
||||
property_update_received.emit(readable_data["node_id"], readable_data["property_name"], readable_data["value"])
|
||||
|
||||
|
||||
# Print the packet to output
|
||||
print("Packet: %s" % readable_data)
|
||||
|
25
assets/core/networking/scripts/Syncronizer.gd
Normal file
25
assets/core/networking/scripts/Syncronizer.gd
Normal file
@ -0,0 +1,25 @@
|
||||
extends Node
|
||||
|
||||
class_name Syncronizer
|
||||
|
||||
@export var properties_to_sync: Array = []
|
||||
|
||||
signal property_changed(node_id: int, property_name: String, value: Variant)
|
||||
|
||||
func _ready() -> void:
|
||||
for property_name in properties_to_sync:
|
||||
self.connect("property_changed", Callable(self, "_on_property_changed"))
|
||||
|
||||
NetworkManager.property_update_received.connect(Callable(self, "_on_property_update_received"))
|
||||
|
||||
|
||||
func _on_property_changed(node_id: int, property_name: String, value: Variant) -> void:
|
||||
if node_id == get_instance_id() and property_name in properties_to_sync:
|
||||
self.set(property_name, value)
|
||||
emit_signal("property_changed", node_id, property_name, value)
|
||||
|
||||
|
||||
func set_property(property_name: String, value: Variant) -> void:
|
||||
if property_name in properties_to_sync:
|
||||
self.set(property_name, value)
|
||||
emit_signal("property_changed", get_instance_id(), property_name, value)
|
Loading…
Reference in New Issue
Block a user