diff --git a/project.godot b/project.godot index 7b6acbc..821e21d 100644 --- a/project.godot +++ b/project.godot @@ -69,7 +69,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://src/state_machine_animated_actor.gd" }, { -"base": "Object", +"base": "Reference", "class": "StateModifier", "language": "GDScript", "path": "res://src/state_modifier.gd" diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index 1653fe9..3185306 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -562,8 +562,12 @@ script = ExtResource( 2 ) player_number = 1 interactable_node = NodePath("../Interactable_Receiver") +[node name="movement_state_machine" parent="." index="3"] +debug_state_machine = true + [node name="idle" parent="movement_state_machine" index="0"] script = ExtResource( 4 ) +debug_state = true move_speed = 1.0 animation_sequence = [ "idle" ] jump_node = NodePath("../jump") @@ -573,12 +577,14 @@ roll_node = NodePath("../roll") [node name="fall" parent="movement_state_machine" index="1"] script = ExtResource( 6 ) +debug_state = true move_speed = 90.0 animation_sequence = [ "jump" ] landing_node = NodePath("") [node name="move" parent="movement_state_machine" index="2"] script = ExtResource( 5 ) +debug_state = true move_speed = 90.0 animation_sequence = [ "step", "run" ] jump_node = NodePath("../jump") diff --git a/src/playerD/states/attack.gd b/src/playerD/states/attack.gd index 9e669ee..410cef4 100644 --- a/src/playerD/states/attack.gd +++ b/src/playerD/states/attack.gd @@ -16,6 +16,8 @@ onready var move_state: State = get_node(move_node) var can_fire = true signal do_attack() +var draw_weapon_modifier: StateModifier + func enter() -> void: #.enter() ##TODO: Turn this to clear only the animation modifiers. @@ -54,6 +56,19 @@ func enter() -> void: animations.frame = previous_state_frame_number _: print("Warning!: Attack state encountered unhandled prev animation: ", previous_animation_name) + + draw_weapon_modifier = StateModifier.new() + var mod_timer :Timer = draw_weapon_modifier.ready( "idle_shoot" , draw_weapon_modifier.TYPE.ANIMATION_SUFFIX, 2.0) + add_child(mod_timer) +# connect() + mod_timer.connect("timeout", draw_weapon_modifier, "_on_Timer_timeout") + mod_timer.connect("timeout", self, "_on_Timer_timeout") + draw_weapon_modifier.state_timeout.start() + #mod_timer.connect("timeout",) + +func _on_Timer_timeout(): + print("Oh Crap! I this worked too!") + animations.stop() func process_frame(delta: float) -> State: # if animations.frame == 2: diff --git a/src/playerD/states/fall.gd b/src/playerD/states/fall.gd index ae55959..1e0729f 100644 --- a/src/playerD/states/fall.gd +++ b/src/playerD/states/fall.gd @@ -3,9 +3,20 @@ extends StateAnimatedActor export (NodePath) var idle_node export (NodePath) var landing_node -onready var idle_state: State = get_node(idle_node) +onready var idle_state: StateAnimatedActor = get_node(idle_node) #onready var landing_mod: StateModifier = get_node(landing_node) +var landing_modifier: StateModifier + +func _ready(): + landing_modifier= StateModifier.new() + #add_child(modifier) + #modifier.init_ref() + landing_modifier.ready( "jump" , landing_modifier.TYPE.EXIT_ANIMATION) + landing_modifier.starting_frame = 6 + #print("ready! MOD") + + func enter() -> void: # var landing_mod_index = modifier_stack_ref.rfind(landing_mod) # if landing_mod_index != -1: @@ -26,13 +37,15 @@ func process_physics(delta: float) -> State: parent.transform.x.x = move_component.get_movement_direction() if parent.is_on_floor(): + print("DO you even!?: ", landing_modifier.animation_name) + #modifier.reference() + idle_state.modifier = landing_modifier return idle_state - return null -func exit() -> void: - .exit() -# push_animation_state_modifier(landing_mod) -# $"../landing".enter() -# modifier_stack_ref.push_front($"../landing") - return +#func exit() -> void: +# .exit() +## push_animation_state_modifier(landing_mod) +## $"../landing".enter() +## modifier_stack_ref.push_front($"../landing") +# return diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index 4e53548..85fe819 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -29,6 +29,10 @@ signal frame_reached(state_name, animation_name, frame_number) export(Dictionary) var emitter_frame_subscriptions var frame_signal_emitted: bool = false +var animation_finished: bool = false + +var transition_state: StateAnimatedActor + # this just wouldn't work well. Maybe I can try a resource # export(Array, NodePath) var transition_state_nodes @@ -52,6 +56,8 @@ var previous_state_frame_number : int var previous_state_name: String var previous_speed_multiplier: float +var modifier: StateModifier + #var animation_sequence_timer: Timer @@ -65,6 +71,8 @@ func _ready(): state_timeout.one_shot = true state_timeout.autostart = false add_child(state_timeout) + + #modifier = StateModifier.new() func enter() -> void: @@ -83,6 +91,13 @@ func enter() -> void: move_component.current_movement_state = self.name emit_signal("state_entered") #modifier_stack_ref = state_modifiers + + if modifier != null: + if modifier.modifier_type == modifier.TYPE.EXIT_ANIMATION: + #print("OHHH Modifier Applies! ", modifier.animation_name) + mod_animation_sequence.push_front(modifier.animation_name) + enter_frame = modifier.starting_frame + # A new attempt at animation modifiers # if modifier_stack_ref.empty() == false: @@ -148,8 +163,20 @@ func enter() -> void: func exit() -> void: emit_signal("state_exited") # animations.disconnect("animation_finished", self, "_on_AnimatedSprite_animation_finished") + #modifier = null return +func transfer_modifiers(exiting_state_modifier : StateModifier): + if modifier == null: # We have no existing modifier applied. + match exiting_state_modifier.modifier_type: + exiting_state_modifier.TYPE.ANIMATION_SUFFIX: + print("Transferring Animation Suffix") + modifier = exiting_state_modifier + exiting_state_modifier.TYPE.EXIT_ANIMATION: + print("Exit Animation: well this was useless.") + else: + print("Insert modifier merge function here...") + func process_input(_event: InputEvent) -> State: return null diff --git a/src/state_machine_animated_actor.gd b/src/state_machine_animated_actor.gd index e001ebc..b281a0a 100644 --- a/src/state_machine_animated_actor.gd +++ b/src/state_machine_animated_actor.gd @@ -6,6 +6,9 @@ func change_state(new_state: State) -> void: # 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 current_state = new_state current_state.enter() @@ -48,7 +51,7 @@ func process_frame(delta: float) -> void: # 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 +# 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 @@ -83,7 +86,8 @@ func process_frame(delta: float) -> void: func _on_AnimatedSprite_animation_finished(): - +# if debug_state_machine: +# print("Stop!!!!!") ##TODO: # It's hard to pop an exit animation off when it's stacked with another kind of animation. # for i in state_modifiers.size(): diff --git a/src/state_modifier.gd b/src/state_modifier.gd index dcf14d2..d3c52ec 100644 --- a/src/state_modifier.gd +++ b/src/state_modifier.gd @@ -1,5 +1,5 @@ class_name StateModifier -extends Object +extends Reference ## State modification ## ## A state modifier doesn't have any direct control of a game object. @@ -10,7 +10,7 @@ extends Object ## ## @WIP -enum type {NONE,EXIT_ANIMATION} +enum TYPE {NONE,EXIT_ANIMATION, ANIMATION_SUFFIX, REPLACE_ANIMATION} export var debug_state: bool = false @@ -19,26 +19,23 @@ export var animation_name: String ## Modification Type ## if an animation is specified, the default behavior will be just to override ## the state animation. Or perform a 'Replace Animation' -export(String, "None", - "Exit Animation", - "Animation Suffix", - "Replace Animation") var modifier_type = "None" +var modifier_type = TYPE.NONE -export var starting_frame: int = 0 +var starting_frame: int = 0 # Move Speed in Pixels Per Second # These should only apply if Modification Type Set to None. # (But I'm not sure if I like that model.) -export var move_speed: float -export var move_speed_modifier: float = 0 -export var move_speed_modifier_decay: float = 0 +var move_speed: float +var move_speed_modifier: float = 0 +var move_speed_modifier_decay: float = 0 -export var timeout_seconds: float = 0.0 +var timeout_seconds: float = 0.0 # Attempting to use this as an animation suffix that can linger after # state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc. -export var animation_suffix: bool = false -export var pre_append_animation: bool = false +var animation_suffix: bool = false +var pre_append_animation: bool = false # not sure if I can do the array thing from state change. Maybe? # disabling this sequencing for now. @@ -52,21 +49,34 @@ var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") var state_timeout: Timer -func _ready(): +#func copy_modifier() -> StateModifier: +# var new_modifier = StateModifier.new() +# new_modifier.ready(animation_name, modifier_type, timeout_seconds) +# +# return StateModifier.new() + +func ready(anim_name:String = '', type = TYPE.NONE, timeout : float = 0) -> Timer: # If somebody forgot to specify the type - if animation_name != '' and modifier_type == "None": - modifier_type = "Replace Animation" - state_timeout = Timer.new() - if timeout_seconds > 0: - state_timeout.wait_time = timeout_seconds - state_timeout.one_shot = true - state_timeout.autostart = false + if anim_name != '' and type == TYPE.NONE: + modifier_type = TYPE.REPLACE_ANIMATION + animation_name = anim_name + modifier_type = type + if timeout > 0: + state_timeout = Timer.new() + state_timeout.wait_time = timeout + state_timeout.one_shot = true + state_timeout.autostart = false + return state_timeout #add_child(state_timeout) + return null + +func _on_Timer_timeout(): + print("Oh Crap! I can't beleive it worked") func enter() -> void: if debug_state: print("Apply State Modifier: ", self.name) - state_timeout.start() +# state_timeout.start() #modifier_stack_ref = state_modifiers return