Compressed states
This commit is contained in:
parent
f312e0a4a6
commit
ff08e6e4f9
2 changed files with 21 additions and 13 deletions
|
|
@ -7620,6 +7620,9 @@ height = 3.7087402
|
||||||
properties/0/path = NodePath("PlayerInput:direction")
|
properties/0/path = NodePath("PlayerInput:direction")
|
||||||
properties/0/spawn = true
|
properties/0/spawn = true
|
||||||
properties/0/replication_mode = 1
|
properties/0/replication_mode = 1
|
||||||
|
properties/1/path = NodePath("PlayerInput:compressed_states")
|
||||||
|
properties/1/spawn = true
|
||||||
|
properties/1/replication_mode = 1
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")]
|
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,15 @@ extends MultiplayerSynchronizer
|
||||||
|
|
||||||
class_name PlayerInput
|
class_name PlayerInput
|
||||||
|
|
||||||
|
const SCOPE: int = 0b1
|
||||||
|
const CROUCH: int = 0b10
|
||||||
|
const WALK: int = 0b100
|
||||||
|
|
||||||
#region SYNC
|
#region SYNC
|
||||||
@export var direction: Vector2
|
@export var direction: Vector2
|
||||||
|
@export var compressed_states: int
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var crouching: bool = false
|
|
||||||
var scoping: bool = false
|
|
||||||
var walking: bool = false
|
|
||||||
|
|
||||||
signal jumped
|
signal jumped
|
||||||
signal drop
|
signal drop
|
||||||
signal switch_weapon(to_slot: StringName)
|
signal switch_weapon(to_slot: StringName)
|
||||||
|
|
@ -62,37 +63,41 @@ func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("plr_drop"):
|
if event.is_action_pressed("plr_drop"):
|
||||||
drop_on_server.rpc_id(1)
|
drop_on_server.rpc_id(1)
|
||||||
|
|
||||||
|
var crouching: bool = compressed_states & CROUCH
|
||||||
|
var walking: bool = compressed_states & WALK
|
||||||
|
var scoping: bool = compressed_states & SCOPE
|
||||||
|
|
||||||
if event.is_action_pressed("plr_crouch"):
|
if event.is_action_pressed("plr_crouch"):
|
||||||
if ClientSettings.TOGGLE_CROUCH:
|
if ClientSettings.TOGGLE_CROUCH:
|
||||||
crouch_on_server.rpc_id(1,crouching)
|
crouch_on_server.rpc_id(1,crouching)
|
||||||
crouching = not crouching
|
compressed_states ^= CROUCH
|
||||||
elif not crouching:
|
elif not crouching:
|
||||||
crouching = true
|
compressed_states |= CROUCH
|
||||||
crouch_on_server.rpc_id(1,false)
|
crouch_on_server.rpc_id(1,false)
|
||||||
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
|
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
|
||||||
crouching = false
|
compressed_states &= ~CROUCH
|
||||||
crouch_on_server.rpc_id(1,true)
|
crouch_on_server.rpc_id(1,true)
|
||||||
|
|
||||||
if event.is_action_pressed("plr_walk"):
|
if event.is_action_pressed("plr_walk"):
|
||||||
if ClientSettings.TOGGLE_WALK:
|
if ClientSettings.TOGGLE_WALK:
|
||||||
walk_on_server.rpc_id(1,walking)
|
walk_on_server.rpc_id(1,walking)
|
||||||
walking = not walking
|
compressed_states ^= WALK
|
||||||
elif not walking:
|
elif not walking:
|
||||||
walking = true
|
compressed_states |= WALK
|
||||||
walk_on_server.rpc_id(1,false)
|
walk_on_server.rpc_id(1,false)
|
||||||
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
|
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
|
||||||
walking = false
|
compressed_states &= ~WALK
|
||||||
walk_on_server.rpc_id(1,true)
|
walk_on_server.rpc_id(1,true)
|
||||||
|
|
||||||
if event.is_action_pressed("plr_scope"):
|
if event.is_action_pressed("plr_scope"):
|
||||||
if ClientSettings.TOGGLE_SCOPE:
|
if ClientSettings.TOGGLE_SCOPE:
|
||||||
scope_on_server.rpc_id(1,scoping)
|
scope_on_server.rpc_id(1,scoping)
|
||||||
scoping = not scoping
|
compressed_states ^= SCOPE
|
||||||
elif not scoping:
|
elif not scoping:
|
||||||
scoping = true
|
compressed_states |= SCOPE
|
||||||
scope_on_server.rpc_id(1,false)
|
scope_on_server.rpc_id(1,false)
|
||||||
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
|
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
|
||||||
scoping = false
|
compressed_states &= ~SCOPE
|
||||||
scope_on_server.rpc_id(1,true)
|
scope_on_server.rpc_id(1,true)
|
||||||
|
|
||||||
if event.is_action_pressed("plr_reload"):
|
if event.is_action_pressed("plr_reload"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue