DaxSoft

Salvar Variável & Switche

Jan 25th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. #==============================================================================
  2. # • Salvar Variável & Switche
  3. #==============================================================================
  4. # Autor: Dax
  5. # Versão: 2.0
  6. # Site: www.dax-soft.weebly.com
  7. # Requerimento: Dax Core
  8. #==============================================================================
  9. # • Descrição:
  10. #------------------------------------------------------------------------------
  11. # Salva variáveis e switches num arquivo, permitindo assim, salvar os valores
  12. # delas e carrega-los.
  13. # SVS.save : Salva as informações.
  14. # SVS.load : Carrega as informações.
  15. #==============================================================================
  16. Dax.register(:SVS, "Dax", 2.0, "13/01/15")
  17. # Módulo Salvar Variável e Switche | Carregar.
  18. module SVS
  19. # extensão self
  20. extend self
  21. # Deixe dentro dá constante abaixo os ID de cada variável que irá ser salva.
  22. IDV = [1, 2, 3]
  23. # Deixe dentro dá constante abaixo os ID de cada switche que irá ser salva.
  24. ISW = [1, 2, 3]
  25. # Deixe true, para fazer todo o processo automáticamente. Ou deixe false
  26. # para deixar a vossa escolha.
  27. PROCESS = true
  28. # Salvar.
  29. def save()
  30. str = ""
  31. variables = []
  32. switches = []
  33. IDV.each { |i| variables[i] = $game_variables[i] }
  34. ISW.each { |i| switches[i] = $game_switches[i] }
  35. variables, switches = variables.compact, switches.compact
  36. file = File.open("./__switche_variables.txt", "wb")
  37. variables.each_with_index { |v, i|
  38. str << "<variables:#{IDV[i]}>#{v}</variables>\t"
  39. str << "\r\n"
  40. }
  41. switches.each_with_index { |v, i|
  42. str << "<switches:#{ISW[i]}>#{v}</switches>"
  43. str << "\r\n"
  44. }
  45. file.write(str)
  46. file.close
  47. Crypt.enfile("./__switche_variables.txt", true)
  48. end
  49. # Load
  50. def load()
  51. return unless FileTest.exist?("./__switche_variables.drvd2")
  52. boolean = ->(str) {
  53. return false if str == "false"
  54. return true if str == "true"
  55. }
  56. Crypt.rdefile("./__switche_variables.drvd2").split(/\n/).each { |s|
  57. if s =~ /<variables:(\d+)>(\d+)<\/variables>/im
  58. $game_variables[$1.to_i] = $2.to_i
  59. next
  60. elsif s =~ /<switches:(\d+)>(\w+)<\/switches>/im
  61. $game_switches[$1.to_i] = boolean[$2]
  62. next
  63. end
  64. next
  65. }
  66. end
  67. # Métodos... (NÃO MEXA AQUI CASO NÃO SAIBA DO QUE SE TRATA.)
  68. DEFS_ = [["on_save_success", "on_load_success", "goto_title"], ["File", "File", "Base"],
  69. ["save", "load", "save"]]
  70. end
  71. # Processo automático.
  72. if SVS::PROCESS
  73. # Cenas que irão ser salvas.
  74. ["Scene_Save", "Scene_Load", "Scene_Gameover"].each_with_index { |scene, index|
  75. eval("
  76. class #{scene} < Scene_#{SVS::DEFS_[1][index]}
  77. alias :savedVariablesAndSwitche_#{SVS::DEFS_[0][index]} :#{SVS::DEFS_[0][index]}
  78. def #{SVS::DEFS_[0][index]}
  79. savedVariablesAndSwitche_#{SVS::DEFS_[0][index]}
  80. SVS.#{SVS::DEFS_[2][index]}
  81. end
  82. end
  83. ")
  84. }
  85. end
Advertisement
Add Comment
Please, Sign In to add comment