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
|
||||
#TODO: Confirm that this is a reference to the state in the
|
||||
###### State machine
|
||||
# if new_state is StateAnimatedActor: #Testing this. Update: It works
|
||||
# current_state = new_state
|
||||
# else:
|
||||
# push_warning("Received non animated Actor state.")
|
||||
current_state = new_state
|
||||
if new_state is StateAnimatedActor: #Testing this. Update: It works
|
||||
current_state = new_state
|
||||
print("It's an animated Actor state!")
|
||||
else:
|
||||
push_warning("Received non animated Actor state.")
|
||||
#current_state = new_state
|
||||
|
||||
|
|
|
|||
|
|
@ -41,12 +41,10 @@ var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|||
var modifier: StateModifier
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
if debug_state:
|
||||
print(" entering State: ", self.name)
|
||||
func enter() -> void:
|
||||
# Call parent class enter
|
||||
.enter()
|
||||
|
||||
# Reset movespeed counters
|
||||
#move_component.momentum.x = move_speed_modifier
|
||||
jerk = 0
|
||||
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,103 +1,32 @@
|
|||
class_name StateMachineAnimatedActor extends StateMachine
|
||||
|
||||
#func change_state(new_state: State) -> void:
|
||||
# if new_state.state_ready == false:
|
||||
# # Don't transition to unready state
|
||||
# return
|
||||
# if current_state:
|
||||
# current_state.exit()
|
||||
# # Set parameters for information
|
||||
# if new_state is StateAnimatedActor and current_state is StateAnimatedActor:
|
||||
# set_previous_animation( current_state, new_state)
|
||||
# if current_state.modifier: # Current state has a modifier
|
||||
# new_state.transfer_modifiers(current_state.modifier)
|
||||
# current_state.modifier = null
|
||||
# if current_state.physics_modifier: # Current state has a physics modifier
|
||||
# new_state.physics_modifier = current_state.physics_modifier
|
||||
# current_state.physics_modifier = null
|
||||
#
|
||||
# current_state = new_state
|
||||
# current_state.enter()
|
||||
## if(state_modifiers.size() > 0 and debug_state_machine):
|
||||
## print("Active Modifiers:")
|
||||
## for mods in state_modifiers:
|
||||
## print(mods.name)
|
||||
|
||||
# Initialize the state machine by giving each child state a reference to the
|
||||
# parent object it belongs to and enter the default starting_state.
|
||||
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) )
|
||||
## I'm not sure I need a subtype anymore
|
||||
func _ready():
|
||||
print ("ready animactor state machine.")
|
||||
for s in states:
|
||||
print ("sname: ", s.name)
|
||||
var this_state = s
|
||||
if this_state is StateAnimatedActor:
|
||||
print("Adding state ", this_state.name)
|
||||
#check for empty state name
|
||||
if this_state.name != '':
|
||||
#check for unique state name
|
||||
if !(states_index.has(this_state.name)):
|
||||
# call setup
|
||||
this_state.setup()
|
||||
if debug_state_machine:
|
||||
print("Initializing State Node: ", s)
|
||||
this_state.debug_state = true
|
||||
if this_state.state_timeout != null:
|
||||
add_child(this_state.state_timeout)
|
||||
# Add to state index
|
||||
states_index[this_state.name] = this_state
|
||||
else:
|
||||
push_error("Multiple states with same name in: ")
|
||||
else:
|
||||
print("State missing name in: " )
|
||||
|
||||
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/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://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://lib/classes/actor.gd" type="Script" id=8]
|
||||
|
||||
[sub_resource type="Resource" id=1]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource( 4 )
|
||||
debug_state = true
|
||||
debug_state = false
|
||||
timeout_seconds = 2.0
|
||||
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"]
|
||||
collision_layer = 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user