mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-15 04:01:41 +00:00
# MAINTAINER - USE THE BUTTON THAT SAYS "MERGE MASTER" THEN SET THE PR TO AUTO-MERGE! IT'S MUCH EASIER FOR ME TO FIX THINGS BEFORE THEY SKEW RATHER THAN AFTER THE FACT. ## About The Pull Request Hey there, This took a while to do, but here's the gist: Python file now regexes every file in `/code` except for those that have some valid reason to be tacking on more global defines. Some of those reasons are simply just that I don't have the time right now (doing what you see in this PR took a few hours) to refactor and parse what should belong and what should be thrown out. For the time being though, this PR will at least _halt_ people making the mistake of not `#undef`ing any files they `#define` "locally", or within the scope of a file. Most people forget to do this and this leads to a lot of mess later on due to how many variables can be unmanaged on the global level. I've made this mistake, you've made this mistake, it's a common thing. Let's automatically check for it so it can be fixed no-stress. Scenarios this PR corrects: * Forgetting to undef a define but undeffing others. * Not undeffing any defines in your file. * Earmarking a define as a "file local" define, but not defining it. * Having a define be a "file local" define, but having it be used elsewhere. * Having a "local" define not even be in the file that it only shows up in. * Having a completely unused define* (* I kept some of these because they seemed important... Others were junked.) ## Why It's Good For The Game If you wanna use it across multiple files, no reason to not make it a global define (maybe there's a few reasons but let's assume that this is the 95% case). Let me know if you don't like how I re-arranged some of the defines and how you'd rather see it be implemented, and I'd be happy to do that. This was mostly just "eh does it need it or not" sorta stuff. I used a pretty cool way to detect if we should use the standardized GitHub "error" output, you can see the results of that here https://github.com/san7890/bruhstation/actions/runs/4549766579/jobs/8022186846#step:7:792 ## Changelog Nothing that really concerns players. (I fixed up all this stuff using vscode, no regexes beyond what you see in the python script. sorry downstreams)
77 lines
2.6 KiB
Plaintext
77 lines
2.6 KiB
Plaintext
/**
|
|
* # Router Component
|
|
*
|
|
* Writes one of multiple inputs to one of multiple outputs.
|
|
*/
|
|
/obj/item/circuit_component/router
|
|
display_name = "Router"
|
|
desc = "Copies the input chosen by \"Input Selector\" to the output chosen by \"Output Selector\"."
|
|
category = "Utility"
|
|
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
|
|
|
var/datum/port/input/option/router_options
|
|
|
|
/// Which ports to connect.
|
|
var/datum/port/input/input_selector
|
|
var/datum/port/input/output_selector
|
|
|
|
/// How many ports to have.
|
|
var/input_port_amount = 4
|
|
var/output_port_amount = 4
|
|
|
|
/// Current type of the ports
|
|
var/current_type
|
|
|
|
/// The ports to route.
|
|
var/list/datum/port/input/ins
|
|
var/list/datum/port/output/outs
|
|
|
|
/obj/item/circuit_component/router/populate_options()
|
|
router_options = add_option_port("Router Options", GLOB.wiremod_basic_types)
|
|
|
|
/obj/item/circuit_component/router/populate_ports()
|
|
current_type = router_options.value
|
|
if(input_port_amount > 1)
|
|
input_selector = add_input_port("Input Selector", PORT_TYPE_NUMBER, default = 1)
|
|
if(output_port_amount > 1)
|
|
output_selector = add_input_port("Output Selector", PORT_TYPE_NUMBER, default = 1)
|
|
ins = list()
|
|
for(var/port_id in 1 to input_port_amount)
|
|
ins += add_input_port(input_port_amount > 1 ? "Input [port_id]" : "Input", current_type)
|
|
outs = list()
|
|
for(var/port_id in 1 to output_port_amount)
|
|
outs += add_output_port(output_port_amount > 1 ? "Output [port_id]" : "Output", current_type)
|
|
|
|
/obj/item/circuit_component/router/Destroy()
|
|
input_selector = null
|
|
output_selector = null
|
|
ins.Cut()
|
|
ins = null
|
|
outs.Cut()
|
|
outs = null
|
|
return ..()
|
|
|
|
|
|
// If I is in range, L[I]. If I is out of range, wrap around.
|
|
#define WRAPACCESS(L, I) L[(((I || 1)-1)%length(L)+length(L))%length(L)+1]
|
|
/obj/item/circuit_component/router/pre_input_received(datum/port/input/port)
|
|
var/current_option = router_options.value
|
|
if(current_type != current_option)
|
|
current_type = current_option
|
|
for(var/datum/port/input/input as anything in ins)
|
|
input.set_datatype(current_type)
|
|
for(var/datum/port/output/output as anything in outs)
|
|
output.set_datatype(current_type)
|
|
|
|
/obj/item/circuit_component/router/input_received(datum/port/input/port)
|
|
var/datum/port/input/input = WRAPACCESS(ins, input_selector ? input_selector.value : 1)
|
|
var/datum/port/output/output = WRAPACCESS(outs, output_selector ? output_selector.value : 1)
|
|
output.set_output(input.value)
|
|
|
|
/obj/item/circuit_component/router/multiplexer
|
|
display_name = "Multiplexer"
|
|
desc = "Copies the input chosen by \"Input Selector\" to the output."
|
|
output_port_amount = 1
|
|
|
|
#undef WRAPACCESS
|