Files
Bubberstation/code/modules/wiremod/components/list/index_table.dm
SkyratBot 5df645a0f0 [MIRROR] Adds clarity to the associative list data type in wiremod [MDB IGNORE] (#19498)
* Adds clarity to the associative list data type in wiremod (#73536)

## About The Pull Request

Once pulled, these changes will adjust how the associative list data
type is shown like on circuits and the description of the index table
component.

![assoclists1](https://user-images.githubusercontent.com/72105993/219969642-e9d76aa7-4f8e-40e5-a864-ae473b78c34e.png)

![assoclists2](https://user-images.githubusercontent.com/72105993/219969644-00b570ea-0c43-4190-9eb9-c8ac97bd1522.png)
## Why It's Good For The Game

Given the entry difficulty level of the circuits system, some players
may find themselves overwhelmed and frustrated seeing that their index
table component's output is not connecting to the index list component's
input, despite there being an index associative list component they may
not be aware of. These changes should hopefully lead players to learn
more about associative lists and how different they are from normal
lists. Just adding "assoc." to the descriptor should lead players to
search the term in the component printer and find the index associative
table.
## Changelog
🆑
qol: Made associative lists more apparent in circuits.
/🆑

* Adds clarity to the associative list data type in wiremod

---------

Co-authored-by: CesarBaylina <72105993+CesarBaylina@users.noreply.github.com>
2023-02-22 14:40:14 -08:00

40 lines
1.3 KiB
Plaintext

/**
* # Index Table Component
*
* Gets the row of a table as an associative list using the index inputted. Will return no value if the index is invalid or a proper table is not returned.
*/
/obj/item/circuit_component/index_table
display_name = "Index Table"
desc = "Gets the row of a table as an associative list using the index inputted. Will return no value if the index is invalid or a proper table is not returned."
category = "List"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The list to perform the filter on
var/datum/port/input/received_table
/// The target index
var/datum/port/input/target_index
/// The filtered list
var/datum/port/output/output_list
/obj/item/circuit_component/index_table/populate_ports()
received_table = add_input_port("Input", PORT_TYPE_TABLE)
target_index = add_input_port("Index", PORT_TYPE_NUMBER)
output_list = add_output_port("Output", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
/obj/item/circuit_component/index_table/input_received(datum/port/input/port)
var/list/target_list = received_table.value
if(!islist(target_list) || !length(target_list))
output_list.set_output(null)
return
var/index = target_index.value
if(index < 1 || index > length(target_list))
output_list.set_output(null)
return
output_list.set_output(target_list[index])