bazar_alea/client/player/PlayerNetworkingComponent.gd

87 lines
3 KiB
GDScript

extends Node
class_name PlayerNetworkingComponent
@export var character_movement_component : NodePath
@onready var PlayerRef = get_node(character_movement_component)
var sync_camera_h_transform : Transform3D
var sync_camera_v_transform : Transform3D
var sync_view_mode : Global.VIEW_MODE = Global.VIEW_MODE.THIRD_PERSON
var sync_CameraHOffset : float
var sync_position : Vector3:
set(value):
sync_position = value
processed_position = false
var sync_mesh_rotation : Vector3
var sync_direction : Vector3
var sync_input_is_moving : bool
var sync_gait : Global.GAIT = Global.GAIT.WALKING
var sync_rotation_mode : Global.ROTATION_MODE = Global.ROTATION_MODE.VELOCITY_DIRECTION
var sync_stance : Global.STANCE = Global.STANCE.STANDING
var sync_movement_state : Global.MOVEMENT_STATE = Global.MOVEMENT_STATE.GROUNDED
var sync_movement_action : Global.MOVEMENT_ACTION = Global.MOVEMENT_ACTION.NONE
var sync_velocity : Vector3
var processed_position : bool
@export var id:int = 0:
get:
return id
set(value):
id = value
func _ready():
#$MultiplayerSynchronizer.set_multiplayer_authority(str(get_parent().name).to_int())
pass
func set_id(value:int) -> void:
id = value
func is_local_authority() -> bool:
if Multi.is_offline():
return true
else:
return id == Multi.get_id()
#return str(get_parent().name).to_int() == Multi.get_id()
# if multiplayer.multiplayer_peer is OfflineMultiplayerPeer:
# return true
# else:
# return str(get_parent().name).to_int() == multiplayer.get_unique_id()
#sync player on clients
func _physics_process(_delta):
return
# if !is_local_authority():
# if not processed_position:
# PlayerRef.character_node.position = sync_position
# processed_position = true
# PlayerRef.mesh_ref.rotation = sync_mesh_rotation
# PlayerRef.input_direction = sync_direction
# PlayerRef.gait = sync_gait
# PlayerRef.stance = sync_stance
# PlayerRef.rotation_mode = sync_rotation_mode
# PlayerRef.camera_root.VObject.transform = sync_camera_v_transform
# PlayerRef.camera_root.HObject.transform = sync_camera_h_transform
# PlayerRef.camera_root.view_mode = sync_CameraHOffset
# PlayerRef.camera_root.CameraHOffset = sync_CameraHOffset
# PlayerRef.movement_state = sync_movement_state
# PlayerRef.movement_action = sync_movement_action
## PlayerRef.velocity = sync_velocity
# PlayerRef.input_is_moving = sync_input_is_moving
# return
# sync_position = PlayerRef.character_node.position
# sync_mesh_rotation = PlayerRef.mesh_ref.rotation
# sync_direction = PlayerRef.input_direction
# sync_gait = PlayerRef.gait
# sync_stance = PlayerRef.stance
# sync_rotation_mode = PlayerRef.rotation_mode
# sync_camera_h_transform = PlayerRef.camera_root.HObject.transform
# sync_camera_v_transform = PlayerRef.camera_root.VObject.transform
# sync_movement_state = PlayerRef.movement_state
# sync_movement_action = PlayerRef.movement_action
# sync_input_is_moving = PlayerRef.input_is_moving
# sync_view_mode = PlayerRef.camera_root.view_mode
# sync_CameraHOffset = PlayerRef.camera_root.CameraHOffset