Multiple Movement Modifier
This commit is contained in:
parent
0ac1c4abef
commit
d422ae61dd
|
|
@ -27,12 +27,12 @@ export var debug_name :String
|
||||||
func modify(_movement_parameters :MovementParameters):
|
func modify(_movement_parameters :MovementParameters):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func apply_multiple_modifiers( _modifiers: Array):
|
func apply_multiple_modifiers( _modifiers: Array, _movement_direction :Vector2):
|
||||||
for m in _modifiers:
|
for m in _modifiers:
|
||||||
if m is StateModifierMovement:
|
if m is StateModifierMovement:
|
||||||
apply_state_modifier(m)
|
apply_state_modifier(m, _movement_direction)
|
||||||
|
|
||||||
func apply_state_modifier(_modifier :StateModifierMovement):
|
func apply_state_modifier(_modifier :StateModifierMovement, _movement_direction :Vector2):
|
||||||
#_modifier.direction == _modifier.APPLIED_DIRECTIONS.LEFT_OR_UP
|
#_modifier.direction == _modifier.APPLIED_DIRECTIONS.LEFT_OR_UP
|
||||||
match _modifier.modifier_type:
|
match _modifier.modifier_type:
|
||||||
StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT:
|
StateModifierMovement.SUB_TYPE.NEGATIVE_CONSTRAINT:
|
||||||
|
|
|
||||||
|
|
@ -153,9 +153,9 @@ func apply_state_modifier(movement_parameters :MovementParameters) -> MovementPa
|
||||||
# movement_parameters.apply_state_modifier(modifier)
|
# movement_parameters.apply_state_modifier(modifier)
|
||||||
|
|
||||||
var active_mods :bool= true
|
var active_mods :bool= true
|
||||||
var mods :Array = get_state_machine_modifiers.call_func('StateModifierMovement', active_mods)
|
var mods :Array = get_state_machine_modifiers.call_func('StateModifierMovement', active_mods, current_state.is_grounded)
|
||||||
if (mods.size() > 0):
|
if (mods.size() > 0):
|
||||||
movement_parameters.apply_multiple_modifiers(mods)
|
movement_parameters.apply_multiple_modifiers(mods, Vector2(0,0))
|
||||||
return movement_parameters
|
return movement_parameters
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,16 @@ func merge_modifiers():
|
||||||
this_mod_type.merge(m)
|
this_mod_type.merge(m)
|
||||||
|
|
||||||
## When trying to get multiple modifiers
|
## When trying to get multiple modifiers
|
||||||
func get_modifiers_of_type(_modifier_type :String, _only_active: bool = false) -> Array:
|
func get_modifiers_of_type(_modifier_type :String,
|
||||||
|
_only_active: bool = false,
|
||||||
|
_first_condition :bool = true,
|
||||||
|
_second_condition :bool = true) -> Array:
|
||||||
var mod_array :Array = []
|
var mod_array :Array = []
|
||||||
for m in state_modifiers:
|
for m in state_modifiers:
|
||||||
if m.to_string() == _modifier_type:
|
if m.to_string() == _modifier_type:
|
||||||
if (_only_active and m.is_active) or _only_active == false:
|
if (_only_active and m.is_active) or _only_active == false:
|
||||||
|
## invoke additional status checks if they're implemented for this modifier
|
||||||
|
if m.status_check_1(_first_condition) and m.status_check_2(_first_condition):
|
||||||
mod_array.append(m)
|
mod_array.append(m)
|
||||||
return mod_array
|
return mod_array
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,11 @@ func copy(_copy_state: StateModifier):
|
||||||
name = _copy_state.name
|
name = _copy_state.name
|
||||||
modifier_type = _copy_state.modifier_type
|
modifier_type = _copy_state.modifier_type
|
||||||
|
|
||||||
|
func status_check_1(condition :bool) -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
|
func status_check_2(condition :bool) -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
func merge(_merge_from_modifier: StateModifier):
|
func merge(_merge_from_modifier: StateModifier):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,16 @@ func copy(_copy_state: StateModifier):
|
||||||
_copy_state.horizontal_speed = horizontal_speed
|
_copy_state.horizontal_speed = horizontal_speed
|
||||||
_copy_state.horizontal_acceleration = horizontal_acceleration
|
_copy_state.horizontal_acceleration = horizontal_acceleration
|
||||||
|
|
||||||
|
## Overrident to check whether this state is a grounded and this modifier
|
||||||
|
## should only apply while in the air.
|
||||||
|
func status_check_1(condition :bool) -> bool:
|
||||||
|
var is_grounded :bool = condition
|
||||||
|
if only_grounded == true and is_grounded == false:
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
func merge(_merge_from_modifier: StateModifier):
|
func merge(_merge_from_modifier: StateModifier):
|
||||||
.merge(_merge_from_modifier)
|
.merge(_merge_from_modifier)
|
||||||
is_active = _merge_from_modifier.is_active
|
is_active = _merge_from_modifier.is_active
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user