Files
Bubberstation/code/modules/wiremod/core/variable.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

54 lines
1.8 KiB
Plaintext

/**
* A circuit variable that holds the name, the datatype and the colour of the variable (taken from the datatype).
*
* Used in integrated circuits for setter and getter circuit components.
*/
/datum/circuit_variable
/// The display name of the circuit variable
var/name
/// The datatype of the circuit variable. Used by the setter and getter circuit components
var/datatype
/// The datatype handler for the circuit variable.
var/datum/circuit_datatype/datatype_handler
/// The colour that appears in the UI. The value is set to the datatype's matching colour
var/color
/// The current value held by the variable.
var/value
/// The components that are currently listening. Triggers them when the value is updated.
var/list/obj/item/circuit_component/listeners
/datum/circuit_variable/New(name, datatype)
. = ..()
src.name = name
src.datatype = datatype
src.datatype_handler = GLOB.circuit_datatypes[datatype]
src.listeners = list()
src.color = datatype_handler.color
/// Sets the value of the circuit component and triggers the appropriate listeners
/datum/circuit_variable/proc/set_value(new_value)
value = new_value
for(var/obj/item/circuit_component/component as anything in listeners)
component.trigger_component()
/datum/circuit_variable/proc/on_listener_qdel(datum/listener)
SIGNAL_HANDLER
listeners -= listener
/// Adds a listener to receive inputs when the variable has a value that is set.
/datum/circuit_variable/proc/add_listener(obj/item/circuit_component/to_add)
listeners += to_add
RegisterSignal(to_add, COMSIG_QDELETING, PROC_REF(on_listener_qdel))
/// Removes a listener to receive inputs when the variable has a value that is set. Listener will usually clean themselves up
/datum/circuit_variable/proc/remove_listener(obj/item/circuit_component/to_remove)
UnregisterSignal(to_remove, COMSIG_QDELETING)
listeners -= to_remove