Added command_started signal

This commit is contained in:
Alexey 2025-07-26 16:49:10 +03:00
commit 70922afadb
2 changed files with 33 additions and 2 deletions

View file

@ -17,6 +17,7 @@ enum Command {
signal command_pushed(commands: Dictionary) signal command_pushed(commands: Dictionary)
signal command_popped(commands: Array[CommandQueue.Command]) signal command_popped(commands: Array[CommandQueue.Command])
signal command_started(command: Array[CommandQueue.Command])
## Human-readable hand numbers. You could even make extra hands with it, if you wish ## Human-readable hand numbers. You could even make extra hands with it, if you wish
enum Side { LEFT, RIGHT } enum Side { LEFT, RIGHT }
@ -44,6 +45,8 @@ func push(pushed_commands: Dictionary) -> void:
for side in commands: for side in commands:
command_queue[side].push_back(commands[side]) command_queue[side].push_back(commands[side])
command_pushed.emit(commands) command_pushed.emit(commands)
if command_queue[Side.LEFT].size() == 1:
start_command()
## Remove first command from queue and signal about it ## Remove first command from queue and signal about it
func pop() -> void: func pop() -> void:
@ -54,6 +57,16 @@ func pop() -> void:
for side in Side.values(): for side in Side.values():
commands.push_back(command_queue[side].pop_front()) commands.push_back(command_queue[side].pop_front())
command_popped.emit(commands) command_popped.emit(commands)
# Start new command
if command_queue[Side.LEFT].size() > 0:
start_command()
## Get current commands and emit command_started
func start_command() -> void:
var commands = []
for side in Side.values():
commands.push_back(current_command(side))
command_started.emit(commands)
## Returns currently executed command for given side ## Returns currently executed command for given side
func current_command(side: CommandQueue.Side) -> CommandQueue.Command: func current_command(side: CommandQueue.Side) -> CommandQueue.Command:

View file

@ -21,6 +21,7 @@ var slot_actions: Array[StringName] = [ "slot_primary", "slot_secondary", "slot_
func _ready() -> void: func _ready() -> void:
queue.command_pushed.connect(on_queue_command_pushed) queue.command_pushed.connect(on_queue_command_pushed)
queue.command_popped.connect(on_queue_command_popped) queue.command_popped.connect(on_queue_command_popped)
queue.command_started.connect(on_queue_command_started)
weapons.slot_selected.connect(on_weapon_slot_selected) weapons.slot_selected.connect(on_weapon_slot_selected)
@ -95,7 +96,6 @@ func on_weapon_slot_selected():
weapon_player.remove_animation_library("current") weapon_player.remove_animation_library("current")
current_weapon = weapons.current_weapon current_weapon = weapons.current_weapon
print('im here')
current_weapon.fired.connect(on_weapon_fired) current_weapon.fired.connect(on_weapon_fired)
current_weapon.fire_failed.connect(finish_task) current_weapon.fire_failed.connect(finish_task)
@ -135,6 +135,14 @@ func on_queue_command_popped(commands):
CommandQueue.Side.RIGHT: CommandQueue.Side.RIGHT:
handle_ended_right_command(commands[i]) handle_ended_right_command(commands[i])
func on_queue_command_started(commands):
for i in CommandQueue.Side.size():
match CommandQueue.Side.values()[i]:
CommandQueue.Side.LEFT:
handle_started_left_command(commands[i])
CommandQueue.Side.RIGHT:
handle_started_right_command(commands[i])
func update_ammo_label(): func update_ammo_label():
ammo_label.text = "{ammo}/{max}".format({ ammo_label.text = "{ammo}/{max}".format({
ammo = current_weapon.ammo, ammo = current_weapon.ammo,
@ -173,6 +181,15 @@ func handle_ended_right_command(command: CommandQueue.Command):
current_weapon.reload() current_weapon.reload()
update_ammo_label() update_ammo_label()
func handle_started_left_command(command: CommandQueue.Command):
match command:
pass
func handle_started_right_command(command: CommandQueue.Command):
match command:
CommandQueue.Command.FIRE:
current_weapon.request_fire()
func handle_current_left_command(command: CommandQueue.Command): func handle_current_left_command(command: CommandQueue.Command):
match command: match command:
pass pass
@ -180,4 +197,5 @@ func handle_current_left_command(command: CommandQueue.Command):
func handle_current_right_command(command: CommandQueue.Command): func handle_current_right_command(command: CommandQueue.Command):
match command: match command:
CommandQueue.Command.FIRE: CommandQueue.Command.FIRE:
if not current_weapon.is_firing:
current_weapon.request_fire() current_weapon.request_fire()