Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • Salvar Variável & Switche
- #==============================================================================
- # Autor: Dax
- # Versão: 2.0
- # Site: www.dax-soft.weebly.com
- # Requerimento: Dax Core
- #==============================================================================
- # • Descrição:
- #------------------------------------------------------------------------------
- # Salva variáveis e switches num arquivo, permitindo assim, salvar os valores
- # delas e carrega-los.
- # SVS.save : Salva as informações.
- # SVS.load : Carrega as informações.
- #==============================================================================
- Dax.register(:SVS, "Dax", 2.0, "13/01/15")
- # Módulo Salvar Variável e Switche | Carregar.
- module SVS
- # extensão self
- extend self
- # Deixe dentro dá constante abaixo os ID de cada variável que irá ser salva.
- IDV = [1, 2, 3]
- # Deixe dentro dá constante abaixo os ID de cada switche que irá ser salva.
- ISW = [1, 2, 3]
- # Deixe true, para fazer todo o processo automáticamente. Ou deixe false
- # para deixar a vossa escolha.
- PROCESS = true
- # Salvar.
- def save()
- str = ""
- variables = []
- switches = []
- IDV.each { |i| variables[i] = $game_variables[i] }
- ISW.each { |i| switches[i] = $game_switches[i] }
- variables, switches = variables.compact, switches.compact
- file = File.open("./__switche_variables.txt", "wb")
- variables.each_with_index { |v, i|
- str << "<variables:#{IDV[i]}>#{v}</variables>\t"
- str << "\r\n"
- }
- switches.each_with_index { |v, i|
- str << "<switches:#{ISW[i]}>#{v}</switches>"
- str << "\r\n"
- }
- file.write(str)
- file.close
- Crypt.enfile("./__switche_variables.txt", true)
- end
- # Load
- def load()
- return unless FileTest.exist?("./__switche_variables.drvd2")
- boolean = ->(str) {
- return false if str == "false"
- return true if str == "true"
- }
- Crypt.rdefile("./__switche_variables.drvd2").split(/\n/).each { |s|
- if s =~ /<variables:(\d+)>(\d+)<\/variables>/im
- $game_variables[$1.to_i] = $2.to_i
- next
- elsif s =~ /<switches:(\d+)>(\w+)<\/switches>/im
- $game_switches[$1.to_i] = boolean[$2]
- next
- end
- next
- }
- end
- # Métodos... (NÃO MEXA AQUI CASO NÃO SAIBA DO QUE SE TRATA.)
- DEFS_ = [["on_save_success", "on_load_success", "goto_title"], ["File", "File", "Base"],
- ["save", "load", "save"]]
- end
- # Processo automático.
- if SVS::PROCESS
- # Cenas que irão ser salvas.
- ["Scene_Save", "Scene_Load", "Scene_Gameover"].each_with_index { |scene, index|
- eval("
- class #{scene} < Scene_#{SVS::DEFS_[1][index]}
- alias :savedVariablesAndSwitche_#{SVS::DEFS_[0][index]} :#{SVS::DEFS_[0][index]}
- def #{SVS::DEFS_[0][index]}
- savedVariablesAndSwitche_#{SVS::DEFS_[0][index]}
- SVS.#{SVS::DEFS_[2][index]}
- end
- end
- ")
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment