Removes a signal and a list from the movetype handler element. (#86119)

## About The Pull Request
We can already stop the floating anim by adding the no floating trait,
COMSIG_PAUSE_FLOATING_ANIM and the relative paused_floating_anim_atoms
list are redundant as we can just use the `TRAIT_CALLBACK_REMOVE` macro
and timers.

## Why It's Good For The Game
Less crap in the way of a one big bespoke element that manages the
movetypes of every living mob in the game.

## Changelog
N/A
This commit is contained in:
Ghom
2024-09-06 06:58:39 +02:00
committed by GitHub
parent 291f80c412
commit a66065cb6d
4 changed files with 7 additions and 29 deletions
@@ -1,6 +1,3 @@
// /datum/element/movetype_handler signals
/// Called when the floating anim has to be temporarily stopped and restarted later: (timer)
#define COMSIG_PAUSE_FLOATING_ANIM "pause_floating_anim"
/// From base of datum/element/movetype_handler/on_movement_type_trait_gain: (flag, old_movement_type)
#define COMSIG_MOVETYPE_FLAG_ENABLED "movetype_flag_enabled"
/// From base of datum/element/movetype_handler/on_movement_type_trait_loss: (flag, old_movement_type)
+3
View File
@@ -196,6 +196,9 @@
/// Trait given by a fulton extraction pack
#define FULTON_PACK_TRAIT "fulton-pack"
/// Trait from mob/living/update_transform()
#define UPDATE_TRANSFORM_TRAIT "update_transform"
/// Trait granted by the berserker hood.
#define BERSERK_TRAIT "berserk_trait"
/// Trait granted by [/obj/item/rod_of_asclepius]
+2 -25
View File
@@ -8,7 +8,6 @@
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
var/list/attached_atoms = list()
var/list/paused_floating_anim_atoms = list()
/datum/element/movetype_handler/Attach(datum/target)
. = ..()
@@ -22,7 +21,6 @@
RegisterSignals(movable_target, GLOB.movement_type_removetrait_signals, PROC_REF(on_movement_type_trait_loss))
RegisterSignal(movable_target, SIGNAL_ADDTRAIT(TRAIT_NO_FLOATING_ANIM), PROC_REF(on_no_floating_anim_trait_gain))
RegisterSignal(movable_target, SIGNAL_REMOVETRAIT(TRAIT_NO_FLOATING_ANIM), PROC_REF(on_no_floating_anim_trait_loss))
RegisterSignal(movable_target, COMSIG_PAUSE_FLOATING_ANIM, PROC_REF(pause_floating_anim))
attached_atoms[movable_target] = TRUE
if(movable_target.movement_type & (FLOATING|FLYING) && !HAS_TRAIT(movable_target, TRAIT_NO_FLOATING_ANIM))
@@ -32,14 +30,12 @@
var/list/signals_to_remove = list(
SIGNAL_ADDTRAIT(TRAIT_NO_FLOATING_ANIM),
SIGNAL_REMOVETRAIT(TRAIT_NO_FLOATING_ANIM),
COMSIG_PAUSE_FLOATING_ANIM
)
signals_to_remove += GLOB.movement_type_addtrait_signals
signals_to_remove += GLOB.movement_type_removetrait_signals
UnregisterSignal(source, signals_to_remove)
attached_atoms -= source
paused_floating_anim_atoms -= source
STOP_FLOATING_ANIM(source)
return ..()
@@ -51,7 +47,7 @@
return
var/old_state = source.movement_type
source.movement_type |= flag
if(!(old_state & (FLOATING|FLYING)) && (source.movement_type & (FLOATING|FLYING)) && !paused_floating_anim_atoms[source] && !HAS_TRAIT(source, TRAIT_NO_FLOATING_ANIM))
if(!(old_state & (FLOATING|FLYING)) && (source.movement_type & (FLOATING|FLYING)) && !HAS_TRAIT(source, TRAIT_NO_FLOATING_ANIM))
DO_FLOATING_ANIM(source)
SEND_SIGNAL(source, COMSIG_MOVETYPE_FLAG_ENABLED, flag, old_state)
@@ -78,24 +74,5 @@
/// Called when the TRAIT_NO_FLOATING_ANIM trait is removed from the mob. Restarts the bobbing animation.
/datum/element/movetype_handler/proc/on_no_floating_anim_trait_loss(atom/movable/source, trait)
SIGNAL_HANDLER
if(source.movement_type & (FLOATING|FLYING) && !paused_floating_anim_atoms[source])
if(source.movement_type & (FLOATING|FLYING))
DO_FLOATING_ANIM(source)
///Pauses the floating animation for the duration of the timer... plus [tickrate - (world.time + timer) % tickrate] to be precise.
/datum/element/movetype_handler/proc/pause_floating_anim(atom/movable/source, timer)
SIGNAL_HANDLER
if(paused_floating_anim_atoms[source] < world.time + timer)
STOP_FLOATING_ANIM(source)
if(!length(paused_floating_anim_atoms))
START_PROCESSING(SSdcs, src) //1 second tickrate.
paused_floating_anim_atoms[source] = world.time + timer
/datum/element/movetype_handler/process()
for(var/_paused in paused_floating_anim_atoms)
var/atom/movable/paused = _paused
if(paused_floating_anim_atoms[paused] < world.time)
if(paused.movement_type & (FLOATING|FLYING) && !HAS_TRAIT(paused, TRAIT_NO_FLOATING_ANIM))
DO_FLOATING_ANIM(paused)
paused_floating_anim_atoms -= paused
if(!length(paused_floating_anim_atoms))
STOP_PROCESSING(SSdcs, src)
@@ -58,7 +58,8 @@
if(!changed) //Nothing has been changed, nothing has to be done.
return
SEND_SIGNAL(src, COMSIG_PAUSE_FLOATING_ANIM, 0.3 SECONDS)
ADD_TRAIT(src, TRAIT_NO_FLOATING_ANIM, UPDATE_TRANSFORM_TRAIT)
addtimer(TRAIT_CALLBACK_REMOVE(src, TRAIT_NO_FLOATING_ANIM, UPDATE_TRANSFORM_TRAIT), 0.3 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE)
//if true, we want to avoid any animation time, it'll tween and not rotate at all otherwise.
var/is_opposite_angle = SIMPLIFY_DEGREES(lying_angle+180) == lying_prev
animate(src, transform = ntransform, time = is_opposite_angle ? 0 : UPDATE_TRANSFORM_ANIMATION_TIME, pixel_y = final_pixel_y, dir = final_dir, easing = (EASE_IN|EASE_OUT))