Vast improvements and a working finite state machine, working on new guild member registration.

This commit is contained in:
2025-07-24 08:41:19 -04:00
parent 90151369de
commit dc30d1b15c
100 changed files with 1987 additions and 194 deletions

27
fsm/machines/newbie.gd Normal file
View File

@@ -0,0 +1,27 @@
extends StateMachine
func advance_state() -> void:
var last_state = curr_state
var args : Array = [actor]
exit_state(curr_state)
match(last_state.name):
"Wait":
if last_state.next_state != "":
if !states.has(last_state.next_state):
printerr("Tried to switch to missing state %s" % last_state.next_state)
pass
enter_state(states[last_state.next_state])
args.append_array(last_state.next_state_args)
else:
pass
"Queue":
enter_state(states["Wait"])
args.append_array(["busy", "Register"])
"Register":
enter_state(states["Register"])
"Leave":
enter_state(states["Leave"])
if curr_state != null:
curr_state.execute.callv(args)

View File

@@ -0,0 +1 @@
uid://dthatmb3if73u

View File

@@ -0,0 +1,23 @@
extends StateMachine
func advance_state() -> void:
var last_state = curr_state
var args : Array = [actor]
exit_state(curr_state)
match(last_state.name):
"Wait":
if last_state.next_state != "":
if !states.has(last_state.next_state):
printerr("Tried to switch to missing state %s" % last_state.next_state)
pass
enter_state(states[last_state.next_state])
args.append_array(last_state.next_state_args)
else:
pass
"Advance Queue":
enter_state(states["Wait"])
args.append_array(["", "Advance Queue"])
if curr_state != null:
curr_state.execute.callv(args)

View File

@@ -0,0 +1 @@
uid://cggu0yihq0unt

View File

@@ -0,0 +1,43 @@
class_name StateMachine extends Node
@export var starting_state : String = ""
var states : Dictionary[String, StateNode] = {}
var curr_state : StateNode = null
var actor = null
func _ready() -> void:
for child in get_children():
if child is StateNode:
states[child.name] = child
child.state_machine = self
child.completed.connect(_on_state_completed)
func start() -> void:
if starting_state != "":
var state : StateNode = states.get(starting_state)
if state == null:
printerr("Starting state not found! Expected %s" % [starting_state])
else:
enter_state(state)
curr_state.execute(actor)
func exit_state(state : StateNode) -> void:
curr_state.exit()
curr_state = null
pass
func enter_state(state : StateNode) -> void:
curr_state = state
curr_state.enter()
pass
func advance_state() -> void:
pass
func _on_state_completed(state : StateNode) -> void:
if state == curr_state:
advance_state()
else:
printerr("Wrong state completed! %s when expecting %s" % [state.name, curr_state])

View File

@@ -0,0 +1 @@
uid://u81fhi8157bg

22
fsm/machines/test.gd Normal file
View File

@@ -0,0 +1,22 @@
extends StateMachine
func advance_state() -> void:
var last_state = curr_state
var args : Array = [actor]
exit_state(curr_state)
match(last_state.name):
"Wait":
if last_state.next_state != "":
if !states.has(last_state.next_state):
printerr("Tried to switch to missing state %s" % last_state.next_state)
pass
enter_state(states[last_state.next_state])
args.append_array(last_state.next_state_args)
else:
pass
"Test":
enter_state(states["Wait"])
args.append_array(["busy", "Test"])
if curr_state != null:
curr_state.execute.callv(args)

1
fsm/machines/test.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://djd8pv5xbgud3