weapon system rework
This commit is contained in:
parent
0ffc2b2497
commit
30b01100f0
27 changed files with 352 additions and 190 deletions
|
|
@ -1,6 +1,5 @@
|
|||
extends Node
|
||||
|
||||
|
||||
class_name StateMachine
|
||||
|
||||
@export var current_state: State
|
||||
|
|
@ -19,18 +18,36 @@ func on_transition_required(to: StringName):
|
|||
push_warning("Incorrect state request: " + to)
|
||||
return
|
||||
|
||||
change_state(states[to])
|
||||
|
||||
func change_state(to_state: State) -> void:
|
||||
if current_state != null:
|
||||
current_state.exit()
|
||||
current_state = to_state
|
||||
current_state.enter()
|
||||
|
||||
update_remote_machines.rpc(to_state.name)
|
||||
|
||||
@rpc("authority","call_local","unreliable")
|
||||
func clear_state():
|
||||
if current_state == null:
|
||||
return
|
||||
current_state.exit()
|
||||
current_state = null
|
||||
|
||||
@rpc("authority","call_remote","unreliable")
|
||||
func update_remote_machines(to: StringName) -> void:
|
||||
if current_state != null:
|
||||
current_state.exit()
|
||||
current_state = states[to]
|
||||
current_state.enter()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.update(delta)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.physics_update(delta)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
@abstract
|
||||
extends Node
|
||||
|
||||
|
||||
class_name State
|
||||
|
||||
signal transition(to: StringName)
|
||||
|
||||
@abstract func enter() -> void
|
||||
@abstract func exit() -> void
|
||||
@abstract func update(delta: float) -> void
|
||||
@abstract func physics_update(delta: float) -> void
|
||||
func update(delta: float) -> void:
|
||||
pass
|
||||
func physics_update(delta: float) -> void:
|
||||
pass
|
||||
|
|
|
|||
27
scripts/state_machine/substate_machine.gd
Normal file
27
scripts/state_machine/substate_machine.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends StateMachine
|
||||
|
||||
class_name SubStateMachine
|
||||
|
||||
@export var enter_state: State
|
||||
|
||||
func enter() -> void:
|
||||
change_state(enter_state)
|
||||
|
||||
func exit() -> void:
|
||||
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
|
||||
1
scripts/state_machine/substate_machine.gd.uid
Normal file
1
scripts/state_machine/substate_machine.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://btc5vyvccdqfp
|
||||
Loading…
Add table
Add a link
Reference in a new issue