Skip to content

Commit 5cff038

Browse files
committed
Simplify drain animation code
1 parent b1c9480 commit 5cff038

2 files changed

Lines changed: 26 additions & 28 deletions

File tree

lib/minigun/hud/flow_diagram.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,18 @@ def get_drain_distance(stage_data)
379379
ticks_since_finished
380380
end
381381

382+
# Check if connection has flowing animation (vs idle/drained state)
383+
def connection_flowing?(stage_data)
384+
stage_data[:status] == :running
385+
end
386+
382387
# Draw a fan-out connection (one source to multiple targets)
383388
def render_fanout_connection(terminal, from_pos, target_positions, stage_data, x_offset, y_offset)
384389
from_x = from_pos[:x] + from_pos[:width] / 2
385390
from_y = from_pos[:y] + from_pos[:height]
386391

387-
# Get drain distance (non-nil when stage finished)
388392
drain_distance = get_drain_distance(stage_data)
389-
390-
# Connection is active if flowing OR draining
391-
# When draining, keep animation visible until fully drained
392-
active = (stage_data[:throughput] && stage_data[:throughput] > 0) || !drain_distance.nil?
393+
active = connection_flowing?(stage_data)
393394

394395
# Calculate split point (horizontal spine where fan-out occurs)
395396
split_y = from_y + 1
@@ -457,11 +458,8 @@ def render_fanin_connection(terminal, source_positions, to_pos, stage_data, x_of
457458
to_x = to_pos[:x] + to_pos[:width] / 2
458459
to_y = to_pos[:y]
459460

460-
# Get drain distance (non-nil when stage finished)
461461
drain_distance = get_drain_distance(stage_data)
462-
463-
# Connection is active if flowing OR draining
464-
active = (stage_data[:throughput] && stage_data[:throughput] > 0) || !drain_distance.nil?
462+
active = connection_flowing?(stage_data)
465463

466464
# Calculate merge point (where horizontal lines converge)
467465
# Place it 1 line above the target
@@ -546,11 +544,8 @@ def render_connection_line(terminal, from_pos, to_pos, stage_data, x_offset, y_o
546544
to_x = to_pos[:x] + to_pos[:width] / 2
547545
to_y = to_pos[:y]
548546

549-
# Get drain distance (non-nil when stage finished)
550547
drain_distance = get_drain_distance(stage_data)
551-
552-
# Connection is active if flowing OR draining
553-
active = (stage_data[:throughput] && stage_data[:throughput] > 0) || !drain_distance.nil?
548+
active = connection_flowing?(stage_data)
554549

555550
# Distance counter starts at 0 from source
556551
distance = 0

lib/minigun/hud/theme.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,11 @@ def self.flow_medium
9797
Terminal::COLORS[:cyan]
9898
end
9999

100-
# Draining animation colors (darker, showing flow winding down)
100+
# Draining animation color (darker, showing flow winding down)
101101
def self.drain_dim
102102
Terminal::COLORS[:gray]
103103
end
104104

105-
def self.drain_medium
106-
Terminal::COLORS[:gray]
107-
end
108-
109105
# Subtle flowing animation for each box drawing character type
110106
# Each frame has: [character, color_method_symbol]
111107
FLOW_ANIMATION = {
@@ -265,17 +261,24 @@ def self.drain_medium
265261
# @param drain_distance [Integer, nil] How far the drain has progressed from source (nil if not draining)
266262
# @return [Array<String, String>] [character, color_code]
267263
def self.animated_flow_char(char_type, distance, animation_frame, active, drain_distance: nil)
268-
# Show animation if active OR draining (drain_distance is non-nil)
269-
return [static_char_for_type(char_type), muted] unless active || !drain_distance.nil?
270-
271-
# Check if this cell has been reached by the drain wave
272-
# drain_distance is the number of ticks since finishing
273-
# Cells are drained when distance <= drain_distance (inclusive)
274-
draining = !drain_distance.nil? && distance <= drain_distance
264+
# Check if this cell has been drained (wave reached it)
265+
drained = !drain_distance.nil? && distance <= drain_distance
266+
267+
# Check if drain is in progress but wave hasn't reached this cell yet
268+
draining = !drain_distance.nil? && distance > drain_distance
269+
270+
# Determine which animation to use:
271+
# - If drained: gray static (drained)
272+
# - If active OR draining: cyan animated (flowing/draining)
273+
# - Otherwise: gray static (idle/not started)
274+
frames = if drained
275+
DRAIN_ANIMATION[char_type]
276+
elsif active || draining
277+
FLOW_ANIMATION[char_type]
278+
else
279+
DRAIN_ANIMATION[char_type] # Gray for idle state
280+
end
275281

276-
# Use draining animation if this cell has been reached by the drain wave
277-
# Otherwise use normal flow animation
278-
frames = draining ? DRAIN_ANIMATION[char_type] : FLOW_ANIMATION[char_type]
279282
return [static_char_for_type(char_type), muted] unless frames
280283

281284
# Calculate phase based on distance from source and global animation frame

0 commit comments

Comments
 (0)