Rewrote CommandQueue
This commit is contained in:
parent
91f939d9fc
commit
ef17945a59
4 changed files with 53 additions and 32 deletions
52
base/scripts/player/command_queue.gd
Normal file
52
base/scripts/player/command_queue.gd
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## Queue that represents player's hand interactions with game mechanics
|
||||||
|
class_name CommandQueue
|
||||||
|
|
||||||
|
## Commands that can be pushed to queue
|
||||||
|
enum Command {
|
||||||
|
NONE,
|
||||||
|
TAKE_WEAPON,
|
||||||
|
SHOOT,
|
||||||
|
RELOAD,
|
||||||
|
HOLSTER_WEAPON,
|
||||||
|
TAKE_ZAZA,
|
||||||
|
LIGHT_ZAZA,
|
||||||
|
SMOKE
|
||||||
|
}
|
||||||
|
|
||||||
|
signal command_pushed(Side, Command)
|
||||||
|
signal command_popped(Side, Command)
|
||||||
|
|
||||||
|
## Human-readable hand numbers. You could even make extra hands with it, if you wish
|
||||||
|
enum Side { LEFT, RIGHT }
|
||||||
|
|
||||||
|
## Used anywhere you could get null
|
||||||
|
const DEFAULT_COMMAND = Command.NONE
|
||||||
|
|
||||||
|
## Dictionary filled with queues for each side
|
||||||
|
var command_queue: Dictionary = {}
|
||||||
|
|
||||||
|
func _init() -> void:
|
||||||
|
for side in Side.values():
|
||||||
|
var arr: Array[Command] = []
|
||||||
|
command_queue[side] = arr
|
||||||
|
|
||||||
|
func push(commands: Array[Command], sides: Array[Side]):
|
||||||
|
for i in range(len(commands)):
|
||||||
|
command_queue[sides[i]].push_back(commands[i])
|
||||||
|
command_pushed.emit(sides[i], commands[i])
|
||||||
|
|
||||||
|
func pop():
|
||||||
|
# Checking if stack is actually empty (arrays must have same size)
|
||||||
|
if command_queue[Side.LEFT].size() == 0:
|
||||||
|
return
|
||||||
|
for side in Side.values():
|
||||||
|
var command = command_queue[side].pop_front()
|
||||||
|
command_popped.emit(side, command)
|
||||||
|
|
||||||
|
func current_command(side: Side):
|
||||||
|
var command = command_queue[side].front()
|
||||||
|
if command == null:
|
||||||
|
return DEFAULT_COMMAND
|
||||||
|
return command
|
|
@ -1,31 +0,0 @@
|
||||||
extends RefCounted
|
|
||||||
|
|
||||||
class_name CommandStack
|
|
||||||
## Commands that can be pushed to stack
|
|
||||||
enum Command {
|
|
||||||
None,
|
|
||||||
TakeWeapon,
|
|
||||||
Shoot,
|
|
||||||
Reload,
|
|
||||||
HolsterWeapon,
|
|
||||||
TakeZaza,
|
|
||||||
LightZaza,
|
|
||||||
Smoke
|
|
||||||
}
|
|
||||||
|
|
||||||
var left_command_stack: Array[Command] = []
|
|
||||||
var right_command_stack: Array[Command] = []
|
|
||||||
|
|
||||||
func push(left_command: Command = Command.None, right_command: Command = Command.None):
|
|
||||||
left_command_stack.push_back(left_command)
|
|
||||||
right_command_stack.push_back(right_command)
|
|
||||||
|
|
||||||
func pop():
|
|
||||||
left_command_stack.pop_back()
|
|
||||||
right_command_stack.pop_back()
|
|
||||||
|
|
||||||
func current_left_command() -> Command:
|
|
||||||
return left_command_stack.back()
|
|
||||||
|
|
||||||
func current_right_command() -> Command:
|
|
||||||
return right_command_stack.back()
|
|
|
@ -5,7 +5,7 @@ extends CharacterBody3D
|
||||||
@export var vertical_sensivity = 0.005
|
@export var vertical_sensivity = 0.005
|
||||||
@export var horizontal_sensivity = 0.005
|
@export var horizontal_sensivity = 0.005
|
||||||
|
|
||||||
var stack: CommandStack = CommandStack.new()
|
var queue: CommandQueue = CommandQueue.new()
|
||||||
|
|
||||||
@onready var camera: Camera3D = $"Camera"
|
@onready var camera: Camera3D = $"Camera"
|
||||||
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
|
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue