daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Object
  2. #------------------------------------------------------------------
  3. class Object
  4.   def string?
  5.     return false
  6.   end
  7. end
  8. #-----------------------------------------------------------------
  9. # String
  10. #------------------------------------------------------------------
  11. class String
  12.   def string?
  13.     true
  14.   end
  15. end
  16. #------------------------------------------------------------------
  17. module Export_Messages
  18.   #------------------------------------------------------------------
  19.   # Enabled - When true, data will export.  Otherwise no.
  20.   #------------------------------------------------------------------
  21.   ENABLED = true
  22.  
  23.   #------------------------------------------------------------------
  24.   # Maps File - File in which contains the map information
  25.   #------------------------------------------------------------------
  26.   MapsFile = "./Data/MapInfos.rvdata2"
  27.  
  28.   #------------------------------------------------------------------
  29.   # Event Messages Folder
  30.   #------------------------------------------------------------------
  31.   EVENT_MESSAGES_FOLDER = "./Messages/"
  32.  
  33.   #------------------------------------------------------------------
  34.   # Make Folder Name (from map ID and MAP)
  35.   #------------------------------------------------------------------
  36.   def self.make_folder_name(id, map)
  37.     return sprintf("%03d_%s", id, map.name);
  38.   end
  39.   #------------------------------------------------------------------
  40.   # Export Messages
  41.   #------------------------------------------------------------------
  42.   # This exports all the events messaging in the game on every map
  43.   #------------------------------------------------------------------
  44.   def self.export_messages
  45.     maps = load_data(MapsFile)
  46.     if !Dir.exist?(EVENT_MESSAGES_FOLDER)
  47.       Dir.mkdir(EVENT_MESSAGES_FOLDER)
  48.     end
  49.     for id in 1...maps.size+1
  50.       mapFile = sprintf("Data/Map%03d.rvdata2", id)
  51.       mapInfo = maps[id]
  52.       map = load_data(mapFile) rescue next
  53.       foldername = EVENT_MESSAGES_FOLDER + make_folder_name(id, mapInfo)
  54.       if !Dir.exist?(foldername)
  55.         Dir.mkdir(foldername)
  56.       end
  57.       for event_id in map.events.keys
  58.         event = map.events[event_id]
  59.         for i in 0...event.pages.size
  60.           filename = sprintf("%s/%03d_%s_%02d.txt", foldername, event_id, event.name, i+1)
  61.           if File.exist?(filename)
  62.             File.delete(filename)
  63.           end
  64.           file = File.new(filename, 'a') #open file in append mode
  65.           file.write(sprintf("%03d %s Page_%02d", event_id, event.name, i+1))
  66.           write_linebreak(file)
  67.          
  68.           page = event.pages[i]
  69.          
  70.           event_string_data = build_event_string_data(page)
  71.          
  72.           file.write(event_string_data)
  73.           file.close
  74.          
  75.           if event_string_data == ""
  76.             File.delete(filename)
  77.           end
  78.         end
  79.        
  80.       end
  81.     end
  82.     print "Finished Exporting messages to file\n"
  83.   end
  84.   #------------------------------------------------------------------
  85.   # Construct message string data
  86.   #------------------------------------------------------------------
  87.   def self.build_event_string_data(page)
  88.     save_string = []
  89.     @index = 0
  90.     #------------------------------------------------------------------
  91.     # Walk list and check each item.  
  92.     # Since choices already sort items for us, no additional sort is needed.
  93.     #------------------------------------------------------------------
  94.     while page.list[@index] != nil
  95.       event_data = page.list[@index]
  96.       indent = "\t " * event_data.indent
  97.       if ([101, 401].include?(event_data.code))
  98.         s = event_data.parameters[0]
  99.         save_string << indent + "[MESSAGE]" + s unless s == ""
  100.       elsif [402].include?(event_data.code)
  101.         for s in event_data.parameters
  102.           save_string << indent + "[CHOICE]" + s if s.string?
  103.         end
  104.       elsif [404].include?(event_data.code)
  105.         save_string << indent + "[END_CHOICE]"
  106.       end
  107.       @index += 1
  108.     end
  109.     return save_string.join("\n")
  110.   end
  111.   #------------------------------------------------------------------
  112.   # Write Linebreak
  113.   #------------------------------------------------------------------
  114.   def self.write_linebreak(file)
  115.     file.write("\r\n")
  116.   end
  117.   if ENABLED
  118.     export_messages
  119.   end
  120. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top