bazar_alea/client/player/PlayerNetworkingComponent.gd

87 lines
2.9 KiB
GDScript3
Raw Normal View History

2023-11-14 21:41:08 +00:00
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
2023-11-19 19:41:38 +00:00
var sync_view_mode : Global.VIEW_MODE = Global.VIEW_MODE.third_person
2023-11-14 21:41:08 +00:00
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
2023-11-19 19:41:38 +00:00
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
2023-11-14 21:41:08 +00:00
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
2023-11-20 22:18:02 +00:00
func set_id(value:int) -> void:
2023-11-14 21:41:08 +00:00
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):
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