Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EXTRACT_TEXT = false
- EXTRACT_CONDITIONAL_BRANCHES = true
- EXTRACT_CONTROL_SWITCHES = true
- EXTRACT_CONTROL_VARIABLES = true
- EXTRACT_CODES = []
- EXTRACT_CODES << 101 if EXTRACT_TEXT
- EXTRACT_CODES << 102 if EXTRACT_TEXT
- EXTRACT_CODES << 401 if EXTRACT_TEXT
- EXTRACT_CODES << 111 if EXTRACT_CONDITIONAL_BRANCHES
- EXTRACT_CODES << 121 if EXTRACT_CONTROL_SWITCHES
- EXTRACT_CODES << 122 if EXTRACT_CONTROL_VARIABLES
- def update_sprite
- if @sprite.nil?
- @sprite = Sprite.new
- @sprite.bitmap = Bitmap.new(640, 120)
- end
- current = $current
- unless current == $last
- $last = current
- @sprite.bitmap.clear
- unless current.nil?
- @sprite.bitmap.draw_text(8,4,600,32,$last.map)
- @sprite.bitmap.draw_text(8,40,600,32,$last.event)
- end
- end
- end
- ##
- # A separate thread that will run and make sure the Graphics.update is updated
- # every now and then.
- #
- Thread.new {
- loop do
- # Lets the thread sleep for a while to minimize CPU usage
- sleep 0.1
- # Update the sprite
- update_sprite
- # Update the graphics
- Graphics.update
- end
- }
- Current = Struct.new(:map, :event)
- $current = nil
- Map = Struct.new(:name, :map_id, :events)
- Event = Struct.new(:name, :event_id, :pages)
- Page = Struct.new(:number, :list)
- ListElement = Struct.new(:message, :type)
- ######
- ######
- class Map
- def write_to_stream(io)
- io.print "\r\n########################################"
- io.print "\r\n# Map #{map_id} ~ #{name} (#{events.size} events)\r\n"
- io.print "########################################\r\n"
- for event in events
- event.write_to_stream(io)
- end
- end
- end
- class Event
- def write_to_stream(io)
- io.print "\r\n-= Event #{event_id} - #{name} =-\r\n"
- for page in pages
- page.write_to_stream(io)
- end
- end
- end
- class Page
- def write_to_stream(io)
- io.print "Page #{number}:\r\n"
- for element in list
- element.write_to_stream(io)
- io.print "\r\n"
- end
- end
- end
- class ListElement
- def write_to_stream(io)
- io.print message
- end
- end
- ######
- def process_list(list)
- # Go through the event commands in the list
- rlist = [] # resulting list
- command_index = 0
- while command_index < list.size
- command_index = process_event_command(list, command_index, rlist)
- command_index += 1
- end
- return rlist
- end
- def process_event_command(list, index, rlist)
- command_index = index
- command = list[command_index]
- if (!EXTRACT_CODES.include?(command.code))
- # Skip
- return command_index;
- end
- # Handle code
- case command.code
- when 101
- message = command.parameters[0].rstrip
- loop do
- break unless command_index + 1 < list.size
- if list[command_index+1].code == 401
- command_index += 1
- message += " " + list[command_index].parameters[0].rstrip
- elsif list[command_index+1].code == 102
- command_index += 1
- for text in list[command_index].parameters[0]
- message += "\r\n" + text.rstrip
- end
- else
- break
- end
- end
- rlist << ListElement.new(message, 'text')
- when 102
- message = ""
- for text in list[command_index].parameters[0]
- message += "\r\n" + text.rstrip
- end
- rlist << ListElement.new(message, 'choice')
- when 111
- type = command.parameters[0] == 1 ? 'variable' : 'switch'
- message = "Conditional branch using #{type}[#{command.parameters[0]}]"
- rlist << ListElement.new(message, 'conditional')
- when 121
- range = command.parameters[0] .. command.parameters[1]
- if command.parameters[0] != command.parameters[1]
- range_str = range.to_s
- else
- range_str = command.parameters[0].to_s
- end
- message = "Control switches #{range_str}"
- rlist << ListElement.new(message, 'control_switch')
- when 122
- range = command.parameters[0] .. command.parameters[1]
- if command.parameters[0] != command.parameters[1]
- range_str = range.to_s
- else
- range_str = command.parameters[0].to_s
- end
- message = "Control variables #{range_str}"
- rlist << ListElement.new(message, 'control_variable')
- end
- return command_index
- end
- ######
- class CommonEvent < Struct.new(:name, :event_id, :list)
- def write_to_stream(io)
- io.print "\r\n-= Common Event #{event_id} - #{name} =-\r\n"
- for element in list
- element.write_to_stream(io)
- io.print "\r\n"
- end
- end
- end
- common_events = load_data('Data/CommonEvents.rxdata')
- ces = []
- for ce in common_events.compact
- # Look at which event is currently processing
- cur = Current.new("Processing common events...",
- "Common event #{ce.id} - #{ce.name}")
- $current = cur
- # Process the list
- list = process_list(ce.list)
- unless list.empty?
- # Create struct
- current_ce = CommonEvent.new(ce.name, ce.id, list)
- ces << current_ce
- end
- end
- ######
- ######
- class Troop < Event
- def write_to_stream(io)
- io.print "\r\n-= Troop #{event_id} - #{name} =-\r\n"
- for page in pages
- page.write_to_stream(io)
- end
- end
- end
- troops = load_data('Data\Troops.rxdata')
- battle_events = []
- for event in troops.compact
- # Look at which event is currently processing
- cur = Current.new("Processing battle events...",
- "Troop " + event.id.to_s + " - " + event.name)
- $current = cur
- # Create the event struct
- current_event = Troop.new(event.name, event.id, [])
- # Create pages
- event.pages.each_with_index do |page, page_index|
- list = process_list(page.list)
- unless list.empty?
- current_page = Page.new(page_index+1, list)
- current_event.pages << current_page
- end
- end
- # Let's disregard useless events
- battle_events << current_event unless current_event.pages.empty?
- end
- ######
- ######
- infos = load_data('Data\MapInfos.rxdata')
- maps = []
- for map_id, map_info in infos.sort
- # Create map struct
- current_map = Map.new(map_info.name, map_id, [])
- maps << current_map
- map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
- # Create event structs
- for event_id, event in map.events.sort
- # Look at which event is currently processing
- cur = Current.new("Map " + map_id.to_s + " - " + map_info.name,
- "Event " + event_id.to_s + " - " + event.name)
- $current = cur
- # Create the event struct
- current_event = Event.new(event.name, event_id, [])
- # Create pages
- event.pages.each_with_index do |page, page_index|
- list = process_list(page.list)
- unless list.empty?
- current_page = Page.new(page_index+1, list)
- # Let's disregard useless pages
- current_event.pages << current_page
- end
- end
- # Let's disregard useless events
- current_map.events << current_event unless current_event.pages.empty?
- end
- end
- # Update status info
- cur = Current.new("All maps have been processed",
- "Writing to a text file")
- $current = cur
- File.open('Dialogue_Map.txt', 'wb') {|f|
- f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE MAPS\r\n\r\n"
- for map in maps
- map.write_to_stream(f)
- end
- }
- File.open('Dialogue_Common.txt', 'wb') {|f|
- f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE COMMON EVENTS\r\n\r\n"
- for ce in ces
- ce.write_to_stream(f)
- end
- }
- File.open('Dialogue_Battle.txt', 'wb') {|f|
- f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE BATTLE EVENTS\r\n\r\n"
- for be in battle_events
- be.write_to_stream(f)
- end
- }
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement