Added AbstractState and StateMachine

This commit is contained in:
2026-01-30 23:42:34 +03:00
parent ecc1fbc05a
commit 7f12066244
9 changed files with 70 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
class_name AbstractState
extends Node
@warning_ignore("unused_signal")
signal new_state(state: AbstractState)
func enter() -> void:
pass
func exit() -> void:
pass
@warning_ignore("unused_parameter")
func process(delta: float) -> void:
pass
@warning_ignore("unused_parameter")
func physics_process(delta: float) -> void:
pass
+1
View File
@@ -0,0 +1 @@
uid://ciuxe344aok4n
+6
View File
@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://c7adrbfobmvl8"]
[ext_resource type="Script" uid="uid://ciuxe344aok4n" path="res://game/state_machine/abstract_state.gd" id="1_80326"]
[node name="AbstractState" type="Node" unique_id=739226464]
script = ExtResource("1_80326")
+22
View File
@@ -0,0 +1,22 @@
class_name StateMachine
extends Node
var current_state : AbstractState
func _process(delta: float) -> void:
if current_state:
current_state.process(delta)
func _physics_process(delta: float) -> void:
if current_state:
current_state.physics_process(delta)
func change_state(new_state: AbstractState) -> void:
if current_state:
current_state.exit()
current_state = new_state
current_state.enter()
+1
View File
@@ -0,0 +1 @@
uid://bghuevstlp4yp
+6
View File
@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://3ll3i1fgktg2"]
[ext_resource type="Script" uid="uid://bghuevstlp4yp" path="res://game/state_machine/state_machine.gd" id="1_ncw1q"]
[node name="StateMachine" type="Node" unique_id=633169960]
script = ExtResource("1_ncw1q")