Advertisement
Archeia

EVENT TEXT BETA A

Feb 14th, 2015
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.49 KB | None | 0 0
  1. module Yami
  2.   module Event_Text
  3.    
  4.     # Configuration
  5.     TEXT_FOLDER = "Text"
  6.    
  7.     # Regular Expression
  8.     COMMAND = /(.*):/i
  9.     END_COMMAND = /END (.*)/i
  10.     PARA = /[ ]*(.*):[ ]*(.+)/i
  11.     SECTION = /SECTION[ ](\w+)/
  12.     END_SECTION = /END SECTION/
  13.    
  14.     # Parses Command
  15.     def self.parse(file)
  16.       file = TEXT_FOLDER + "/" + file
  17.       return [] unless FileTest.exist?(file)
  18.       result = {}
  19.       io = File.open(file)
  20.       all_lines = io.read
  21.       #----
  22.       @sm = false
  23.       @sc = false
  24.       @messages = []
  25.       @scripts = []
  26.       @section = nil
  27.       #----
  28.       all_lines.split(/[\r\n]+/).each { |line|
  29.         case line
  30.         when PARA
  31.           next unless @section
  32.           action = $1
  33.           value = $2.scan(/[^, ]+[^,]*/i)
  34.           #---
  35.           case action.upcase
  36.           when "MESSAGE OPTION"
  37.             if @sm
  38.               @message_option = []
  39.               value.each_index { |i|
  40.                 add = value[i]; add = add.to_i if i > 0
  41.                 @message_option.push(add)
  42.               }
  43.               next
  44.             end
  45.           when "COMMON EVENT"
  46.             common_event = RPG::EventCommand.new(117, 0, [value[0].to_i])
  47.             result[@section].push(common_event)
  48.           end
  49.         when COMMAND
  50.           next unless @section
  51.           case $1.to_s.upcase
  52.           when "SHOW MESSAGE"
  53.             if !@sm && !@sc
  54.               @sm = true
  55.               next
  56.             end
  57.           when "SCRIPT CALL"
  58.             if !@sm && !@sc
  59.               @sc = true
  60.               next
  61.             end
  62.           end
  63.         when END_COMMAND
  64.           next unless @section
  65.           case $1.to_s.upcase
  66.           when "SHOW MESSAGE"
  67.             @message_option = ["", 0, 0, 2] unless @message_option
  68.             option = RPG::EventCommand.new(101, 0, @message_option)
  69.             @message_option = nil
  70.             #---
  71.             result[@section].push(option)
  72.             @messages.each { |c| result[@section].push(c) }
  73.             @messages.clear
  74.             #---
  75.             @sm = false
  76.             next
  77.           when "SCRIPT CALL"
  78.             @scripts.each { |c| result[@section].push(c) }
  79.             @scripts.clear
  80.             @sc = false
  81.             next
  82.           end
  83.         when SECTION
  84.           if !@sm && !@sc
  85.             @section = $1.downcase
  86.             result[@section] ||= []
  87.           end
  88.         when END_SECTION
  89.           if !@sm && !@sc
  90.             @section = nil
  91.           end
  92.         end
  93.         if @sm
  94.           message = RPG::EventCommand.new(401, 0, [line.to_s])
  95.           @messages.push(message)
  96.         end
  97.         if @sc
  98.           code = @scripts.size > 0 ? 655 : 355
  99.           script = RPG::EventCommand.new(code, 0, [line.to_s])
  100.           @scripts.push(script)
  101.         end
  102.       }
  103.       #----
  104.       io.close
  105.       return result
  106.     end
  107.    
  108.   end
  109. end
  110.  
  111. class Game_Interpreter
  112.  
  113.   alias evtxt_setup setup
  114.   def setup(list, event_id = 0)
  115.     evtxt_setup(list, event_id)
  116.     setup_evtxt
  117.   end
  118.  
  119.   def setup_evtxt
  120.     @list.each_index { |i|
  121.       if [108, 408].include?(@list[i].code)
  122.         dummy = @list[i]
  123.         if @list[i].parameters[0] =~ /EVENT TEXT:[ ](.*)/i
  124.           value = $1.scan(/[^, ]+[^,]*/i)
  125.           result = Yami::Event_Text.parse(value[0])
  126.           if value[1]
  127.             result[value[1].downcase].reverse.each { |r| @list.insert(i, r) }
  128.           end
  129.           @list.delete(dummy)
  130.         end
  131.       end
  132.     }
  133.   end
  134.  
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement