From fec9a5d7251b09aa8f2ab185635710b1b85db070 Mon Sep 17 00:00:00 2001 From: Autisem <36102060+Autisem@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:32:54 +0100 Subject: [PATCH] Adds a new NFC component for circuits (#87286) ## About The Pull Request TODO: - [x] Main circuit code - [x] BCI compatibility - [x] Limiting range in some way(not intended as a private cross map coms system) This adds a new NFC component, its similair to NTNet component with the distinction it will only be received by the shell's circuit you target. Allowing more targeted networking for things like remotes I'd love suggestions for a max range, if any. Because im not really sure. Maby circuit has to be in vision for it to work? gif is too big so here is direct link to discord embedded gif showing it off https://cdn.discordapp.com/attachments/326831214667235328/1296810437295341649/example.gif?ex=6713a455&is=671252d5&hm=f87b282ac71c318eac03b4a53e03ebcfd91e5a0b0a1e9165beb3f87318b96809& ## Why It's Good For The Game NTNet is powerfull for making networked circuits, but I lack a good way to create a direct "remote" with complex data. I want to make a circuit that makes it easier to controll other circuits in a less strictly coupeld way and this seems like a clean way to make those ## Changelog :cl: add: A new cirucit component allows NFC communications /:cl: --------- Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> --- code/__DEFINES/dcs/signals/signals_circuit.dm | 3 + .../research/designs/wiremod_designs.dm | 10 +++ .../research/techweb/nodes/circuit_nodes.dm | 2 + .../wiremod/components/utility/nfc_receive.dm | 80 +++++++++++++++++++ .../wiremod/components/utility/nfc_send.dm | 48 +++++++++++ .../components/utility/nfc_send_literal.dm | 36 +++++++++ tgstation.dme | 3 + 7 files changed, 182 insertions(+) create mode 100644 code/modules/wiremod/components/utility/nfc_receive.dm create mode 100644 code/modules/wiremod/components/utility/nfc_send.dm create mode 100644 code/modules/wiremod/components/utility/nfc_send_literal.dm diff --git a/code/__DEFINES/dcs/signals/signals_circuit.dm b/code/__DEFINES/dcs/signals/signals_circuit.dm index 3fe4e80fdb2..08d5f675b28 100644 --- a/code/__DEFINES/dcs/signals/signals_circuit.dm +++ b/code/__DEFINES/dcs/signals/signals_circuit.dm @@ -82,6 +82,9 @@ /// Called when an equipment action component is removed from a shell (/obj/item/circuit_component/equipment_action/action_comp) #define COMSIG_CIRCUIT_ACTION_COMPONENT_UNREGISTERED "circuit_action_component_unregistered" +/// Called when an NFC sender sends data to this circuit +#define COMSIG_CIRCUIT_NFC_DATA_SENT "circuit_nfc_data_receive" + ///Sent to the shell component when a circuit is attached. #define COMSIG_SHELL_CIRCUIT_ATTACHED "shell_circuit_attached" ///Sent to the shell component when a circuit is removed. diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index e848356359d..418dec186e9 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -347,6 +347,16 @@ id = "comp_ntnet_send" build_path = /obj/item/circuit_component/ntnet_send +/datum/design/component/nfc_send + name = "NFC Transmitter" + id = "comp_nfc_send" + build_path = /obj/item/circuit_component/nfc_send + +/datum/design/component/nfc_receive + name = "NFC Receiver" + id = "comp_nfc_receive" + build_path = /obj/item/circuit_component/nfc_receive + /datum/design/component/list_literal/ntnet_send name = "NTNet Transmitter List Literal" id = "comp_ntnet_send_list_literal" diff --git a/code/modules/research/techweb/nodes/circuit_nodes.dm b/code/modules/research/techweb/nodes/circuit_nodes.dm index e654abbf4df..554e9997c04 100644 --- a/code/modules/research/techweb/nodes/circuit_nodes.dm +++ b/code/modules/research/techweb/nodes/circuit_nodes.dm @@ -59,6 +59,8 @@ "comp_ntnet_receive", "comp_ntnet_send", "comp_ntnet_send_list_literal", + "comp_nfc_send", + "comp_nfc_receive", "comp_pinpointer", "comp_pressuresensor", "comp_radio", diff --git a/code/modules/wiremod/components/utility/nfc_receive.dm b/code/modules/wiremod/components/utility/nfc_receive.dm new file mode 100644 index 00000000000..03e8d3ff2e4 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_receive.dm @@ -0,0 +1,80 @@ +/** + * # NFC Receiver Component + * + * Sends a data package through NFC directly to a shell + * if we ever get more shells like BCI's that are nested, keep in mind this may not work correctly unless adjusted + */ + + +/obj/item/circuit_component/nfc_receive + display_name = "NFC Receiver" + desc = "Receives data packages through NFC. If Encryption Key is set then only signals with the same Encryption Key will be received." + category = "Utility" + + circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL //trigger_output + + /// The list type + var/datum/port/input/option/list_options + + /// Data being received + var/datum/port/output/data_package + + /// Encryption key + var/datum/port/input/enc_key + +/obj/item/circuit_component/nfc_receive/populate_options() + list_options = add_option_port("List Type", GLOB.wiremod_basic_types) + +/obj/item/circuit_component/nfc_receive/populate_ports() + data_package = add_output_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY)) + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + +/obj/item/circuit_component/nfc_receive/register_shell(atom/movable/shell) + RegisterSignal(shell, COMSIG_CIRCUIT_NFC_DATA_SENT, PROC_REF(nfc_receive)) + RegisterSignal(shell, COMSIG_ORGAN_IMPLANTED, PROC_REF(on_organ_implanted)) + RegisterSignal(shell, COMSIG_ORGAN_REMOVED, PROC_REF(on_organ_removed)) + +/obj/item/circuit_component/nfc_receive/unregister_shell(atom/movable/shell) + UnregisterSignal(shell, list( + COMSIG_CIRCUIT_NFC_DATA_SENT, + COMSIG_ORGAN_IMPLANTED, + COMSIG_ORGAN_REMOVED, + )) + +/obj/item/circuit_component/nfc_receive/proc/on_organ_implanted(datum/source, mob/living/carbon/owner) + SIGNAL_HANDLER + + RegisterSignal(owner, COMSIG_CIRCUIT_NFC_DATA_SENT, PROC_REF(nfc_receive)) + +/obj/item/circuit_component/nfc_receive/proc/on_organ_removed(datum/source, mob/living/carbon/owner) + SIGNAL_HANDLER + + UnregisterSignal(owner, COMSIG_CIRCUIT_NFC_DATA_SENT) + + +/obj/item/circuit_component/nfc_receive/pre_input_received(datum/port/input/port) + if(port == list_options) + var/new_datatype = list_options.value + data_package.set_datatype(PORT_TYPE_LIST(new_datatype)) + + +/obj/item/circuit_component/nfc_receive/proc/nfc_receive(obj/item/circuit_component/source,obj/sender, list/data) + SIGNAL_HANDLER + + if(get_dist(sender,parent) >= 10) + return + + if(data["enc_key"] != enc_key.value) + return + + var/datum/weakref/ref = data["port"] + var/datum/port/input/port = ref?.resolve() + if(!port) + return + + var/datum/circuit_datatype/datatype_handler = data_package.datatype_handler + if(!datatype_handler?.can_receive_from_datatype(port.datatype)) + return + + data_package.set_output(data["data"]) + trigger_output.set_output(COMPONENT_SIGNAL) diff --git a/code/modules/wiremod/components/utility/nfc_send.dm b/code/modules/wiremod/components/utility/nfc_send.dm new file mode 100644 index 00000000000..437e6a4b198 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_send.dm @@ -0,0 +1,48 @@ +/** + * # NFC Transmitter Component + * + * Sends a data package through NFC + * Only the targeted shell will receive the message + */ + +/obj/item/circuit_component/nfc_send + display_name = "NFC Transmitter" + desc = "Sends a data package through NTNet. If Encryption Key is set then transmitted data will be only picked up by receivers with the same Encryption Key." + category = "Utility" + + circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL + + /// The list type + var/datum/port/input/option/list_options + + /// The targeted circuit + var/datum/port/input/target + + /// Data being sent + var/datum/port/input/data_package + + /// Encryption key + var/datum/port/input/enc_key + +/obj/item/circuit_component/nfc_send/populate_options() + list_options = add_option_port("List Type", GLOB.wiremod_basic_types) + +/obj/item/circuit_component/nfc_send/populate_ports() + data_package = add_input_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY)) + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + target = add_input_port("Target", PORT_TYPE_ATOM) + +/obj/item/circuit_component/nfc_send/should_receive_input(datum/port/input/port) + . = ..() + if(!.) + return FALSE + +/obj/item/circuit_component/nfc_send/pre_input_received(datum/port/input/port) + if(port == list_options) + var/new_datatype = list_options.value + data_package.set_datatype(PORT_TYPE_LIST(new_datatype)) + +/obj/item/circuit_component/nfc_send/input_received(datum/port/input/port) + if(isatom(target.value)) + var/atom/target_enty = target.value + SEND_SIGNAL(target_enty, COMSIG_CIRCUIT_NFC_DATA_SENT, parent, list("data" = data_package.value, "enc_key" = enc_key.value, "port" = WEAKREF(data_package))) diff --git a/code/modules/wiremod/components/utility/nfc_send_literal.dm b/code/modules/wiremod/components/utility/nfc_send_literal.dm new file mode 100644 index 00000000000..c56104ebeb0 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_send_literal.dm @@ -0,0 +1,36 @@ +/** + * # NFC Transmitter List Literal Component + * + * Create a list literal and send a data package through NFC + * + * This file is based off of nfc_sendl.dm + * Any changes made to those files should be copied over with discretion + */ +/obj/item/circuit_component/list_literal/nfc_send + display_name = "NFC Transmitter List Literal" + desc = "Creates a list literal data package and sends it through NFC. If Encryption Key is set then transmitted data will be only picked up by receivers with the same Encryption Key." + category = "Utility" + + /// Encryption key + var/datum/port/input/enc_key + + /// The targeted circuit + var/datum/port/input/target + +/obj/item/circuit_component/list_literal/nfc_send/populate_ports() + . = ..() + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + target = add_input_port("Target", PORT_TYPE_ATOM) + +/obj/item/circuit_component/list_literal/nfc_send/should_receive_input(datum/port/input/port) + . = ..() + if(!.) + return FALSE + /// If the server is down, don't use power or attempt to send data + return find_functional_ntnet_relay() + +/obj/item/circuit_component/list_literal/nfc_send/input_received(datum/port/input/port) + . = ..() + if(isatom(target.value)) + var/atom/target_enty = target.value + SEND_SIGNAL(target_enty, COMSIG_CIRCUIT_NFC_DATA_SENT, list("data" = list_output.value, "enc_key" = enc_key.value, "port" = WEAKREF(list_output))) diff --git a/tgstation.dme b/tgstation.dme index aa62e44aa74..2fcc53ac455 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -6407,6 +6407,9 @@ #include "code\modules\wiremod\components\table\select.dm" #include "code\modules\wiremod\components\utility\clock.dm" #include "code\modules\wiremod\components\utility\delay.dm" +#include "code\modules\wiremod\components\utility\nfc_receive.dm" +#include "code\modules\wiremod\components\utility\nfc_send.dm" +#include "code\modules\wiremod\components\utility\nfc_send_literal.dm" #include "code\modules\wiremod\components\utility\router.dm" #include "code\modules\wiremod\components\utility\timepiece.dm" #include "code\modules\wiremod\components\utility\typecast.dm"