CommandQueue API changes and firing proper handling
This commit is contained in:
parent
59cda54407
commit
7595cd54d8
4 changed files with 28 additions and 16 deletions
|
@ -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="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"]
|
[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"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jjqxs"]
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D"]
|
[node name="Player" type="CharacterBody3D"]
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
[ext_resource type="Script" uid="uid://bvurg687pt06s" path="res://base/scripts/weapons/barrel.gd" id="2_n0n7m"]
|
[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"]
|
[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"]
|
[sub_resource type="Resource" id="Resource_ij06d"]
|
||||||
script = ExtResource("2_bt0tf")
|
script = ExtResource("2_bt0tf")
|
||||||
fire_delay = 0.5
|
fire_delay = 0.5
|
||||||
|
|
|
@ -15,7 +15,7 @@ enum Command {
|
||||||
SMOKE
|
SMOKE
|
||||||
}
|
}
|
||||||
|
|
||||||
signal command_pushed(sides: Array[CommandQueue.Side], commands: Array[CommandQueue.Command])
|
signal command_pushed(commands: Dictionary)
|
||||||
signal command_popped(commands: Array[CommandQueue.Command])
|
signal command_popped(commands: 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
|
||||||
|
@ -29,16 +29,21 @@ var command_queue: Dictionary = {}
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
for side in Side.values():
|
for side in Side.values():
|
||||||
|
print(side)
|
||||||
var arr: Array[Command] = []
|
var arr: Array[Command] = []
|
||||||
command_queue[side] = arr
|
command_queue[side] = arr
|
||||||
|
|
||||||
## Add command to queue and signal about it
|
## Add command to queue and signal about it
|
||||||
func push(commands: Array[CommandQueue.Command], sides: Array[CommandQueue.Side]) -> void:
|
func push(pushed_commands: Dictionary) -> void:
|
||||||
assert(sides.size() == Side.size())
|
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()):
|
for side in commands:
|
||||||
command_queue[sides[i]].push_back(commands[i])
|
command_queue[side].push_back(commands[side])
|
||||||
command_pushed.emit(sides, commands)
|
command_pushed.emit(commands)
|
||||||
|
|
||||||
## Remove first command from queue and signal about it
|
## Remove first command from queue and signal about it
|
||||||
func pop() -> void:
|
func pop() -> void:
|
||||||
|
|
|
@ -29,13 +29,22 @@ func _ready() -> void:
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
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 \
|
var fire_action = Input.is_action_just_pressed('shoot') if \
|
||||||
current_weapon.fire_mode is SingleFireMode else \
|
current_weapon.fire_mode is SingleFireMode else \
|
||||||
Input.is_action_pressed('shoot')
|
Input.is_action_pressed('shoot')
|
||||||
if fire_action:
|
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():
|
for side in CommandQueue.Side.values():
|
||||||
var command = queue.current_command(side)
|
var command = queue.current_command(side)
|
||||||
|
@ -67,13 +76,13 @@ func _input(event):
|
||||||
camera.rotation.x = new_rotation
|
camera.rotation.x = new_rotation
|
||||||
rotation.y -= event.relative.x * horizontal_sensivity
|
rotation.y -= event.relative.x * horizontal_sensivity
|
||||||
|
|
||||||
func on_queue_command_pushed(sides, commands):
|
func on_queue_command_pushed(commands: Dictionary):
|
||||||
for i in sides.size():
|
for side in commands:
|
||||||
match sides[i]:
|
match side:
|
||||||
CommandQueue.Side.LEFT:
|
CommandQueue.Side.LEFT:
|
||||||
handle_new_left_command(commands[i])
|
handle_new_left_command(commands[side])
|
||||||
CommandQueue.Side.RIGHT:
|
CommandQueue.Side.RIGHT:
|
||||||
handle_new_right_command(commands[i])
|
handle_new_right_command(commands[side])
|
||||||
|
|
||||||
func fire_task_finish():
|
func fire_task_finish():
|
||||||
queue.pop()
|
queue.pop()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue