Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Yami
- module Event_Text
- # Configuration
- TEXT_FOLDER = "Text"
- # Regular Expression
- COMMAND = /(.*):/i
- END_COMMAND = /END (.*)/i
- PARA = /[ ]*(.*):[ ]*(.+)/i
- SECTION = /SECTION[ ](\w+)/
- END_SECTION = /END SECTION/
- # Parses Command
- def self.parse(file)
- file = TEXT_FOLDER + "/" + file
- return [] unless FileTest.exist?(file)
- result = {}
- io = File.open(file)
- all_lines = io.read
- #----
- @sm = false
- @sc = false
- @messages = []
- @scripts = []
- @section = nil
- #----
- all_lines.split(/[\r\n]+/).each { |line|
- case line
- when PARA
- next unless @section
- action = $1
- value = $2.scan(/[^, ]+[^,]*/i)
- #---
- case action.upcase
- when "MESSAGE OPTION"
- if @sm
- @message_option = []
- value.each_index { |i|
- add = value[i]; add = add.to_i if i > 0
- @message_option.push(add)
- }
- next
- end
- when "COMMON EVENT"
- common_event = RPG::EventCommand.new(117, 0, [value[0].to_i])
- result[@section].push(common_event)
- end
- when COMMAND
- next unless @section
- case $1.to_s.upcase
- when "SHOW MESSAGE"
- if !@sm && !@sc
- @sm = true
- next
- end
- when "SCRIPT CALL"
- if !@sm && !@sc
- @sc = true
- next
- end
- end
- when END_COMMAND
- next unless @section
- case $1.to_s.upcase
- when "SHOW MESSAGE"
- @message_option = ["", 0, 0, 2] unless @message_option
- option = RPG::EventCommand.new(101, 0, @message_option)
- @message_option = nil
- #---
- result[@section].push(option)
- @messages.each { |c| result[@section].push(c) }
- @messages.clear
- #---
- @sm = false
- next
- when "SCRIPT CALL"
- @scripts.each { |c| result[@section].push(c) }
- @scripts.clear
- @sc = false
- next
- end
- when SECTION
- if !@sm && !@sc
- @section = $1.downcase
- result[@section] ||= []
- end
- when END_SECTION
- if !@sm && !@sc
- @section = nil
- end
- end
- if @sm
- message = RPG::EventCommand.new(401, 0, [line.to_s])
- @messages.push(message)
- end
- if @sc
- code = @scripts.size > 0 ? 655 : 355
- script = RPG::EventCommand.new(code, 0, [line.to_s])
- @scripts.push(script)
- end
- }
- #----
- io.close
- return result
- end
- end
- end
- class Game_Interpreter
- alias evtxt_setup setup
- def setup(list, event_id = 0)
- evtxt_setup(list, event_id)
- setup_evtxt
- end
- def setup_evtxt
- @list.each_index { |i|
- if [108, 408].include?(@list[i].code)
- dummy = @list[i]
- if @list[i].parameters[0] =~ /EVENT TEXT:[ ](.*)/i
- value = $1.scan(/[^, ]+[^,]*/i)
- result = Yami::Event_Text.parse(value[0])
- if value[1]
- result[value[1].downcase].reverse.each { |r| @list.insert(i, r) }
- end
- @list.delete(dummy)
- end
- end
- }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement