class_name StateModifier
extends Node
## State modification
##
## A state modifier doesn't have any direct control of a game object. 
## They are transfered from the enter and exit of other states and 
## influence the movement or animation of their parent states. 
## Rather than going full into paralell state machines I hope that this 
## modifier will be suitable for a basic state machine.
##
## @WIP

export var debug_state: bool = false

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"

export 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

export 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

# not sure if I can do the array thing from state change. Maybe? 
# disabling this sequencing for now. 
# export(Array, String) var animation_sequence
# var animation_index: int = 0
# var current_animation_sequence: int = 0

var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")

#var animation_sequence_timer: Timer

var state_timeout: Timer

func _ready():
	# 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
	add_child(state_timeout)

func enter() -> void:
	if debug_state:
		print("Apply State Modifier: ", self.name)
	state_timeout.start()
	#modifier_stack_ref = state_modifiers
	return

func exit() -> void:
	pass

func _update():
	pass
