End of lesson 18 The command processor, Chapter 5

This commit is contained in:
2025-04-05 19:27:03 -03:00
parent d6ef6289ea
commit 909c385dee
22 changed files with 174 additions and 47 deletions

View File

@@ -0,0 +1,46 @@
extends Timer
class_name CommandProcessor
signal BROADCAST_COMMAND(label)
var resumeWaiting:bool = true
func _ready():
CommandDispatcher.PROCESS_COMMAND.connect(processCommand)
CommandDispatcher.WAIT_FOR_COMMAND.connect(waitForCommand)
CommandDispatcher.PAUSE_PROCESSOR.connect(pauseProcessor)
func processCommand(command:Command):
if (is_stopped()):
return
stop()
command.COMMAND_PROCESSED.connect(onCommandProcessed)
BROADCAST_COMMAND.emit(command.getCommandText())
command.execute()
func waitForCommand():
resumeWaiting = true
start()
func pauseProcessor():
stop()
resumeWaiting = false
func onCommandProcessed(result):
if (result != null):
print(result)
if (resumeWaiting):
waitForCommand()
func _on_timeout():
processCommand(PassCommand.new())