Started State Machine Implementation
This commit is contained in:
parent
cb164ef859
commit
376bf912c7
3 changed files with 81 additions and 21 deletions
|
|
@ -5,26 +5,36 @@ config:
|
||||||
stateDiagram
|
stateDiagram
|
||||||
[*] --> GameSetup
|
[*] --> GameSetup
|
||||||
GameSetup --> WhiteTurn
|
GameSetup --> WhiteTurn
|
||||||
state TurnPhases {
|
state ChessGame {
|
||||||
WhiteTurn --> HandSetup
|
WhiteTurn --> HandSetup
|
||||||
BlackTurn --> HandSetup
|
BlackTurn --> HandSetup
|
||||||
HandSetup --> ResolvePersistentEffects : Draw Cards
|
|
||||||
ResolvePersistentEffects --> ApplyTileEffects
|
HandSetup --> DrawPhase
|
||||||
ApplyTileEffects --> AttachCards
|
DrawPhase --> ResolvePersistentEffects : Draw/Discard
|
||||||
|
|
||||||
|
ResolvePersistentEffects --> ApplyTileEffects : Update Durations
|
||||||
|
ApplyTileEffects --> PreMovePhase
|
||||||
|
|
||||||
|
PreMovePhase --> AttachCards : Play Cards
|
||||||
AttachCards --> ApplyCardEffects
|
AttachCards --> ApplyCardEffects
|
||||||
ApplyCardEffects --> Movement
|
ApplyCardEffects --> Movement
|
||||||
Movement --> EvaluatePosition
|
|
||||||
|
Movement --> PostMovePhase
|
||||||
|
PostMovePhase --> EvaluatePosition : Resolve Move Effects
|
||||||
|
|
||||||
state EvaluatePosition {
|
state EvaluatePosition {
|
||||||
[*] --> CheckStatus
|
[*] --> CheckStatus
|
||||||
CheckStatus --> Checkmate : In Checkmate
|
CheckStatus --> Checkmate : In Checkmate
|
||||||
CheckStatus --> Draw : In Draw
|
CheckStatus --> Draw : In Draw
|
||||||
CheckStatus --> ValidMove : Game Continues
|
CheckStatus --> ValidMove : Game Continues
|
||||||
ValidMove --> SpecialMoves
|
ValidMove --> SpecialMoves : En Passant/Castle/Promote
|
||||||
SpecialMoves --> [*]
|
SpecialMoves --> [*]
|
||||||
}
|
}
|
||||||
EvaluatePosition --> WhiteTurn : White's Turn
|
|
||||||
EvaluatePosition --> BlackTurn : Black's Turn
|
EvaluatePosition --> CleanupPhase
|
||||||
EvaluatePosition --> RoundEnd : Game Over
|
CleanupPhase --> WhiteTurn : White's Turn
|
||||||
|
CleanupPhase --> BlackTurn : Black's Turn
|
||||||
|
CleanupPhase --> RoundEnd : Game Over
|
||||||
}
|
}
|
||||||
RoundEnd --> ShopPhase
|
RoundEnd --> ShopPhase
|
||||||
ShopPhase --> GameSetup : Next Round
|
ShopPhase --> GameSetup : Next Round
|
||||||
|
|
|
||||||
16
Systems/StateMachine/State.gd
Normal file
16
Systems/StateMachine/State.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
class_name State extends Node
|
||||||
|
|
||||||
|
|
||||||
|
signal finished(nextStatePath: String, data: Dictionary)
|
||||||
|
|
||||||
|
func handleInput(_event: InputEvent) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func update(_delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func enter(previousStatePath: String, data := {}) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
pass
|
||||||
34
Systems/StateMachine/StateMachine.gd
Normal file
34
Systems/StateMachine/StateMachine.gd
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
class_name StateMachine extends Node
|
||||||
|
|
||||||
|
@export var initialState: State = null
|
||||||
|
|
||||||
|
@onready var state: State = (func getInitialState() -> State:
|
||||||
|
return initialState if initialState != null else get_child(0)
|
||||||
|
).call()
|
||||||
|
|
||||||
|
|
||||||
|
func ready() -> void:
|
||||||
|
for stateNode: State in find_children("*", "State"):
|
||||||
|
stateNode.finished.connect(transitionToNextState)
|
||||||
|
|
||||||
|
await owner.ready
|
||||||
|
state.enter("")
|
||||||
|
|
||||||
|
|
||||||
|
func unhandledInput(event: InputEvent) -> void:
|
||||||
|
state.handleInput(event)
|
||||||
|
|
||||||
|
|
||||||
|
func process(delta: float) -> void:
|
||||||
|
state.update(delta)
|
||||||
|
|
||||||
|
|
||||||
|
func transitionToNextState(targetStatePath: String, data: Dictionary = {}) -> void:
|
||||||
|
if not has_node(targetStatePath):
|
||||||
|
printerr(owner.name + ": Trying to transition to state " + targetStatePath + " but it does not exist.")
|
||||||
|
return
|
||||||
|
var previousStatePath := state.name
|
||||||
|
state.exit()
|
||||||
|
state = get_node(targetStatePath)
|
||||||
|
state.enter(previousStatePath, data)
|
||||||
|
|
||||||
Loading…
Reference in a new issue