def SetGamePath(self, path): """ Sets the game path """ if not self.custom: setSetting('GamePath', path) else: name = 'GamePath_' + self.name setSetting(name, path)
def SetLastLevel(self, path): """ Sets the last loaded level """ if path in {None, 'None', 'none', True, 'True', 'true', False, 'False', 'false', 0, 1, ''}: return if not self.custom: setSetting('LastLevel', path) else: name = 'LastLevel_' + self.name setSetting(name, path)
def LoadGameDef(name=None, dlg=None): """ Loads a game definition """ # # global globals_.gamedef if dlg: dlg.setMaximum(7) # Put the whole thing into a try-except clause # to catch whatever errors may happen try: # Load the globals_.gamedef if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 1)) # Loading game patch... globals_.gamedef = ReggieGameDefinition(name) if globals_.gamedef.custom and ( not globals_.settings.contains('GamePath_' + globals_.gamedef.name)): # First-time usage of this globals_.gamedef. Have the # user pick a stage folder so we can load stages # and tilesets from there QtWidgets.QMessageBox.information( None, globals_.trans.string('Gamedefs', 2), globals_.trans.string('Gamedefs', 3, '[game]', globals_.gamedef.name), QtWidgets.QMessageBox.Ok) result = globals_.mainWindow.HandleChangeGamePath(True) if result is not True: QtWidgets.QMessageBox.information( None, globals_.trans.string('Gamedefs', 4), globals_.trans.string('Gamedefs', 5, '[game]', globals_.gamedef.name), QtWidgets.QMessageBox.Ok) else: QtWidgets.QMessageBox.information( None, globals_.trans.string('Gamedefs', 6), globals_.trans.string('Gamedefs', 7, '[game]', globals_.gamedef.name), QtWidgets.QMessageBox.Ok) if dlg: dlg.setValue(1) # Load spritedata.xml and spritecategories.xml if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 8)) # Loading sprite data... LoadSpriteData() LoadSpriteListData(True) LoadSpriteCategories(True) if globals_.mainWindow: globals_.mainWindow.spriteViewPicker.clear() for cat in globals_.SpriteCategories: globals_.mainWindow.spriteViewPicker.addItem(cat[0]) globals_.mainWindow.sprPicker.LoadItems( ) # Reloads the sprite picker list items globals_.mainWindow.spriteViewPicker.setCurrentIndex( 0) # Sets the sprite picker to category 0 (enemies) globals_.mainWindow.spriteDataEditor.setSprite( globals_.mainWindow.spriteDataEditor.spritetype, True) # Reloads the sprite data editor fields globals_.mainWindow.spriteDataEditor.update() if dlg: dlg.setValue(2) # Load BgA/BgB names if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 9)) # Loading background names... LoadBgANames(True) LoadBgBNames(True) if dlg: dlg.setValue(3) # Reload tilesets if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 10)) # Reloading tilesets... LoadObjDescriptions(True) # reloads ts1_descriptions if globals_.mainWindow is not None: globals_.mainWindow.ReloadTilesets(True) LoadTilesetNames(True) # reloads tileset names LoadTilesetInfo(True) # reloads tileset info if dlg: dlg.setValue(4) # Load sprites.py if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 11)) # Loading sprite image data... if globals_.Area is not None: SLib.SpritesFolders = globals_.gamedef.recursiveFiles( 'sprites', False, True) SLib.ImageCache.clear() SLib.SpriteImagesLoaded.clear() sprites.LoadBasics() spriteClasses = globals_.gamedef.getImageClasses() for s in globals_.Area.sprites: if s.type in SLib.SpriteImagesLoaded: continue if s.type not in spriteClasses: continue spriteClasses[s.type].loadImages() SLib.SpriteImagesLoaded.add(s.type) for s in globals_.Area.sprites: if s.type in spriteClasses: s.setImageObj(spriteClasses[s.type]) else: s.setImageObj(SLib.SpriteImage) if dlg: dlg.setValue(5) # Reload the sprite-picker text if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 12)) # Applying sprite image data... if globals_.Area is not None: for spr in globals_.Area.sprites: spr.UpdateListItem() # Reloads the sprite-picker text if dlg: dlg.setValue(6) # Load entrance names if dlg: dlg.setLabelText(globals_.trans.string( 'Gamedefs', 16)) # Loading entrance names... LoadEntranceNames(True) if dlg: dlg.setValue(7) except Exception: raise # # Something went wrong. # if dlg: dlg.setValue(7) # autocloses it # QtWidgets.QMessageBox.information(None, globals_.trans.string('Gamedefs', 17), globals_.trans.string('Gamedefs', 18, '[error]', str(e))) # if name is not None: LoadGameDef(None) # return False # Success! if dlg: setSetting('LastGameDef', name) return True
def LoadGameDef(name=None, dlg=None): """ Loads a game definition """ if dlg: dlg.setMaximum(7) # Put the whole thing into a try-except clause # to catch whatever errors may happen try: # Load the globals_.gamedef if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 1)) # Loading game patch... globals_.gamedef = ReggieGameDefinition(name) globals_.gamedef.__init2__() if globals_.gamedef.custom and (not globals_.settings.contains('StageGamePath_' + globals_.gamedef.name)): # First-time usage of this globals_.gamedef. Have the # user pick a stage folder so we can load stages # and tilesets from there pressed_button = QtWidgets.QMessageBox.information(None, globals_.trans.string('Gamedefs', 2), globals_.trans.string('Gamedefs', 3, '[game]', globals_.gamedef.name), QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel ) if pressed_button == QtWidgets.QMessageBox.Cancel: return False if globals_.mainWindow is None: # This check avoids an error because globals_.mainWindow is None # when first loading the editor. Returning False here avoids a # loop where the user cannot open the editor because the program # closes after returning the error. return False result = globals_.mainWindow.HandleChangeGamePath(True) if result: msg_ids = (6, 7) else: msg_ids = (4, 5) QtWidgets.QMessageBox.information(None, globals_.trans.string('Gamedefs', msg_ids[0]), globals_.trans.string('Gamedefs', msg_ids[1], '[game]', globals_.gamedef.name), QtWidgets.QMessageBox.Ok ) if not result: # If the user refused to select a game path, abort the patch # switching process. return False if dlg: dlg.setValue(1) # Load spritedata.xml and spritecategories.xml if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 8)) # Loading sprite data... LoadSpriteData() LoadSpriteListData(True) LoadSpriteCategories(True) if globals_.mainWindow is not None: globals_.mainWindow.spriteViewPicker.clear() for cat in globals_.SpriteCategories: globals_.mainWindow.spriteViewPicker.addItem(cat[0]) globals_.mainWindow.sprPicker.LoadItems() # Reloads the sprite picker list items globals_.mainWindow.spriteViewPicker.setCurrentIndex(0) # Sets the sprite picker to category 0 (enemies) globals_.mainWindow.spriteDataEditor.setSprite(globals_.mainWindow.spriteDataEditor.spritetype, True) # Reloads the sprite data editor fields if dlg: dlg.setValue(2) # Load BgA/BgB names if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 9)) # Loading background names... LoadBgANames(True) LoadBgBNames(True) if dlg: dlg.setValue(3) # Reload tilesets if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 10)) # Reloading tilesets... LoadObjDescriptions(True) # reloads ts1_descriptions if globals_.mainWindow is not None: globals_.mainWindow.ReloadTilesets(True) LoadTilesetNames(True) # reloads tileset names LoadTilesetInfo(True) # reloads tileset info if dlg: dlg.setValue(4) # Load sprites.py if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 11)) # Loading sprite image data... # Always load the sprites folders so the correct sprite images can be # loaded when Reggie is started. This avoids loading all sprite images # again and also simplifies the sprite image code. SLib.SpritesFolders = globals_.gamedef.recursiveFiles('sprites', False, True) if globals_.Area is not None: SLib.ImageCache.clear() SLib.SpriteImagesLoaded.clear() sprites.LoadBasics() spriteClasses = globals_.gamedef.getImageClasses() for s in globals_.Area.sprites: if s.type in SLib.SpriteImagesLoaded: continue if s.type not in spriteClasses: continue spriteClasses[s.type].loadImages() SLib.SpriteImagesLoaded.add(s.type) for s in globals_.Area.sprites: if s.type in spriteClasses: s.setImageObj(spriteClasses[s.type]) else: s.setImageObj(SLib.SpriteImage) if dlg: dlg.setValue(5) # Reload the sprite-picker text if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 12)) # Applying sprite image data... if globals_.Area is not None: for spr in globals_.Area.sprites: spr.UpdateListItem() # Reloads the sprite-picker text if dlg: dlg.setValue(6) # Load entrance names if dlg: dlg.setLabelText(globals_.trans.string('Gamedefs', 16)) # Loading entrance names... LoadEntranceNames(True) if dlg: dlg.setValue(7) except Exception: raise # # Something went wrong. # if dlg: dlg.setValue(7) # autocloses it # QtWidgets.QMessageBox.information(None, globals_.trans.string('Gamedefs', 17), globals_.trans.string('Gamedefs', 18, '[error]', str(e))) # if name is not None: LoadGameDef(None) # return False # Success! if dlg: setSetting('LastGameDef', name) return True