Beispiel #1
0
    def __init__(self):

        # get args
        self.args = _cmd_args
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']

        # load config
        self.config = self.load_config(self.configFile)

        # allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        # change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        # alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.videoLayer = False
        self.restartRequested = False
Beispiel #2
0
    def __init__(self):
        global args
        self.args = args

        self.playing = self.args['song']
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']
        self.diff = self.args['diff']
        self.part = self.args['part']
        self.mode = self.args['mode']
        self.players = self.args['players']

        self.config = self.load_config(self.configFile)

        #Lysdestic - Allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        #Lysdestic - Change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        #Lysdestic - Alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.init_oneshot()

        self.videoLayer = False
        self.restartRequested = False
Beispiel #3
0
class SceneTest(unittest.TestCase):
    def setUp(self):
        # set up the engine with a config and a world
        config_filename = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
        config = Config.load(config_filename, setAsDefault=True)
        self.engine = GameEngine(config)
        self.engine.startWorld(1)

    def test_init(self):
        scene = Scene(self.engine)
        self.assertEqual(scene.engine, self.engine)
        self.assertEqual(scene.time, 0.0)

    def test_add_player(self):
        scene = Scene(self.engine)
        player = "P"
        scene.addPlayer(player)
        self.assertIn(player, scene.players)

    def test_remove_player(self):
        scene = Scene(self.engine)
        player = "P1"
        scene.addPlayer(player)
        self.assertIn(player, scene.players)
        scene.removePlayer(player)
        self.assertNotIn(player, scene.players)

    def test_run(self):
        scene = Scene(self.engine)
        ticks = 1
        scene.run(ticks)
        self.assertEqual(scene.time, ticks / 50.0)
Beispiel #4
0
    def setUp(self):
        # set config file
        config_file = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
        self.config = Config.load(config_file, setAsDefault=True)

        # init the game engine
        self.engine = GameEngine(self.config)
Beispiel #5
0
    def __init__(self):
        global args
        self.args = args

        self.playing = self.args['song']
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']
        self.diff = self.args['diff']
        self.part = self.args['part']
        self.mode = self.args['mode']
        self.players = self.args['players']

        self.config = self.load_config(self.configFile)

        #Lysdestic - Allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        #Lysdestic - Change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        #Lysdestic - Alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.init_oneshot()

        self.videoLayer = False
        self.restartRequested = False
Beispiel #6
0
    def __init__(self):

        # get args
        self.args = _cmd_args
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']

        # load config
        self.config = self.load_config(self.configFile)

        # allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        # change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        # alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.videoLayer = False
        self.restartRequested = False
Beispiel #7
0
class GameEngineTest(unittest.TestCase):
    def setUp(self):
        # set config file
        config_file = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
        self.config = Config.load(config_file, setAsDefault=True)

        # init the game engine
        self.engine = GameEngine(self.config)

    def test_init(self):
        self.assertTrue(self.engine.running)

    def test_quit(self):
        self.assertTrue(self.engine.running)
        self.engine.quit()
        self.assertFalse(self.engine.running)

    def tearDown(self):
        self.engine.quit()
Beispiel #8
0
class GameEngineTest(unittest.TestCase):

    def setUp(self):
        # set config file
        config_file = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
        self.config = Config.load(config_file, setAsDefault=True)

        # init the game engine
        self.engine = GameEngine(self.config)

    def test_init(self):
        self.assertTrue(self.engine.running)

    def test_quit(self):
        self.assertTrue(self.engine.running)
        self.engine.quit()
        self.assertFalse(self.engine.running)

    def tearDown(self):
        self.engine.quit()
Beispiel #9
0
    def setUp(self):
        # set config file
        config_file = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
        self.config = Config.load(config_file, setAsDefault=True)

        # set choices
        choices = [
            ("Choice 1", my_callback),
        ]

        # init the engine
        engine = GameEngine(self.config)

        # init the menu
        self.menu = Menu(engine, choices)
Beispiel #10
0
class Main():
    def __init__(self):
        global args
        self.args = args

        self.playing = self.args['song']
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']
        self.diff = self.args['diff']
        self.part = self.args['part']
        self.mode = self.args['mode']
        self.players = self.args['players']

        self.config = self.load_config(self.configFile)

        #Lysdestic - Allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        #Lysdestic - Change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        #Lysdestic - Alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.init_oneshot()

        self.videoLayer = False
        self.restartRequested = False

    @staticmethod
    def load_config(configPath):
        ''' Load the configuration file. '''
        if configPath is not None:
            if configPath.lower() == "reset":

                # Get os specific location of config file, and remove it.
                fileName = os.path.join(
                    VFS.getWritableResourcePath(),
                    Version.PROGRAM_UNIXSTYLE_NAME + ".ini")
                os.remove(fileName)

                # Recreate it
                config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini",
                                     setAsDefault=True)

            else:
                # Load specified config file
                config = Config.load(configPath, setAsDefault=True)
        else:
            # Use default configuration file
            config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini",
                                 setAsDefault=True)

        return config

    def init_oneshot(self):
        ''' Determine if oneshot mode is valid. '''
        # I think this code can be moved elsewhere...
        self.engine.cmdPlay = 0

        # Check for a valid invocation of one-shot mode.
        if self.playing is not None:
            log.debug('Validating song directory for one-shot mode.')

            library = Config.get("setlist", "base_library")
            basefolder = os.path.join(Version.dataPath(), library, "songs",
                                      self.playing)

            if not os.path.exists(os.path.join(basefolder, "song.ini")):

                if not (os.path.exists(os.path.join(basefolder, "notes.mid"))
                        or os.path.exists(
                            os.path.join(basefolder, "notes-unedited.mid"))):

                    if not (os.path.exists(os.path.join(
                            basefolder, "song.ogg")) or os.path.exists(
                                os.path.join(basefolder, "guitar.ogg"))):

                        log.warn(
                            "Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode."
                            % self.playing)
                        self.engine.startupMessages.append(
                            _("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode."
                              ) % self.playing)
                        return

            # Set up one-shot mode
            log.debug('Entering one-shot mode.')
            Config.set("setlist", "selected_song", playing)

            self.engine.cmdPlay = 1

            if diff is not None:
                self.engine.cmdDiff = int(diff)
            if part is not None:
                self.engine.cmdPart = int(part)

            if players == 1:
                self.engine.cmdMode = players, mode, 0
            else:
                self.engine.cmdMode = players, 0, mode

    def restart(self):
        log.notice("Restarting.")
        self.engine.audio.close()
        self.restartRequested = True

    def run(self):

        # Perhapse this could be implemented in a better way...
        # Play the intro video if it is present, we have the capability, and
        # we are not in one-shot mode.
        if not self.engine.cmdPlay:
            themename = Config.get("coffee", "themename")
            vidSource = os.path.join(Version.dataPath(), 'themes', themename,
                                     'menu', 'intro.ogv')
            if os.path.isfile(vidSource):
                try:
                    vidPlayer = VideoLayer(self.engine,
                                           vidSource,
                                           cancellable=True)
                except (IOError, VideoPlayerError):
                    log.error("Error loading intro video:")
                else:
                    vidPlayer.play()
                    self.engine.view.pushLayer(vidPlayer)
                    self.videoLayer = True
                    self.engine.ticksAtStart = pygame.time.get_ticks()
                    while not vidPlayer.finished:
                        self.engine.run()
                    self.engine.view.popLayer(vidPlayer)
                    self.engine.view.pushLayer(MainMenu(self.engine))
        if not self.videoLayer:
            self.engine.setStartupLayer(MainMenu(self.engine))

        # Run the main game loop.
        try:
            self.engine.ticksAtStart = pygame.time.get_ticks()
            while self.engine.run():
                pass
        except KeyboardInterrupt:
            log.notice("Left mainloop due to KeyboardInterrupt.")
            # don't reraise

        # Restart the program if the engine is asking that we do so.
        if self.engine.restartRequested:
            self.restart()

        # evilynux - MainMenu class already calls this - useless?
        self.engine.quit()
Beispiel #11
0
class Main():
    def __init__(self):
        global args
        self.args = args

        self.playing = self.args['song']
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']
        self.diff = self.args['diff']
        self.part = self.args['part']
        self.mode = self.args['mode']
        self.players = self.args['players']

        self.config = self.load_config(self.configFile)

        #Lysdestic - Allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        #Lysdestic - Change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        #Lysdestic - Alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.init_oneshot()

        self.videoLayer = False
        self.restartRequested = False

    @staticmethod
    def load_config(configPath):
        ''' Load the configuration file. '''
        if configPath is not None:
            if configPath.lower() == "reset":

                # Get os specific location of config file, and remove it.
                fileName = os.path.join(VFS.getWritableResourcePath(), Version.PROGRAM_UNIXSTYLE_NAME + ".ini")
                os.remove(fileName)

                # Recreate it
                config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)

            else:
                # Load specified config file
                config = Config.load(configPath, setAsDefault = True)
        else:
            # Use default configuration file
            config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)

        return config

    def init_oneshot(self):
        ''' Determine if oneshot mode is valid. '''
        # I think this code can be moved elsewhere...
        self.engine.cmdPlay = 0

        # Check for a valid invocation of one-shot mode.
        if self.playing is not None:
            log.debug('Validating song directory for one-shot mode.')

            library = Config.get("setlist","base_library")
            basefolder = os.path.join(Version.dataPath(),library,"songs",self.playing)


            if not os.path.exists(os.path.join(basefolder, "song.ini")):

                if not (os.path.exists(os.path.join(basefolder, "notes.mid")) or
                        os.path.exists(os.path.join(basefolder, "notes-unedited.mid"))):

                    if not (os.path.exists(os.path.join(basefolder, "song.ogg")) or
                            os.path.exists(os.path.join(basefolder, "guitar.ogg"))):

                        log.warn("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode." % self.playing)
                        self.engine.startupMessages.append(_("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode.") % self.playing)
                        return

            # Set up one-shot mode
            log.debug('Entering one-shot mode.')
            Config.set("setlist", "selected_song", playing)

            self.engine.cmdPlay = 1

            if diff is not None:
                self.engine.cmdDiff = int(diff)
            if part is not None:
                self.engine.cmdPart = int(part)

            if players == 1:
                self.engine.cmdMode = players, mode, 0
            else:
                self.engine.cmdMode = players, 0, mode

    def restart(self):
        log.notice("Restarting.")
        self.engine.audio.close()
        self.restartRequested = True

    def run(self):

        # Perhapse this could be implemented in a better way...
        # Play the intro video if it is present, we have the capability, and
        # we are not in one-shot mode.
        if not self.engine.cmdPlay:
            themename = Config.get("coffee", "themename")
            vidSource = os.path.join(Version.dataPath(), 'themes', themename, 'menu', 'intro.ogv')
            if os.path.isfile(vidSource):
                try:
                    vidPlayer = VideoLayer(self.engine, vidSource, cancellable=True)
                except (IOError, VideoPlayerError):
                    log.error("Error loading intro video:")
                else:
                    vidPlayer.play()
                    self.engine.view.pushLayer(vidPlayer)
                    self.videoLayer = True
                    self.engine.ticksAtStart = pygame.time.get_ticks()
                    while not vidPlayer.finished:
                        self.engine.run()
                    self.engine.view.popLayer(vidPlayer)
                    self.engine.view.pushLayer(MainMenu(self.engine))
        if not self.videoLayer:
            self.engine.setStartupLayer(MainMenu(self.engine))

        # Run the main game loop.
        try:
            self.engine.ticksAtStart = pygame.time.get_ticks()
            while self.engine.run():
                pass
        except KeyboardInterrupt:
            log.notice("Left mainloop due to KeyboardInterrupt.")
            # don't reraise

        # Restart the program if the engine is asking that we do so.
        if self.engine.restartRequested:
            self.restart()

        # evilynux - MainMenu class already calls this - useless?
        self.engine.quit()
Beispiel #12
0
class Main():
    def __init__(self):

        # get args
        self.args = _cmd_args
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']

        # load config
        self.config = self.load_config(self.configFile)

        # allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        # change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        # alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.videoLayer = False
        self.restartRequested = False

    @staticmethod
    def load_config(configPath):
        ''' Load the configuration file. '''
        if configPath is not None:
            if configPath.lower() == "reset":

                # Get os specific location of config file, and remove it.
                fileName = os.path.join(
                    VFS.getWritableResourcePath(),
                    Version.PROGRAM_UNIXSTYLE_NAME + ".ini")
                os.remove(fileName)

                # Recreate it
                config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini",
                                     setAsDefault=True)

            else:
                # Load specified config file
                config = Config.load(configPath, setAsDefault=True)
        else:
            # Use default configuration file
            config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini",
                                 setAsDefault=True)

        return config

    def restart(self):
        logger.info("Restarting.")
        self.engine.audio.close()
        self.restartRequested = True

    def run(self):
        # Perhapse this could be implemented in a better way...
        # Play the intro video if it is present, we have the capability
        themename = Config.get("coffee", "themename")
        vidSource = os.path.join(Version.dataPath(), 'themes', themename,
                                 'menu', 'intro.ogv')
        if os.path.isfile(vidSource):
            try:
                vidPlayer = VideoLayer(self.engine,
                                       vidSource,
                                       cancellable=True)
            except (IOError, VideoPlayerError):
                logger.error("Error loading intro video:")
            else:
                vidPlayer.play()
                self.engine.view.pushLayer(vidPlayer)
                self.videoLayer = True
                self.engine.ticksAtStart = pygame.time.get_ticks()
                while not vidPlayer.finished:
                    self.engine.run()
                self.engine.view.popLayer(vidPlayer)
                self.engine.view.pushLayer(MainMenu(self.engine))

        if not self.videoLayer:
            self.engine.setStartupLayer(MainMenu(self.engine))

        # Run the main game loop.
        try:
            self.engine.ticksAtStart = pygame.time.get_ticks()
            while self.engine.run():
                pass
        except KeyboardInterrupt:
            logger.info("Left mainloop due to KeyboardInterrupt.")
            # don't reraise

        # Restart the program if the engine is asking that we do so.
        if self.engine.restartRequested:
            self.restart()

        # evilynux - MainMenu class already calls this - useless?
        self.engine.quit()
Beispiel #13
0
 def setUp(self):
     # set up the engine with a config and a world
     config_filename = Version.PROGRAM_UNIXSTYLE_NAME + ".ini"
     config = Config.load(config_filename, setAsDefault=True)
     self.engine = GameEngine(config)
     self.engine.startWorld(1)
Beispiel #14
0
class Main():
    def __init__(self):

        # get args
        self.args = _cmd_args
        self.configFile = self.args['config']
        self.fullscreen = self.args['fullscreen']
        self.resolution = self.args['resolution']
        self.theme = self.args['theme']

        # load config
        self.config = self.load_config(self.configFile)

        # allow support for manipulating fullscreen via CLI
        if self.fullscreen is not None:
            Config.set("video", "fullscreen", self.fullscreen)

        # change resolution from CLI
        if self.resolution is not None:
            Config.set("video", "resolution", self.resolution)

        # alter theme from CLI
        if self.theme is not None:
            Config.set("coffee", "themename", self.theme)

        self.engine = GameEngine(self.config)

        self.videoLayer = False
        self.restartRequested = False

    @staticmethod
    def load_config(configPath):
        ''' Load the configuration file. '''
        if configPath is not None:
            if configPath.lower() == "reset":

                # Get os specific location of config file, and remove it.
                fileName = os.path.join(VFS.getWritableResourcePath(), Version.PROGRAM_UNIXSTYLE_NAME + ".ini")
                os.remove(fileName)

                # Recreate it
                config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault=True)

            else:
                # Load specified config file
                config = Config.load(configPath, setAsDefault=True)
        else:
            # Use default configuration file
            config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault=True)

        return config

    def restart(self):
        logger.info("Restarting.")
        self.engine.audio.close()
        self.restartRequested = True

    def run(self):
        # Perhapse this could be implemented in a better way...
        # Play the intro video if it is present, we have the capability
        themename = Config.get("coffee", "themename")
        vidSource = os.path.join(Version.dataPath(), 'themes', themename, 'menu', 'intro.ogv')
        if os.path.isfile(vidSource):
            try:
                vidPlayer = VideoLayer(self.engine, vidSource, cancellable=True)
            except (IOError, VideoPlayerError):
                logger.error("Error loading intro video:")
            else:
                vidPlayer.play()
                self.engine.view.pushLayer(vidPlayer)
                self.videoLayer = True
                self.engine.ticksAtStart = pygame.time.get_ticks()
                while not vidPlayer.finished:
                    self.engine.run()
                self.engine.view.popLayer(vidPlayer)
                self.engine.view.pushLayer(MainMenu(self.engine))

        if not self.videoLayer:
            self.engine.setStartupLayer(MainMenu(self.engine))

        # Run the main game loop.
        try:
            self.engine.ticksAtStart = pygame.time.get_ticks()
            while self.engine.run():
                pass
        except KeyboardInterrupt:
            logger.info("Left mainloop due to KeyboardInterrupt.")
            # don't reraise

        # Restart the program if the engine is asking that we do so.
        if self.engine.restartRequested:
            self.restart()

        # evilynux - MainMenu class already calls this - useless?
        self.engine.quit()