Merge pull request #7195 from Citadel-Station-13/upstream-merge-38574

[MIRROR] Global component signals
This commit is contained in:
LetterJay
2018-06-24 18:20:17 -05:00
committed by GitHub
10 changed files with 98 additions and 1 deletions
+11 -1
View File
@@ -334,6 +334,16 @@
/obj/item/stack/sheet/metal/fifty,
/turf/open/floor/plating/asteroid/airless,
/area/ruin/unpowered/no_grav)
"XA" = (
/obj/structure/fluff/bus/passable/seat{
icon_state = "backseat"
},
/obj/effect/decal/cleanable/dirt,
/obj/item/toy/plush/awakenedplushie,
/turf/open/floor/plasteel/airless/dark{
icon_state = "bus"
},
/area/ruin/unpowered/no_grav)
(1,1,1) = {"
aa
@@ -484,7 +494,7 @@ ab
ae
ad
aj
am
XA
az
aK
ad
+11
View File
@@ -1,3 +1,6 @@
#define SEND_SIGNAL(target, sigtype, arguments...) ( !target.datum_components ? NONE : target._SendSignal(sigtype, list(##arguments)) )
#define SEND_GLOBAL_SIGNAL(sigtype, arguments...) ( !SSdcs.comp_lookup[sigtype] ? NONE : SSdcs._SendGlobalSignal(sigtype, list(##arguments)) )
//shorthand
#define GET_COMPONENT_FROM(varname, path, target) var##path/##varname = ##target.GetComponent(##path)
#define GET_COMPONENT(varname, path) GET_COMPONENT_FROM(varname, path, src)
@@ -14,6 +17,14 @@
// All signals. Format:
// When the signal is called: (signal arguments)
// global signals
// These are signals which can be listened to by any component on any parent
// GLOBAL SIGNALS MUST START WITH "!"
#define COMSIG_GLOB_NEW_Z "!new_z" //from base of datum/controller/subsystem/mapping/proc/add_new_zlevel(): (list/args)
#define COMSIG_GLOB_VAR_EDIT "!var_edit" //called after a successful var edit somewhere in the world: (list/args)
//////////////////////////////////////////////////////////////////
// /datum signals
#define COMSIG_COMPONENT_ADDED "component_added" //when a component is added to a datum: (/datum/component)
#define COMSIG_COMPONENT_REMOVING "component_removing" //before a component is removed from a datum because of RemoveComponent: (/datum/component)
+35
View File
@@ -0,0 +1,35 @@
SUBSYSTEM_DEF(dcs)
name = "Datum Component System"
flags = SS_NO_INIT | SS_NO_FIRE
var/list/comp_lookup = list() // A signal:list(components) assoc list
/datum/controller/subsystem/dcs/proc/_SendGlobalSignal(sigtype, list/arguments)
. = NONE
for(var/i in comp_lookup[sigtype])
var/datum/component/comp = i
if(!comp.enabled)
continue
var/datum/callback/CB = comp.signal_procs[sigtype]
if(!CB)
continue // Should we error from this?
. |= CB.InvokeAsync(arglist(arguments))
/datum/controller/subsystem/dcs/proc/RegisterSignal(datum/component/comp, sigtype)
if(!comp_lookup[sigtype])
comp_lookup[sigtype] = list()
comp_lookup[sigtype][comp] = TRUE
/datum/controller/subsystem/dcs/proc/UnregisterSignal(datum/component/comp, list/sigtypes)
if(!length(sigtypes))
sigtypes = list(sigtypes)
for(var/sigtype in sigtypes)
switch(length(comp_lookup[sigtype]))
if(1)
comp_lookup -= sigtype
if(2 to INFINITY)
comp_lookup[sigtype] -= comp
/datum/controller/subsystem/dcs/Recover()
comp_lookup = SSdcs.comp_lookup
+4
View File
@@ -58,6 +58,7 @@
if(!silent)
P.SendSignal(COMSIG_COMPONENT_REMOVING, src)
parent = null
SSdcs.UnregisterSignal(src, signal_procs)
LAZYCLEARLIST(signal_procs)
return ..()
@@ -93,6 +94,9 @@
if(!override && procs[sig_type])
stack_trace("[sig_type] overridden. Use override = TRUE to suppress this warning")
if(sig_type[1] == "!")
SSdcs.RegisterSignal(src, sig_type)
procs[sig_type] = proc_or_callback
enabled = TRUE
+23
View File
@@ -0,0 +1,23 @@
// This is just a bit of fun while making an example for global signal
/datum/component/edit_complainer
var/list/say_lines
/datum/component/edit_complainer/Initialize(list/text)
if(!ismovableatom(parent))
return COMPONENT_INCOMPATIBLE
var/static/list/default_lines = list(
"CentCom's profligacy frays another thread.",
"Another tug at the weave.",
"Who knows when the stresses will finally shatter the form?",
"Even now a light shines through the cracks.",
"CentCom once more twists knowledge beyond its authority.",
"There is an uncertain air in the mansus.",
)
say_lines = text || default_lines
RegisterSignal(COMSIG_GLOB_VAR_EDIT, .proc/var_edit_react)
/datum/component/edit_complainer/proc/var_edit_react(list/arguments)
var/atom/movable/master = parent
master.say(pick(say_lines))
+10
View File
@@ -510,3 +510,13 @@
attack_verb = list("blorbled", "slimed", "absorbed")
squeak_override = list('sound/effects/blobattack.ogg' = 1)
gender = FEMALE //given all the jokes and drawings, I'm not sure the xenobiologists would make a slimeboy
/obj/item/toy/plush/awakenedplushie
name = "awakened plushie"
desc = "An ancient plushie that has grown enlightened to the true nature of reality."
icon_state = "plushie_awake"
item_state = "plushie_awake"
/obj/item/toy/plush/awakenedplushie/ComponentInitialize()
. = ..()
AddComponent(/datum/component/edit_complainer)
@@ -629,6 +629,7 @@ GLOBAL_PROTECT(VVpixelmovement)
if (O.vv_edit_var(variable, var_new) == FALSE)
to_chat(src, "Your edit was rejected by the object.")
return
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_VAR_EDIT, args)
log_world("### VarEdit by [key_name(src)]: [O.type] [variable]=[var_value] => [var_new]")
log_admin("[key_name(src)] modified [original_name]'s [variable] from [html_encode("[var_value]")] to [html_encode("[var_new]")]")
var/msg = "[key_name_admin(src)] modified [original_name]'s [variable] from [var_value] to [var_new]"
@@ -17,6 +17,7 @@
z_list += S
/datum/controller/subsystem/mapping/proc/add_new_zlevel(name, traits = list(), z_type = /datum/space_level)
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_Z, args)
var/new_z = z_list.len + 1
if (world.maxz < new_z)
world.incrementMaxZ()
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

+2
View File
@@ -209,6 +209,7 @@
#include "code\controllers\subsystem\blackbox.dm"
#include "code\controllers\subsystem\communications.dm"
#include "code\controllers\subsystem\dbcore.dm"
#include "code\controllers\subsystem\dcs.dm"
#include "code\controllers\subsystem\disease.dm"
#include "code\controllers\subsystem\events.dm"
#include "code\controllers\subsystem\fire_burning.dm"
@@ -328,6 +329,7 @@
#include "code\datums\components\decal.dm"
#include "code\datums\components\earhealing.dm"
#include "code\datums\components\earprotection.dm"
#include "code\datums\components\edit_complainer.dm"
#include "code\datums\components\empprotection.dm"
#include "code\datums\components\forensics.dm"
#include "code\datums\components\infective.dm"