Files
Bubberstation/code/datums/elements/_element.dm
spookydonut 210ba5c571 Adds linting for equipped() pickup() dropped() (#46614)
* lint some inventory procs

* lineends

* f

*  line end

* lineend

* fuck

* changes per review
2019-09-25 02:31:29 -07:00

43 lines
1.4 KiB
Plaintext

/**
* A holder for simple behaviour that can be attached to many different types
*
* Only one element of each type is instanced during game init.
* Otherwise acts basically like a lightweight component.
*/
/datum/element
/// Option flags for element behaviour
var/element_flags = NONE
/// Activates the functionality defined by the element on the given target datum
/datum/element/proc/Attach(datum/target)
SHOULD_CALL_PARENT(TRUE)
if(type == /datum/element)
return ELEMENT_INCOMPATIBLE
if(element_flags & ELEMENT_DETACH)
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/Detach)
/// Deactivates the functionality defines by the element on the given datum
/datum/element/proc/Detach(datum/source, force)
SHOULD_CALL_PARENT(TRUE)
UnregisterSignal(source, COMSIG_PARENT_QDELETING)
/datum/element/Destroy(force)
if(!force)
return QDEL_HINT_LETMELIVE
SSdcs.elements_by_type -= type
return ..()
//DATUM PROCS
/// Finds the singleton for the element type given and attaches it to src
/datum/proc/AddElement(eletype, ...)
var/datum/element/ele = SSdcs.GetElement(eletype)
args[1] = src
if(ele.Attach(arglist(args)) == ELEMENT_INCOMPATIBLE)
CRASH("Incompatible [eletype] assigned to a [type]! args: [json_encode(args)]")
/// Finds the singleton for the element type given and detaches it from src
/datum/proc/RemoveElement(eletype)
var/datum/element/ele = SSdcs.GetElement(eletype)
ele.Detach(src)