#!/usr/bin/ruby
require File.expand_path(File.dirname(__FILE__)) + '/../lib/flame_channel_parser'
require 'optparse'
require "update_hints"

options = {:destination => $stdout }
op = OptionParser.new

op.banner = "Usage: framecurve_from_flame /usr/discreet/projects/BoringBeautySpot/timewarp/shot2_tw.timewarp"
op.on(" -s", "--startframe FRAME", 
  Integer, "Bake the time curve upto this specific frame (defaults to the end of the setup"
) {|from| options[:start_frame] = from }
op.on(" -e", "--endframe FRAME",
  Integer, "Bake the time curve from this specific frame (defaults to frame 1)"
) {|upto| options[:end_frame] = upto }

op.parse!

setup_path = ARGV.shift

fail "No input file path provided. Use --help for usage information." unless setup_path
fail "File does not exist" unless File.exist?(setup_path)

# Setup the destination
destination_path = setup_path.gsub(/\.(\w+)$/, '.framecurve.txt')
File.open(destination_path, "wb") do | f |
  FlameChannelParser::TimewarpExtractor.new.extract(setup_path, options.merge(:destination => f))
end

UpdateHints.version_check("flame_channel_parser", FlameChannelParser::VERSION, $stderr)
