mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 22:19:30 +01:00
Fixed animating filters with circuits and added special signal ports for instant circuit execution. (#61851)
Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
This commit is contained in:
co-authored by
Watermelon914
parent
6cc7382e9a
commit
f6dfff674f
@@ -6,16 +6,51 @@
|
||||
desc = "Begins an animation on the target. Create animation steps by chaining \"Animation Step\" components off of the \"Perform Animation\" port."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_INSTANT|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
/// Whether we are animating an atom or a filter on the atom
|
||||
var/datum/port/input/option/atom_or_filter
|
||||
|
||||
/// The filter to animate
|
||||
var/datum/port/input/filter_target
|
||||
/// The target to animate
|
||||
var/datum/port/input/target
|
||||
|
||||
/// The amount of times this animation will loop
|
||||
var/datum/port/input/animation_loops
|
||||
|
||||
/// Used to determine if the animation runs in parallel or not.
|
||||
var/datum/port/input/parallel
|
||||
/// Called to stop all animations on this object
|
||||
var/datum/port/input/stop_all_animations
|
||||
/// Called when performing the animation.
|
||||
var/datum/port/output/animate_event
|
||||
|
||||
/obj/item/circuit_component/begin_animation/populate_options()
|
||||
var/static/list/component_options = list(
|
||||
COMP_ANIMATE_ATOM,
|
||||
COMP_ANIMATE_FILTER,
|
||||
)
|
||||
|
||||
atom_or_filter = add_option_port("Target Options", component_options)
|
||||
|
||||
/obj/item/circuit_component/begin_animation/populate_ports()
|
||||
target = add_input_port("Target", PORT_TYPE_ATOM)
|
||||
parallel = add_input_port("Parallel", PORT_TYPE_NUMBER, default = 1)
|
||||
animation_loops = add_input_port("Loops", PORT_TYPE_NUMBER)
|
||||
animate_event = add_output_port("Perform Animation", PORT_TYPE_SIGNAL)
|
||||
stop_all_animations = add_input_port("Stop All Animations", PORT_TYPE_SIGNAL, trigger = .proc/stop_animations)
|
||||
animate_event = add_output_port("Perform Animation", PORT_TYPE_INSTANT_SIGNAL)
|
||||
|
||||
/obj/item/circuit_component/begin_animation/pre_input_received(datum/port/input/port)
|
||||
if(port == atom_or_filter)
|
||||
if(filter_target)
|
||||
remove_input_port(filter_target)
|
||||
filter_target = null
|
||||
|
||||
if(atom_or_filter.value == COMP_ANIMATE_FILTER)
|
||||
filter_target = add_input_port("Filter Name", PORT_TYPE_STRING, order = 0.5)
|
||||
|
||||
/obj/item/circuit_component/begin_animation/proc/stop_animations(datum/port/input/port)
|
||||
CIRCUIT_TRIGGER
|
||||
if(!target.value)
|
||||
return
|
||||
animate(target.value, null)
|
||||
|
||||
/obj/item/circuit_component/begin_animation/input_received(datum/port/input/port, list/return_values)
|
||||
if(!target.value)
|
||||
@@ -25,29 +60,30 @@
|
||||
animate_event.set_output(COMPONENT_SIGNAL)
|
||||
var/list/result = SScircuit_component.execute_instant_run()
|
||||
|
||||
if(!result)
|
||||
if(!result || !result["animation_steps"])
|
||||
return
|
||||
|
||||
var/atom/target_atom = target.value
|
||||
var/last_step_used_filter = FALSE
|
||||
if(result["animation_steps"])
|
||||
animate(target_atom, pixel_x = pixel_x, time = 0, loop = animation_loops.value, flags = ANIMATION_PARALLEL) //Just to start the animation
|
||||
for(var/list/step in result["animation_steps"])
|
||||
if(step["filter"])
|
||||
var/filter = target_atom.get_filter(step["filter"])
|
||||
if(filter)
|
||||
last_step_used_filter = TRUE
|
||||
animate(filter, step["vars"], time = step["time"], easing = step["easing"], flags = step["flags"])
|
||||
var/list/filter_params = target_atom.filter_data[step["filter"]]
|
||||
for(var/param in step["vars"])
|
||||
if(filter_params.Find(param))
|
||||
filter_params[param] = step["vars"][param]
|
||||
else
|
||||
if(last_step_used_filter)
|
||||
last_step_used_filter = FALSE
|
||||
animate(target_atom, step["vars"], time = step["time"], easing = step["easing"], flags = step["flags"])
|
||||
else
|
||||
animate(time = step["time"], step["vars"], easing = step["easing"], flags = step["flags"])
|
||||
var/target_for_animation = target_atom
|
||||
if(atom_or_filter.value == COMP_ANIMATE_FILTER)
|
||||
target_for_animation = target_atom.get_filter(filter_target.value)
|
||||
|
||||
if(!target_for_animation)
|
||||
return
|
||||
|
||||
var/extra_flags = NONE
|
||||
if(parallel.value)
|
||||
extra_flags |= ANIMATION_PARALLEL
|
||||
|
||||
var/list/first_step = popleft(result["animation_steps"])
|
||||
animate(target_for_animation, time = first_step["time"], first_step["vars"], loop = animation_loops.value, easing = first_step["easing"], flags = first_step["flags"]|extra_flags)
|
||||
for(var/list/step as anything in result["animation_steps"])
|
||||
animate(time = step["time"], step["vars"], easing = step["easing"], flags = step["flags"])
|
||||
if(atom_or_filter.value == COMP_ANIMATE_FILTER)
|
||||
var/list/filter_params = target_atom.filter_data[filter_target.value]
|
||||
for(var/param in step["vars"])
|
||||
if(filter_params.Find(param))
|
||||
filter_params[param] = step["vars"][param]
|
||||
|
||||
/obj/item/circuit_component/animation_step
|
||||
display_name = "Animation Step"
|
||||
@@ -55,38 +91,18 @@
|
||||
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
|
||||
|
||||
var/datum/port/input/option/atom_or_filter
|
||||
|
||||
var/datum/port/input/animation_variables
|
||||
|
||||
var/datum/port/input/animation_filter
|
||||
|
||||
var/datum/port/input/animation_time
|
||||
var/datum/port/input/animation_easing
|
||||
var/datum/port/input/animation_flags
|
||||
|
||||
/obj/item/circuit_component/animation_step/populate_options()
|
||||
var/static/list/component_options = list(
|
||||
COMP_ANIMATE_ATOM,
|
||||
COMP_ANIMATE_FILTER,
|
||||
)
|
||||
|
||||
atom_or_filter = add_option_port("Target", component_options)
|
||||
|
||||
/obj/item/circuit_component/animation_step/populate_ports()
|
||||
animation_variables = add_input_port("Variables", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY), order = 1.66)
|
||||
animation_time = add_input_port("Time", PORT_TYPE_NUMBER, order = 1.66)
|
||||
animation_easing = add_input_port("Easing", PORT_TYPE_NUMBER, order = 1.66)
|
||||
animation_flags = add_input_port("Flags", PORT_TYPE_NUMBER, order = 1.66)
|
||||
|
||||
/obj/item/circuit_component/animation_step/pre_input_received(datum/port/input/port)
|
||||
if(port == atom_or_filter)
|
||||
if((atom_or_filter.value == COMP_ANIMATE_ATOM) && animation_filter)
|
||||
remove_input_port(animation_filter)
|
||||
animation_filter = null
|
||||
else if((atom_or_filter.value == COMP_ANIMATE_FILTER) && !animation_filter)
|
||||
animation_filter = add_input_port("Filter Name", PORT_TYPE_STRING, order = 1.33)
|
||||
|
||||
/obj/item/circuit_component/animation_step/input_received(datum/port/input/port, list/return_values)
|
||||
if(!return_values)
|
||||
return
|
||||
@@ -96,16 +112,16 @@
|
||||
|
||||
var/list/variables = animation_variables.value
|
||||
|
||||
if(!variables)
|
||||
return
|
||||
|
||||
var/list/step = list(
|
||||
"vars" = variables.Copy(),
|
||||
"time" = animation_time.value,
|
||||
"time" = animation_time.value * (1 SECONDS),
|
||||
"easing" = animation_easing.value,
|
||||
"flags" = animation_flags.value
|
||||
)
|
||||
|
||||
if(atom_or_filter.value == COMP_ANIMATE_FILTER)
|
||||
step["filter"] = animation_filter.value
|
||||
|
||||
return_values["animation_steps"] += list(step)
|
||||
|
||||
#undef COMP_ANIMATE_ATOM
|
||||
|
||||
@@ -11,10 +11,6 @@ GLOBAL_LIST_INIT(wiremod_filter_info, list(
|
||||
"y" = PORT_TYPE_NUMBER,
|
||||
"size" = PORT_TYPE_NUMBER,
|
||||
),
|
||||
"color" = list(
|
||||
"color" = PORT_TYPE_LIST(PORT_TYPE_ANY),
|
||||
"space" = PORT_TYPE_NUMBER,
|
||||
),
|
||||
"displace" = list(
|
||||
"x" = PORT_TYPE_NUMBER,
|
||||
"y" = PORT_TYPE_NUMBER,
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
unregister = add_input_port("Unregister Current", PORT_TYPE_SIGNAL, order = 2, trigger = .proc/unregister_signals)
|
||||
|
||||
add_source_entity()
|
||||
event_triggered = add_output_port("Triggered", PORT_TYPE_SIGNAL, order = 2)
|
||||
event_triggered = add_output_port("Triggered", PORT_TYPE_INSTANT_SIGNAL, order = 2)
|
||||
|
||||
/obj/item/circuit_component/signal_handler/proc/add_source_entity()
|
||||
if(target)
|
||||
@@ -145,7 +145,7 @@
|
||||
signal_ports = ports_to_load
|
||||
for(var/list/data in signal_ports)
|
||||
if(data["is_response"])
|
||||
var/datum/port/input/bitflag_input = add_input_port(data["name"], PORT_TYPE_SIGNAL, order = 1, trigger = .proc/handle_bitflag_received)
|
||||
var/datum/port/input/bitflag_input = add_input_port(data["name"], PORT_TYPE_RESPONSE_SIGNAL, order = 1, trigger = .proc/handle_bitflag_received)
|
||||
input_signal_ports[bitflag_input] = data["bitflag"]
|
||||
else
|
||||
output_signal_ports += add_output_port(data["name"], data["type"], order = 1)
|
||||
|
||||
@@ -22,6 +22,9 @@ GLOBAL_LIST_INIT_TYPED(circuit_datatypes, /datum/circuit_datatype, generate_circ
|
||||
/// The flags of the circuit datatype
|
||||
var/datatype_flags = 0
|
||||
|
||||
/// The datatypes that this datatype can receive from.
|
||||
var/list/can_receive_from = list()
|
||||
|
||||
/// Whether this datatype should be loaded into the global circuit_datatypes list.
|
||||
var/abstract = FALSE
|
||||
|
||||
@@ -43,7 +46,7 @@ GLOBAL_LIST_INIT_TYPED(circuit_datatypes, /datum/circuit_datatype, generate_circ
|
||||
* * datatype_to_check - The datatype to check
|
||||
*/
|
||||
/datum/circuit_datatype/proc/can_receive_from_datatype(datatype_to_check)
|
||||
return datatype == datatype_to_check // This is already done by default on the input port.
|
||||
return datatype == datatype_to_check || (datatype_to_check in can_receive_from)
|
||||
|
||||
/**
|
||||
* Called when the datatype is given to a port.
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
datatype = PORT_TYPE_DATUM
|
||||
color = "yellow"
|
||||
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT
|
||||
|
||||
/datum/circuit_datatype/datum/can_receive_from_datatype(datatype_to_check)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
return datatype_to_check == PORT_TYPE_ATOM
|
||||
can_receive_from = list(
|
||||
PORT_TYPE_ATOM,
|
||||
)
|
||||
|
||||
/datum/circuit_datatype/datum/convert_value(datum/port/port, value_to_convert)
|
||||
var/datum/object = value_to_convert
|
||||
|
||||
@@ -3,12 +3,5 @@
|
||||
color = "green"
|
||||
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT
|
||||
|
||||
/datum/circuit_datatype/number/can_receive_from_datatype(datatype_to_check)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
return datatype_to_check == PORT_TYPE_NUMBER
|
||||
|
||||
/datum/circuit_datatype/number/handle_manual_input(datum/port/input/port, mob/user, user_input)
|
||||
return text2num(user_input)
|
||||
|
||||
@@ -11,17 +11,13 @@
|
||||
datatype = PORT_TYPE_OPTION
|
||||
color = "violet"
|
||||
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT
|
||||
can_receive_from = list(
|
||||
PORT_TYPE_STRING,
|
||||
)
|
||||
|
||||
/datum/circuit_datatype/option/is_compatible(datum/port/gained_port)
|
||||
return istype(gained_port, /datum/port/input/option)
|
||||
|
||||
/datum/circuit_datatype/option/can_receive_from_datatype(datatype_to_check)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
return datatype_to_check == PORT_TYPE_STRING
|
||||
|
||||
/datum/circuit_datatype/option/convert_value(datum/port/input/option/port, value_to_convert, force = FALSE)
|
||||
if(force)
|
||||
return value_to_convert
|
||||
|
||||
@@ -2,16 +2,26 @@
|
||||
datatype = PORT_TYPE_SIGNAL
|
||||
color = "teal"
|
||||
datatype_flags = DATATYPE_FLAG_ALLOW_MANUAL_INPUT|DATATYPE_FLAG_AVOID_VALUE_UPDATE
|
||||
|
||||
/datum/circuit_datatype/signal/can_receive_from_datatype(datatype_to_check)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
return datatype_to_check == PORT_TYPE_NUMBER
|
||||
can_receive_from = list(
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_INSTANT_SIGNAL,
|
||||
PORT_TYPE_RESPONSE_SIGNAL,
|
||||
)
|
||||
|
||||
/datum/circuit_datatype/signal/handle_manual_input(datum/port/input/port, mob/user, user_input)
|
||||
var/atom/parent = port.connected_component
|
||||
if(parent)
|
||||
parent.balloon_alert(user, "triggered [port.name]")
|
||||
return COMPONENT_SIGNAL
|
||||
|
||||
/datum/circuit_datatype/signal/instant_signal
|
||||
datatype = PORT_TYPE_INSTANT_SIGNAL
|
||||
|
||||
/datum/circuit_datatype/signal/instant_signal/is_compatible(datum/port/port)
|
||||
return istype(port, /datum/port/output)
|
||||
|
||||
/datum/circuit_datatype/signal/response_signal
|
||||
datatype = PORT_TYPE_RESPONSE_SIGNAL
|
||||
|
||||
/datum/circuit_datatype/signal/response_signal/is_compatible(datum/port/port)
|
||||
return istype(port, /datum/port/input)
|
||||
|
||||
@@ -162,9 +162,9 @@
|
||||
|
||||
|
||||
/obj/item/circuit_component/airlock_access_event/populate_ports()
|
||||
open_airlock = add_input_port("Should Open Airlock", PORT_TYPE_SIGNAL, trigger = .proc/should_open_airlock)
|
||||
open_airlock = add_input_port("Should Open Airlock", PORT_TYPE_RESPONSE_SIGNAL, trigger = .proc/should_open_airlock)
|
||||
accessing_entity = add_output_port("Accessing Entity", PORT_TYPE_ATOM)
|
||||
event_triggered = add_output_port("Event Triggered", PORT_TYPE_SIGNAL)
|
||||
event_triggered = add_output_port("Event Triggered", PORT_TYPE_INSTANT_SIGNAL)
|
||||
|
||||
|
||||
/obj/item/circuit_component/airlock_access_event/proc/should_open_airlock(datum/port/input/port, list/return_values)
|
||||
|
||||
Reference in New Issue
Block a user