Zeriab

[RGSS] Quick and dirty script calls to text file script

Sep 10th, 2014
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def update_sprite
  2.   if @sprite.nil?
  3.     @sprite = Sprite.new
  4.     @sprite.bitmap = Bitmap.new(640, 120)
  5.   end
  6.   current = $current
  7.   unless current == $last
  8.     $last = current
  9.     @sprite.bitmap.clear
  10.     unless current.nil?
  11.       @sprite.bitmap.draw_text(8,4,600,32,$last.map)
  12.       @sprite.bitmap.draw_text(8,40,600,32,$last.event)
  13.     end
  14.   end
  15. end
  16.  
  17. ##
  18. # A separate thread that will run and make sure the Graphics.update is updated
  19. # every now and then.
  20. #
  21. Thread.new {
  22.   loop do
  23.     # Lets the thread sleep for a while to minimize CPU usage
  24.     sleep 0.1
  25.     # Update the sprite
  26.     update_sprite
  27.     # Update the graphics
  28.     Graphics.update
  29.   end
  30. }
  31.  
  32. Current = Struct.new(:map, :event)
  33. $current = nil
  34.  
  35. Map = Struct.new(:name, :map_id, :events)
  36. Event = Struct.new(:name, :event_id, :pages)
  37. Page = Struct.new(:number, :list)
  38. ListElement = Struct.new(:message, :type)
  39.  
  40. ######
  41. ######
  42.  
  43. class Map
  44.   def write_to_stream(io)
  45.     io.print "\r\n########################################"
  46.     io.print "\r\n# Map #{map_id} ~ #{name}  (#{events.size} events)\r\n"
  47.     io.print "########################################\r\n"
  48.     for event in events
  49.       event.write_to_stream(io)
  50.     end
  51.   end
  52. end
  53.  
  54. class Event
  55.   def write_to_stream(io)
  56.     io.print "\r\n-= Event #{event_id} - #{name} =-\r\n"
  57.     for page in pages
  58.       page.write_to_stream(io)
  59.     end
  60.   end
  61. end
  62.  
  63. class Page
  64.   def write_to_stream(io)
  65.     io.print "Page #{number}:\r\n"
  66.     for element in list
  67.       element.write_to_stream(io)
  68.       io.print "\r\n"
  69.     end
  70.   end
  71. end
  72.  
  73. class ListElement
  74.   def write_to_stream(io)
  75.     io.print message
  76.   end
  77. end
  78.  
  79. ######
  80. def process_list(list)
  81.   # Go through the event commands in the list
  82.   rlist = [] # resulting list
  83.   command_index = 0
  84.   while command_index < list.size
  85.     command = list[command_index]
  86.     if command.code == 355 && command.parameters[0] != nil
  87.       message = command.parameters[0].rstrip
  88.       loop do
  89.         break unless command_index + 1 < list.size
  90.         if list[command_index+1].code == 656
  91.           command_index += 1
  92.           message += " " + list[command_index].parameters[0].rstrip
  93.         elsif list[command_index+1].code == 655
  94.           command_index += 1
  95.           for text in list[command_index].parameters[0]
  96.             message += "\r\n" + text.rstrip
  97.           end
  98.         else
  99.           break
  100.         end
  101.       end
  102.       rlist << ListElement.new(message, 'text')
  103.     end
  104.     command_index += 1
  105.   end
  106.   return rlist
  107. end
  108. ######
  109.  
  110. class CommonEvent < Struct.new(:name, :event_id, :list)
  111.   def write_to_stream(io)
  112.     io.print "\r\n-= Common Event #{event_id} - #{name} =-\r\n"
  113.     for element in list
  114.       element.write_to_stream(io)
  115.       io.print "\r\n"
  116.     end
  117.   end
  118. end
  119.  
  120. common_events = load_data('Data/CommonEvents.rxdata')
  121. ces = []
  122. for ce in common_events.compact
  123.   # Look at which event is currently processing
  124.   cur = Current.new("Processing common events...",
  125.                     "Common event #{ce.id} - #{ce.name}")
  126.   $current = cur
  127.   # Process the list
  128.   list = process_list(ce.list)
  129.   unless list.empty?
  130.     # Create struct
  131.     current_ce = CommonEvent.new(ce.name, ce.id, list)
  132.     ces << current_ce
  133.   end
  134. end
  135.  
  136. ######
  137. ######
  138.  
  139. class Troop < Event
  140.   def write_to_stream(io)
  141.     io.print "\r\n-= Troop #{event_id} - #{name} =-\r\n"
  142.     for page in pages
  143.       page.write_to_stream(io)
  144.     end
  145.   end
  146. end
  147.  
  148. troops = load_data('Data\Troops.rxdata')
  149.  
  150. battle_events = []
  151. for event in troops.compact
  152.   # Look at which event is currently processing
  153.   cur = Current.new("Processing battle events...",
  154.                     "Troop " + event.id.to_s + " - " + event.name)
  155.   $current = cur
  156.   # Create the event struct
  157.   current_event = Troop.new(event.name, event.id, [])
  158.   # Create pages
  159.   event.pages.each_with_index do |page, page_index|
  160.     list = process_list(page.list)
  161.     unless list.empty?
  162.       current_page = Page.new(page_index+1, list)
  163.       current_event.pages << current_page
  164.     end
  165.   end
  166.   # Let's disregard useless events
  167.   battle_events << current_event unless current_event.pages.empty?
  168. end
  169.  
  170. ######
  171. ######
  172.  
  173. infos = load_data('Data\MapInfos.rxdata')
  174.  
  175. maps = []
  176. for map_id, map_info in infos.sort
  177.   # Create map struct
  178.   current_map = Map.new(map_info.name, map_id, [])
  179.   maps << current_map
  180.   map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
  181.   # Create event structs
  182.   for event_id, event in map.events.sort
  183.     # Look at which event is currently processing
  184.     cur = Current.new("Map " + map_id.to_s + " - " + map_info.name,
  185.                       "Event " + event_id.to_s + " - " + event.name)
  186.     $current = cur
  187.     # Create the event struct
  188.     current_event = Event.new(event.name, event_id, [])
  189.     # Create pages
  190.     event.pages.each_with_index do |page, page_index|
  191.       list = process_list(page.list)
  192.       unless list.empty?
  193.         current_page = Page.new(page_index+1, list)
  194.         # Let's disregard useless pages
  195.         current_event.pages << current_page
  196.       end
  197.     end
  198.     # Let's disregard useless events
  199.     current_map.events << current_event unless current_event.pages.empty?
  200.   end
  201. end
  202.  
  203. # Update status info
  204. cur = Current.new("All maps have been processed",
  205.                   "Writing to a text file")
  206. $current = cur
  207.  
  208. File.open('ScriptCalls_Map.txt', 'wb') {|f|
  209.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE MAPS\r\n\r\n"
  210.   for map in maps
  211.     map.write_to_stream(f)
  212.   end
  213. }
  214.  
  215. File.open('ScriptCalls_Common.txt', 'wb') {|f|
  216.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE COMMON EVENTS\r\n\r\n"
  217.   for ce in ces
  218.     ce.write_to_stream(f)
  219.   end
  220. }
  221.  
  222. File.open('ScriptCalls_Battle.txt', 'wb') {|f|
  223.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE BATTLE EVENTS\r\n\r\n"
  224.   for be in battle_events
  225.     be.write_to_stream(f)
  226.   end
  227. }
  228. exit
RAW Paste Data