[MIRROR] Improves proccall admin circuit component. Adds the option to not resolve weakrefs for set variables and proccall admin circuit components. [MDB IGNORE] (#11471)

* Improves proccall admin circuit component. Adds the option to not resolve weakrefs for set variables and proccall admin circuit components. (#64564)

* Improves proccall admin circuit function

* Improves proccall admin circuit component. Adds the option to not resolve weakrefs for set variables and proccall admin circuit components.

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
This commit is contained in:
SkyratBot
2022-02-12 21:10:10 +00:00
committed by GitHub
co-authored by Watermelon914
parent 5163ba307b
commit fa4a85b41a
3 changed files with 276 additions and 17 deletions
+123 -16
View File
@@ -15,21 +15,36 @@
var/datum/port/input/option/proccall_options
/// Expected type of output
var/datum/port/input/option/expected_output_type
/// Entity to proccall on
var/datum/port/input/entity
/// Proc to call
var/datum/port/input/proc_name
/// Arguments
var/datum/port/input/arguments
/// A list of arguments
var/list/datum/port/input/arguments = list()
/// Returns the output from the proccall
var/datum/port/output/output_value
/// Whether we resolve all the weakrefs passed as arguments
var/resolve_weakref = TRUE
ui_buttons = list(
"cog" = "configure",
)
/obj/item/circuit_component/proccall/ui_perform_action(mob/user, action)
if(action == "configure")
interact(user)
/obj/item/circuit_component/proccall/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ProcCallMenu", "ProcCall Configuration Menu")
ui.open()
ui.set_autoupdate(FALSE)
/obj/item/circuit_component/proccall/populate_options()
var/static/list/component_options = list(
COMP_PROC_OBJECT,
@@ -38,19 +53,107 @@
proccall_options = add_option_port("Proccall Options", component_options)
expected_output_type = add_option_port("Expected Output Type", GLOB.wiremod_fundamental_types)
/obj/item/circuit_component/proccall/populate_ports()
entity = add_input_port("Target", PORT_TYPE_DATUM)
entity = add_input_port("Target", PORT_TYPE_DATUM, order = 0.5)
proc_name = add_input_port("Proc Name", PORT_TYPE_STRING)
arguments = add_input_port("Arguments", PORT_TYPE_LIST(PORT_TYPE_ANY))
output_value = add_output_port("Output Value", PORT_TYPE_ANY)
/obj/item/circuit_component/proccall/pre_input_received(datum/port/input/port)
if(port == expected_output_type)
if(output_value.datatype != expected_output_type.value)
output_value.set_datatype(expected_output_type.value)
if(proccall_options.value == COMP_PROC_GLOBAL)
if(entity)
remove_input_port(entity)
entity = null
else
if(!entity)
entity = add_input_port("Target", PORT_TYPE_DATUM, order = 0.5)
/obj/item/circuit_component/proccall/ui_data(mob/user)
. = list()
var/list/input_ports = list()
for(var/datum/port/input/port as anything in arguments)
input_ports += list(list(
"name" = port.name,
"color" = port.color,
"datatype" = port.datatype,
))
.["input_ports"] = input_ports
.["expected_output"] = output_value.datatype
.["expected_output_color"] = output_value.color
.["resolve_weakref"] = resolve_weakref
/obj/item/circuit_component/proccall/ui_static_data(mob/user)
. = list()
.["possible_types"] = GLOB.wiremod_fundamental_types
/obj/item/circuit_component/proccall/ui_status(mob/user)
if(!check_rights_for(user.client, R_VAREDIT))
return UI_CLOSE
return UI_INTERACTIVE
/obj/item/circuit_component/proccall/save_data_to_list(list/component_data)
. = ..()
var/list/input_ports = list()
for(var/datum/port/input/port as anything in arguments)
input_ports += list(list(
"name" = port.name,
"datatype" = port.datatype,
))
component_data["input_ports"] = input_ports
component_data["expected_output_type"] = output_value.datatype
component_data["resolve_weakref"] = resolve_weakref
/obj/item/circuit_component/proccall/load_data_from_list(list/component_data)
if(component_data["resolve_weakref"] != null)
resolve_weakref = component_data["resolve_weakref"]
if(component_data["expected_output_type"])
output_value.set_datatype(component_data["expected_output_type"])
for(var/list/data as anything in component_data["input_ports"])
arguments += add_input_port(data["name"], data["datatype"])
return ..()
/obj/item/circuit_component/proccall/ui_act(action, list/params)
. = ..()
if(.)
return
. = TRUE
switch(action)
if("set_expected_output")
var/new_type = params["datatype"]
if(!(new_type in GLOB.wiremod_fundamental_types))
return
output_value.set_datatype(new_type)
if("resolve_weakref")
resolve_weakref = !resolve_weakref
if("add_argument")
arguments += add_input_port("Port [length(arguments)]", PORT_TYPE_ANY)
if("remove_argument")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
remove_input_port(arguments[index])
arguments.Splice(index, index+1)
if("rename_argument")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
var/datum/port/input/argument = arguments[index]
argument.name = trim(copytext(params["name"], 1, PORT_MAX_NAME_LENGTH))
SStgui.update_uis(parent)
if("set_argument_datatype")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
var/datum/port/input/argument = arguments[index]
var/new_type = params["datatype"]
if(!(new_type in GLOB.wiremod_fundamental_types))
return
argument.set_datatype(new_type)
/obj/item/circuit_component/proccall/input_received(datum/port/input/port)
var/called_on
@@ -63,7 +166,9 @@
return
var/to_invoke = proc_name.value
var/list/params = arguments.value || list()
var/list/params = list()
for(var/datum/port/input/argument_port as anything in arguments)
params += list(argument_port.value)
if(!to_invoke)
return
@@ -71,9 +176,11 @@
if(called_on != GLOBAL_PROC && !hascall(called_on, to_invoke))
return
var/list/resolved_params = recursive_list_resolve(params)
log_admin_circuit("[parent.get_creator()] proccalled '[to_invoke]' on [called_on] with params \[[resolved_params.Join(", ")]].")
INVOKE_ASYNC(src, .proc/do_proccall, called_on, to_invoke, resolved_params)
if(resolve_weakref)
params = recursive_list_resolve(params)
log_admin_circuit("[parent.get_creator()] proccalled '[to_invoke]' on [called_on] with params \[[params.Join(", ")]].")
INVOKE_ASYNC(src, .proc/do_proccall, called_on, to_invoke, params)
/obj/item/circuit_component/proccall/proc/do_proccall(called_on, to_invoke, params)
var/result = HandleUserlessProcCall(parent.get_creator(), called_on, to_invoke, params)
@@ -9,6 +9,9 @@
category = "Admin"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
/// Whether to resolve weakrefs or not
var/datum/port/input/resolve_weakrefs
/// Entity to set variable of
var/datum/port/input/entity
@@ -20,6 +23,7 @@
/obj/item/circuit_component/set_variable/populate_ports()
resolve_weakrefs = add_input_port("Resolve Weakrefs", PORT_TYPE_NUMBER, default = TRUE)
entity = add_input_port("Target", PORT_TYPE_DATUM)
variable_name = add_input_port("Variable Name", PORT_TYPE_STRING)
new_value = add_input_port("New Value", PORT_TYPE_ANY)
@@ -31,7 +35,7 @@
return
var/resolved_new_value = new_value.value
if(islist(resolved_new_value))
if(islist(resolved_new_value) && resolve_weakrefs.value)
var/list/to_resolve = resolved_new_value
resolved_new_value = recursive_list_resolve(to_resolve)
@@ -0,0 +1,148 @@
import { BooleanLike } from "common/react";
import { useBackend } from "../backend";
import { Stack, Section, Input, Button, Dropdown, NoticeBox } from "../components";
import { Window } from "../layouts";
type Port = {
name: string,
color: string,
datatype: string,
}
type ProcCallMenuData = {
input_ports: Port[],
possible_types: string[],
expected_output: string,
expected_output_color: string,
resolve_weakref: BooleanLike,
}
export const ProcCallMenu = (props, context) => {
const { act, data } = useBackend<ProcCallMenuData>(context);
const {
input_ports,
possible_types,
expected_output,
expected_output_color,
resolve_weakref,
} = data;
return (
<Window width={500} height={400}>
<Window.Content scrollable>
<Stack grow height="100%">
<Stack.Item>
<Section fill title="Options">
<Stack vertical width="180px">
<Stack.Item color="label">
Expected Output:
</Stack.Item>
<Stack.Item>
<Dropdown width="100%"
displayText={expected_output}
options={possible_types}
color={expected_output_color}
onSelected={(value) => act("set_expected_output", { datatype: value })}
/>
</Stack.Item>
<Stack.Divider />
<Stack.Item>
<Button.Checkbox
content="Resolve Weakref"
textAlign="center"
checked={resolve_weakref}
onClick={() => act("resolve_weakref")}
fluid
/>
</Stack.Item>
<Stack.Item>
<NoticeBox info width="100%">
This determines whether we automatically resolve any
weakrefs in lists.
</NoticeBox>
</Stack.Item>
</Stack>
</Section>
</Stack.Item>
<Stack.Item grow>
<Section fill title="Arguments">
<Stack vertical>
{input_ports.map((val, index) => (
<PortEntry
key={index}
name={val.name}
color={val.color}
datatype={val.datatype}
datatypeOptions={possible_types}
onRemove={() => act("remove_argument", {
index: index+1,
})}
onSetType={type => act("set_argument_datatype", {
index: index+1,
datatype: type,
})}
onEnter={(e, value) => act("rename_argument", {
index: index+1,
name: value,
})}
/>
))}
<Stack.Item>
<Button
fluid
content="Add Argument"
color="good"
icon="plus"
onClick={() => act("add_argument")}
/>
</Stack.Item>
</Stack>
</Section>
</Stack.Item>
</Stack>
</Window.Content>
</Window>
);
};
const PortEntry = (props, context) => {
const {
onRemove,
onEnter,
onSetType,
name,
datatype,
datatypeOptions = [],
color,
...rest
} = props;
return (
<Stack.Item {...rest}>
<Stack>
<Stack.Item grow>
<Input
placeholder="Name"
value={name}
onChange={onEnter}
fluid
/>
</Stack.Item>
<Stack.Item>
<Dropdown
displayText={datatype}
options={datatypeOptions}
onSelected={onSetType}
color={color}
/>
</Stack.Item>
<Stack.Item>
<Button
icon="times"
color="red"
onClick={onRemove}
/>
</Stack.Item>
</Stack>
</Stack.Item>
);
};