From d5990e24c39474cfea7ada9831a3ecc884d298bd Mon Sep 17 00:00:00 2001 From: BombasticTom <85838311+BombasticTom@users.noreply.github.com> Date: Thu, 23 May 2024 17:50:17 +0200 Subject: [PATCH] tweaks and fixes --- .gitignore | 1 - psychtobase/main.py | 795 ++++++++++++++-------------- psychtobase/src/Utils.py | 9 +- psychtobase/src/tools/ChartTools.py | 2 + 4 files changed, 407 insertions(+), 400 deletions(-) diff --git a/.gitignore b/.gitignore index 3675517..4688027 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ Weekend1/ vs-skippa-psychengine/ ## Files -**/SONGTEST/* CodeTest.py fnf-porter.code-workspace Thumbs.db diff --git a/psychtobase/main.py b/psychtobase/main.py index 8503f88..9d36e6d 100644 --- a/psychtobase/main.py +++ b/psychtobase/main.py @@ -20,428 +20,427 @@ vocalSplitMasterToggle = True def folderMake(folder_path): - if not os.path.exists(folder_path): - try: - os.makedirs(folder_path) - except Exception as e: - logging.error(f'Something went wrong: {e}') + if not os.path.exists(folder_path): + try: + os.makedirs(folder_path) + except Exception as e: + logging.error(f'Something went wrong: {e}') def fileCopy(source, destination): - if os.path.exists(source): - try: - shutil.copyfile(source, destination) - except Exception as e: - logging.error(f'Something went wrong: {e}') - else: - logging.warn(f'Path {source} doesn\'t exist.') + if os.path.exists(source): + try: + shutil.copyfile(source, destination) + except Exception as e: + logging.error(f'Something went wrong: {e}') + else: + logging.warn(f'Path {source} doesn\'t exist.') def treeCopy(source, destination): - if not os.path.exists(destination) and os.path.exists(source): - try: - shutil.copytree(source, destination) - except Exception as e: - logging.error(f'Something went wrong: {e}') - elif not os.path.exists(source): - logging.warn(f'Path {source} does not exist.') + if not os.path.exists(destination) and os.path.exists(source): + try: + shutil.copytree(source, destination) + except Exception as e: + logging.error(f'Something went wrong: {e}') + elif not os.path.exists(source): + logging.warn(f'Path {source} does not exist.') def convert(psych_mod_folder, result_folder, options): - runtime = time.process_time() - - logging.info(""" - -============================= - NEW CONVERSION STARTED -============================= - """) - - logging.info('Converting started...') - logging.info(options) - - modName = psych_mod_folder # MOD FOLDER PSYCH ENGINE - modFoldername = os.path.basename(psych_mod_folder) - - logging.info(f'Converting from{psych_mod_folder} to {result_folder}') - - if options.get('modpack_meta', False): - logging.info('Converting pack.json') - - dir = Constants.FILE_LOCS.get('PACKJSON') - psychPackJson = dir[0] - polymodMetaDir = dir[1] - - if os.path.exists(f'{modName}{psychPackJson}'): - polymod_meta = ModTools.convertPack(json.loads(open(f'{modName}{psychPackJson}', 'r').read())) - folderMake(f'{result_folder}/{modFoldername}/') - open(f'{result_folder}/{modFoldername}/{polymodMetaDir}', 'w').write(json.dumps(polymod_meta, indent=4)) - - logging.info('pack.json converted and saved') - else: - folderMake(f'{result_folder}/{modFoldername}/') - open(f'{result_folder}/{modFoldername}/{polymodMetaDir}', 'w').write(json.dumps(ModTools.defaultPolymodMeta(), indent=4)) - logging.warn('pack.json not found. Replaced it with default') - - logging.info('Copying pack.png') - dir = Constants.FILE_LOCS.get('PACKPNG') - psychPackPng = dir[0] - polymodIcon = dir[1] - - if os.path.exists(f'{modName}{psychPackPng}'): - folderMake(f'{result_folder}/{modFoldername}/') - try: - fileCopy(f'{modName}{psychPackPng}', f'{result_folder}/{modFoldername}/{polymodIcon}') - except Exception as e: - logging.error(f'Could not copy pack.png file: {e}') - else: - logging.warn('pack.png not found. Replacing it with default') - try: - _polyEncode = b'iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsEAAA7BAbiRa+0AAAkcSURBVHhe7Z2xbhQ7GIXDfQwUURCegQJBCgrgAVIAFVWkUCNoKNOAqINERZUgxAMECgpAFDwDQRFCeY175zN79prRzCYz2ZOs2PNJlj0e2+OZOfPbWRv+C/82rIQwZ/6ZxCHMlQgrWIiwgoUIK1iIsIKFCCtYiLCChQgrWIiwgoUIK1iIsIKFCCtYiLCChQgrWIiwgoUIK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PtdUIfztFkfg+qqD/WzqPsDpHV90pQF9Y3yqqNzor4m1M9Z90pe/ZzPg7nMsbrmSNqh0DUxh3qONWvfkvZ1MRyyVYfrtre7aKjc2Ngocb21R3MyzZPG7pHC2jQvrgzD2k+GNYV6Pqk9ZipzdHQ07Rf9UVn6ozRWGKvC3A4ODw9LDF3WuUb7wajPs4Ehe9Vc2OZYCALxaJvJaaAdHiDzC+dEen19vcTsqZon2hRI/9W2xAb1R9b3oc6i/sgJY/aqzRubsGDoA+pDcx4shqxRTXuXql4eQlldXS1pWbVZ+7iwZrwk9lTVVgir294xCppIy6rOgg+C/r969Wpq9VSv/vjon+Zis1AZ2qJd9Zf8Wfd4VliFBc28YZIaj14AL7brJfJXWzMnKUMJQwLC4LoIhfKcaw83ffC187K0jZkgAXGOPiifF4qFOAmyUNSp/2LmGNTmcf3b3t4uMf1AQPv7+yWt/pJeBLIIHSzYLVZYTiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoGVlb+A3vagv0fYDEJAAAAAElFTkSuQmCC' - polymodIconpath = f'{result_folder}/{modFoldername}/{polymodIcon}' - with open(polymodIconpath, 'wb') as output_file: - #cause the image wasnt working in the executable - output_file.write(b64decode(_polyEncode)) - except Exception as e: - logging.error(f'Could not write default file: {e}') - - logging.info('Parsing and converting credits.txt') - dir = Constants.FILE_LOCS.get('CREDITSTXT') - - psychCredits = dir[0] - modCredits = dir[1] - - if os.path.exists(f'{modName}{psychCredits}'): - folderMake(f'{result_folder}/{modFoldername}/') - resultCredits = ModTools.convertCredits(open(f'{modName}{psychCredits}', 'r').read()) - open(f'{result_folder}/{modFoldername}/{modCredits}', 'w').write(resultCredits) - else: - logging.warn(f'Could not find {modName}{psychCredits}') - - if options.get('charts', False): - - chartFolder = Constants.FILE_LOCS.get('CHARTFOLDER') - psychChartFolder = modName + chartFolder[0] - - folderMake(f'{result_folder}/{modFoldername}{chartFolder[1]}') - - songs = files.findAll(f'{psychChartFolder}*') - - for song in songs: - logging.info(f'Checking if {song} is a valid chart directory...') - if os.path.isdir(song): - logging.info(f'Loading charts in {song}') - - outputpath = f'{result_folder}/{modFoldername}' - songChart = ChartObject(song, outputpath) - - logging.info(f'Converting charts of {song}...') - songChart.convert() - - songName = songChart.songNameRaw - charts.append({ - 'songKey': songName, - 'sections': songChart.sections, - 'bpm': songChart.startingBpm, - 'player': songChart.metadata['playData']['characters']['player'], - 'opponent': songChart.metadata['playData']['characters']['opponent'] - }) - - logging.info(f'{song} charts converted, saving') - songChart.save() - - if options.get('characters', { + runtime = time.process_time() + + logging.info(Utils.coolText("NEW CONVERSION STARTED")) + + logging.info('Converting started...') + logging.info(options) + + modName = psych_mod_folder # MOD FOLDER PSYCH ENGINE + modFoldername = os.path.basename(psych_mod_folder) + + logging.info(f'Converting from{psych_mod_folder} to {result_folder}') + + if options.get('modpack_meta', False): + logging.info('Converting pack.json') + + dir = Constants.FILE_LOCS.get('PACKJSON') + psychPackJson = dir[0] + polymodMetaDir = dir[1] + + if os.path.exists(f'{modName}{psychPackJson}'): + polymod_meta = ModTools.convertPack(json.loads(open(f'{modName}{psychPackJson}', 'r').read())) + folderMake(f'{result_folder}/{modFoldername}/') + open(f'{result_folder}/{modFoldername}/{polymodMetaDir}', 'w').write(json.dumps(polymod_meta, indent=4)) + + logging.info('pack.json converted and saved') + else: + folderMake(f'{result_folder}/{modFoldername}/') + open(f'{result_folder}/{modFoldername}/{polymodMetaDir}', 'w').write(json.dumps(ModTools.defaultPolymodMeta(), indent=4)) + logging.warn('pack.json not found. Replaced it with default') + + logging.info('Copying pack.png') + dir = Constants.FILE_LOCS.get('PACKPNG') + psychPackPng = dir[0] + polymodIcon = dir[1] + + if os.path.exists(f'{modName}{psychPackPng}'): + folderMake(f'{result_folder}/{modFoldername}/') + try: + fileCopy(f'{modName}{psychPackPng}', f'{result_folder}/{modFoldername}/{polymodIcon}') + except Exception as e: + logging.error(f'Could not copy pack.png file: {e}') + else: + logging.warn('pack.png not found. Replacing it with default') + try: + _polyEncode = b'iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsEAAA7BAbiRa+0AAAkcSURBVHhe7Z2xbhQ7GIXDfQwUURCegQJBCgrgAVIAFVWkUCNoKNOAqINERZUgxAMECgpAFDwDQRFCeY175zN79prRzCYz2ZOs2PNJlj0e2+OZOfPbWRv+C/82rIQwZ/6ZxCHMlQgrWIiwgoUIK1iIsIKFCCtYiLCChQgrWIiwgoUIK1iIsIKFCCtYiLCChQgrWIiwgoUIK1gYJawLFy6U8ObNm0nObx4+fFjy79y5M8k5nufPn5c6V65cmeSEk7Dozy0WK1iIsIIFq7AYKjVs/vjxY5om9PHly5dpGYbUIW3U5wgaqus2aQO6hhLS5FGea5NmeFdZHfeh+pTXtIBAe8f1XXUVaKOmvgfCwsM/phgK1Qh7e3uTnN9sbW2V/Nu3b5djzqtsO1AWnj17Vo7X1tbKMTHHQ9r4/Plz53mC+qhjygLtK+/g4KAE0upHfb4d1EYb9b0duvLVd123K/BsYNb9qb+LxpkNhc3DQcQrzQsrxx8+fChxDV9p86BLen9/v8Q1fW1sb2+XuHnI5TyheXEl7+nTpyVWna9fv5b4/fv3JYZv376tHB0dlfStW7dKLNSm+gVqow+uRZ1G1OWYuo1I/ui7LOeLFy9KDOo7ZeHJkycl7ro/tbOojBIWNziU69evl/jmzZslbsPD14NEQF30tfH9+/cS6wXA/fv3S0y7vETVOTw8LMMKSHw/f/6cimV9fb3EQkK7fPnyie9b11pdXS0xbGxslFjn1GcJTGIClQX62nV/Dx48mKQWk1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YirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoWIqxgIcIKFiKsYCHCChYirGAhwgoGVlb+A3vagv0fYDEJAAAAAElFTkSuQmCC' + polymodIconpath = f'{result_folder}/{modFoldername}/{polymodIcon}' + with open(polymodIconpath, 'wb') as output_file: + #cause the image wasnt working in the executable + output_file.write(b64decode(_polyEncode)) + except Exception as e: + logging.error(f'Could not write default file: {e}') + + logging.info('Parsing and converting credits.txt') + dir = Constants.FILE_LOCS.get('CREDITSTXT') + + psychCredits = dir[0] + modCredits = dir[1] + + if os.path.exists(f'{modName}{psychCredits}'): + folderMake(f'{result_folder}/{modFoldername}/') + resultCredits = ModTools.convertCredits(open(f'{modName}{psychCredits}', 'r').read()) + open(f'{result_folder}/{modFoldername}/{modCredits}', 'w').write(resultCredits) + else: + logging.warn(f'Could not find {modName}{psychCredits}') + + if options.get('charts', False): + + chartFolder = Constants.FILE_LOCS.get('CHARTFOLDER') + psychChartFolder = modName + chartFolder[0] + + folderMake(f'{result_folder}/{modFoldername}{chartFolder[1]}') + + songs = files.findAll(f'{psychChartFolder}*') + + for song in songs: + # logging.info(f'Checking if {song} is a valid chart directory...') + if os.path.isdir(song): + logging.info(f'Found {song}, validating data in it') + + outputpath = f'{result_folder}/{modFoldername}' + + try: + songChart = ChartObject(song, outputpath) + except FileNotFoundError: + logging.warning(f"{song} data not found! Skipping...") + continue + except Exception as e: + logging.warning("ERROR!" + e) + continue + else: + logging.info(f'{song} successfully initialized! Converting') + + songChart.convert() + + songName = songChart.songNameRaw + charts.append({ + 'songKey': songName, + 'sections': songChart.sections, + 'bpm': songChart.startingBpm, + 'player': songChart.metadata['playData']['characters']['player'], + 'opponent': songChart.metadata['playData']['characters']['opponent'] + }) + + logging.info(f'{song} charts converted, saving') + songChart.save() + + if options.get('characters', { 'assets': False })['assets']: - logging.info('Copying character assets...') + logging.info('Copying character assets...') - dir = Constants.FILE_LOCS.get('CHARACTERASSETS') - psychCharacterAssets = modName + dir[0] - bgCharacterAssets = dir[1] + dir = Constants.FILE_LOCS.get('CHARACTERASSETS') + psychCharacterAssets = modName + dir[0] + bgCharacterAssets = dir[1] - folderMake(f'{result_folder}/{modFoldername}{bgCharacterAssets}') + folderMake(f'{result_folder}/{modFoldername}{bgCharacterAssets}') - for character in files.findAll(f'{psychCharacterAssets}*'): - if not os.path.isdir(character): - logging.info(f'Copying asset {character}') - try: - fileCopy(character, result_folder + f'/{modFoldername}' + bgCharacterAssets + os.path.basename(character)) - except Exception as e: - logging.error(f'Could not copy asset {character}: {e}') - else: - logging.warn(f'{character} is a directory, not a file! Skipped') + for character in files.findAll(f'{psychCharacterAssets}*'): + if not os.path.isdir(character): + logging.info(f'Copying asset {character}') + try: + fileCopy(character, result_folder + f'/{modFoldername}' + bgCharacterAssets + os.path.basename(character)) + except Exception as e: + logging.error(f'Could not copy asset {character}: {e}') + else: + logging.warn(f'{character} is a directory, not a file! Skipped') - if options.get('characters', { + if options.get('characters', { 'json': False })['json']: - logging.info('Converting character jsons...') + logging.info('Converting character jsons...') - dir = Constants.FILE_LOCS.get('CHARACTERJSONS') + dir = Constants.FILE_LOCS.get('CHARACTERJSONS') - psychCharacters = modName + dir[0] - bgCharacters = dir[1] + psychCharacters = modName + dir[0] + bgCharacters = dir[1] - folderMake(f'{result_folder}/{modFoldername}{bgCharacters}') + folderMake(f'{result_folder}/{modFoldername}{bgCharacters}') - for character in files.findAll(f'{psychCharacters}*'): - logging.info(f'Checking if {character} is a file...') - if not os.path.isdir(character) and character.endswith('.json'): - converted_char = CharacterObject(character, result_folder + f'/{modFoldername}' + bgCharacters) + for character in files.findAll(f'{psychCharacters}*'): + logging.info(f'Checking if {character} is a file...') + if not os.path.isdir(character) and character.endswith('.json'): + converted_char = CharacterObject(character, result_folder + f'/{modFoldername}' + bgCharacters) - converted_char.convert() - converted_char.save() - else: - logging.warn(f'{character} is a directory, or not a json! Skipped') + converted_char.convert() + converted_char.save() + else: + logging.warn(f'{character} is a directory, or not a json! Skipped') - if options.get('characters', { + if options.get('characters', { 'icons': False })['icons']: - logging.info('Copying character icons...') - - dir = Constants.FILE_LOCS.get('CHARACTERICON') - psychCharacterAssets = modName + dir[0] - bgCharacterAssets = dir[1] - - folderMake(f'{result_folder}/{modFoldername}{bgCharacterAssets}') - - for character in files.findAll(f'{psychCharacterAssets}*'): - if not os.path.isdir(character): - logging.info(f'Copying asset {character}') - try: - fileCopy(character, result_folder + f'/{modFoldername}' + bgCharacterAssets + os.path.basename(character)) - except Exception as e: - logging.error(f'Could not copy asset {character}: {e}') - else: - logging.warn(f'{character} is a directory, not a file! Skipped') - - songOptions = options.get('songs', { - 'inst': False, - 'voices': False, - 'split': False - }) - if songOptions: - dir = Constants.FILE_LOCS.get('SONGS') - psychSongs = modName + dir[0] - bgSongs = dir[1] - - folderMake(f'{result_folder}/{modFoldername}{bgSongs}') - - _allSongFiles = files.findAll(f'{psychSongs}*') - - for song in _allSongFiles: - _songKeyUnformatted = os.path.basename(song) - songKeyFormatted = _songKeyUnformatted.replace(' ', '-').lower() - - _allSongFilesClear = [os.path.basename(__song) for __song in _allSongFiles] - isPsych073Song = 'Voices-Opponent.ogg' in _allSongFilesClear and 'Voices-Player.ogg' in _allSongFilesClear - - logging.info(f'Checking if {song} is a valid song directory...') - if os.path.isdir(song): - logging.info(f'Copying files in {song}') - for songFile in files.findAll(f'{song}/*'): - if os.path.basename(songFile) == 'Inst.ogg' and songOptions['inst']: - logging.info(f'Copying asset {songFile}') - try: - folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') - fileCopy(songFile, - f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') - except Exception as e: - logging.error(f'Could not copy asset {songFile}: {e}') - elif os.path.basename(songFile) == 'Voices.ogg' and songOptions['split'] and vocalSplitMasterToggle and not isPsych073Song: - # Vocal Split - songKey = _songKeyUnformatted - - chart = None - for _chart in charts: - if _chart['songKey'] == songKey: - chart = charts[charts.index(_chart)] - - if chart != None: - sections = chart['sections'] - bpm = chart['bpm'] - logging.info(f'Vocal Split ({songKey}) BPM is {bpm}') - path = song + '/' - resultPath = result_folder + f'/{modFoldername}{bgSongs}{songKeyFormatted}/' - songChars = [chart['player'], - chart['opponent']] - - #print(songChars) - - logging.info(f'Vocal Split currently running for: {songKey}') - logging.info(f'Passed the following paths: {path} || {resultPath}') - logging.info(f'Passed characters: {songChars}') - - vocal_split_thread = threading.Thread(target=VocalSplit.vocalsplit, args=(sections, bpm, path, resultPath, songKey, songChars)) - vocal_split_thread.start() - vocal_split_thread.join() - else: - logging.warn(f'No chart was found for {songKey} so the vocal file will be copied instead.') - try: - folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') - fileCopy(songFile, - f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') - except Exception as e: - logging.error(f'Could not copy asset {songFile}: {e}') - elif isPsych073Song: - songKey = _songKeyUnformatted - - folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') - - chart = None - for _chart in charts: - if _chart['songKey'] == songKey: - chart = charts[charts.index(_chart)] - - if chart != None: - try: - if os.path.basename(songFile) == 'Voices-Player.ogg': - fileCopy(songFile, f"{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/Voices-{chart.metadata['playData']['characters'].get('player')}.ogg") - elif os.path.basename(songFile) == 'Voices-Opponent.ogg': - fileCopy(songFile, f"{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/Voices-{chart.metadata['playData']['characters'].get('opponent')}.ogg") - - except Exception as e: - logging.error(f'Could not copy asset {songFile}: {e}') - else: - logging.warning(f'{songKeyFormatted} is a Psych Engine 0.7.3 song with separated vocals. Copy rename was attempted, however your chart was not found. These files will be copied instead.') - ## Psst! If you were taken here, your chart is needed to set your character to the file! - fileCopy(songFile, - f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') - - elif songOptions['voices']: - logging.info(f'Copying asset {songFile}') - if not vocalSplitMasterToggle: - logging.warning('Vocal Split is disabled! This copy is the last.') - - try: - folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') - fileCopy(songFile, - f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') - except Exception as e: - logging.error(f'Could not copy asset {songFile}: {e}') - weekCOptions = options.get('weeks', { + logging.info('Copying character icons...') + + dir = Constants.FILE_LOCS.get('CHARACTERICON') + psychCharacterAssets = modName + dir[0] + bgCharacterAssets = dir[1] + + folderMake(f'{result_folder}/{modFoldername}{bgCharacterAssets}') + + for character in files.findAll(f'{psychCharacterAssets}*'): + if not os.path.isdir(character): + logging.info(f'Copying asset {character}') + try: + fileCopy(character, result_folder + f'/{modFoldername}' + bgCharacterAssets + os.path.basename(character)) + except Exception as e: + logging.error(f'Could not copy asset {character}: {e}') + else: + logging.warn(f'{character} is a directory, not a file! Skipped') + + songOptions = options.get('songs', { + 'inst': False, + 'voices': False, + 'split': False + }) + if songOptions: + dir = Constants.FILE_LOCS.get('SONGS') + psychSongs = modName + dir[0] + bgSongs = dir[1] + + folderMake(f'{result_folder}/{modFoldername}{bgSongs}') + + _allSongFiles = files.findAll(f'{psychSongs}*') + + for song in _allSongFiles: + _songKeyUnformatted = os.path.basename(song) + songKeyFormatted = _songKeyUnformatted.replace(' ', '-').lower() + + _allSongFilesClear = [os.path.basename(__song) for __song in _allSongFiles] + isPsych073Song = 'Voices-Opponent.ogg' in _allSongFilesClear and 'Voices-Player.ogg' in _allSongFilesClear + + logging.info(f'Checking if {song} is a valid song directory...') + if os.path.isdir(song): + logging.info(f'Copying files in {song}') + for songFile in files.findAll(f'{song}/*'): + if os.path.basename(songFile) == 'Inst.ogg' and songOptions['inst']: + logging.info(f'Copying asset {songFile}') + try: + folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') + fileCopy(songFile, + f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') + except Exception as e: + logging.error(f'Could not copy asset {songFile}: {e}') + elif os.path.basename(songFile) == 'Voices.ogg' and songOptions['split'] and vocalSplitMasterToggle and not isPsych073Song: + # Vocal Split + songKey = _songKeyUnformatted + + chart = None + for _chart in charts: + if _chart['songKey'] == songKey: + chart = charts[charts.index(_chart)] + + if chart != None: + sections = chart['sections'] + bpm = chart['bpm'] + logging.info(f'Vocal Split ({songKey}) BPM is {bpm}') + path = song + '/' + resultPath = result_folder + f'/{modFoldername}{bgSongs}{songKeyFormatted}/' + songChars = [chart['player'], + chart['opponent']] + + #print(songChars) + + logging.info(f'Vocal Split currently running for: {songKey}') + logging.info(f'Passed the following paths: {path} || {resultPath}') + logging.info(f'Passed characters: {songChars}') + + vocal_split_thread = threading.Thread(target=VocalSplit.vocalsplit, args=(sections, bpm, path, resultPath, songKey, songChars)) + vocal_split_thread.start() + vocal_split_thread.join() + else: + logging.warn(f'No chart was found for {songKey} so the vocal file will be copied instead.') + try: + folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') + fileCopy(songFile, + f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') + except Exception as e: + logging.error(f'Could not copy asset {songFile}: {e}') + elif isPsych073Song: + songKey = _songKeyUnformatted + + folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') + + chart = None + for _chart in charts: + if _chart['songKey'] == songKey: + chart = charts[charts.index(_chart)] + + if chart != None: + try: + if os.path.basename(songFile) == 'Voices-Player.ogg': + fileCopy(songFile, f"{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/Voices-{chart.metadata['playData']['characters'].get('player')}.ogg") + elif os.path.basename(songFile) == 'Voices-Opponent.ogg': + fileCopy(songFile, f"{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/Voices-{chart.metadata['playData']['characters'].get('opponent')}.ogg") + + except Exception as e: + logging.error(f'Could not copy asset {songFile}: {e}') + else: + logging.warning(f'{songKeyFormatted} is a Psych Engine 0.7.3 song with separated vocals. Copy rename was attempted, however your chart was not found. These files will be copied instead.') + ## Psst! If you were taken here, your chart is needed to set your character to the file! + fileCopy(songFile, + f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') + + elif songOptions['voices']: + logging.info(f'Copying asset {songFile}') + if not vocalSplitMasterToggle: + logging.warning('Vocal Split is disabled! This copy is the last.') + + try: + folderMake(f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}') + fileCopy(songFile, + f'{result_folder}/{modFoldername}{bgSongs}{songKeyFormatted}/{os.path.basename(songFile)}') + except Exception as e: + logging.error(f'Could not copy asset {songFile}: {e}') + weekCOptions = options.get('weeks', { 'props': False, # Asset 'levels': False, 'titles': False # Asset }) - if weekCOptions['levels']: - logging.info('Converting weeks (levels)...') - - dir = Constants.FILE_LOCS.get('WEEKS') - psychWeeks = modName + dir[0] - baseLevels = dir[1] - - folderMake(f'{result_folder}/{modFoldername}{baseLevels}') - - for week in files.findAll(f'{psychWeeks}*.json'): - logging.info(f'Loading {week} into the converter...') - - weekJSON = json.loads(open(week, 'r').read()) - week_filename = os.path.basename(week) - converted_week = WeekTools.convert(weekJSON, modName, week_filename) - open(f'{result_folder}/{modFoldername}{baseLevels}{week_filename}', 'w').write(json.dumps(converted_week, indent=4)) - - if weekCOptions['props']: - logging.info('Copying prop assets...') - - dir = Constants.FILE_LOCS.get('WEEKCHARACTERASSET') - psychWeeks = modName + dir[0] - baseLevels = dir[1] - - allXml = files.findAll(f'{psychWeeks}*.xml') - allPng = files.findAll(f'{psychWeeks}*.png') - for asset in allXml + allPng: - logging.info(f'Copying {asset}') - try: - folderMake(f'{result_folder}/{modFoldername}{baseLevels}') - fileCopy(asset, - f'{result_folder}/{modFoldername}{baseLevels}{os.path.basename(asset)}') - except Exception as e: - logging.error(f'Could not copy asset {asset}: {e}') - - if weekCOptions['titles']: - logging.info('Copying level titles...') - - dir = Constants.FILE_LOCS.get('WEEKIMAGE') - psychWeeks = modName + dir[0] - baseLevels = dir[1] - - allPng = files.findAll(f'{psychWeeks}*.png') - for asset in allPng: - logging.info(f'Copying {asset}') - try: - folderMake(f'{result_folder}/{modFoldername}{baseLevels}') - fileCopy(asset, - f'{result_folder}/{modFoldername}{baseLevels}{os.path.basename(asset)}') - except Exception as e: - logging.error(f'Could not copy asset {asset}: {e}') - - if options.get('stages', False): - logging.info('Converting stages...') - - dir = Constants.FILE_LOCS.get('STAGE') - psychStages = modName + dir[0] - baseStages = dir[1] - - allStageJSON = files.findAll(f'{psychStages}*.json') - for asset in allStageJSON: - logging.info(f'Converting {asset}') - folderMake(f'{result_folder}/{modFoldername}{baseStages}') - stageJSON = json.loads(open(asset, 'r').read()) - assetPath = f'{result_folder}/{modFoldername}{baseStages}{os.path.basename(asset)}' - - stageLua = asset.replace('.json', '.lua') - logging.info(f'Parsing .lua with matching .json name: {stageLua}') - - luaProps = [] - if os.path.exists(stageLua): - logging.info(f'Parsing {stageLua} and attempting to extract methods and calls') - try: - luaProps = StageLuaParse.parseStage(stageLua) - except Exception as e: - logging.error(f'Could not complete parsing of {stageLua}: {e}') - - logging.info(f'Converting Stage JSON') - stageJSONConverted = json.dumps(StageTool.convert(stageJSON, os.path.basename(asset), luaProps), indent=4) - open(assetPath, 'w').write(stageJSONConverted) - - if options.get('images'): # Images include XMLs - logging.info('Copying images') - - dir = Constants.FILE_LOCS.get('IMAGES') - psychImages = modName + dir[0] - baseImages = dir[1] - - allimagesandfolders = files.findAll(f'{psychImages}*') - for asset in allimagesandfolders: - logging.info(f'Checking on {asset}') - - if os.path.isdir(asset): - logging.info(f'{asset} is directory, checking if it should be excluded...') - folderName = os.path.basename(asset) - if not folderName in Constants.EXCLUDE_FOLDERS_IMAGES['PsychEngine']: - logging.info(f'{asset} is not excluded... attempting to copy.') - try: - pathTo = f'{result_folder}/{modFoldername}{baseImages}{folderName}' - #logging.debug(pathTo) - - #folderMake(f'{result_folder}/{modFoldername}{baseImages}{folderName}') - treeCopy(asset, pathTo) - except Exception as e: - logging.error(f'Failed to copy {asset}: {e}') - else: - logging.warn(f'{asset} is excluded. Skipped') - - else: - logging.info(f'{asset} is file, copying') - try: - folderMake(f'{result_folder}/{modFoldername}{baseImages}') - fileCopy(asset, f'{result_folder}/{modFoldername}{baseImages}{os.path.basename(asset)}') - except Exception as e: - logging.error(f'Failed to copy {asset}: {e}') - - #convlen = Utils.getRuntime(runtime) - logging.info(""" - -============================= - CONVERSION ENDED -============================= - """) - logging.info(f'Conversion done: Took {runtime}s') \ No newline at end of file + if weekCOptions['levels']: + logging.info('Converting weeks (levels)...') + + dir = Constants.FILE_LOCS.get('WEEKS') + psychWeeks = modName + dir[0] + baseLevels = dir[1] + + folderMake(f'{result_folder}/{modFoldername}{baseLevels}') + + for week in files.findAll(f'{psychWeeks}*.json'): + logging.info(f'Loading {week} into the converter...') + + weekJSON = json.loads(open(week, 'r').read()) + week_filename = os.path.basename(week) + converted_week = WeekTools.convert(weekJSON, modName, week_filename) + open(f'{result_folder}/{modFoldername}{baseLevels}{week_filename}', 'w').write(json.dumps(converted_week, indent=4)) + + if weekCOptions['props']: + logging.info('Copying prop assets...') + + dir = Constants.FILE_LOCS.get('WEEKCHARACTERASSET') + psychWeeks = modName + dir[0] + baseLevels = dir[1] + + allXml = files.findAll(f'{psychWeeks}*.xml') + allPng = files.findAll(f'{psychWeeks}*.png') + for asset in allXml + allPng: + logging.info(f'Copying {asset}') + try: + folderMake(f'{result_folder}/{modFoldername}{baseLevels}') + fileCopy(asset, + f'{result_folder}/{modFoldername}{baseLevels}{os.path.basename(asset)}') + except Exception as e: + logging.error(f'Could not copy asset {asset}: {e}') + + if weekCOptions['titles']: + logging.info('Copying level titles...') + + dir = Constants.FILE_LOCS.get('WEEKIMAGE') + psychWeeks = modName + dir[0] + baseLevels = dir[1] + + allPng = files.findAll(f'{psychWeeks}*.png') + for asset in allPng: + logging.info(f'Copying {asset}') + try: + folderMake(f'{result_folder}/{modFoldername}{baseLevels}') + fileCopy(asset, + f'{result_folder}/{modFoldername}{baseLevels}{os.path.basename(asset)}') + except Exception as e: + logging.error(f'Could not copy asset {asset}: {e}') + + if options.get('stages', False): + logging.info('Converting stages...') + + dir = Constants.FILE_LOCS.get('STAGE') + psychStages = modName + dir[0] + baseStages = dir[1] + + allStageJSON = files.findAll(f'{psychStages}*.json') + for asset in allStageJSON: + logging.info(f'Converting {asset}') + folderMake(f'{result_folder}/{modFoldername}{baseStages}') + stageJSON = json.loads(open(asset, 'r').read()) + assetPath = f'{result_folder}/{modFoldername}{baseStages}{os.path.basename(asset)}' + + stageLua = asset.replace('.json', '.lua') + logging.info(f'Parsing .lua with matching .json name: {stageLua}') + + luaProps = [] + if os.path.exists(stageLua): + logging.info(f'Parsing {stageLua} and attempting to extract methods and calls') + try: + luaProps = StageLuaParse.parseStage(stageLua) + except Exception as e: + logging.error(f'Could not complete parsing of {stageLua}: {e}') + + logging.info(f'Converting Stage JSON') + stageJSONConverted = json.dumps(StageTool.convert(stageJSON, os.path.basename(asset), luaProps), indent=4) + open(assetPath, 'w').write(stageJSONConverted) + + if options.get('images'): # Images include XMLs + logging.info('Copying images') + + dir = Constants.FILE_LOCS.get('IMAGES') + psychImages = modName + dir[0] + baseImages = dir[1] + + allimagesandfolders = files.findAll(f'{psychImages}*') + for asset in allimagesandfolders: + logging.info(f'Checking on {asset}') + + if os.path.isdir(asset): + logging.info(f'{asset} is directory, checking if it should be excluded...') + folderName = os.path.basename(asset) + if not folderName in Constants.EXCLUDE_FOLDERS_IMAGES['PsychEngine']: + logging.info(f'{asset} is not excluded... attempting to copy.') + try: + pathTo = f'{result_folder}/{modFoldername}{baseImages}{folderName}' + #logging.debug(pathTo) + + #folderMake(f'{result_folder}/{modFoldername}{baseImages}{folderName}') + treeCopy(asset, pathTo) + except Exception as e: + logging.error(f'Failed to copy {asset}: {e}') + else: + logging.warn(f'{asset} is excluded. Skipped') + + else: + logging.info(f'{asset} is file, copying') + try: + folderMake(f'{result_folder}/{modFoldername}{baseImages}') + fileCopy(asset, f'{result_folder}/{modFoldername}{baseImages}{os.path.basename(asset)}') + except Exception as e: + logging.error(f'Failed to copy {asset}: {e}') + + #convlen = Utils.getRuntime(runtime) + logging.info(Utils.coolText("CONVERSION COMPLETED")) + logging.info(f'Conversion done: Took {runtime}s') \ No newline at end of file diff --git a/psychtobase/src/Utils.py b/psychtobase/src/Utils.py index 279d209..a5448a0 100644 --- a/psychtobase/src/Utils.py +++ b/psychtobase/src/Utils.py @@ -67,4 +67,11 @@ def focusCamera(time:float, char:bool): """ Function created for faster creation of camera change events. """ - return event(time, "FocusCamera", {"char": "0" if char else "1"}) \ No newline at end of file + return event(time, "FocusCamera", {"char": "0" if char else "1"}) + +def coolText(text:str) -> str: + length = max(30, len(text) + 5) + length += len(text) % 2 + + text = " " * ((length - len(text)) // 2) + text + return "\n" + "=" * length + f"\n{text}\n" + "=" * length \ No newline at end of file diff --git a/psychtobase/src/tools/ChartTools.py b/psychtobase/src/tools/ChartTools.py index 57280c1..44577d7 100644 --- a/psychtobase/src/tools/ChartTools.py +++ b/psychtobase/src/tools/ChartTools.py @@ -81,6 +81,8 @@ def initCharts(self): if len(difficulties) > 0: self.sampleChart = charts.get(difficulties[0]) + else: + raise FileNotFoundError("Chart not found!") def setMetadata(self): # Chart used to get character data (ASSUMING all charts use the same characters and stages)