Implemented player interaction with command queue

This commit is contained in:
Alexey 2025-07-17 12:56:34 +03:00
commit 76a057943b
5 changed files with 106 additions and 12 deletions

View file

@ -12,10 +12,25 @@ var queue: CommandQueue = CommandQueue.new()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
queue.command_pushed.connect(on_queue_command_pushed)
queue.command_popped.connect(on_queue_command_popped)
weapon_player.current_animation = "static"
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _process(_delta: float) -> void:
# TODO: use proper weapon system, this is just for testing command queue
if Input.is_action_pressed("shoot") \
and queue.current_command(CommandQueue.Side.RIGHT) \
== CommandQueue.DEFAULT_COMMAND:
queue.push([
CommandQueue.Command.NONE,
CommandQueue.Command.SHOOT
], [
CommandQueue.Side.LEFT,
CommandQueue.Side.RIGHT
])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
var direction = Vector3.ZERO
@ -38,3 +53,54 @@ func _input(event):
)
camera.rotation.x = new_rotation
rotation.y -= event.relative.x * horizontal_sensivity
func on_queue_command_pushed(sides, commands):
for i in sides.size():
match sides[i]:
CommandQueue.Side.LEFT:
handle_new_left_command(commands[i])
CommandQueue.Side.RIGHT:
handle_new_right_command(commands[i])
func handle_new_left_command(command: CommandQueue.Command):
match command:
CommandQueue.Command.NONE:
pass
_:
print('New command %s is not implemented for left hand.' % str(command))
func handle_new_right_command(command: CommandQueue.Command):
match command:
CommandQueue.Command.NONE:
pass
CommandQueue.Command.SHOOT:
weapon_player.play('shoot')
_:
print('New command %s is not implemented for right hand.' % str(command))
func shoot_animation_ended():
queue.pop()
func on_queue_command_popped(commands):
for i in CommandQueue.Side.size():
match CommandQueue.Side.values()[i]:
CommandQueue.Side.LEFT:
handle_ended_left_command(commands[i])
CommandQueue.Side.RIGHT:
handle_ended_right_command(commands[i])
func handle_ended_left_command(command: CommandQueue.Command):
match command:
CommandQueue.Command.NONE:
pass
_:
print('Ended command %s is not implemented for left hand.' % str(command))
func handle_ended_right_command(command: CommandQueue.Command):
match command:
CommandQueue.Command.NONE:
pass
CommandQueue.Command.SHOOT:
weapon_player.play('static')
_:
print('Ended command %s is not implemented for right hand.' % str(command))