mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
[MIRROR] Fixes the foreach and filter circuit component [MDB IGNORE] (#9469)
* Fixes the foreach and filter circuit component (#62798) Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com> * Fixes the foreach and filter circuit component Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
This commit is contained in:
co-authored by
Watermelon914
Watermelon914
parent
97d1558209
commit
241d22ec4b
@@ -65,19 +65,18 @@
|
||||
|
||||
/obj/item/circuit_component/filter_list/input_received(datum/port/input/port)
|
||||
var/index = 1
|
||||
var/start_tick_usage = TICK_USAGE
|
||||
var/list/filtered_list = list()
|
||||
for(var/element_in_list in list_to_filter.value)
|
||||
if(index > limit && !parent.admin_only)
|
||||
break
|
||||
SScircuit_component.queue_instant_run(start_tick_usage)
|
||||
SScircuit_component.queue_instant_run()
|
||||
element.set_output(element_in_list)
|
||||
current_index.set_output(index)
|
||||
on_next_index.set_output(COMPONENT_SIGNAL)
|
||||
index += 1
|
||||
var/list/result = SScircuit_component.execute_instant_run()
|
||||
if(!result)
|
||||
visible_message("[src] starts to overheat!")
|
||||
balloon_alert_to_viewers("[src] starts to overheat!")
|
||||
on_failed.set_output(COMPONENT_SIGNAL)
|
||||
return
|
||||
if(result["accept_entry"])
|
||||
|
||||
@@ -7,13 +7,16 @@
|
||||
display_name = "For Each"
|
||||
desc = "A component that loops through each element in a list."
|
||||
category = "List"
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
|
||||
|
||||
/// The list type
|
||||
var/datum/port/input/option/list_options
|
||||
|
||||
/// The list to iterate over
|
||||
var/datum/port/input/list_to_iterate
|
||||
/// Move to the next index
|
||||
var/datum/port/input/next_index
|
||||
/// Resets the index to 0
|
||||
var/datum/port/input/reset_index
|
||||
|
||||
/// The current element from the list
|
||||
var/datum/port/output/element
|
||||
@@ -24,8 +27,8 @@
|
||||
/// A signal that is sent when the list has finished iterating
|
||||
var/datum/port/output/on_finished
|
||||
|
||||
/// The limit of iterations before it breaks. Used to prevent from someone iterating a massive list constantly
|
||||
var/limit = 300
|
||||
var/current_actual_index = 1
|
||||
|
||||
|
||||
/obj/item/circuit_component/foreach/populate_options()
|
||||
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
|
||||
@@ -38,19 +41,29 @@
|
||||
|
||||
/obj/item/circuit_component/foreach/populate_ports()
|
||||
list_to_iterate = add_input_port("List Input", PORT_TYPE_LIST(PORT_TYPE_ANY))
|
||||
next_index = add_input_port("Next Index", PORT_TYPE_SIGNAL, trigger = .proc/trigger_next_index)
|
||||
reset_index = add_input_port("Reset And Trigger", PORT_TYPE_SIGNAL, trigger = .proc/restart)
|
||||
|
||||
element = add_output_port("Element", PORT_TYPE_ANY)
|
||||
current_index = add_output_port("Index", PORT_TYPE_NUMBER)
|
||||
on_next_index = add_output_port("Next Index", PORT_TYPE_SIGNAL)
|
||||
on_finished = add_output_port("On Finished", PORT_TYPE_SIGNAL)
|
||||
|
||||
/obj/item/circuit_component/foreach/input_received(datum/port/input/port)
|
||||
var/index = 1
|
||||
for(var/element_in_list in list_to_iterate.value)
|
||||
if(index > limit && !parent.admin_only)
|
||||
break
|
||||
element.set_output(element_in_list)
|
||||
current_index.set_output(index)
|
||||
on_next_index.set_output(COMPONENT_SIGNAL)
|
||||
index += 1
|
||||
on_finished.set_output(COMPONENT_SIGNAL)
|
||||
/obj/item/circuit_component/foreach/proc/restart(datum/port/input/port)
|
||||
CIRCUIT_TRIGGER
|
||||
current_actual_index = 1
|
||||
trigger_next_index(port)
|
||||
|
||||
/obj/item/circuit_component/foreach/proc/trigger_next_index(datum/port/input/port)
|
||||
CIRCUIT_TRIGGER
|
||||
|
||||
var/list/to_check = list_to_iterate.value
|
||||
if(!to_check)
|
||||
return
|
||||
if(current_actual_index > length(to_check))
|
||||
on_finished.set_output(COMPONENT_SIGNAL)
|
||||
return
|
||||
element.set_output(to_check[current_actual_index])
|
||||
current_index.set_output(current_actual_index)
|
||||
on_next_index.set_output(COMPONENT_SIGNAL)
|
||||
current_actual_index += 1
|
||||
|
||||
@@ -21,5 +21,4 @@
|
||||
output = add_output_port("Output", PORT_TYPE_NUMBER)
|
||||
|
||||
/obj/item/circuit_component/tonumber/input_received(datum/port/input/port)
|
||||
|
||||
output.set_output(text2num(input_port.value))
|
||||
|
||||
Reference in New Issue
Block a user