Guest User

Untitled

a guest
Nov 4th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. #AssetRain - Brupter
  2. #1: Put this in the same place as the folder from Trillix/ClientTools and your project folder
  3. #2: Run with the assets folder as the first argument and the project folder as a second optional argument if you want it to automatically move the files as well
  4. #i.e.: python3.6 AssetRain.py AssetsFolder ProjectFolder
  5.  
  6. import os, sys, glob
  7.  
  8. #Remove all .as files within the folder
  9. def removeAS(path):
  10. for file in glob.glob(path + '/src/**/*.as', recursive = True):
  11. os.remove(file)
  12.  
  13.  
  14. #Remove empty folders, not needed, but helpful if you plan to manually move the files from the Trillix folder to your project folder
  15. def removeEmptyFolders(path):
  16. #Make sure the current path is to a folder
  17. if not os.path.isdir(path):
  18. return
  19.  
  20. files = os.listdir(path)
  21. #For each file in the current folder, recursively run removeEmptyFolders
  22. if len(files):
  23. for f in files:
  24. nextpath = os.path.join(path, f)
  25. removeEmptyFolders(nextpath)
  26.  
  27. files = os.listdir(path)
  28. #If the only file left in the current folder is .DS_Store, delete it so the folder is empty
  29. if len(files) == 1:
  30. if files[0] == ".DS_Store":
  31. os.remove(path + "/.DS_Store")
  32. files = []
  33. #If the current folder is empty, delete it
  34. if len(files) == 0:
  35. os.rmdir(path)
  36.  
  37.  
  38. def createNewAssetAS(path):
  39. pngformat = "package PACKAGEHOLDER\n{\n\timport mx.core.*;\n\n\t[Embed(source=\"NAMEHOLDER.png\")]\n\tpublic class NAMEHOLDER extends mx.core.BitmapAsset\n\t{\n\t\tpublic function NAMEHOLDER()\n\t\t{\n\t\t}\n\t}\n}"
  40. jpgformat = "package PACKAGEHOLDER\n{\n\timport mx.core.*;\n\n\t[Embed(source=\"NAMEHOLDER.jpg\")]\n\tpublic class NAMEHOLDER extends mx.core.BitmapAsset\n\t{\n\t\tpublic function NAMEHOLDER()\n\t\t{\n\t\t}\n\t}\n}"
  41. datformat = "package PACKAGEHOLDER\n{\n\timport mx.core.*;\n\n\t[Embed(source=\"NAMEHOLDER.dat\", mimeType=\"application/octet-stream\")]\n\tpublic class NAMEHOLDER extends mx.core.ByteArrayAsset\n\t{\n\t\tpublic function NAMEHOLDER()\n\t\t{\n\t\t}\n\t}\n}"
  42. swfgraphicsformat = "package PACKAGEHOLDER\n{\n\timport flash.display.MovieClip;\n\n\t[Embed(source=\"NAMEHOLDER.swf\", symbol=\"PACKAGEHOLDER.NAMEHOLDER\")]\n\tpublic dynamic class NAMEHOLDER extends MovieClip\n\t{\n\t\tpublic function NAMEHOLDER()\n\t\t{\n\t\t}\n\t}\n}"
  43. swffontformat = "package PACKAGEHOLDER\n{\n\timport mx.core.*;\n\n\t[Embed(source=\"NAMEHOLDER.swf\", symbol=\"PACKAGEHOLDER.NAMEHOLDER\")]\n\tpublic class NAMEHOLDER extends FontAsset\n\t{\n\tpublic function NAMEHOLDER()\n\t\t{\n\t\t}\n\t}\n}"
  44. maploadingscreen = "package\n{\n\timport flash.display.MovieClip;\n\n\t[Embed(source=\"MapLoadingScreen.swf\", symbol=\"MapLoadingScreen\")]\n\tpublic dynamic class MapLoadingScreen extends MovieClip\n\t{\n\t\tpublic function MapLoadingScreen()\n\t\t{\n\t\t}\n\t\tpublic var difficulty_indicators:MovieClip;\n\t\tpublic var mapNameContainer:MovieClip;\n\t\tpublic var bgGroup:MovieClip;\n\t}\n}"
  45.  
  46. #For all .png files, create an actionscript file with the correct format
  47. for png in glob.glob(path + '/src/**/*.png', recursive = True):
  48. filename = png[:-4] + ".as"
  49. package, name = png.rsplit('/', 1)
  50. package = package[len(path)+1:]
  51. name = name[:-4]
  52. package = package.replace('/', '.')[4:]
  53. asfile = open(filename, 'w')
  54. asfile.write(pngformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
  55. asfile.close()
  56.  
  57. #For all .jpg files, create an actionscript file with the correct format
  58. for jpg in glob.glob(path + '/src/**/*.jpg', recursive = True):
  59. filename = jpg[:-4] + ".as"
  60. package, name = jpg.rsplit('/', 1)
  61. package = package[len(path)+1:]
  62. name = name[:-4]
  63. package = package.replace('/', '.')[4:]
  64. asfile = open(filename, 'w')
  65. asfile.write(jpgformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
  66. asfile.close()
  67.  
  68. #For all .dat files, create an actionscript file with the correct format
  69. for dat in glob.glob(path + '/src/**/*.dat', recursive = True):
  70. filename = dat[:-4] + ".as"
  71. package, name = dat.rsplit('/', 1)
  72. package = package[len(path)+1:]
  73. name = name[:-4]
  74. package = package.replace('/', '.')[4:]
  75. asfile = open(filename, 'w')
  76. asfile.write(datformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
  77. asfile.close()
  78.  
  79. #For all .swf files, create an actionscript file with the correct format
  80. for swf in glob.glob(path + '/src/**/*.swf', recursive = True):
  81. filename = swf[:-4] + ".as"
  82. package, name = swf.rsplit('/', 1)
  83. asfile = open(filename, 'w')
  84. if (name == "MapLoadingScreen.swf"):
  85. asfile.write(maploadingscreen)
  86. else:
  87. package = package[len(path)+1:]
  88. name = name[:-4]
  89. package = package.replace('/', '.')[4:]
  90. if (name.lower().find("font") != -1) or (name.lower().find("text") != -1):
  91. asfile.write(swffontformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
  92. else:
  93. asfile.write(swfgraphicsformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
  94. asfile.close()
  95.  
  96.  
  97.  
  98. #Move files from the Trillix folder to the same location in the project folder
  99. def relocate(path1, path2):
  100. for file in glob.glob(path1 + '/src/**/*', recursive = True):
  101. if not os.path.isdir(file):
  102. #newfile is the same path but within the project folder
  103. newfile = path2 + file[len(path1):]
  104.  
  105. #Delete the file in the project folder if it exists
  106. if os.path.isfile(newfile):
  107. os.remove(newfile)
  108.  
  109. #Move the file from the Trillix folder to the project folder
  110. os.rename(file, newfile)
  111.  
  112.  
  113. def main():
  114. #Make sure there is at least one argument
  115. if len(sys.argv) == 1:
  116. print("Please at least include the path of the folder from Trillix")
  117. return
  118.  
  119. #Get the path of the Trillix folder
  120. cwd = os.getcwd()
  121. trillixPath = cwd + '/' + sys.argv[1]
  122. if trillixPath[-1] == '/':
  123. trillixPath = trillixPath[:-1]
  124.  
  125. #If the path is valid, run the first 3 functions
  126. if (os.path.isdir(trillixPath)):
  127. print("Removing .as files...")
  128. removeAS(trillixPath)
  129. print("Removing empty folders...")
  130. removeEmptyFolders(trillixPath)
  131. print("Generating new .as files...")
  132. createNewAssetAS(trillixPath)
  133. else:
  134. print(trillixPath + " is not a directory, please try again.")
  135. return
  136.  
  137. #If there is a second argument, get the path of the project folder
  138. if len(sys.argv) == 3:
  139. projectPath = cwd + '/' + sys.argv[2]
  140. if projectPath[-1] == '/':
  141. projectPath = projectPath[:-1]
  142.  
  143. #If the path is valid, relocate the files
  144. if os.path.isdir(projectPath):
  145. print("Relocating files...")
  146. relocate(trillixPath, projectPath)
  147. else:
  148. print(projectPath + " is not a directory, please try again.")
  149. return
  150.  
  151. print("Finished!")
  152.  
  153. if __name__ == "__main__":
  154. main()
Advertisement
Add Comment
Please, Sign In to add comment