Example #1
0
 def SetGamePath(self, path):
     """
     Sets the game path
     """
     if not self.custom:
         setSetting('GamePath', path)
     else:
         name = 'GamePath_' + self.name
         setSetting(name, path)
Example #2
0
 def SetLastLevel(self, path):
     """
     Sets the last loaded level
     """
     if path in (None, 'None', 'none', True, 'True', 'true', False, 'False',
                 'false', 0, 1, ''):
         return
     print('Last loaded level set to ' + str(path))
     if not self.custom:
         setSetting('LastLevel', path)
     else:
         name = 'LastLevel_' + self.name
         setSetting(name, path)
Example #3
0
def LoadGameDef(name=None, dlg=None):
    """
    Loads a game definition
    """
    # Put the whole thing into a try-except clause
    # to catch whatever errors may happen
    try:
        # Load the gamedef
        globals.gamedef = MiyamotoGameDefinition(name)
        if globals.gamedef.custom and (not globals.settings.contains('GamePath_' + globals.gamedef.name)) and globals.mainWindow:
            # First-time usage of this 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)

        # Load BG names
        LoadBGNames()

        # Load spritedata.xml and spritecategories.xml
        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()

        # Reload tilesets
        LoadObjDescriptions(True)  # reloads ts1_descriptions
        LoadTilesetNames(True)  # reloads tileset names

        # Load sprites.py
        if globals.Area is not None:
            SLib.SpritesFolders = globals.gamedef.recursiveFiles('sprites', False, True)

            SLib.ImageCache.clear()
            SLib.SpriteImagesLoaded.clear()
            SLib.loadVines()

            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)

        # Reload the sprite-picker text
        if globals.Area is not None:
            for spr in globals.Area.sprites:
                spr.UpdateListItem()  # Reloads the sprite-picker text

        # Load entrance names
        LoadEntranceNames(True)

    except Exception as e:
        raise
    #    # Something went wrong.
    #    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