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:
Watermelon914
2021-10-08 13:29:59 +01:00
committed by GitHub
parent 6cc7382e9a
commit f6dfff674f
10 changed files with 98 additions and 84 deletions
@@ -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)