def saveGameAs(): config = dataFiles.configFile path = str(dataFiles.config_path) if not dataFiles.first_save_load \ else os.path.join( os.path.dirname(dataFiles.config_path), 'saved_games', 'untitled.cfg') saves_dir = os.path.dirname(path) print("GUU: %s"%path) #ask for new name newName = QtGui.QFileDialog.getSaveFileName(window, 'Save game as... (Create new config file and data files)', path, selectedFilter='*.cfg', filter='*.cfg') if newName: newName = str(newName) log ("New name is: "+ newName) #write new file names into cfg dict config['Items'] = \ os.path.basename(newName).replace('.cfg','')+'_items.txt' config['Actions'] = \ os.path.basename(newName).replace('.cfg','')+'_actions.txt' config['Characters'] = \ os.path.basename(newName).replace('.cfg','')+'_chars.txt' #save new cfg dict with new name dataFiles.saveJSON(newName, config) #save data files with new names dataFiles.saveJSON (os.path.join(saves_dir, config['Characters']), dataFiles.Characters) dataFiles.saveJSON(os.path.join(saves_dir, config['Actions']),dataFiles.Actions) dataFiles.saveJSON(os.path.join(saves_dir, config['Items']), dataFiles.Items) window.setWindowTitle('GMH - '+newName) dataFiles.first_save_load = False log ("Game saved as %s"%newName)
def saveGameAs(): config = dataFiles.configFile path = str(dataFiles.config_path) if not dataFiles.first_save_load \ else os.path.join( os.path.dirname(dataFiles.config_path), 'saved_games', 'untitled.cfg') saves_dir = os.path.dirname(path) print("GUU: %s" % path) #ask for new name newName = QtGui.QFileDialog.getSaveFileName( window, 'Save game as... (Create new config file and data files)', path, selectedFilter='*.cfg', filter='*.cfg') if newName: newName = str(newName) log("New name is: " + newName) #write new file names into cfg dict config['Items'] = \ os.path.basename(newName).replace('.cfg','')+'_items.txt' config['Actions'] = \ os.path.basename(newName).replace('.cfg','')+'_actions.txt' config['Characters'] = \ os.path.basename(newName).replace('.cfg','')+'_chars.txt' #save new cfg dict with new name dataFiles.saveJSON(newName, config) #save data files with new names dataFiles.saveJSON(os.path.join(saves_dir, config['Characters']), dataFiles.Characters) dataFiles.saveJSON(os.path.join(saves_dir, config['Actions']), dataFiles.Actions) dataFiles.saveJSON(os.path.join(saves_dir, config['Items']), dataFiles.Items) window.setWindowTitle('GMH - ' + newName) dataFiles.first_save_load = False log("Game saved as %s" % newName)
def saveAllChars(data): dataFiles.saveJSON(dataFiles.configFile['Characters'], data)