Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - External Texts (Adjusted for ASR)
- # Version : 1.0
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (This script documentation is written in informal indonesian language)
- # =============================================================================
- ($imported ||= {})[:Theo_ExternalTexts] = true
- # =============================================================================
- # Change Logs:
- # -----------------------------------------------------------------------------
- # 2014.02.07 - Finished script
- # =============================================================================
- =begin
- Perkenalan :
- Sempat berkeinginan untuk ngebikin game kamu jadi dual language? Namun keburu
- males duluan lantaran bakal kebanyakan percabangan? Pengen nyatet dialog
- in game pake file external biar bisa saling cross check dengan timmu? Script
- ini bisa menjawab keinginanmu
- Cara penggunaan :
- Pasang script ini di bawah material namun di atas main
- Buat folder baru di dalam folder data dengan nama "Texts"
- Buat file baru di dalam folder tersebut dengan Ms.Excel (atawa software
- sejenisnya). Isi dengan format yang udah wa jelasin diblog. Simpan dengan
- ekstensi [dot]csv
- Terms of use :
- Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
- keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
- dipake buat komersil, jangan lupa, gw dibagi gratisannya.
- =end
- # =============================================================================
- # Tentukan switch ID untuk merubah bahasa disini. Isi dengan 0 jika kamu
- # tidak menggunakannya
- # =============================================================================
- TextSwitch = 20
- # =============================================================================
- # Jangan sentuh apapun setelah baris ini
- # =============================================================================
- module Theo
- module MsgCache
- Text_Key = /<(.+)>/
- Text_Skip = /#+/
- def self.init
- @cache = {}
- end
- def self.openfile(path)
- path = "Data/Texts/#{path}.csv"
- if @cache[path]
- @cache[path]
- else
- set_cache(path)
- end
- end
- def self.set_cache(path)
- @cache[path] = TextMessages.new(path)
- @cache[path]
- end
- def self.get_text(path, key)
- openfile(path).get_text(key) rescue nil
- end
- end
- end
- Theo::MsgCache.init
- class Game_Interpreter
- def set_message(path, key)
- wait_for_message
- text_file = Theo::MsgCache.get_text(path, key)
- unless text_file
- msgbox "Message with following keys doesn't exist\n\n"+
- "Path : #{path}.csv\n"+
- "Key : #{key}\n\n"+
- "Please recheck once again"
- return
- end
- eval(text_file.face_name)
- $game_message.background = text_file.background
- $game_message.position = text_file.position
- text_file.get_text.each do |text_msg|
- $game_message.add(text_msg)
- end
- case next_event_code
- when 102 # Show Choices
- @index += 1
- setup_choices(@list[@index].parameters)
- when 103 # Input Number
- @index += 1
- setup_num_input(@list[@index].parameters)
- when 104 # Select Item
- @index += 1
- setup_item_choice(@list[@index].parameters)
- end
- wait_for_message
- end
- end
- class TextMessages
- def initialize(path)
- @texts = {}
- @path = path
- setup(path)
- end
- def setup(path)
- file = File.open(path, 'r')
- text_node = nil
- file.each_line do |data|
- array = data.split(/[\n;]/)
- next if array[0] =~ Theo::MsgCache::Text_Skip
- if array[0][Theo::MsgCache::Text_Key]
- key = $1.to_s
- text_node = TextMessage.new
- text_node.face_name = array[1].to_s
- #~ text_node.face_index = array[2].to_i
- text_node.position = array[2].to_i if array[2]
- text_node.background = array[3].to_i
- @texts[key] = text_node
- elsif text_node
- text_node.text1.push(array[0]) if !array[0].empty?
- text2 = array[1].to_s
- text_node.text2.push(text2) if !text2.empty?
- end
- end
- file.close
- end
- def get_text(key)
- @texts[key]
- end
- end
- class TextMessage
- attr_accessor :face_index
- attr_accessor :face_name
- attr_accessor :position
- attr_accessor :background
- attr_accessor :text1
- attr_accessor :text2
- def initialize
- @face_index = 0
- @face_name = ''
- @position = 2
- @background = 0
- @text1 = []
- @text2 = []
- end
- def get_text
- $game_switches[TextSwitch] ? text2 : text1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment