[MIRROR] Adds a user type to integrated circuits, refactors the list pick component. [MDB IGNORE] (#24827)

* Adds a user type to integrated circuits, refactors the list pick component. (#79412)

## About The Pull Request
Added a user type to integrated circuits that can't be stored as a user
type but can be typecasted to entity. Useful for components that
directly ask for an input from the user, like the list pick component.

Refactored the list pick component to use this user port and to also
send failure signals whenever a success signal is not sent.
Removed the triggered port for the list pick component.

Also fixes a runtime that occurs with the list pick component if the
list passed in only contains null values.

## Why It's Good For The Game
Can't force a prompt onto people who haven't interacted with your
circuit.

## Changelog
🆑
add: Added a user type to integrated circuits
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* Adds a user type to integrated circuits, refactors the list pick 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:
SkyratBot
2023-11-06 21:21:54 -05:00
committed by GitHub
co-authored by Watermelon914 Watermelon914
parent c8ff874784
commit 2b5cfd484f
17 changed files with 71 additions and 57 deletions
@@ -15,7 +15,6 @@
/obj/item/circuit_component/list_pick/assoc/make_list_port()
input_list = add_input_port("List", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
/obj/item/circuit_component/list_pick/assoc/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
@@ -38,15 +38,6 @@
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/assoc_literal/populate_ports()
AddComponent(/datum/component/circuit_component_add_port, \
port_list = entry_ports, \
add_action = "add", \
remove_action = "remove", \
port_type = PORT_TYPE_ANY, \
prefix = "Index", \
minimum_amount = 1, \
maximum_amount = 20 \
)
AddComponent(/datum/component/circuit_component_add_port, \
port_list = key_ports, \
add_action = "add", \
@@ -56,6 +47,15 @@
minimum_amount = 1, \
maximum_amount = 20 \
)
AddComponent(/datum/component/circuit_component_add_port, \
port_list = entry_ports, \
add_action = "add", \
remove_action = "remove", \
port_type = PORT_TYPE_ANY, \
prefix = "Value", \
minimum_amount = 1, \
maximum_amount = 20 \
)
list_output = add_output_port("Value", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY), order = 1.1)
/obj/item/circuit_component/assoc_literal/input_received(datum/port/input/port)
@@ -27,39 +27,24 @@
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
var/index_type = PORT_TYPE_NUMBER
/obj/item/circuit_component/list_pick/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/list_pick/proc/make_list_port()
input_list = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_ANY))
input_list = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_STRING))
/obj/item/circuit_component/list_pick/populate_ports()
input_name = add_input_port("Input Name", PORT_TYPE_STRING)
user = add_input_port("User", PORT_TYPE_ATOM)
user = add_input_port("User", PORT_TYPE_USER)
make_list_port()
output = add_output_port("Picked Item", PORT_TYPE_NUMBER)
trigger_output = add_output_port("Triggered", PORT_TYPE_SIGNAL)
output = add_output_port("Picked Item", PORT_TYPE_STRING)
failure = add_output_port("On Failure", PORT_TYPE_SIGNAL)
success = add_output_port("On Succes", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/list_pick/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
input_list.set_datatype(PORT_TYPE_LIST(new_type))
output.set_datatype(new_type)
success = add_output_port("On Success", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/list_pick/input_received(datum/port/input/port)
if(parent.Adjacent(user.value))
var/mob/mob_user = user.value
if(!ismob(mob_user) || HAS_TRAIT_FROM(parent, TRAIT_CIRCUIT_UI_OPEN, REF(mob_user)))
failure.set_output(COMPONENT_SIGNAL)
return
if(ismob(user.value))
trigger_output.set_output(COMPONENT_SIGNAL)
INVOKE_ASYNC(src, PROC_REF(show_list), user.value, input_name.value, input_list.value)
INVOKE_ASYNC(src, PROC_REF(show_list), mob_user, input_name.value, input_list.value)
/// Show a list of options to the user using standed TGUI input list
/obj/item/circuit_component/list_pick/proc/show_list(mob/user, message, list/showed_list)
@@ -68,10 +53,17 @@
return
if(!message)
message = "circuit input"
if(!(user.can_perform_action(src, FORBID_TELEKINESIS_REACH)))
if(!(user.can_perform_action(parent.shell, FORBID_TELEKINESIS_REACH|ALLOW_SILICON_REACH|ALLOW_RESTING)))
failure.set_output(COMPONENT_SIGNAL)
return
var/user_ref = REF(user)
ADD_TRAIT(parent, TRAIT_CIRCUIT_UI_OPEN, user_ref)
var/picked = tgui_input_list(user, message = message, items = showed_list)
if(!(user.can_perform_action(src, FORBID_TELEKINESIS_REACH)))
REMOVE_TRAIT(parent, TRAIT_CIRCUIT_UI_OPEN, user_ref)
if(QDELETED(src))
return
if(!(user.can_perform_action(parent.shell, FORBID_TELEKINESIS_REACH|ALLOW_SILICON_REACH|ALLOW_RESTING)))
failure.set_output(COMPONENT_SIGNAL)
return
choose_item(picked, showed_list)
+1
View File
@@ -4,6 +4,7 @@
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT|DATATYPE_FLAG_ALLOW_ATOM_INPUT
can_receive_from = list(
PORT_TYPE_ATOM,
PORT_TYPE_USER
)
/datum/circuit_datatype/datum/convert_value(datum/port/port, value_to_convert)
+3
View File
@@ -2,6 +2,9 @@
datatype = PORT_TYPE_ATOM
color = "purple"
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT|DATATYPE_FLAG_ALLOW_ATOM_INPUT
can_receive_from = list(
PORT_TYPE_USER,
)
/datum/circuit_datatype/entity/convert_value(datum/port/port, value_to_convert)
var/atom/object = value_to_convert
+9
View File
@@ -0,0 +1,9 @@
/datum/circuit_datatype/user
datatype = PORT_TYPE_USER
color = "label"
/datum/circuit_datatype/user/convert_value(datum/port/port, value_to_convert)
var/datum/object = value_to_convert
if(QDELETED(object))
return null
return object
+1 -2
View File
@@ -31,7 +31,7 @@
var/datum/port/output/entity
/obj/item/circuit_component/bot/populate_ports()
entity = add_output_port("User", PORT_TYPE_ATOM)
entity = add_output_port("User", PORT_TYPE_USER)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/bot/register_shell(atom/movable/shell)
@@ -46,4 +46,3 @@
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
signal.set_output(COMPONENT_SIGNAL)
@@ -114,7 +114,7 @@
send_message_signal = add_input_port("Send Message", PORT_TYPE_SIGNAL)
show_charge_meter = add_input_port("Show Charge Meter", PORT_TYPE_NUMBER, trigger = PROC_REF(update_charge_action))
user_port = add_output_port("User", PORT_TYPE_ATOM)
user_port = add_output_port("User", PORT_TYPE_USER)
/obj/item/circuit_component/bci_core/Destroy()
QDEL_NULL(charge_action)
+11 -13
View File
@@ -34,7 +34,7 @@
var/datum/port/output/entity
/obj/item/circuit_component/controller/populate_ports()
entity = add_output_port("User", PORT_TYPE_ATOM)
entity = add_output_port("User", PORT_TYPE_USER)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)
alt = add_output_port("Alternate Signal", PORT_TYPE_SIGNAL)
right = add_output_port("Extra Signal", PORT_TYPE_SIGNAL)
@@ -51,6 +51,12 @@
COMSIG_CLICK_ALT,
))
/obj/item/circuit_component/controller/proc/handle_trigger(atom/source, user, port_name, datum/port/output/port_signal)
source.balloon_alert(user, "clicked [port_name] button")
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
port_signal.set_output(COMPONENT_SIGNAL)
/**
* Called when the shell item is used in hand
*/
@@ -58,10 +64,7 @@
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked primary button")
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
signal.set_output(COMPONENT_SIGNAL)
handle_trigger(source, user, "primary", signal)
/**
* Called when the shell item is alt-clicked
@@ -70,10 +73,8 @@
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked alternate button")
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
alt.set_output(COMPONENT_SIGNAL)
handle_trigger(source, user, "alternate", alt)
/**
* Called when the shell item is right-clicked in active hand
@@ -82,7 +83,4 @@
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked extra button")
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
right.set_output(COMPONENT_SIGNAL)
handle_trigger(source, user, "extra", right)
+1 -2
View File
@@ -27,7 +27,7 @@
var/datum/port/output/output
/obj/item/circuit_component/keyboard_shell/populate_ports()
entity = add_output_port("User", PORT_TYPE_ATOM)
entity = add_output_port("User", PORT_TYPE_USER)
output = add_output_port("Message", PORT_TYPE_STRING)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)
@@ -53,4 +53,3 @@
output.set_output(message)
signal.set_output(COMPONENT_SIGNAL)
+1 -1
View File
@@ -123,7 +123,7 @@
toggle_suit = add_input_port("Toggle Suit", PORT_TYPE_SIGNAL)
select_module = add_input_port("Select Module", PORT_TYPE_SIGNAL)
// States
wearer = add_output_port("Wearer", PORT_TYPE_ATOM)
wearer = add_output_port("Wearer", PORT_TYPE_USER)
deployed = add_output_port("Deployed", PORT_TYPE_NUMBER)
activated = add_output_port("Activated", PORT_TYPE_NUMBER)
selected_module = add_output_port("Selected Module", PORT_TYPE_STRING)
+1 -1
View File
@@ -95,7 +95,7 @@
/obj/item/circuit_component/money_bot/populate_ports()
total_money = add_output_port("Total Money", PORT_TYPE_NUMBER)
money_input = add_output_port("Last Input Money", PORT_TYPE_NUMBER)
entity = add_output_port("User", PORT_TYPE_ATOM)
entity = add_output_port("User", PORT_TYPE_USER)
money_trigger = add_output_port("Money Input", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/money_bot/register_shell(atom/movable/shell)