Compare commits

..

No commits in common. "d5818f1c17b9d92792a1c30346f3c52d58451e06" and "ec869ed1cc0b81cdf3e28dbddfac56698d993b35" have entirely different histories.

10 changed files with 90 additions and 226 deletions

View File

@ -39,8 +39,7 @@ func _ready():
# processed
current_state = get_node(callable_state_machine).current_state
#state_machine_modifiers = get_node(callable_state_machine).state_modifiers
## Not doing it this way anymore modifier is applied when one arrives by signal.
#modifier = get_node(callable_state_machine).merged_animation_state_modifiers
modifier = get_node(callable_state_machine).merged_animation_state_modifiers
# Sprites should only have a process function
# but if I have this will the sprite still animate?
@ -90,7 +89,6 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
animation_index = index
current_animation_sequence = animation_index
## TODO: this runs everytime since the modifier will apply once and stay referenced.
if modifier:
##TODO: Apply the animation starting frame
#modifier.animation_starting_frame
@ -242,14 +240,9 @@ func _on_state_change(old_state_name:String, new_state :State):
else:
push_warning("Received non animated Actor state.")
func _on_modifiers_updated(_modifier_type :int, _modifier_action :int, _merged_modifier :StateModifier):
func _on_modifiers_updated(_modifier_type :int, _modifier_action :int):
##TODO: There's so many things I could maybe do here but lets target the
# current use case.
##
## If the signalled merged modifier is a Animation one set it
if _merged_modifier is StateModifierAnimatedActor:
modifier = _merged_modifier
print("<<--- >> is active? ", modifier.is_active)
## current use case.
if _modifier_type == StateModifierAnimatedActor.TYPE.ANIMATION_SUFFIX:
print("A: ", animation, " F: ", frame, " -Modifier Changed Signal")
# Wait for frame to finish before doing anything.

View File

@ -1,32 +0,0 @@
class_name MovementParameters
extends Reference
## Vector based ones for x and y
export var base_move_speed :Vector2
export var base_move_acceleration :Vector2
export var move_speed_modifier :Vector2
export var move_speed_modifier_acceleration :Vector2
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
var jerk: float = 0.0
# export var base_h_move_speed :float
# export var base_h_move_acceleration :float
# export var h_move_speed_modifier :float
# export var h_move_modifier_move_acceleration :float
# export var base_v_move_speed :float
# export var base_v_move_acceleration :float
# export var v_move_speed_modifier :float
# export var v_move_modifier_move_acceleration :float
func modify(_movement_parameters :MovementParameters):
pass
# var movement_params :Dictionary = {
# "_base_h_move_speed" : _state.horizontal_speed,
# "_base_h_move_acceleration" : _state.horizontal_acceleration,
# "_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
# "_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
# "_jerk_factor" : _state.jerk_factor,
# "_gravity" : _state.gravity
# }

View File

@ -32,7 +32,7 @@ var acceleration = Vector2(0,0)
var physics_delta:float
var process_delta:float
var modifier: StateModifierMovement
var modifier: StateModifierAnimatedActor
#Removing Probably not used
#var attack_function: FuncRef
@ -50,7 +50,7 @@ func _ready():
## A reference to the current state machine state
current_state = get_node(callable_state_machine).current_state
## A reference to the state machine merged modifiers
#modifier = get_node(callable_state_machine).merged_animation_state_modifiers
modifier = get_node(callable_state_machine).merged_animation_state_modifiers
############
## These get called by the parent
@ -149,16 +149,14 @@ func new_move_actor_as_desired(_delta :float,
_movement_override_normal := Vector2(0,0),
_velocity_override := Vector2(0,0)) -> Vector2:
## Calculated movement speed.
# var movement_params :Dictionary = {
# "_base_h_move_speed" : _state.horizontal_speed,
# "_base_h_move_acceleration" : _state.horizontal_acceleration,
# "_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
# "_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
# "_jerk_factor" : _state.jerk_factor,
# "_gravity" : _state.gravity
# }
var movement_parameters :MovementParameters = _state.get_movement_parameters()
var movement_params :Dictionary = {
"_base_h_move_speed" : _state.horizontal_speed,
"_base_h_move_acceleration" : _state.horizontal_acceleration,
"_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
"_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
"_jerk_factor" : _state.jerk_factor,
"_gravity" : _state.gravity
}
var calc_velocity = Vector2.ZERO
if _velocity_override.x != 0.0:
calc_velocity.x = _velocity_override.x
@ -183,7 +181,7 @@ func new_move_actor_as_desired(_delta :float,
# but if a modifier applies, or an accelleration is given.
# an entirely differant process occurs.
##
var h_speed = resolve_h_speed(movement_parameters)
var h_speed = resolve_h_speed(movement_params)
#if h_speed != Vector2.ZERO:
# pass
## If an override has been passed (we're ignoring input direction
@ -194,7 +192,7 @@ func new_move_actor_as_desired(_delta :float,
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
## Which direction will acceleration be applied.
calc_acceleration.x = resolve_h_acceleration(movement_parameters, calc_velocity, move_direction.x)
calc_acceleration.x = resolve_h_acceleration(movement_params, calc_velocity, move_direction.x)
## Direction of inertia not equal to move direction
## If inertia is applying in a direction
@ -260,7 +258,7 @@ func new_move_actor_as_desired(_delta :float,
## Neutralize the inertia? but how?
## Recalc the acceleration with inertia
#var friction :Vector2
calc_friction.x = resolve_h_acceleration(movement_parameters,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
if calc_friction.x != 0.0: ## No dapening acceleration applies
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
## Apply friction
@ -284,7 +282,7 @@ func new_move_actor_as_desired(_delta :float,
## For now, y component of velocity is just gravity
#calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
calc_inertia.y += movement_parameters.gravity * _delta
calc_inertia.y += movement_params["_gravity"] * _delta
calc_velocity.y = calc_inertia.y
## calc x component of felicty
@ -323,23 +321,23 @@ func apply_movement_to_parent( _velocity :Vector2) -> void:
## Returns an Vector where x is MIN_SPEED and y is MAX_SPEED
func resolve_h_speed(_params :MovementParameters) -> Vector2:
var base_speed :float = _params.base_move_speed.x
func resolve_h_speed(_params :Dictionary) -> Vector2:
var base_speed :float = _params["_base_h_move_speed"]
## if a speed difference applies
if _params.move_speed_modifier.x != 0:
var speed_differance = base_speed + _params.move_speed_modifier.x
if _params["_base_h_move_speed_modifier"] != 0:
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
return(Vector2(base_speed, speed_differance))
return Vector2(base_speed,base_speed)
func resolve_h_acceleration(_params :MovementParameters, _inertia :Vector2, _move_direction :float) -> float:
func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direction :float) -> float:
## TODO: Adjust for jerk, determine if we're currently experiencing accel
## if a speed difference applies
var _acceleration :float = 0.0
var base_speed :float = _params.base_move_speed.x
if _params.move_speed_modifier.x != 0:
var speed_differance = base_speed + _params.move_speed_modifier.x
_acceleration = _params.base_move_acceleration.x + _params.move_speed_modifier_acceleration.x
var base_speed :float = _params["_base_h_move_speed"]
if _params["_base_h_move_speed_modifier"] != 0:
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
##WIP: Add part where offset acceleration only applies until the inertia equals the offset or whatever
# if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
# #print("I should add the modifier acceleration maybe?")
@ -347,7 +345,7 @@ func resolve_h_acceleration(_params :MovementParameters, _inertia :Vector2, _mov
# else:
# print ("not yet.")
else:
_acceleration = _params.base_move_acceleration.x
_acceleration = _params["_base_h_move_acceleration"]
## This works but I want to try something differant.
# if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):

View File

@ -41,12 +41,3 @@ func enter() -> void:
return
func get_movement_parameters() -> MovementParameters:
var movement_parameters = MovementParameters.new()
movement_parameters.base_move_speed.x = horizontal_speed
movement_parameters.base_move_acceleration.x = horizontal_acceleration
movement_parameters.move_speed_modifier.x = horizontal_speed_offset
movement_parameters.move_speed_modifier_acceleration.x = horizontal_speed_offset_acceleration
return movement_parameters

View File

@ -3,13 +3,12 @@ class_name StateMachine extends Node
export var debug_state_machine: bool = false
signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid, _merged_modifier)
signal modifiers_updated(modifier_type, modifier_eventid)
var current_state: State
var state_modifiers: Array
var merged_modifiers : Dictionary
#onready var merged_animation_state_modifiers :StateModifierAnimatedActor = StateModifierAnimatedActor.new()
onready var merged_animation_state_modifiers :StateModifierAnimatedActor = StateModifierAnimatedActor.new()
export var starting_state_name = 'default'
export(Array,Resource) var states
@ -49,25 +48,19 @@ func _ready():
push_error("State machine cannot find starting state: " + starting_state_name)
#func _physics_process(delta):
# if(state_modifiers.size() > 0):
# merged_animation_state_modifiers.reset()
# merged_animation_state_modifiers.animation_name = 'floopy doo,'
# #merge_modifiers()
func _physics_process(delta):
if(state_modifiers.size() > 0):
merged_animation_state_modifiers.reset()
merged_animation_state_modifiers.animation_name = 'floopy doo,'
merge_modifiers()
func merge_modifiers():
#merged_animation_state_modifiers.reset()
for modgroup in merged_modifiers.keys():
merged_modifiers["StateModifierAnimatedActor"].reset()
merged_animation_state_modifiers.reset()
for m in state_modifiers:
if m is StateModifierAnimatedActor:
if merged_modifiers.has("StateModifierAnimatedActor") == false:
merged_modifiers["StateModifierAnimatedActor"] = StateModifierAnimatedActor.new()
#print(m.name)
var this_mod_type :StateModifierAnimatedActor = merged_modifiers["StateModifierAnimatedActor"]
if m.is_active:
#merged_animation_state_modifiers.merge(m)
this_mod_type.merge(m)
merged_animation_state_modifiers.merge_StateModifierAnimatedActor(m)
# Change to the new state by first calling any exit logic on the current state.
func change_state(new_state: State) -> void:
@ -120,16 +113,13 @@ func push_state_modifier(_state_modifier: StateModifier) -> void:
if debug_state_machine:
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
func handle_modifier_events(eventID :int, modifier_class_name :String):
##TODO: why did I care about the events? they both do the same thing
func handle_modifier_events(eventID :int):
if eventID == StateModifier.EVENT_ID.ACTIVATED:
if debug_state_machine:
print ("A mod activated! Which one though?", modifier_class_name)
print ("A mod activated! Which one though?")
merge_modifiers()
emit_signal("modifiers_updated",merged_modifiers[modifier_class_name].modifier_type,
eventID,
merged_modifiers[modifier_class_name] )
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
elif eventID == StateModifier.EVENT_ID.DEACTIVATED:
merge_modifiers()
emit_signal("modifiers_updated",merged_modifiers[modifier_class_name].modifier_type, eventID, merged_modifiers[modifier_class_name])
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)

View File

@ -86,10 +86,6 @@ var state_call_function: FuncRef
# mp.directional_modifier = modifier_properties.directional_modifier
# return mp
## Because I've tried a few ways to identify the object without a CR error
func _to_string():
return "StateModifier"
func setup(modifier_name:String, type = TYPE.NONE,_timeout_seconds : float = 0):
name = modifier_name
modifier_type = type
@ -106,11 +102,8 @@ func reset():
modifier_type = TYPE.NONE
func copy(_copy_state: StateModifier):
## This should really be the other way.
# _copy_state.name = name
# _copy_state.modifier_type = modifier_type
name = _copy_state.name
modifier_type = _copy_state.modifier_type
_copy_state.name = name
_copy_state.modifier_type = modifier_type
func merge(_merge_from_modifier: StateModifier):
@ -120,12 +113,12 @@ func activate():
is_active = true
if timeout != null:
timeout.start()
emit_signal("modifier_event",EVENT_ID.ACTIVATED, to_string())
emit_signal("modifier_event",EVENT_ID.ACTIVATED)
func deactivate():
is_active = false
print(name," <- Got call to deactivate.")
emit_signal("modifier_event",EVENT_ID.DEACTIVATED, to_string())
emit_signal("modifier_event",EVENT_ID.DEACTIVATED)
#func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
# name = modifier_name

View File

@ -8,8 +8,15 @@ var animation_suffix: String = ''
var animation_starting_frame: int = 0
var animation_speed: float
func _to_string():
return "StateModifierAnimatedActor"
var horizontal_speed: float = 0
var horizontal_acceleration: float = 0
## Movement Speed Offsets (Positive or Negative)
var horizontal_speed_offset: float = 0
## Applies only if offset applies
var horizontal_speed_offset_acceleration: float = 0
var jerk_factor: float = 0
var gravity: int = 0
func reset():
.reset()
@ -17,64 +24,45 @@ func reset():
animation_suffix = ''
animation_starting_frame = 0
func copy(_copy_state: StateModifier):
horizontal_speed = 0
horizontal_acceleration = 0
## Movement Speed Offsets (Positive or Negative)
horizontal_speed_offset = 0
## Applies only if offset applies
horizontal_speed_offset_acceleration = 0
jerk_factor = 0
func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
.copy(_copy_state)
## Using is gives me cyclic redundancy problems
#if _copy_state is StateModifierAnimatedActor:
#if _copy_state.is_class("StateModifierAnimatedActor"):
if _copy_state.to_string() == "StateModifierAnimatedActor":
_copy_state.animation_name = animation_name
_copy_state.animation_starting_frame = animation_starting_frame
_copy_state.animation_speed = animation_speed
else:
print_debug("Non AnimatedActor modifier passed into this modifier")
_copy_state.animation_name = animation_name
_copy_state.animation_starting_frame = animation_starting_frame
_copy_state.animation_speed = animation_speed
##DEPR: Need to remove this
#func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
# .copy(_copy_state)
# _copy_state.animation_name = animation_name
# _copy_state.animation_starting_frame = animation_starting_frame
# _copy_state.animation_speed = animation_speed
##TODO: finish these
_copy_state.horizontal_speed = horizontal_speed
_copy_state.horizontal_acceleration = horizontal_acceleration
func merge(_merge_from_modifier: StateModifier):
func merge_StateModifierAnimatedActor(_merge_from_modifier: StateModifierAnimatedActor):
.merge(_merge_from_modifier)
#print(_merge_from_modifier.to_string(), " I'm a mod named: ", _merge_from_modifier.get_class())
#if _merge_from_modifier is StateModifierAnimatedActor:
if _merge_from_modifier.to_string() == "StateModifierAnimatedActor":
if modifier_type == TYPE.NONE and _merge_from_modifier.modifier_type != TYPE.NONE:
modifier_type = _merge_from_modifier.modifier_type
if modifier_type == TYPE.NONE and _merge_from_modifier.modifier_type != TYPE.NONE:
modifier_type = _merge_from_modifier.modifier_type
#_copy_state.animation_name += animation_name
match _merge_from_modifier.modifier_type:
TYPE.ANIMATION_SUFFIX:
# Attempt to seemlessly transition animations.
if _merge_from_modifier.animation_suffix != '':
animation_suffix = _merge_from_modifier.animation_suffix
TYPE.REPLACE_ANIMATION:
if _merge_from_modifier.animation_name != '':
animation_name = _merge_from_modifier.animation_name
# _: # None
# print ('physics?')
#_copy_state.animation_name += animation_name
match _merge_from_modifier.modifier_type:
TYPE.ANIMATION_SUFFIX:
# Attempt to seemlessly transition animations.
if _merge_from_modifier.animation_suffix != '':
animation_suffix = _merge_from_modifier.animation_suffix
TYPE.REPLACE_ANIMATION:
if _merge_from_modifier.animation_name != '':
animation_name = _merge_from_modifier.animation_name
_: # None
#print ('physics?')
horizontal_speed += _merge_from_modifier.horizontal_speed
horizontal_acceleration += _merge_from_modifier.horizontal_acceleration
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration
##DEPR: Need to remove this
#func merge_StateModifierAnimatedActor(_merge_from_modifier: StateModifierAnimatedActor):
# .merge(_merge_from_modifier)
# if modifier_type == TYPE.NONE and _merge_from_modifier.modifier_type != TYPE.NONE:
# modifier_type = _merge_from_modifier.modifier_type
#
# #_copy_state.animation_name += animation_name
# match _merge_from_modifier.modifier_type:
# TYPE.ANIMATION_SUFFIX:
# # Attempt to seemlessly transition animations.
# if _merge_from_modifier.animation_suffix != '':
# animation_suffix = _merge_from_modifier.animation_suffix
# TYPE.REPLACE_ANIMATION:
# if _merge_from_modifier.animation_name != '':
# animation_name = _merge_from_modifier.animation_name
# _: # None
# print ('physics?')
#
#
#_copy_state.animation_starting_frame = animation_starting_frame
#_copy_state.animation_speed = animation_speed

View File

@ -1,41 +0,0 @@
class_name StateModifierMovement
extends StateModifier
## Movement Modifiers
var horizontal_speed: float = 0
var horizontal_acceleration: float = 0
## Movement Speed Offsets (Positive or Negative)
var horizontal_speed_offset: float = 0
## Applies only if offset applies
var horizontal_speed_offset_acceleration: float = 0
var jerk_factor: float = 0
var gravity: int = 0
func _to_string():
return "StateModifierMovement"
func reset():
.reset()
horizontal_speed = 0
horizontal_acceleration = 0
## Movement Speed Offsets (Positive or Negative)
horizontal_speed_offset = 0
## Applies only if offset applies
horizontal_speed_offset_acceleration = 0
jerk_factor = 0
func copy(_copy_state: StateModifier):
.copy(_copy_state)
if _copy_state.to_string() == "StateModifierMovement":
_copy_state.horizontal_speed = horizontal_speed
_copy_state.horizontal_acceleration = horizontal_acceleration
func merge(_merge_from_modifier: StateModifier):
.merge(_merge_from_modifier)
if _merge_from_modifier.to_string() == "StateModifierMovement":
horizontal_speed += _merge_from_modifier.horizontal_speed
horizontal_acceleration += _merge_from_modifier.horizontal_acceleration
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration

View File

@ -89,11 +89,6 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/classes/movement_component.gd"
}, {
"base": "Reference",
"class": "MovementParameters",
"language": "GDScript",
"path": "res://lib/classes/movement_parameters.gd"
}, {
"base": "Node",
"class": "Movement_StateReceiver",
"language": "GDScript",
@ -154,11 +149,6 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://lib/classes/state_modifier_animation.gd"
}, {
"base": "StateModifier",
"class": "StateModifierMovement",
"language": "GDScript",
"path": "res://lib/classes/state_modifier_movement.gd"
}, {
"base": "CanvasLayer",
"class": "UIComponent",
"language": "GDScript",
@ -181,7 +171,6 @@ _global_script_class_icons={
"LevelTransition": "",
"Modifier_Receiver": "",
"MovementComponent": "",
"MovementParameters": "",
"Movement_StateReceiver": "",
"PlayerData": "",
"Projectile": "",
@ -194,7 +183,6 @@ _global_script_class_icons={
"StateMachineAnimatedActor": "",
"StateModifier": "",
"StateModifierAnimatedActor": "",
"StateModifierMovement": "",
"UIComponent": ""
}
@ -413,10 +401,6 @@ dash_2={
common/enable_pause_aware_picking=true
2d/default_gravity=600
[mono]
project/assembly_name="Attempt 2"
[physics]
2d/default_gravity=280

View File

@ -76,5 +76,5 @@ func _on_state_exited_attack_sword():
print("you just swung your sword, you should get a modifier.")
#attack_sword.timeout.start()
attack_sword.activate()
print ("you has merged as? :" ,modifier.animation_suffix)
print ("you has merged as? :" ,modifier.animation_name)