mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-28 23:58:07 +01:00
Adds the bare minimum admin components and allows admins to define list literals. (#60240)
Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> Co-authored-by: carshalash <carshalash@gmail.com> Co-authored-by: tgstation-server <tgstation-server@tgstation13.org>
This commit is contained in:
co-authored by
Watermelon914
carshalash
tgstation-server
parent
cb4166c18c
commit
96f1c2abae
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* # Get Variable Component
|
||||
*
|
||||
* A component that gets a variable on an object
|
||||
*/
|
||||
/obj/item/circuit_component/get_variable
|
||||
display_name = "Get Variable"
|
||||
desc = "A component that gets a variable on an object."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// Entity to get variable of
|
||||
var/datum/port/input/entity
|
||||
|
||||
/// Variable name
|
||||
var/datum/port/input/variable_name
|
||||
|
||||
/// Variable value
|
||||
var/datum/port/output/output_value
|
||||
|
||||
|
||||
/obj/item/circuit_component/get_variable/Initialize()
|
||||
. = ..()
|
||||
entity = add_input_port("Target", PORT_TYPE_ATOM)
|
||||
variable_name = add_input_port("Variable Name", PORT_TYPE_STRING)
|
||||
|
||||
output_value = add_output_port("Output Value", PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/get_variable/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
var/atom/object = entity.input_value
|
||||
var/var_name = variable_name.input_value
|
||||
if(!var_name || !object)
|
||||
output_value.set_output(null)
|
||||
return
|
||||
|
||||
if(!object.can_vv_get(var_name) || !(var_name in object.vars))
|
||||
output_value.set_output(null)
|
||||
return
|
||||
|
||||
output_value.set_output(object.vars[var_name])
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* # Proc Call Component
|
||||
*
|
||||
* A component that calls a proc on an object and outputs the return value
|
||||
*/
|
||||
/obj/item/circuit_component/proccall
|
||||
display_name = "Proc Call"
|
||||
desc = "A component that gets a variable on an object."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// Entity to proccall on
|
||||
var/datum/port/input/entity
|
||||
|
||||
/// Proc to call
|
||||
var/datum/port/input/proc_name
|
||||
|
||||
/// Arguments
|
||||
var/datum/port/input/arguments
|
||||
|
||||
/// Returns the output from the proccall
|
||||
var/datum/port/output/output_value
|
||||
|
||||
/obj/item/circuit_component/proccall/populate_options()
|
||||
var/static/list/component_options = list(
|
||||
COMP_PROC_OBJECT,
|
||||
COMP_PROC_GLOBAL,
|
||||
)
|
||||
|
||||
options = component_options
|
||||
|
||||
/obj/item/circuit_component/proccall/Initialize()
|
||||
. = ..()
|
||||
entity = add_input_port("Target", PORT_TYPE_ATOM)
|
||||
proc_name = add_input_port("Proc Name", PORT_TYPE_STRING)
|
||||
arguments = add_input_port("Arguments", PORT_TYPE_LIST)
|
||||
|
||||
output_value = add_output_port("Output Value", PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/proccall/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/called_on
|
||||
if(current_option == COMP_PROC_OBJECT)
|
||||
called_on = entity.input_value
|
||||
else
|
||||
called_on = GLOBAL_PROC
|
||||
|
||||
if(!called_on)
|
||||
return
|
||||
|
||||
var/to_invoke = proc_name.input_value
|
||||
var/params = arguments.input_value || list()
|
||||
|
||||
if(!to_invoke)
|
||||
return
|
||||
|
||||
GLOB.AdminProcCaller = "CHAT_[parent.display_name]" //_ won't show up in ckeys so it'll never match with a real admin
|
||||
var/result = WrapAdminProcCall(called_on, to_invoke, params)
|
||||
GLOB.AdminProcCaller = null
|
||||
|
||||
output_value.set_output(result)
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* # SDQL Component
|
||||
*
|
||||
* A component that performs an sdql operation
|
||||
*/
|
||||
/obj/item/circuit_component/sdql_operation
|
||||
display_name = "SDQL Operation"
|
||||
desc = "A component that performs an SDQL operation when invoked."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// SDQL Operation to invoke
|
||||
var/datum/port/input/sdql_operation
|
||||
|
||||
var/datum/port/output/results
|
||||
|
||||
|
||||
/obj/item/circuit_component/sdql_operation/Initialize()
|
||||
. = ..()
|
||||
sdql_operation = add_input_port("SDQL String", PORT_TYPE_STRING)
|
||||
results = add_output_port("Result", PORT_TYPE_LIST)
|
||||
|
||||
/obj/item/circuit_component/sdql_operation/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/operation = sdql_operation.input_value
|
||||
|
||||
if(GLOB.AdminProcCaller || !operation)
|
||||
return TRUE
|
||||
|
||||
GLOB.AdminProcCaller = "CHAT_[parent.display_name]" //_ won't show up in ckeys so it'll never match with a real admin
|
||||
var/list/result = world.SDQL2_query(operation, parent.get_creator_admin(), parent.get_creator())
|
||||
GLOB.AdminProcCaller = null
|
||||
|
||||
results.set_output(result)
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* # Set Variable Component
|
||||
*
|
||||
* A component that sets a variable on an object
|
||||
*/
|
||||
/obj/item/circuit_component/set_variable
|
||||
display_name = "Set Variable"
|
||||
desc = "A component that sets a variable on an object."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// Entity to set variable of
|
||||
var/datum/port/input/entity
|
||||
|
||||
/// Variable name
|
||||
var/datum/port/input/variable_name
|
||||
|
||||
/// New value to set the variable name to.
|
||||
var/datum/port/input/new_value
|
||||
|
||||
|
||||
/obj/item/circuit_component/set_variable/Initialize()
|
||||
. = ..()
|
||||
entity = add_input_port("Target", PORT_TYPE_ATOM)
|
||||
variable_name = add_input_port("Variable Name", PORT_TYPE_STRING)
|
||||
new_value = add_input_port("New Value", PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/set_variable/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
var/atom/object = entity.input_value
|
||||
var/var_name = variable_name.input_value
|
||||
if(!var_name || !object)
|
||||
return
|
||||
|
||||
object.vv_edit_var(var_name, new_value.input_value)
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* # Spawn Atom Component
|
||||
*
|
||||
* Spawns an atom.
|
||||
*/
|
||||
/obj/item/circuit_component/spawn_atom
|
||||
display_name = "Spawn Atom"
|
||||
desc = "A component that returns the value of a list at a given index."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// The input path to convert into a typepath
|
||||
var/datum/port/input/input_path
|
||||
|
||||
/// The turf to spawn them at
|
||||
var/datum/port/input/spawn_at
|
||||
|
||||
/// Parameters to pass to the atom being spawned
|
||||
var/datum/port/input/parameters
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/spawned_atom
|
||||
|
||||
/obj/item/circuit_component/spawn_atom/Initialize()
|
||||
. = ..()
|
||||
input_path = add_input_port("Type", PORT_TYPE_ANY)
|
||||
spawn_at = add_input_port("Spawn At", PORT_TYPE_ATOM)
|
||||
parameters = add_input_port("Parameters", PORT_TYPE_LIST)
|
||||
|
||||
spawned_atom = add_output_port("Spawned Atom", PORT_TYPE_ATOM)
|
||||
|
||||
/obj/item/circuit_component/spawn_atom/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/typepath = input_path.input_value
|
||||
|
||||
if(!ispath(typepath, /atom))
|
||||
return
|
||||
|
||||
var/list/params = parameters.input_value
|
||||
if(!params)
|
||||
params = list()
|
||||
|
||||
params.Insert(1, spawn_at.input_value)
|
||||
|
||||
spawned_atom.set_output(new typepath(arglist(params)))
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* # To Type Component
|
||||
*
|
||||
* Converts a string into a typepath. Useful for adding components.
|
||||
*/
|
||||
/obj/item/circuit_component/to_type
|
||||
display_name = "String To Type"
|
||||
desc = "A component that returns the value of a list at a given index."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// The input path to convert into a typepath
|
||||
var/datum/port/input/input_path
|
||||
|
||||
/// The type output
|
||||
var/datum/port/output/type_output
|
||||
|
||||
/obj/item/circuit_component/to_type/Initialize()
|
||||
. = ..()
|
||||
input_path = add_input_port("Type", PORT_TYPE_STRING)
|
||||
type_output = add_output_port("Typepath", PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/to_type/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
type_output.set_output(text2path(input_path.input_value))
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* # List Literal Component
|
||||
*
|
||||
* Return a list literal.
|
||||
*/
|
||||
/obj/item/circuit_component/list_literal
|
||||
display_name = "List Literal"
|
||||
desc = "A component that returns the value of a list at a given index. Attack in hand to increase list size, right click to decrease list size."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/list_output
|
||||
|
||||
var/length = 0
|
||||
|
||||
var/default_list_size = 2
|
||||
|
||||
var/min_size = 1
|
||||
var/max_size = 20
|
||||
|
||||
/obj/item/circuit_component/list_literal/save_data_to_list(list/component_data)
|
||||
. = ..()
|
||||
component_data["length"] = length
|
||||
|
||||
/obj/item/circuit_component/list_literal/load_data_from_list(list/component_data)
|
||||
set_list_size(component_data["length"])
|
||||
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/list_literal/proc/set_list_size(new_size)
|
||||
if(new_size <= 0)
|
||||
for(var/datum/port/input/port in input_ports)
|
||||
if(port != trigger_input)
|
||||
remove_input_port(port)
|
||||
length = 0
|
||||
return
|
||||
|
||||
while(length > new_size)
|
||||
var/index = length(input_ports)
|
||||
if(trigger_input)
|
||||
index -= 1
|
||||
remove_input_port(input_ports[index])
|
||||
length--
|
||||
|
||||
while(length < new_size)
|
||||
length++
|
||||
var/index = length(input_ports)
|
||||
if(trigger_input)
|
||||
index -= 1
|
||||
add_input_port("Index [index+1]", PORT_TYPE_ANY, index = index+1)
|
||||
|
||||
/obj/item/circuit_component/list_literal/Initialize()
|
||||
. = ..()
|
||||
set_list_size(default_list_size)
|
||||
list_output = add_output_port("Value", PORT_TYPE_LIST)
|
||||
|
||||
/obj/item/circuit_component/list_literal/Destroy()
|
||||
list_output = null
|
||||
return ..()
|
||||
|
||||
// Increases list length
|
||||
/obj/item/circuit_component/list_literal/attack_self(mob/user, list/modifiers)
|
||||
. = ..()
|
||||
set_list_size(min(length + 1, max_size))
|
||||
balloon_alert(user, "new size is now [length]")
|
||||
|
||||
// Decreases list length
|
||||
/obj/item/circuit_component/list_literal/attack_self_secondary(mob/user, list/modifiers)
|
||||
. = ..()
|
||||
set_list_size(max(length - 1, min_size))
|
||||
balloon_alert(user, "new size is now [length]")
|
||||
|
||||
/obj/item/circuit_component/list_literal/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/new_literal = list()
|
||||
for(var/datum/port/input/input_port as anything in input_ports)
|
||||
// Prevents lists from merging together
|
||||
new_literal += list(input_port.input_value)
|
||||
|
||||
list_output.set_output(new_literal)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* # Typecast Component
|
||||
*
|
||||
* A component that casts a value to a type if it matches or outputs null.
|
||||
*/
|
||||
/obj/item/circuit_component/typecast
|
||||
display_name = "Typecast"
|
||||
desc = "A component that casts a value to a type if it matches or outputs null."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
var/datum/port/input/input_value
|
||||
|
||||
var/datum/port/output/output_value
|
||||
|
||||
var/current_type
|
||||
|
||||
/obj/item/circuit_component/typecast/Initialize()
|
||||
. = ..()
|
||||
current_type = current_option
|
||||
input_value = add_input_port("Input", PORT_TYPE_ANY)
|
||||
output_value = add_output_port("Output", current_option)
|
||||
|
||||
/obj/item/circuit_component/typecast/populate_options()
|
||||
var/static/component_options = list(
|
||||
PORT_TYPE_STRING,
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_LIST,
|
||||
PORT_TYPE_ATOM,
|
||||
)
|
||||
options = component_options
|
||||
|
||||
/obj/item/circuit_component/typecast/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(current_type != current_option)
|
||||
current_type = current_option
|
||||
output_value.set_datatype(current_type)
|
||||
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/value = input_value.input_value
|
||||
var/value_to_set = null
|
||||
switch(current_option)
|
||||
if(PORT_TYPE_STRING)
|
||||
if(istext(value))
|
||||
value_to_set = value
|
||||
if(PORT_TYPE_NUMBER)
|
||||
if(isnum(value))
|
||||
value_to_set = value
|
||||
if(PORT_TYPE_LIST)
|
||||
if(islist(value))
|
||||
value_to_set = value
|
||||
if(PORT_TYPE_ATOM)
|
||||
if(isatom(value))
|
||||
value_to_set = value
|
||||
|
||||
output_value.set_output(value_to_set)
|
||||
@@ -9,15 +9,6 @@
|
||||
|
||||
input_port_amount = 1
|
||||
|
||||
GLOBAL_LIST_INIT(comp_typecheck_options, list(
|
||||
PORT_TYPE_STRING,
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_LIST,
|
||||
PORT_TYPE_ATOM,
|
||||
COMP_TYPECHECK_MOB,
|
||||
COMP_TYPECHECK_HUMAN,
|
||||
))
|
||||
|
||||
/obj/item/circuit_component/compare/typecheck/populate_options()
|
||||
var/static/component_options = list(
|
||||
PORT_TYPE_STRING,
|
||||
|
||||
Reference in New Issue
Block a user