Implemented player interaction with command queue
This commit is contained in:
parent
ef17945a59
commit
76a057943b
5 changed files with 106 additions and 12 deletions
|
@ -15,8 +15,8 @@ enum Command {
|
|||
SMOKE
|
||||
}
|
||||
|
||||
signal command_pushed(Side, Command)
|
||||
signal command_popped(Side, Command)
|
||||
signal command_pushed(sides: Array[CommandQueue.Side], 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
|
||||
enum Side { LEFT, RIGHT }
|
||||
|
@ -32,21 +32,26 @@ func _init() -> void:
|
|||
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])
|
||||
## Add command to queue and signal about it
|
||||
func push(commands: Array[CommandQueue.Command], sides: Array[CommandQueue.Side]):
|
||||
assert(sides.size() == Side.size())
|
||||
|
||||
for i in range(commands.size()):
|
||||
command_queue[sides[i]].push_back(commands[i])
|
||||
command_pushed.emit(sides, commands)
|
||||
|
||||
## Remove first command from queue and signal about it
|
||||
func pop():
|
||||
# Checking if stack is actually empty (arrays must have same size)
|
||||
if command_queue[Side.LEFT].size() == 0:
|
||||
return
|
||||
var commands = []
|
||||
for side in Side.values():
|
||||
var command = command_queue[side].pop_front()
|
||||
command_popped.emit(side, command)
|
||||
commands.push_back(command_queue[side].pop_front())
|
||||
command_popped.emit(commands)
|
||||
|
||||
func current_command(side: Side):
|
||||
var command = command_queue[side].front()
|
||||
if command == null:
|
||||
func current_command(side: CommandQueue.Side):
|
||||
if command_queue[side].is_empty():
|
||||
return DEFAULT_COMMAND
|
||||
var command = command_queue[side].front()
|
||||
return command
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue