Files
Bubberstation/code/modules/wiremod/components/utility/nfc_receive.dm
Autisem fec9a5d725 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&

<img
src="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
🆑
add: A new cirucit component allows NFC communications
/🆑

---------

Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
2024-11-02 14:32:54 +01:00

81 lines
2.6 KiB
Plaintext

/**
* # 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)