mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-31 12:01:47 +00:00
If you came here thinking this was some game feature then you are in the wrong place. Here is where I ramble about code. This adds /datum/element as a sort of sibling to components. Only one of each type gets instanced and they do not get tied directly to any particular thing like a component does. Basically they're a very lightweight component for doing simple functionality that doesn't have much state. Originally this concept came about as a kind of component that could be shared between many parents to reduce some resource costs. Doing this would allow us to componentize more behaviors that are a part of too many things to be viable to have a whole component for every single one. For example a component on every space turf would be entirely unviable. With elements it's much more reasonable. This implements a prety bare framework and a couple components are migrated to it. It's ready to be used but I fully expect I'm going to need to refine how it works for all the usecases we'll want it for. Also: this fixes the qdeleted signal. This signal isn't even possible because after qdel is done there's nothing to receive a signal anyway. I've changed it to a qdeling signal instead. I need it to work for some elements to know when to clean themselves up.
30 lines
818 B
Plaintext
30 lines
818 B
Plaintext
/datum/element
|
|
var/element_flags = NONE
|
|
|
|
/datum/element/proc/Attach(datum/target)
|
|
if(type == /datum/element)
|
|
return ELEMENT_INCOMPATIBLE
|
|
if(element_flags & ELEMENT_DETACH)
|
|
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/Detach)
|
|
|
|
/datum/element/proc/Detach(datum/source, force)
|
|
UnregisterSignal(source, COMSIG_PARENT_QDELETING)
|
|
|
|
/datum/element/Destroy(force)
|
|
if(!force)
|
|
return QDEL_HINT_LETMELIVE
|
|
SSdcs.elements_by_type -= type
|
|
return ..()
|
|
|
|
//DATUM PROCS
|
|
|
|
/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)]")
|
|
|
|
/datum/proc/RemoveElement(eletype)
|
|
var/datum/element/ele = SSdcs.GetElement(eletype)
|
|
ele.Detach(src)
|