Skip to content

Commit

Permalink
fix edge case of nested tp_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesZh committed Aug 1, 2024
1 parent 6bcefb5 commit d2b9ab1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/sscharter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def init_state
@bpm_changes = nil
@tip_point_mode_stack = [:none]
@current_tip_point_stack = []
@current_tip_point_group_stack = []
@tip_point_peak = 0
@current_duplicate = 0
@tip_point_start_to_add_stack = [nil]
Expand Down Expand Up @@ -476,13 +477,13 @@ def tip_point mode, *args, preserve_beat: true, **opts, &block
@tip_point_peak += 1
end
result = group preserve_beat: do
@current_tip_point_group = @groups.last
@current_tip_point_group_stack.push @groups.last
instance_eval &block
end
@tip_point_start_to_add_stack.pop
@tip_point_mode_stack.pop
@current_tip_point_stack.pop
@current_tip_point_group = nil
@current_tip_point_group_stack.pop
result
end

Expand Down Expand Up @@ -515,7 +516,7 @@ def push_tip_point_start start_event
return unless tip_point_start
@groups.each do |group|
group.push tip_point_start
break if group.equal?(@current_tip_point_group) && @tip_point_mode_stack.last != :drop
break if group.equal?(@current_tip_point_group_stack.last) && @tip_point_mode_stack.last != :drop
end
end

Expand Down
25 changes: 25 additions & 0 deletions test/test_sscharter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,29 @@ def test_group_nested_in_tip_point_drop
assert_equal group1.first(2), group2
end

def test_group_nested_in_tip_point_chain_twice
chart = Charter.open __method__
chart.offset offset = rand
chart.bpm bpm = rand * 300

group1 = group2 = group3 = note1 = note2 = note3 = nil
chart.tip_point_chain rand, rand, rand do
group2 = tp_chain rand, rand, rand do
group3 = group do
note3 = t rand(100), rand(100)
end
note2 = t rand(100), rand(100)
end
group1 = group do
note1 = t rand(100), rand(100)
end
end
assert_equal chart.events.length, 5
assert_equal note1[:tip_point], chart.events[4][:tip_point]
assert_equal note2[:tip_point], note3[:tip_point]
assert_equal note3[:tip_point], group2[1][:tip_point]
assert_equal group3, [note3]
assert_equal group1, [note1]
end

end

0 comments on commit d2b9ab1

Please sign in to comment.