mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-06-23 15:14:43 +01:00
38c8884d3c
## About The Pull Request A substantial number of number circuit ports, input and output alike, effectively act as boolean flags. That is, they are either input ports that only care about whether the value is or is not zero, or they are output ports that can only output zero or one. This PR adds a boolean datatype, and converts all these ports to booleans. Anything can be connected to a boolean input port, effectively setting the port to the truthiness of the input. Booleans can be connected to number and signal ports, as they all use numbers as their underlying values. ## Why It's Good For The Game Having a proper boolean datatype makes the affected ports a bit more intuitive to compute with. ## Changelog 🆑 qol: Many circuit components have had ports that effectively act as boolean inputs or outputs converted into a new boolean datatype. /🆑 --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
/**
|
|
* # Toggle Component
|
|
*
|
|
* Does a toggle between true and false on trigger
|
|
*/
|
|
/obj/item/circuit_component/compare/toggle
|
|
display_name = "Toggle"
|
|
desc = "A component that toggles between on and off when triggered. All input ports (except for set toggle) will trigger the component."
|
|
category = "Math"
|
|
|
|
/// A signal to reset the toggle back to 0
|
|
var/datum/port/input/toggle_set
|
|
/// A signal to toggle and return the current state
|
|
var/datum/port/input/toggle_and_compare
|
|
|
|
var/toggle_state = FALSE
|
|
|
|
/obj/item/circuit_component/compare/toggle/populate_custom_ports()
|
|
toggle_set = add_input_port("Set Toggle State", PORT_TYPE_BOOLEAN)
|
|
toggle_and_compare = add_input_port("Toggle And Compare", PORT_TYPE_SIGNAL)
|
|
toggle_state = FALSE
|
|
|
|
/obj/item/circuit_component/compare/toggle/input_received(datum/port/input/port)
|
|
if(port == toggle_set)
|
|
toggle_state = !!port.value
|
|
return
|
|
if(COMPONENT_TRIGGERED_BY(toggle_and_compare, port))
|
|
toggle_state = !toggle_state
|
|
if(toggle_state)
|
|
true.set_output(COMPONENT_SIGNAL)
|
|
else
|
|
false.set_output(COMPONENT_SIGNAL)
|
|
return ..()
|
|
|
|
/obj/item/circuit_component/compare/toggle/do_comparisons()
|
|
return toggle_state
|