예제 #1
0
    def Run(self, extra_arg=None):
        """ Figure out which game to play based on the contents of the 
        vp_game_map_file. """

        import config

        if extra_arg is not None:
            logging.getLogger("vpcom").info("Run received extra arg!?")
            logging.getLogger("vpcom").info("Arg was {0}".format(extra_arg))

        vp_game_map_file = config.value_for_key_path(keypath="vp_game_map_file", default="/.")
        vp_game_map = yaml.load(open(vp_game_map_file, "r"))
        game_class = vp_game_map[self.GameName]["kls"]
        game_path = vp_game_map[self.GameName]["path"]
        yamlpath = vp_game_map[self.GameName]["yaml"]
        logging.getLogger("vpcom").info("S11 is ..." + str(self.Sys11))

        try:
            # switch to the directory of the current game
            curr_file_path = os.path.dirname(os.path.abspath(__file__))
            newpath = os.path.realpath(curr_file_path + game_path)
            os.chdir(newpath)

            # add the path to the system path; this lets game relative procgames
            # be found if needed
            sys.path.insert(0, newpath)

            # re-import and re-load config to find game relative config.yaml if existing
            from procgame import config

            config.load()

            # now load procgame --this will be game relative if present, or system-wide if not
            from procgame import *

            # find the class of the game instance
            klass = util.get_class(game_class, game_path)
            self.game = klass()

            self.game.yamlpath = yamlpath
            self.game.log("GameName: " + str(self.GameName))
            self.game.log("SplashInfoLine: " + str(self.SplashInfoLine))

        except Exception, e:
            import traceback

            exc_type, exc_value, exc_traceback = sys.exc_info()

            formatted_lines = traceback.format_exc().splitlines()
            exceptionName = formatted_lines[-1]

            logging.getLogger("vpcom").info("game instantiation error({0})".format(exceptionName))
            logger = logging.getLogger("vpcom")
            logger.info("PYTHON FAILURE (Visual Pinball Bridge is now broken)")
            logger.info("Exception Name {0}".format(e))
            for l in formatted_lines:
                logger.info("{0}".format(l))
            if len(formatted_lines) > 2:
                self.ErrorMsg += "\n" + formatted_lines[-3] + "\n" + formatted_lines[-2] + "\n" + formatted_lines[-1]
            raise
예제 #2
0
	def Run(self):
		""" Figure out which game to play based on the contents of the 
		vp_game_map_file. """

		vp_game_map_file = config.value_for_key_path(keypath='vp_game_map_file', default='/.')
		vp_game_map = yaml.load(open(vp_game_map_file, 'r'))
		game_class = vp_game_map[self.GameName]['kls']
		game_path = vp_game_map[self.GameName]['path']
		yamlpath = vp_game_map[self.GameName]['yaml']

		rundir = vp_game_map['rundir']
		os.chdir(rundir)

		#game_config = yaml.load(open(yamlpath, 'r'))
		#machine_type = game_config['PRGame']['machineType']
		#self.game = None
		
		klass = util.get_class(game_class,game_path)
	 	#self.game = klass(machine_type)
	 	self.game = klass()
		self.game.log("GameName: " + str(self.GameName))
		self.game.log("SplashInfoLine: " + str(self.SplashInfoLine))
		self.game.yamlpath = yamlpath
	 	self.last_lamp_states = self.getLampStates()
	 	self.last_coil_states = self.getCoilStates()
		self.game.setup()

		# Initialize switches.  Call SetSwitch so it can invert
		# normally closed switches as appropriate.
		for i in range(0,120):
			self.SetSwitch(i, False)
		thread.start_new_thread(self.game.run_loop,())

		return True