Found state machine subtype is probably not necessary.
This commit is contained in:
parent
12b9571d3a
commit
5378033645
|
|
@ -194,9 +194,10 @@ func _on_state_change(old_state_name:String, new_state :State):
|
||||||
# set current state to new_state
|
# set current state to new_state
|
||||||
#TODO: Confirm that this is a reference to the state in the
|
#TODO: Confirm that this is a reference to the state in the
|
||||||
###### State machine
|
###### State machine
|
||||||
# if new_state is StateAnimatedActor: #Testing this. Update: It works
|
if new_state is StateAnimatedActor: #Testing this. Update: It works
|
||||||
# current_state = new_state
|
current_state = new_state
|
||||||
# else:
|
print("It's an animated Actor state!")
|
||||||
# push_warning("Received non animated Actor state.")
|
else:
|
||||||
current_state = new_state
|
push_warning("Received non animated Actor state.")
|
||||||
|
#current_state = new_state
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,9 @@ var modifier: StateModifier
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
if debug_state:
|
# Call parent class enter
|
||||||
print(" entering State: ", self.name)
|
.enter()
|
||||||
|
|
||||||
# Reset movespeed counters
|
|
||||||
#move_component.momentum.x = move_speed_modifier
|
|
||||||
jerk = 0
|
jerk = 0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,103 +1,32 @@
|
||||||
class_name StateMachineAnimatedActor extends StateMachine
|
class_name StateMachineAnimatedActor extends StateMachine
|
||||||
|
|
||||||
#func change_state(new_state: State) -> void:
|
## I'm not sure I need a subtype anymore
|
||||||
# if new_state.state_ready == false:
|
func _ready():
|
||||||
# # Don't transition to unready state
|
print ("ready animactor state machine.")
|
||||||
# return
|
for s in states:
|
||||||
# if current_state:
|
print ("sname: ", s.name)
|
||||||
# current_state.exit()
|
var this_state = s
|
||||||
# # Set parameters for information
|
if this_state is StateAnimatedActor:
|
||||||
# if new_state is StateAnimatedActor and current_state is StateAnimatedActor:
|
print("Adding state ", this_state.name)
|
||||||
# set_previous_animation( current_state, new_state)
|
#check for empty state name
|
||||||
# if current_state.modifier: # Current state has a modifier
|
if this_state.name != '':
|
||||||
# new_state.transfer_modifiers(current_state.modifier)
|
#check for unique state name
|
||||||
# current_state.modifier = null
|
if !(states_index.has(this_state.name)):
|
||||||
# if current_state.physics_modifier: # Current state has a physics modifier
|
# call setup
|
||||||
# new_state.physics_modifier = current_state.physics_modifier
|
this_state.setup()
|
||||||
# current_state.physics_modifier = null
|
if debug_state_machine:
|
||||||
#
|
print("Initializing State Node: ", s)
|
||||||
# current_state = new_state
|
this_state.debug_state = true
|
||||||
# current_state.enter()
|
if this_state.state_timeout != null:
|
||||||
## if(state_modifiers.size() > 0 and debug_state_machine):
|
add_child(this_state.state_timeout)
|
||||||
## print("Active Modifiers:")
|
# Add to state index
|
||||||
## for mods in state_modifiers:
|
states_index[this_state.name] = this_state
|
||||||
## print(mods.name)
|
else:
|
||||||
|
push_error("Multiple states with same name in: ")
|
||||||
# Initialize the state machine by giving each child state a reference to the
|
else:
|
||||||
# parent object it belongs to and enter the default starting_state.
|
print("State missing name in: " )
|
||||||
func init_animated_actor(parent: KinematicBody2D) -> void:
|
|
||||||
# for child in get_children():
|
|
||||||
# if child is StateAnimatedActor:
|
|
||||||
# if debug_state_machine:
|
|
||||||
# print("Initializing State Node for ", parent.name, ": ", child.name)
|
|
||||||
# child.parent = parent
|
|
||||||
# child.animations = animations
|
|
||||||
# child.move_component = move_component
|
|
||||||
## child.modifier_stack_ref = state_modifiers
|
|
||||||
# if debug_state_machine:
|
|
||||||
# child.debug_state = true
|
|
||||||
#states["default"] = StateAnimatedActor.new()
|
|
||||||
for s in states.keys():
|
|
||||||
var child = states[s]
|
|
||||||
if child is StateAnimatedActor:
|
|
||||||
if debug_state_machine:
|
|
||||||
print("Initializing State Node for ", parent.name, ": ", s)
|
|
||||||
child.debug_state = true
|
|
||||||
child.parent = parent
|
|
||||||
#child.move_component = move_component
|
|
||||||
child.name = s
|
|
||||||
|
|
||||||
if states.has("default"):
|
|
||||||
print("I still haz default state")
|
|
||||||
change_state(states.default)
|
|
||||||
# current_state = states.default
|
|
||||||
# if current_state is StateAnimatedActor:
|
|
||||||
# current_state.animations = animations
|
|
||||||
# current_state.parent = parent
|
|
||||||
# current_state.move_component = move_component
|
|
||||||
# current_state.enter()
|
|
||||||
# #current_state.set_script("res://lib/templates/Actor/states/idle.gd")
|
|
||||||
|
|
||||||
# Initialize to the default state
|
|
||||||
#change_state(get_node(starting_state))
|
|
||||||
|
|
||||||
#change_state(states.default)
|
|
||||||
|
|
||||||
|
|
||||||
func process_frame(delta: float) -> void:
|
|
||||||
# Check the state modifiers for timeouts, and maybe more conditions later
|
|
||||||
# If the modifier is no longer valid, pop it from the stack.
|
|
||||||
# We could iterate through a whole list of states but I'm not sure i want
|
|
||||||
# states to be that complex.
|
|
||||||
# var current_anim_state :StateAnimatedActor = current_state
|
|
||||||
# if state_modifiers.empty() == false:
|
|
||||||
# for i in range(state_modifiers.size()):
|
|
||||||
# # if this modifer is a timer based one
|
|
||||||
# if state_modifiers[i].state_timeout.time_left == 0 and state_modifiers[i].timeout_seconds !=0:
|
|
||||||
# # Need to do extra stuff if it's an animation based one
|
|
||||||
# if state_modifiers[i].modifier_type == "Animation Suffix":
|
|
||||||
# if debug_state_machine:
|
|
||||||
# print("State Modifier Timeout: ", state_modifiers[i].name, " -> ", state_modifiers[i].animation_name)
|
|
||||||
# # Reset animation suffix
|
|
||||||
# current_anim_state.animation_suffix = ''
|
|
||||||
# # Get the current frame of animation
|
|
||||||
# var current_frame = current_anim_state.animations.frame
|
|
||||||
#
|
|
||||||
# # Set the animation index to the current one
|
|
||||||
# current_anim_state.animation_index = current_anim_state.current_animation_sequence
|
|
||||||
# #current_anim_state.current_animation_sequence
|
|
||||||
# #current_anim_state.animations.play()
|
|
||||||
#
|
|
||||||
# current_anim_state.animations.play(
|
|
||||||
# current_anim_state.mod_animation_sequence[current_anim_state.animation_index])
|
|
||||||
# # Try to set the current frame to the same as before.
|
|
||||||
# current_anim_state.animations.frames.frames.size() >= current_frame
|
|
||||||
# current_anim_state.animations.frame = current_frame
|
|
||||||
#
|
|
||||||
# if debug_state_machine:
|
|
||||||
# print("Pop State Modifier: ", state_modifiers[i].name)
|
|
||||||
# state_modifiers.pop_at(i)
|
|
||||||
if current_state is StateAnimatedActor:
|
|
||||||
current_state.process_animations()
|
|
||||||
change_to_known_state( current_state.process_frame(delta) )
|
|
||||||
|
|
||||||
|
if states_index.has(starting_state_name):
|
||||||
|
change_state(states_index[starting_state_name])
|
||||||
|
else:
|
||||||
|
push_error("State machine cannot find starting state: " + starting_state_name)
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,23 @@
|
||||||
[ext_resource path="res://lib/classes/animated_sprite_state_receiver.gd" type="Script" id=1]
|
[ext_resource path="res://lib/classes/animated_sprite_state_receiver.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://lib/classes/state_machine.gd" type="Script" id=2]
|
[ext_resource path="res://lib/classes/state_machine.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://assets/actors/players/playerE/new_spriteframes.tres" type="SpriteFrames" id=3]
|
[ext_resource path="res://assets/actors/players/playerE/new_spriteframes.tres" type="SpriteFrames" id=3]
|
||||||
[ext_resource path="res://lib/classes/state.gd" type="Script" id=4]
|
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://src/classes/movement_component.gd" type="Script" id=5]
|
[ext_resource path="res://src/classes/movement_component.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://lib/classes/actor.gd" type="Script" id=8]
|
[ext_resource path="res://lib/classes/actor.gd" type="Script" id=8]
|
||||||
|
|
||||||
[sub_resource type="Resource" id=1]
|
[sub_resource type="Resource" id=1]
|
||||||
resource_local_to_scene = true
|
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
debug_state = true
|
debug_state = false
|
||||||
timeout_seconds = 2.0
|
timeout_seconds = 2.0
|
||||||
name = "idle"
|
name = "idle"
|
||||||
|
move_speed = 60.0
|
||||||
|
move_acceleration = 0.0
|
||||||
|
move_speed_modifier = 0.0
|
||||||
|
move_modifier_move_acceleration = 0.0
|
||||||
|
jerk_factor = 0.0
|
||||||
|
animation_sequence = [ "idle", "Max Height" ]
|
||||||
|
emitter_frame_subscriptions = {
|
||||||
|
}
|
||||||
|
|
||||||
[node name="ActorTemplate" type="KinematicBody2D"]
|
[node name="ActorTemplate" type="KinematicBody2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user