[MIRROR] More circuit components. Restructures the circuit components folder to be more organised. (#6142)

* More circuit components. Restructures the circuit components folder to be more organised.

* Mirror!

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Funce <funce.973@gmail.com>
This commit is contained in:
SkyratBot
2021-06-05 17:15:43 +12:00
committed by GitHub
co-authored by Watermelon914 Funce
parent 6e52d05e2e
commit cc5cf407b0
42 changed files with 630 additions and 106 deletions
@@ -0,0 +1,72 @@
/**
* # Light Component
*
* Emits a light of a specific brightness and colour. Requires a shell.
*/
/obj/item/circuit_component/light
display_name = "Light"
/// The colours of the light
var/datum/port/input/red
var/datum/port/input/green
var/datum/port/input/blue
/// The brightness
var/datum/port/input/brightness
/// Whether the light is on or not
var/datum/port/input/on
var/max_power = 5
var/min_lightness = 0.4
var/shell_light_color
/obj/item/circuit_component/light/Initialize()
. = ..()
red = add_input_port("Red", PORT_TYPE_NUMBER)
green = add_input_port("Green", PORT_TYPE_NUMBER)
blue = add_input_port("Blue", PORT_TYPE_NUMBER)
brightness = add_input_port("Brightness", PORT_TYPE_NUMBER)
on = add_input_port("On", PORT_TYPE_NUMBER)
/obj/item/circuit_component/light/Destroy()
red = null
green = null
blue = null
brightness = null
on = null
return ..()
/obj/item/circuit_component/light/register_shell(atom/movable/shell)
. = ..()
TRIGGER_CIRCUIT_COMPONENT(src, null)
/obj/item/circuit_component/light/unregister_shell(atom/movable/shell)
shell.set_light_on(FALSE)
return ..()
/obj/item/circuit_component/light/input_received(datum/port/input/port)
. = ..()
brightness.set_input(clamp(brightness.input_value || 0, 0, max_power), FALSE)
red.set_input(clamp(red.input_value, 0, 255), FALSE)
blue.set_input(clamp(blue.input_value, 0, 255), FALSE)
green.set_input(clamp(green.input_value, 0, 255), FALSE)
var/list/hsl = rgb2hsl(red.input_value || 0, green.input_value || 0, blue.input_value || 0)
var/list/light_col = hsl2rgb(hsl[1], hsl[2], max(min_lightness, hsl[3]))
shell_light_color = rgb(light_col[1], light_col[2], light_col[3])
if(.)
return
if(parent.shell)
set_atom_light(parent.shell)
/obj/item/circuit_component/light/proc/set_atom_light(atom/movable/target_atom)
// Clamp anyways just for safety
var/bright_val = min(max(brightness.input_value || 0, 0), max_power)
target_atom.set_light_power(bright_val)
target_atom.set_light_range(bright_val)
target_atom.set_light_color(shell_light_color)
target_atom.set_light_on(!!on.input_value)
@@ -0,0 +1,34 @@
/**
* # Pull Component
*
* Tells the shell to start pulling on a designated atom. Only works on movable shells.
*/
/obj/item/circuit_component/pull
display_name = "Start Pulling"
/// Frequency input
var/datum/port/input/target
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/pull/Initialize()
. = ..()
target = add_input_port("Target", PORT_TYPE_ATOM)
/obj/item/circuit_component/pull/Destroy()
target = null
return ..()
/obj/item/circuit_component/pull/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/atom/target_atom = target.input_value
if(!target_atom)
return
var/mob/shell = parent.shell
if(!istype(shell) || get_dist(shell, target_atom) > 1 || shell.z != target_atom.z)
return
shell.start_pulling(target_atom)
@@ -0,0 +1,56 @@
/**
* # Radio Component
*
* Listens out for signals on the designated frequencies and sends signals on designated frequencies
*/
/obj/item/circuit_component/radio
display_name = "Radio"
/// Frequency input
var/datum/port/input/freq
/// Signal input
var/datum/port/input/code
/// Current frequency value
var/current_freq = DEFAULT_SIGNALER_CODE
var/datum/radio_frequency/radio_connection
/obj/item/circuit_component/radio/Initialize()
. = ..()
freq = add_input_port("Frequency", PORT_TYPE_NUMBER, default = FREQ_SIGNALER)
code = add_input_port("Code", PORT_TYPE_NUMBER, default = DEFAULT_SIGNALER_CODE)
// These are cleaned up on the parent
trigger_input = add_input_port("Send", PORT_TYPE_SIGNAL)
trigger_output = add_output_port("Received", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/radio/Destroy()
freq = null
code = null
SSradio.remove_object(src, current_freq)
radio_connection = null
return ..()
/obj/item/circuit_component/radio/input_received(datum/port/input/port)
. = ..()
freq.set_input(sanitize_frequency(freq.input_value, TRUE), FALSE)
if(.)
return
var/frequency = freq.input_value
SSradio.remove_object(src, current_freq)
radio_connection = SSradio.add_object(src, frequency, RADIO_SIGNALER)
current_freq = frequency
if(COMPONENT_TRIGGERED_BY(trigger_input, port))
var/datum/signal/signal = new(list("code" = round(code.input_value) || 0))
radio_connection.post_signal(src, signal)
/obj/item/circuit_component/radio/receive_signal(datum/signal/signal)
. = FALSE
if(!signal)
return
if(signal.data["code"] != round(code.input_value || 0))
return
trigger_output.set_output(COMPONENT_SIGNAL)
@@ -0,0 +1,49 @@
/**
* # Speech Component
*
* Sends a message. Requires a shell.
*/
/obj/item/circuit_component/speech
display_name = "Speech"
/// The message to send
var/datum/port/input/message
/// The trigger to send the message
var/datum/port/input/trigger
/// The cooldown for this component of how often it can send speech messages.
var/speech_cooldown = 1 SECONDS
COOLDOWN_DECLARE(next_speech)
/obj/item/circuit_component/speech/Initialize()
. = ..()
message = add_input_port("Message", PORT_TYPE_STRING, FALSE)
trigger = add_input_port("Trigger", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/speech/Destroy()
message = null
trigger = null
return ..()
/obj/item/circuit_component/speech/input_received(datum/port/input/port)
. = ..()
if(.)
return
if(!COMPONENT_TRIGGERED_BY(trigger, port))
return
if(!COOLDOWN_FINISHED(src, next_speech))
return
if(message.input_value)
var/atom/movable/shell = parent.shell
// Prevents appear as the individual component if there is a shell.
if(shell)
shell.say(message.input_value)
else
say(message.input_value)
COOLDOWN_START(src, next_speech, speech_cooldown)