CommandQueue API changes and firing proper handling

This commit is contained in:
Alexey 2025-07-21 16:46:50 +03:00
commit 7595cd54d8
4 changed files with 28 additions and 16 deletions

View file

@ -4,7 +4,6 @@
[ext_resource type="Texture2D" uid="uid://cfw6p5g680c55" path="res://base/assets/sprites/guns/placeholder/shoot1.png" id="2_i1xqq"]
[ext_resource type="PackedScene" uid="uid://bb6ovrbusyxpi" path="res://base/scenes/weapons/weapon_base.tscn" id="2_ma1q3"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jjqxs"]
[node name="Player" type="CharacterBody3D"]

View file

@ -5,7 +5,6 @@
[ext_resource type="Script" uid="uid://bvurg687pt06s" path="res://base/scripts/weapons/barrel.gd" id="2_n0n7m"]
[ext_resource type="AnimationLibrary" uid="uid://cw8bt4hqxpk55" path="res://base/assets/sprites/guns/placeholder/placeholder.tres" id="2_p83j3"]
[sub_resource type="Resource" id="Resource_ij06d"]
script = ExtResource("2_bt0tf")
fire_delay = 0.5

View file

@ -15,7 +15,7 @@ enum Command {
SMOKE
}
signal command_pushed(sides: Array[CommandQueue.Side], commands: Array[CommandQueue.Command])
signal command_pushed(commands: Dictionary)
signal command_popped(commands: Array[CommandQueue.Command])
## Human-readable hand numbers. You could even make extra hands with it, if you wish
@ -29,16 +29,21 @@ var command_queue: Dictionary = {}
func _init() -> void:
for side in Side.values():
print(side)
var arr: Array[Command] = []
command_queue[side] = arr
## Add command to queue and signal about it
func push(commands: Array[CommandQueue.Command], sides: Array[CommandQueue.Side]) -> void:
assert(sides.size() == Side.size())
func push(pushed_commands: Dictionary) -> void:
var commands = pushed_commands
if commands.size() < Side.size():
for side in Side.values():
if not commands.has(side):
commands[side] = DEFAULT_COMMAND
for i in range(commands.size()):
command_queue[sides[i]].push_back(commands[i])
command_pushed.emit(sides, commands)
for side in commands:
command_queue[side].push_back(commands[side])
command_pushed.emit(commands)
## Remove first command from queue and signal about it
func pop() -> void:

View file

@ -29,13 +29,22 @@ func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _process(_delta: float) -> void:
if queue.current_command(CommandQueue.Side.RIGHT) \
== CommandQueue.DEFAULT_COMMAND:
var can_queue_fire = true
var weapon_sides = current_weapon.uses_hands
for side in weapon_sides:
if queue.current_command(side) != CommandQueue.DEFAULT_COMMAND:
can_queue_fire = false
break
if can_queue_fire:
var fire_action = Input.is_action_just_pressed('shoot') if \
current_weapon.fire_mode is SingleFireMode else \
Input.is_action_pressed('shoot')
if fire_action:
queue.push(ONEHANDED_FIRE_COMMAND, DEFAULT_SIDES)
var fire_commands = {}
for side in weapon_sides:
fire_commands[side] = CommandQueue.Command.FIRE
queue.push(fire_commands)
for side in CommandQueue.Side.values():
var command = queue.current_command(side)
@ -67,13 +76,13 @@ 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]:
func on_queue_command_pushed(commands: Dictionary):
for side in commands:
match side:
CommandQueue.Side.LEFT:
handle_new_left_command(commands[i])
handle_new_left_command(commands[side])
CommandQueue.Side.RIGHT:
handle_new_right_command(commands[i])
handle_new_right_command(commands[side])
func fire_task_finish():
queue.pop()