Advertisement
polectron

Sistema DLCs

Jul 16th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. def downloadDLC(url)
  2. string = pbDownloadToString(url)
  3. data = pbParseJson(string)
  4. steps = data["steps"]
  5. counter = 0
  6. for step in steps
  7.  
  8. if step["type"] == "tileset"
  9. tilesets = pbLoadRxData("Data/Tilesets")
  10. if step["action"] == "add" || step["action"] == "update"
  11. pbDownloadToFile(step["file"],"Data/tempTilesets.rxdata")
  12. tempTilesets = pbLoadRxData("Data/tempTilesets")
  13. tilesets[step["id"]] = tempTilesets[step["id"]]
  14. save_data(tilesets,"Data/Tilesets.rxdata")
  15. begin
  16. File.delete("Data/tempTilesets.rxdata")
  17. rescue SystemCallError
  18. end
  19. end
  20. end
  21.  
  22. if step["type"] == "map"
  23. filename = step["file"].split("/")[-1]
  24. if step["action"] == "add"
  25. last = getMapLastOrder()+1
  26. pbDownloadToFile(step["file"], "Data/"+filename)
  27. maps = pbLoadRxData("Data/MapInfos")
  28. map = RPG::MapInfo.new
  29. map.name = step["name"]
  30. map.order = last
  31. maps[step["id"].to_i] = map
  32. save_data(maps,"Data/MapInfos.rxdata")
  33. elsif["action"] == "update"
  34. pbDownloadToFile(step["file"], "Data/"+filename)
  35. end
  36. end
  37.  
  38. if step["type"] == "audio"
  39. if step["action"] == "add" || step["action"] == "update"
  40. pbDownloadToFile(step["file"], "Audio/"+step["name"])
  41. end
  42. end
  43.  
  44. if step["type"] == "graphics"
  45. if step["action"] == "add" || step["action"] == "update"
  46. pbDownloadToFile(step["file"], "Graphics/"+step["name"])
  47. end
  48. end
  49.  
  50. if step["type"] == "script"
  51. if step["action"] == "add" || step["action"] == "update"
  52. content = pbDownloadToString(step["file"])
  53. pbAddScriptToFile(content, step["name"])
  54. end
  55. end
  56.  
  57. # if step["type"] == "pbs"
  58. # if step["action"] == "add" || step["action"] == "update"
  59. # pbDownloadToFile(step["file"], "PBS/"+filename)
  60. # end
  61. # end
  62.  
  63. if step["type"] == "data"
  64. if step["action"] == "add" || step["action"] == "update"
  65. pbDownloadToFile(step["file"], "Data/"+step["name"])
  66. end
  67. end
  68.  
  69. if step["type"] == "variable"
  70. $game_variables[step["id"]] = step["value"]
  71. end
  72.  
  73. if step["type"] == "switch"
  74. game_switches[step["id"]] = step["value"]
  75. end
  76.  
  77. counter += 1
  78. end
  79. $DEBUG = true
  80. msgwindow=Kernel.pbCreateMessageWindow
  81. pbCompileAllData(true) {|msg| Kernel.pbMessageDisplay(msgwindow,msg,false) }
  82. Kernel.pbMessageDisplay(msgwindow,_INTL("Se han compilado todos los datos del juego."))
  83. Kernel.pbDisposeMessageWindow(msgwindow)
  84. $DEBUG = false
  85. end
  86.  
  87. def manageDLCs()
  88. string = pbDownloadToString(DLCSURL)
  89. data = pbParseJson(string)
  90. dlcs = data["dlcs"]
  91. stopdownload = false
  92.  
  93. commands=[]
  94. list = []
  95. n = 0
  96.  
  97. for dlc in dlcs
  98. commands.push(dlc["name"])
  99. n += 1
  100. end
  101. commands.push(_INTL("Salir"))
  102.  
  103. loop do
  104. command=Kernel.pbShowCommands(nil,commands,-1)
  105. if command>=0 && command<commands.length-1
  106. command2=Kernel.pbMessage(_INTL("¿Qué quieres hacer con {1}?",
  107. dlcs[command]["name"]),[
  108. _INTL("Descargar"),
  109. _INTL("Info"),
  110. _INTL("Cancelar")
  111. ],-1)
  112. if command2==0 # Download
  113. pbFadeOutIn(99999){
  114. if !$PokemonGlobal.dlcs.include?(command)
  115. for dependency in dlcs[command]["requires"]
  116. if !$PokemonGlobal.dlcs.include?(dependency)
  117. Kernel.pbMessage(_INTL("Es necesario instalar {1} para poder instalar este DLC",dlcs[dependency]["name"]))
  118. stopdownload = true
  119. end
  120. end
  121. if !stopdownload
  122. Kernel.pbMessage(_INTL("Descargando"))
  123. downloadDLC(dlcs[command]["steps"])
  124. $PokemonGlobal.dlcs.push(command)
  125. Kernel.pbMessage(_INTL("Guardando..."))
  126. pbSave
  127. save_data($PokemonGlobal.dlcs,"Data/dlcs.dat")
  128. end
  129. else
  130. Kernel.pbMessage("Ya tienes instalado este DLC")
  131. end
  132. }
  133. elsif command2==1 # Info
  134. Kernel.pbMessage(_INTL("{1}",dlcs[command]["description"]))
  135. elsif command2==2 # Cancel
  136.  
  137. end
  138. else
  139. break
  140. end
  141. end
  142. end
  143.  
  144. def pbAddScriptToFile(script,sectionname)
  145. begin
  146. scripts=load_data("Data/Scripts.rxdata")
  147. scripts=[] if !scripts
  148. rescue
  149. scripts=[]
  150. end
  151. s=pbFindScript(scripts,sectionname)
  152. if s
  153. s[2]=script.unpack("m")[0]
  154. else
  155. tempscript = scripts[scripts.size-1]
  156. scripts[scripts.size-1] = [rand(100000000),sectionname,script.unpack("m")[0]]
  157. scripts.push(tempscript)
  158. end
  159. save_data(scripts,"Data/Scripts.rxdata")
  160. end
  161.  
  162. def getMapLastOrder()
  163. maps = pbLoadRxData("Data/MapInfos")
  164. last_order = 0
  165. last_id = 0
  166.  
  167. for id in maps.keys
  168. if maps[id].order > last_order
  169. last_order = maps[id].order
  170. end
  171. if id > last_id
  172. last_id = id
  173. end
  174. end
  175.  
  176. return last_order
  177. end
  178.  
  179. def reinstallDLCS()
  180. string = pbDownloadToString(DLCSURL)
  181. data = pbParseJson(string)
  182. dlcs = data["dlcs"]
  183. counter = 0
  184. for dlc in dlcs
  185. if $PokemonGlobal.dlcs.include?(counter)
  186. downloadDLC(dlc["steps"])
  187. end
  188. counter += 1
  189. end
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement