Skip to content

Instantly share code, notes, and snippets.

@spllr
Created September 27, 2012 10:07
Show Gist options
  • Save spllr/3793258 to your computer and use it in GitHub Desktop.
Save spllr/3793258 to your computer and use it in GitHub Desktop.
bmf_dialog
#!/usr/bin/env ruby
#
# Usage:
# make_story dialog_text_file.txt [output.plist]
#
# Make sure you install the plist gem:
# [sudo] gem install plist
#
require "parser"
Gem::Specification.new do |s|
s.name = 'bmf_dialog'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Klaas Speller'
s.email = '[email protected]'
s.summary = 'Dialogs'
s.description = 'Dialogs to plist'
s.files = ['parser.rb']
s.require_path = '.'
s.default_executable = 'parser.rb'
s.executables = ["./bmf_dialog"]
s.default_executable = 'bmf_dialog'
s.add_dependency('plist', ['~> 3.1'])
end
require "rubygems"
require "plist"
read_path = ARGV[0]
plist_path = ARGV[1]
unless read_path
puts "Please provide a path to a dialog file"
exit
end
dialogs = {}
File.open read_path do |file|
file.read.split("-->").each do |txt|
lines = txt.split("\n")
key = lines.shift
next if key.nil?
dialog = []
lines.join("\n").scan(/^(\w+): (.*)\n/) do |m|
dialog << { :speaker => m[0], :message => m[1] }
end
dialogs[key.strip] = dialog
end
end
if plist_path
File.open plist_path, "w+" do |file|
file.write dialogs.to_plist
end
else
puts dialogs.to_plist
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment