lib/import/flame_stabilizer.rb in tracksperanto-2.1.1 vs lib/import/flame_stabilizer.rb in tracksperanto-2.2.0

- old
+ new

@@ -69,21 +69,21 @@ # when it gets Array#flatten'ed def to_ary; end private :to_ary end - def stream_parse(io) + def each report_progress("Extracting setup size") - self.width, self.height = extract_width_and_height_from_stream(io) + self.width, self.height = extract_width_and_height_from_stream(@io) report_progress("Extracting all animation channels") - channels = extract_channels_from_stream(io) + channels = extract_channels_from_stream(@io) raise "The setup contained no channels that we could process" if channels.empty? raise "A channel was nil" if channels.find{|e| e.nil? } report_progress("Assembling tracker curves from channels") - scavenge_trackers_from_channels(channels) {|t| send_tracker(t) } + scavenge_trackers_from_channels(channels) {|t| yield(t) } end private def extract_width_and_height_from_stream(io) w, h = nil, nil @@ -183,16 +183,12 @@ shift_y = channels.find{|e| e.name == "#{t.name}/shift/y" } shift_tuples = zip_curve_tuples(shift_x, shift_y) track_tuples = zip_curve_tuples(track_x, track_y) - base_x, base_y = begin - report_progress("Detecting base value") - find_base_x_and_y(track_tuples, shift_tuples) - rescue UseBase - [track_x.base_value, track_y.base_value] - end + report_progress("Detecting base value") + base_x, base_y = find_base_x_and_y(track_tuples, shift_tuples) total_kf = 1 t.keyframes = shift_tuples.map do | (at, x, y) | # Flame keyframes are sort of minus-one based, so to start at frame 0 # we need to decrement one frame, always. Also, the shift value is inverted! @@ -203,20 +199,12 @@ end return t end - UseBase = RuntimeError - def find_base_x_and_y(track_tuples, shift_tuples) base_track_tuple = track_tuples.find do | track_tuple | shift_tuples.find { |shift_tuple| shift_tuple[0] == track_tuple [0] } - end - if base_track_tuple - base_track_tuple[1..2] - elsif track_tuples[0] - track_tuples[0][1..2] - else - raise UseBase - end + end || track_tuples[0] + base_track_tuple[1..2] end end \ No newline at end of file