TheoAllen

ASR - External Text

Feb 10th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.72 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - External Texts (Adjusted for ASR)
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_ExternalTexts] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2014.02.07 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Sempat berkeinginan untuk ngebikin game kamu jadi dual language? Namun keburu
  17.   males duluan lantaran bakal kebanyakan percabangan? Pengen nyatet dialog
  18.   in game pake file external biar bisa saling cross check dengan timmu? Script
  19.   ini bisa menjawab keinginanmu
  20.  
  21.   Cara penggunaan :
  22.   Pasang script ini di bawah material namun di atas main
  23.   Buat folder baru di dalam folder data dengan nama "Texts"
  24.  
  25.   Buat file baru di dalam folder tersebut dengan Ms.Excel (atawa software
  26.   sejenisnya). Isi dengan format yang udah wa jelasin diblog. Simpan dengan
  27.   ekstensi [dot]csv
  28.  
  29.   Terms of use :
  30.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  31.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  32.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.    
  33.  
  34. =end
  35. # =============================================================================
  36. # Tentukan switch ID untuk merubah bahasa disini. Isi dengan 0 jika kamu
  37. # tidak menggunakannya
  38. # =============================================================================
  39.   TextSwitch = 20
  40. # =============================================================================
  41. # Jangan sentuh apapun setelah baris ini
  42. # =============================================================================
  43. module Theo
  44.   module MsgCache
  45.     Text_Key = /<(.+)>/
  46.     Text_Skip = /#+/
  47.    
  48.     def self.init
  49.       @cache = {}
  50.     end
  51.  
  52.     def self.openfile(path)
  53.       path = "Data/Texts/#{path}.csv"
  54.       if @cache[path]
  55.         @cache[path]
  56.       else
  57.         set_cache(path)
  58.       end
  59.     end
  60.  
  61.     def self.set_cache(path)
  62.       @cache[path] = TextMessages.new(path)
  63.       @cache[path]
  64.     end
  65.  
  66.     def self.get_text(path, key)
  67.       openfile(path).get_text(key) rescue nil
  68.     end
  69.   end
  70. end
  71. Theo::MsgCache.init
  72. class Game_Interpreter
  73.  
  74.   def set_message(path, key)
  75.     wait_for_message
  76.     text_file = Theo::MsgCache.get_text(path, key)
  77.     unless text_file
  78.       msgbox "Message with following keys doesn't exist\n\n"+
  79.       "Path : #{path}.csv\n"+
  80.       "Key : #{key}\n\n"+
  81.       "Please recheck once again"
  82.       return
  83.     end
  84.     eval(text_file.face_name)
  85.     $game_message.background  = text_file.background
  86.     $game_message.position    = text_file.position
  87.     text_file.get_text.each do |text_msg|
  88.       $game_message.add(text_msg)
  89.     end
  90.     case next_event_code
  91.     when 102  # Show Choices
  92.       @index += 1
  93.       setup_choices(@list[@index].parameters)
  94.     when 103  # Input Number
  95.       @index += 1
  96.       setup_num_input(@list[@index].parameters)
  97.     when 104  # Select Item
  98.       @index += 1
  99.       setup_item_choice(@list[@index].parameters)
  100.     end
  101.     wait_for_message
  102.   end
  103.  
  104. end
  105.  
  106. class TextMessages
  107.  
  108.   def initialize(path)
  109.     @texts = {}
  110.     @path = path
  111.     setup(path)
  112.   end
  113.  
  114.   def setup(path)
  115.     file = File.open(path, 'r')
  116.     text_node = nil
  117.     file.each_line do |data|
  118.       array = data.split(/[\n;]/)
  119.       next if array[0] =~ Theo::MsgCache::Text_Skip
  120.       if array[0][Theo::MsgCache::Text_Key]
  121.         key = $1.to_s
  122.         text_node = TextMessage.new
  123.         text_node.face_name = array[1].to_s
  124. #~         text_node.face_index = array[2].to_i
  125.         text_node.position = array[2].to_i if array[2]
  126.         text_node.background = array[3].to_i
  127.         @texts[key] = text_node
  128.       elsif text_node
  129.         text_node.text1.push(array[0]) if !array[0].empty?
  130.         text2 = array[1].to_s
  131.         text_node.text2.push(text2) if !text2.empty?
  132.       end
  133.     end
  134.     file.close
  135.   end
  136.  
  137.   def get_text(key)
  138.     @texts[key]
  139.   end
  140.  
  141. end
  142.  
  143. class TextMessage
  144.   attr_accessor :face_index
  145.   attr_accessor :face_name
  146.   attr_accessor :position
  147.   attr_accessor :background
  148.   attr_accessor :text1
  149.   attr_accessor :text2
  150.  
  151.   def initialize
  152.     @face_index = 0
  153.     @face_name = ''
  154.     @position = 2
  155.     @background = 0
  156.     @text1 = []
  157.     @text2 = []
  158.   end
  159.  
  160.   def get_text
  161.     $game_switches[TextSwitch] ? text2 : text1
  162.   end
  163.  
  164. end
Advertisement
Add Comment
Please, Sign In to add comment