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
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue