Advertisement
polectron

Untitled

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