Created
June 30, 2013 18:42
-
-
Save ethernet8023/5896346 to your computer and use it in GitHub Desktop.
Pass a GM Studio project / project directory / object / script as argument 1, and get it beautified for you ;)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import jsbeautifier | |
| import os | |
| import sys | |
| import re | |
| def beautifyObject(filePath): | |
| f = open(filePath, 'r+') | |
| obj = BeautifulSoup(f, 'xml') | |
| f.close() | |
| for event in obj.find_all('event'): | |
| for action in event.find_all('action'): | |
| try: | |
| if not action.arguments.argument.find('string') is None: | |
| s = action.arguments.argument.find('string') | |
| s.string = jsbeautifier.beautify(s.string) | |
| except: | |
| pass | |
| bsString = obj.prettify() | |
| text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL) | |
| prettyXml = text_re.sub('>\g<1></', bsString) | |
| f = open(filePath, 'w+') | |
| f.write(prettyXml) | |
| f.close() | |
| if __name__ == '__main__': | |
| path = sys.argv[1] | |
| if path.endswith('.gmx'): | |
| print('Working Path: ' + path) | |
| if os.path.isfile(path): | |
| if path.endswith('.project.gmx'): | |
| path, filename = os.path.split(path) | |
| elif path.endswith('.object.gmx'): | |
| print('GameMaker:Studio Object found, beautifying XML and GML...', end='') | |
| beautifyObject(path) | |
| print('prettified & beautified!') | |
| elif path.endswith('.gml'): | |
| print('GameMaker Script found, beautifying GML...', end='') | |
| gml = jsbeautifier.beautify_file(path) | |
| f = open(path, 'w+') | |
| f.write(gml) | |
| f.close() | |
| print('beautified!') | |
| if os.path.isdir(path) and path.endswith('.gmx') and os.path.exists(path + '\\objects\\') and os.path.exists(path + '\\scripts\\'): | |
| print('GameMaker:Studio Project found, beautifying all objects and scripts') | |
| objectsDir = path + '\\objects\\' | |
| scriptsDir = path + '\\scripts\\' | |
| for subdir, dirs, files in os.walk(objectsDir): | |
| for file in files: | |
| print('Found object: ' + file + '...', end='') | |
| beautifyObject(os.path.join(objectsDir, file)) | |
| print('prettified & beautified!') | |
| for subdir, dirs, files in os.walk(scriptsDir): | |
| for file in files: | |
| print('Found script:' + file + '...', end='') | |
| gml = jsbeautifier.beautify_file(os.path.join(scriptsDir, file)) | |
| f = open(os.path.join(scriptsDir, file), 'w+') | |
| f.write(gml) | |
| f.close() | |
| print('beautified!') | |
| else: | |
| print('Woah! That\'s not a GameMaker:Studio File/Project!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment