End of lesson 18 The command processor, Chapter 5
This commit is contained in:
parent
d6ef6289ea
commit
909c385dee
Binary file not shown.
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ccxs3ctob15es"
|
||||
path="res://.godot/imported/main_frame.png-cf8337ea780d2d72badf7c10f22782c2.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://gfx/ui/main_frame.png"
|
||||
dest_files=["res://.godot/imported/main_frame.png-cf8337ea780d2d72badf7c10f22782c2.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
|
|
@ -19,7 +19,8 @@ config/icon="res://icon.svg"
|
|||
[autoload]
|
||||
|
||||
Loader="*res://scripts/loader.gd"
|
||||
GameManager="*res://scripts/GameManager.gd"
|
||||
GameManager="*res://scripts/game/GameManager.gd"
|
||||
CommandDispatcher="*res://scripts/game/commands/CommandDispatcher.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,52 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c0b5w48jk67qd"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c0b5w48jk67qd"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dq5qq5xj76nwe" path="res://scripts/game/game_screen.gd" id="1_uwrxv"]
|
||||
[ext_resource type="Script" uid="uid://c0uvlwmkm3r8o" path="res://scripts/game/game_screen.gd" id="1_uwrxv"]
|
||||
[ext_resource type="Script" uid="uid://dcqqr8b42tn0x" path="res://scripts/game/CommandProcessor.gd" id="2_lbhrr"]
|
||||
[ext_resource type="Texture2D" uid="uid://ccxs3ctob15es" path="res://gfx/ui/main_frame.png" id="2_lnu2h"]
|
||||
[ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="3_lbhrr"]
|
||||
|
||||
[node name="Game" type="Node" node_paths=PackedStringArray("map")]
|
||||
script = ExtResource("1_uwrxv")
|
||||
map = NodePath("Map")
|
||||
|
||||
[node name="Command Processor" type="Timer" parent="."]
|
||||
wait_time = 3.0
|
||||
autostart = true
|
||||
script = ExtResource("2_lbhrr")
|
||||
|
||||
[node name="Map" type="Node" parent="."]
|
||||
|
||||
[node name="UI" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="UI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("2_lnu2h")
|
||||
|
||||
[node name="Left Panel" type="VBoxContainer" parent="UI"]
|
||||
layout_mode = 0
|
||||
offset_left = 13.0
|
||||
offset_top = 15.0
|
||||
offset_right = 166.0
|
||||
offset_bottom = 216.0
|
||||
|
||||
[node name="Command Menu" type="VBoxContainer" parent="UI/Left Panel"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Pass Button" type="Button" parent="UI/Left Panel/Command Menu"]
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("3_lbhrr")
|
||||
text = "Pass"
|
||||
|
||||
[connection signal="timeout" from="Command Processor" to="Command Processor" method="_on_timeout"]
|
||||
[connection signal="pressed" from="UI/Left Panel/Command Menu/Pass Button" to="." method="_on_pass_button_pressed"]
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
extends Node
|
||||
|
||||
var defaultMapPath: String = "res://scenes/game/maps/world_map.tscn"
|
||||
var currentMapPath: String = ""
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func startNewGame():
|
||||
currentMapPath = defaultMapPath
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://0mhwqcwput71
|
||||
|
|
@ -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())
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dcqqr8b42tn0x
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
extends Node
|
||||
|
||||
var defaultMapPath: String = "res://scenes/game/maps/world_map.tscn"
|
||||
var currentMapPath: String = ""
|
||||
|
||||
func startNewGame():
|
||||
currentMapPath = defaultMapPath
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bos3psfp6dgdn
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
class_name Command
|
||||
|
||||
signal COMMAND_PROCESSED(label)
|
||||
|
||||
var commandLabel
|
||||
|
||||
|
||||
func execute():
|
||||
COMMAND_PROCESSED.emit(commandLabel)
|
||||
|
||||
|
||||
func getCommandText():
|
||||
return commandLabel
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b4ee6hsxy7qwc
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
extends Node
|
||||
|
||||
signal PROCESS_COMMAND(command)
|
||||
signal WAIT_FOR_COMMAND
|
||||
signal PAUSE_PROCESSOR
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://buuwlxv16l2lu
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
extends Command
|
||||
|
||||
class_name PassCommand
|
||||
|
||||
func _init() -> void:
|
||||
commandLabel = "Pass"
|
||||
|
||||
func execute():
|
||||
print("Player passed.")
|
||||
COMMAND_PROCESSED.emit(commandLabel)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://1a8ulyob7ld5
|
||||
|
|
@ -8,7 +8,5 @@ class_name GameScreen
|
|||
func _ready() -> void:
|
||||
map.add_child(load(GameManager.currentMapPath).instantiate())
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
func _on_pass_button_pressed() -> void:
|
||||
CommandDispatcher.PROCESS_COMMAND.emit(PassCommand.new())
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://dq5qq5xj76nwe
|
||||
uid://c0uvlwmkm3r8o
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func loadScene(caller: Node, path: String):
|
|||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
if scenePath:
|
||||
var progress: Array = []
|
||||
var loaderStatus: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(scenePath, progress)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,6 @@
|
|||
extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_new_game_button_pressed() -> void:
|
||||
GameManager.startNewGame()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,3 @@ extends Label
|
|||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
text += ProjectSettings.get_setting("application/config/version")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -7,10 +7,5 @@ func _ready() -> void:
|
|||
Loader.LOADING_PROGRESS_UPDATED.connect(_on_progress_updated)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_progress_updated(percentage: float) -> void:
|
||||
loadingBar.value = percentage
|
||||
|
|
|
|||
Loading…
Reference in New Issue