Skip to content

Commit

Permalink
[MIRROR] Fixes Callback Trait Addition/Removal Oversight [MDB IGNORE]…
Browse files Browse the repository at this point in the history
… (#25361) (#907)

* Fixes Callback Trait Addition/Removal Oversight (#80009)

## About The Pull Request

This pissed me off working yesterday, traits are supposed to work on the
`/datum` level, not just the `/atom` level. Let's fix that, while also
cleaning up the code a bunch to make it look better and have error
logging for unwanted cases.
## Changelog
Nothing that concerns players.

* Fixes Callback Trait Addition/Removal Oversight

---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: san7890 <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2023
1 parent b100ea9 commit d64a49a
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions code/__HELPERS/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@
#define TRAIT_CALLBACK_REMOVE(target, trait, source) CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(___TraitRemove), ##target, ##trait, ##source)

///DO NOT USE ___TraitAdd OR ___TraitRemove as a replacement for ADD_TRAIT / REMOVE_TRAIT defines. To be used explicitly for callback.
/proc/___TraitAdd(target,trait,source)
/proc/___TraitAdd(target, trait, source)
if(!target || !trait || !source)
return

if(islist(target))
for(var/i in target)
if(!isatom(i))
continue
var/atom/the_atom = i
ADD_TRAIT(the_atom,trait,source)
else if(isatom(target))
var/atom/the_atom2 = target
ADD_TRAIT(the_atom2,trait,source)
for(var/datum/listed_target in target)
ADD_TRAIT(listed_target, trait, source)
return

ASSERT(isdatum(target), "Invalid target used in TRAIT_CALLBACK_ADD! Expected a datum reference, got [target] instead.")

var/datum/datum_target = target
ADD_TRAIT(datum_target, trait, source)

///DO NOT USE ___TraitAdd OR ___TraitRemove as a replacement for ADD_TRAIT / REMOVE_TRAIT defines. To be used explicitly for callback.
/proc/___TraitRemove(target,trait,source)
/proc/___TraitRemove(target, trait, source)
if(!target || !trait || !source)
return

if(islist(target))
for(var/i in target)
if(!isatom(i))
continue
var/atom/the_atom = i
REMOVE_TRAIT(the_atom,trait,source)
else if(isatom(target))
var/atom/the_atom2 = target
REMOVE_TRAIT(the_atom2,trait,source)
for(var/datum/listed_target in target)
REMOVE_TRAIT(listed_target, trait, source)
return

ASSERT(isdatum(target), "Invalid target used in TRAIT_CALLBACK_REMOVE! Expected a datum reference, got [target] instead.")

var/datum/datum_target = target
REMOVE_TRAIT(datum_target, trait, source)


/// Proc that handles adding multiple traits to a target via a list. Must have a common source and target.
Expand Down

0 comments on commit d64a49a

Please sign in to comment.