Created
September 27, 2012 10:07
-
-
Save spllr/3793258 to your computer and use it in GitHub Desktop.
bmf_dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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