From 70922afadb07e88d0bcd23a172ab467a5103fc63 Mon Sep 17 00:00:00 2001 From: 2ndbeam <2ndbeam@disroot.org> Date: Sat, 26 Jul 2025 16:49:10 +0300 Subject: [PATCH] Added command_started signal --- base/scripts/player/command_queue.gd | 13 +++++++++++++ base/scripts/player/player.gd | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/base/scripts/player/command_queue.gd b/base/scripts/player/command_queue.gd index c2bc34f..37d6673 100644 --- a/base/scripts/player/command_queue.gd +++ b/base/scripts/player/command_queue.gd @@ -17,6 +17,7 @@ enum Command { signal command_pushed(commands: Dictionary) 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 enum Side { LEFT, RIGHT } @@ -44,6 +45,8 @@ func push(pushed_commands: Dictionary) -> void: for side in commands: command_queue[side].push_back(commands[side]) command_pushed.emit(commands) + if command_queue[Side.LEFT].size() == 1: + start_command() ## Remove first command from queue and signal about it func pop() -> void: @@ -54,6 +57,16 @@ func pop() -> void: for side in Side.values(): commands.push_back(command_queue[side].pop_front()) 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 func current_command(side: CommandQueue.Side) -> CommandQueue.Command: diff --git a/base/scripts/player/player.gd b/base/scripts/player/player.gd index e575bef..1207c73 100644 --- a/base/scripts/player/player.gd +++ b/base/scripts/player/player.gd @@ -21,6 +21,7 @@ var slot_actions: Array[StringName] = [ "slot_primary", "slot_secondary", "slot_ func _ready() -> void: queue.command_pushed.connect(on_queue_command_pushed) queue.command_popped.connect(on_queue_command_popped) + queue.command_started.connect(on_queue_command_started) weapons.slot_selected.connect(on_weapon_slot_selected) @@ -95,7 +96,6 @@ func on_weapon_slot_selected(): weapon_player.remove_animation_library("current") current_weapon = weapons.current_weapon - print('im here') current_weapon.fired.connect(on_weapon_fired) current_weapon.fire_failed.connect(finish_task) @@ -135,6 +135,14 @@ func on_queue_command_popped(commands): CommandQueue.Side.RIGHT: 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(): ammo_label.text = "{ammo}/{max}".format({ ammo = current_weapon.ammo, @@ -173,6 +181,15 @@ func handle_ended_right_command(command: CommandQueue.Command): current_weapon.reload() 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): match command: pass @@ -180,4 +197,5 @@ func handle_current_left_command(command: CommandQueue.Command): func handle_current_right_command(command: CommandQueue.Command): match command: CommandQueue.Command.FIRE: - current_weapon.request_fire() + if not current_weapon.is_firing: + current_weapon.request_fire()