From e592b5173ab13ee3d3fd8b0e571dc40a8fb49b73 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 9 Jun 2021 00:42:38 +0200 Subject: [PATCH] Add component and element templates (#59101) (#6195) * Add component and element templates * Convert compoinent and element templates to markdown files * Change element example in template to stateless * Replace element example with gong moving sound Co-authored-by: Jonathan Rubenstein --- code/datums/components/COMPONENT_TEMPLATE.md | 55 ++++++++++++++++++++ code/datums/elements/ELEMENT_TEMPLATE.md | 25 +++++++++ 2 files changed, 80 insertions(+) create mode 100644 code/datums/components/COMPONENT_TEMPLATE.md create mode 100644 code/datums/elements/ELEMENT_TEMPLATE.md diff --git a/code/datums/components/COMPONENT_TEMPLATE.md b/code/datums/components/COMPONENT_TEMPLATE.md new file mode 100644 index 00000000000..223347578e2 --- /dev/null +++ b/code/datums/components/COMPONENT_TEMPLATE.md @@ -0,0 +1,55 @@ + +# Template file for your new component + +See _component.dm for detailed explanations + +```dm +/datum/component/mycomponent + //can_transfer = TRUE // Must have PostTransfer + //dupe_mode = COMPONENT_DUPE_ALLOWED // code/__DEFINES/dcs/flags.dm + var/myvar + +/datum/component/mycomponent/Initialize(myargone, myargtwo) + if(myargone) + myvar = myargone + if(myargtwo) + send_to_playing_players(myargtwo) + +/datum/component/mycomponent/RegisterWithParent() + RegisterSignal(parent, COMSIG_NOT_REAL, ./proc/signalproc) // RegisterSignal can take a signal name by itself, + RegisterSignal(parent, list(COMSIG_NOT_REAL_EITHER, COMSIG_ALMOST_REAL), ./proc/otherproc) // or a list of them to assign to the same proc + +/datum/component/mycomponent/UnregisterFromParent() + UnregisterSignal(parent, COMSIG_NOT_REAL) // UnregisterSignal has similar behavior + UnregisterSignal(parent, list( // But you can just include all registered signals in one call + COMSIG_NOT_REAL, + COMSIG_NOT_REAL_EITHER, + COMSIG_ALMOST_REAL, + )) + +/datum/component/mycomponent/proc/signalproc(datum/source) + SIGNAL_HANDLER + send_to_playing_players("[source] signaled [src]!") + +/* +/datum/component/mycomponent/InheritComponent(datum/component/mycomponent/old, i_am_original, list/arguments) + myvar = old.myvar + + if(i_am_original) + send_to_playing_players("No parent should have to bury their child") +*/ + +/* +/datum/component/mycomponent/PreTransfer() + send_to_playing_players("Goodbye [parent], I'm getting adopted") + +/datum/component/mycomponent/PostTransfer() + send_to_playing_players("Hello my new parent, [parent]! It's nice to meet you!") +*/ + +/* +/datum/component/mycomponent/CheckDupeComponent(datum/mycomponent/new, myargone, myargtwo) + if(myargone == myvar) + return TRUE +*/ +``` diff --git a/code/datums/elements/ELEMENT_TEMPLATE.md b/code/datums/elements/ELEMENT_TEMPLATE.md new file mode 100644 index 00000000000..333375b3508 --- /dev/null +++ b/code/datums/elements/ELEMENT_TEMPLATE.md @@ -0,0 +1,25 @@ + +# Template file for your new element + +See _element.dm for detailed explanations + +```dm +/datum/element/myelement + element_flags = ELEMENT_BESPOKE | ELEMENT_COMPLEX_DETACH | ELEMENT_DETACH | ELEMENT_NOTAREALFLAG // code/__DEFINES/dcs/flags.dm + //id_arg_index = 2 // Use with ELEMENT_BESPOKE + var/list/myvar = list() + +/datum/element/myelement/Attach(datum/target) + if(!ismovable(target)) + return COMPONENT_INCOMPATIBLE + RegisterSignal(target, COMSIG_MOVABLE_MOVED, myproc) + to_chat(target, "Hey, you're in your element.") + +/datum/element/myelement/Detach(datum/source) + UnregisterSignal(source, COMSIG_MOVABLE_MOVED) + to_chat(source, "You feel way out of your element.") + +/datum/element/myelement/proc/myproc(datum/source) + SIGNAL_HANDLER + playsound(source, 'sound/effects/gong.ogg', 50, TRUE) +```