lib/import/flame_stabilizer.rb in tracksperanto-1.9.8 vs lib/import/flame_stabilizer.rb in tracksperanto-1.9.9
- old
+ new
@@ -69,21 +69,21 @@
# when it gets Array#flatten'ed
def to_ary; end
private :to_ary
end
- def parse(io)
+ def stream_parse(io)
report_progress("Extracting setup size")
self.width, self.height = extract_width_and_height_from_stream(io)
report_progress("Extracting all animation channels")
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)
+ scavenge_trackers_from_channels(channels) {|t| send_tracker(t) }
end
private
def extract_width_and_height_from_stream(io)
w, h = nil, nil
@@ -152,23 +152,26 @@
end
channels
end
USEFUL_CHANNELS = %w( /shift/x /shift/y /ref/x /ref/y ).map(&Regexp.method(:new))
+
+ # This method tells the importer whether a channel that has been found in the source
+ # setup is needed. If that method returns ++false++ the channel will be discarded and not
+ # kept in memory. Should you need to write a module that scavenges other Flame animation channels
+ # inherit from this class and rewrite this method to either return +true+ always (then all the channels
+ # will be recovered) or to return +true+ only for channels that you actually need.
def channel_is_useful?(channel_name)
USEFUL_CHANNELS.any?{|e| channel_name =~ e }
end
REF_CHANNEL = "ref" # or "track" - sometimes works sometimes don't
def scavenge_trackers_from_channels(channels)
- trackers = []
channels.select{|e| e.name =~ /\/#{REF_CHANNEL}\/x/}.each do | track_x |
report_progress("Detected reference channel #{track_x}")
- trackers << grab_tracker(channels, track_x)
+ yield grab_tracker(channels, track_x)
end
-
- trackers
end
def grab_tracker(channels, track_x)
t = Tracksperanto::Tracker.new(:name => track_x.name.split('/').shift)
\ No newline at end of file