Sha256: 7865c877917fb47eeb062d47968d279492ca6875a2f7bbbadec8e6c913162451

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# Imports 3D Equalizer's text files
class Tracksperanto::Import::Equalizer < Tracksperanto::Import::Base
  
  class IOI < DelegateClass(IO)
    def initialize(io)
      __setobj__(io)
    end
    
    def gets_non_empty
      line = __getobj__.gets
      return nil if line.nil?
      s = line.strip
      return gets_non_empty if s.empty?
      s
    end
  end
  
  def self.human_name
    "3DE point export file"
  end
  
  
  def parse(passed_io)
    ts = []
    io = IOI.new(passed_io)
    
    num_t = detect_num_of_points(io)
    num_t.times { ts << extract_tracker(io) }
    
    ts
  end
  
  private
    
    def detect_num_of_points(io)
      io.gets_non_empty.to_i
    end
    
    KF_PATTERN = /^(\d+)\s([\-\d\.]+)\s([\-\d\.]+)/
    def extract_tracker(io)
      t = Tracksperanto::Tracker.new(:name => io.gets.strip)
      
      io.gets # Tracker color, internal 3DE repr and 0 is Red
      
      num_of_keyframes = io.gets.to_i
      catch(:__emp) do
        num_of_keyframes.times do
          line = io.gets_non_empty
          throw :__emp unless line
          
          frame, x, y = line.scan(KF_PATTERN).flatten
          t.keyframe!(:frame => (frame.to_i - 1), :abs_x => x, :abs_y => y)
        end
      end
      t
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tracksperanto-1.3.1 lib/import/equalizer.rb
tracksperanto-1.3.0 lib/import/equalizer.rb