Global refactor

This commit is contained in:
Rendo 2025-12-09 11:53:52 +05:00
commit 0589ca4e23
180 changed files with 249 additions and 401 deletions

View file

@ -0,0 +1,60 @@
extends Node
class_name StateMachine
@export var current_state: State
var states: Dictionary[StringName,State] = {}
func _ready() -> void:
for child in get_children():
if child is State:
states[child.name] = child
child.transition.connect(on_transition_required)
else:
push_warning("Child of state machine is not state")
current_state.enter()
func on_transition_required(to: StringName):
if is_multiplayer_authority() == false:
return
if states.has(to) == false:
push_warning("Incorrect state request: " + to)
return
change_state(states[to])
change_state_to_name.rpc(to)
func change_state(to_state: State) -> void:
if current_state != null:
current_state.exit()
current_state = to_state
current_state.enter()
@rpc("authority","call_local","reliable")
func change_state_to_name(to_name: StringName):
if current_state != null:
current_state.exit()
current_state = states[to_name]
current_state.enter()
@rpc("authority","call_local","unreliable")
func clear_state():
if current_state == null:
return
current_state.exit()
current_state = null
func _process(delta: float) -> void:
if current_state == null:
return
current_state.update(delta)
func _input(event: InputEvent) -> void:
if current_state != null:
current_state.state_input(event)
func _physics_process(delta: float) -> void:
if current_state == null:
return
current_state.physics_update(delta)

View file

@ -0,0 +1 @@
uid://3777rkbebgjm

View file

@ -0,0 +1,17 @@
@abstract
extends Node
class_name State
@warning_ignore_start("unused_signal","unused_parameter")
signal transition(to: StringName)
@abstract func enter() -> void
@abstract func exit() -> void
func update(delta: float) -> void:
pass
func physics_update(delta: float) -> void:
pass
func state_input(event: InputEvent) -> void:
pass

View file

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

View file

@ -0,0 +1,35 @@
extends StateMachine
class_name SubStateMachine
@export var enter_state: State
func enter() -> void:
change_state(enter_state)
func exit() -> void:
if is_multiplayer_authority():
clear_state.rpc()
func update(delta: float) -> void:
if current_state == null:
return
current_state.update(delta)
func physics_update(delta: float) -> void:
if current_state == null:
return
current_state.physics_update(delta)
func _process(_delta: float) -> void:
pass
func _physics_process(_delta: float) -> void:
pass
func _input(_event: InputEvent) -> void:
pass
func state_input(event: InputEvent) -> void:
if current_state != null:
current_state.state_input(event)

View file

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