Created
November 24, 2015 14:59
-
-
Save nossidge/878873b8726277aa37d3 to your computer and use it in GitHub Desktop.
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 | |
#encoding: UTF-8 | |
# http://www.gamefaqs.com/snes/563538-chrono-trigger/faqs/31563 | |
################################################################################ | |
# Input: 'Paris in the Spring ' | |
# Output: 'Paris in the Spring ' | |
class String | |
def remove_multiple_chars(charToRemove = ' ') | |
returnString = self | |
diff = '' | |
loop do | |
break if diff == returnString | |
diff = returnString | |
returnString = returnString.gsub(charToRemove*2,charToRemove) | |
end | |
returnString | |
end | |
def remove_multiple_chars!(charToRemove = ' ') | |
self.replace self.remove_multiple_chars(charToRemove) | |
end | |
end | |
################################################################################ | |
buffer = '' | |
File.open('chrono_trigger.txt', 'w') do |fo| | |
File.open('chrono_trigger_raw.txt', 'r').each_line do |line| | |
indent = line[/\A */].length | |
line.strip! | |
# If it's a dialogue line like: | |
# "MOM: Ah, Leene's Bell makes such" | |
# "Marle: Hi, I'm Marle!" | |
dialogueStart = (line =~ /^[A-Za-z]*\:/) | |
# We may not need to output just this line, so add to buffer. | |
if dialogueStart | |
buffer = line.partition(':').last.strip | |
else | |
# If it's a continuation of the dialog. | |
if indent == 3 or indent == 4 | |
buffer = "#{buffer} #{line}".strip | |
end | |
# If it's not a continuation, then output the buffer. | |
if buffer != '' and indent != 3 | |
buffer.remove_multiple_chars!(' ') | |
if buffer.length >= 10 and !buffer.include?("[") and !buffer.include?("]") | |
fo.puts buffer | |
end | |
buffer = '' | |
end | |
end | |
end | |
end | |
################################################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment