Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #AssetRain - Brupter
- #1: Put this in the same place as the folder from Trillix/ClientTools and your project folder
- #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
- #i.e.: python3.6 AssetRain.py AssetsFolder ProjectFolder
- import os, sys, glob
- #Remove all .as files within the folder
- def removeAS(path):
- for file in glob.glob(path + '/src/**/*.as', recursive = True):
- os.remove(file)
- #Remove empty folders, not needed, but helpful if you plan to manually move the files from the Trillix folder to your project folder
- def removeEmptyFolders(path):
- #Make sure the current path is to a folder
- if not os.path.isdir(path):
- return
- files = os.listdir(path)
- #For each file in the current folder, recursively run removeEmptyFolders
- if len(files):
- for f in files:
- nextpath = os.path.join(path, f)
- removeEmptyFolders(nextpath)
- files = os.listdir(path)
- #If the only file left in the current folder is .DS_Store, delete it so the folder is empty
- if len(files) == 1:
- if files[0] == ".DS_Store":
- os.remove(path + "/.DS_Store")
- files = []
- #If the current folder is empty, delete it
- if len(files) == 0:
- os.rmdir(path)
- def createNewAssetAS(path):
- 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}"
- 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}"
- 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}"
- 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}"
- 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}"
- 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}"
- #For all .png files, create an actionscript file with the correct format
- for png in glob.glob(path + '/src/**/*.png', recursive = True):
- filename = png[:-4] + ".as"
- package, name = png.rsplit('/', 1)
- package = package[len(path)+1:]
- name = name[:-4]
- package = package.replace('/', '.')[4:]
- asfile = open(filename, 'w')
- asfile.write(pngformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
- asfile.close()
- #For all .jpg files, create an actionscript file with the correct format
- for jpg in glob.glob(path + '/src/**/*.jpg', recursive = True):
- filename = jpg[:-4] + ".as"
- package, name = jpg.rsplit('/', 1)
- package = package[len(path)+1:]
- name = name[:-4]
- package = package.replace('/', '.')[4:]
- asfile = open(filename, 'w')
- asfile.write(jpgformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
- asfile.close()
- #For all .dat files, create an actionscript file with the correct format
- for dat in glob.glob(path + '/src/**/*.dat', recursive = True):
- filename = dat[:-4] + ".as"
- package, name = dat.rsplit('/', 1)
- package = package[len(path)+1:]
- name = name[:-4]
- package = package.replace('/', '.')[4:]
- asfile = open(filename, 'w')
- asfile.write(datformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
- asfile.close()
- #For all .swf files, create an actionscript file with the correct format
- for swf in glob.glob(path + '/src/**/*.swf', recursive = True):
- filename = swf[:-4] + ".as"
- package, name = swf.rsplit('/', 1)
- asfile = open(filename, 'w')
- if (name == "MapLoadingScreen.swf"):
- asfile.write(maploadingscreen)
- else:
- package = package[len(path)+1:]
- name = name[:-4]
- package = package.replace('/', '.')[4:]
- if (name.lower().find("font") != -1) or (name.lower().find("text") != -1):
- asfile.write(swffontformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
- else:
- asfile.write(swfgraphicsformat.replace("NAMEHOLDER", name).replace("PACKAGEHOLDER", package))
- asfile.close()
- #Move files from the Trillix folder to the same location in the project folder
- def relocate(path1, path2):
- for file in glob.glob(path1 + '/src/**/*', recursive = True):
- if not os.path.isdir(file):
- #newfile is the same path but within the project folder
- newfile = path2 + file[len(path1):]
- #Delete the file in the project folder if it exists
- if os.path.isfile(newfile):
- os.remove(newfile)
- #Move the file from the Trillix folder to the project folder
- os.rename(file, newfile)
- def main():
- #Make sure there is at least one argument
- if len(sys.argv) == 1:
- print("Please at least include the path of the folder from Trillix")
- return
- #Get the path of the Trillix folder
- cwd = os.getcwd()
- trillixPath = cwd + '/' + sys.argv[1]
- if trillixPath[-1] == '/':
- trillixPath = trillixPath[:-1]
- #If the path is valid, run the first 3 functions
- if (os.path.isdir(trillixPath)):
- print("Removing .as files...")
- removeAS(trillixPath)
- print("Removing empty folders...")
- removeEmptyFolders(trillixPath)
- print("Generating new .as files...")
- createNewAssetAS(trillixPath)
- else:
- print(trillixPath + " is not a directory, please try again.")
- return
- #If there is a second argument, get the path of the project folder
- if len(sys.argv) == 3:
- projectPath = cwd + '/' + sys.argv[2]
- if projectPath[-1] == '/':
- projectPath = projectPath[:-1]
- #If the path is valid, relocate the files
- if os.path.isdir(projectPath):
- print("Relocating files...")
- relocate(trillixPath, projectPath)
- else:
- print(projectPath + " is not a directory, please try again.")
- return
- print("Finished!")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment