Basic weapon slots system

This commit is contained in:
Alexey 2025-07-26 13:56:13 +03:00
commit 22a72e572e
7 changed files with 115 additions and 15 deletions

View file

@ -9,7 +9,7 @@ var queue: CommandQueue = CommandQueue.new()
@onready var camera: Camera3D = $"Camera"
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
@onready var weapons: Node3D = $"WeaponContainer"
@onready var weapons: WeaponContainer = $"WeaponContainer"
# Placeholder UI
@onready var ammo_label: Label = $"HUD/Ammo"
@ -20,19 +20,15 @@ func _ready() -> void:
queue.command_pushed.connect(on_queue_command_pushed)
queue.command_popped.connect(on_queue_command_popped)
current_weapon = weapons.get_child(0) as Weapon
current_weapon.fired.connect(on_weapon_fired)
current_weapon.fire_failed.connect(finish_task)
weapon_player.add_animation_library("current", current_weapon.animation_library)
weapon_player.play("current/static")
weapons.slot_selected.connect(on_weapon_slot_selected)
get_tree().create_timer(0.02).timeout.connect(on_weapon_slot_selected)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
update_ammo_label()
func _process(_delta: float) -> void:
if current_weapon == null:
return
var weapon_sides = current_weapon.uses_hands
var weapon_sides_are_free = not queue.sides_are_busy(weapon_sides)
if weapon_sides_are_free:
@ -77,6 +73,25 @@ func _input(event):
camera.rotation.x = new_rotation
rotation.y -= event.relative.x * horizontal_sensivity
func on_weapon_slot_selected():
if current_weapon != null:
current_weapon.fired.disconnect(on_weapon_fired)
current_weapon.fire_failed.disconnect(finish_task)
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)
weapon_player.add_animation_library("current", current_weapon.animation_library)
weapon_player.play("current/static")
update_ammo_label()
func on_queue_command_pushed(commands: Dictionary):
for side in commands:
match side:
@ -91,7 +106,6 @@ func push_copied_command(command: CommandQueue.Command, sides: Array[CommandQueu
commands[side] = command
queue.push(commands)
func finish_task():
queue.pop()