Added job component and queue system
- Introduced a new JobComponent and JobQueue to manage jobs in the game. - Created two new jobs: DigJob and InfectJob with their respective scripts. - Updated CrystalGlowComponent, FreeCameraComponent, MushroomGlowComponent, WaterEffectComponent to improve logging messages. - Adjusted camera movement limits in FreeCameraGameCameraComponent for better control. - Added FiniteStateMachine class for managing states of entities. - Implemented GlowingIdle state as an example of using the state machine. - Included a utility function to fetch file paths by extension from a directory.
This commit is contained in:
parent
fc896925d6
commit
bb5724429a
23 changed files with 311 additions and 29 deletions
|
|
@ -1,7 +1,9 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://ddwnkcnncxmjv"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://ddwnkcnncxmjv"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/scripts/glowling.gd" id="1_aq1kk"]
|
||||
[ext_resource type="Texture2D" uid="uid://b0v24ggq57237" path="res://resources/particles/smallcircle.png" id="2_s3xbi"]
|
||||
[ext_resource type="Script" path="res://entities/scripts/finite_state_machine.gd" id="3_vqtdm"]
|
||||
[ext_resource type="Script" path="res://entities/states/glowling/glowling_idle.gd" id="4_2l3e6"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_01nc3"]
|
||||
resource_name = "GlowingPulse"
|
||||
|
|
@ -63,3 +65,10 @@ energy = 0.7
|
|||
shadow_filter = 2
|
||||
shadow_filter_smooth = 7.5
|
||||
texture = ExtResource("2_s3xbi")
|
||||
|
||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("3_vqtdm")
|
||||
initial_state = NodePath("Idle")
|
||||
|
||||
[node name="Idle" type="Node" parent="StateMachine"]
|
||||
script = ExtResource("4_2l3e6")
|
||||
|
|
|
|||
75
entities/scripts/finite_state_machine.gd
Normal file
75
entities/scripts/finite_state_machine.gd
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
@icon("res://resources/icons/fsm.png")
|
||||
extends Node
|
||||
class_name FiniteStateMachine
|
||||
|
||||
var states : Dictionary = {}
|
||||
var current_state : State
|
||||
@export var initial_state : State
|
||||
|
||||
#NOTE This is a generic finite_state_machine, it handles all states, changes to this code will affect
|
||||
# everything that uses a state machine!
|
||||
|
||||
func _ready() -> void:
|
||||
for child : State in get_children():
|
||||
states[child.name.to_lower()] = child
|
||||
child.state_transition.connect(change_state)
|
||||
|
||||
if initial_state:
|
||||
initial_state.enter()
|
||||
current_state = initial_state
|
||||
|
||||
# Call the current states update function
|
||||
func _process(delta : float) -> void:
|
||||
if current_state:
|
||||
current_state.update(delta)
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
if current_state:
|
||||
current_state.physics_update(delta)
|
||||
|
||||
func get_current_state_name() -> String:
|
||||
if current_state:
|
||||
return current_state.name.to_lower()
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Use force_change_state cautiously, it immediately switches to a state regardless of any transitions.
|
||||
# This is used to force us into a 'death state' when killed
|
||||
func force_change_state(new_state : String) -> void:
|
||||
var newState : State = states.get(new_state.to_lower())
|
||||
|
||||
if !newState:
|
||||
print(new_state + " does not exist in the dictionary of states")
|
||||
return
|
||||
|
||||
if current_state == newState:
|
||||
print("State is same, aborting")
|
||||
return
|
||||
|
||||
# NOTE Calling exit like so: (current_state.Exit()) may cause warnings when flushing queries, like when the enemy is being removed after death.
|
||||
# call_deferred is safe and prevents this from occuring. We get the Exit function from the state as a callable and then call it in a thread-safe manner
|
||||
if current_state:
|
||||
var exit_callable : Callable = Callable(current_state, "exit")
|
||||
exit_callable.call_deferred()
|
||||
|
||||
newState.enter()
|
||||
|
||||
current_state = newState
|
||||
|
||||
func change_state(source_state : State, new_state_name : String) -> void:
|
||||
if source_state != current_state:
|
||||
#print("Invalid change_state trying from: " + source_state.name + " but currently in: " + current_state.name)
|
||||
#This typically only happens when trying to switch from death state following a force_change
|
||||
return
|
||||
|
||||
var new_state : State = states.get(new_state_name.to_lower())
|
||||
if !new_state:
|
||||
print("New state is empty")
|
||||
return
|
||||
|
||||
if current_state:
|
||||
current_state.exit()
|
||||
|
||||
new_state.enter()
|
||||
|
||||
current_state = new_state
|
||||
|
|
@ -8,12 +8,9 @@ class_name MushroomGlow
|
|||
@export var colour_name : String = "blue"
|
||||
|
||||
func _ready() -> void:
|
||||
Log.pr("And dog said let their be light...")
|
||||
Log.pr(position, global_position)
|
||||
set_light_colour(colour_name)
|
||||
animation.play("GlowFlicker")
|
||||
|
||||
|
||||
func set_light_colour(colour : String) -> void:
|
||||
if colour == "blue":
|
||||
inner_glow.color = "4cc5fa"
|
||||
|
|
|
|||
18
entities/scripts/state.gd
Normal file
18
entities/scripts/state.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
@icon("res://resources/icons/fsm.png")
|
||||
extends Node
|
||||
class_name State
|
||||
|
||||
signal state_transition
|
||||
|
||||
func enter(_msg : Dictionary = {}) -> void:
|
||||
pass
|
||||
|
||||
func exit() -> void :
|
||||
pass
|
||||
|
||||
func update(_delta : float) -> void:
|
||||
pass
|
||||
|
||||
func physics_update(_delate : float) -> void:
|
||||
pass
|
||||
|
||||
5
entities/states/glowling/glowling_idle.gd
Normal file
5
entities/states/glowling/glowling_idle.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends State
|
||||
class_name GlowingIdle
|
||||
|
||||
func enter(_msg : Dictionary = {}) -> void:
|
||||
Log.pr("I am a glowling and I am idle...")
|
||||
Loading…
Add table
Add a link
Reference in a new issue