def keyName(value): if value in CONTROL1: name = "Controller 1" control = CONTROL1 n = 0 elif value in CONTROL2: name = "Controller 2" control = CONTROL2 n = 1 elif value in CONTROL3: name = "Controller 3" control = CONTROL3 n = 2 else: name = "Controller 4" control = CONTROL4 n = 3 for j in range(20): if value == control[j]: if self.type[n] == 2: return name + " " + drumkey4names[j] elif self.type[n] == 3: return name + " " + drumkey5names[j] else: return name + " " + guitarkeynames[j] else: log.notice("Key value not found.") return "Error"
def load(self, target = None, name = None, function = lambda: None, synch = False, onLoad = None, onCancel = None): """ Load a file into memory, as either a foreground or background operation. 'function' is the user code that actually loads the file. 'synch' controls how 'function' is called: if synch==True, then function is called immediately, and whatever it returns is returned by this function. If sync==False, then a Loader is created to call 'function' on another thread, and the Loader is returned by this function. After loading is complete, the loaded object will be assigned to (target).(name) if both are defined. :param target: None, or object to receive loaded file. :param name: None, or name of attribute of 'target' to receive loaded file. :param function: function to call to perform the loading :param synch: True to do the loading now, False to return now and load the file in a background thread. :param onLoad: function to call when loading is completed. :param onCancel: function to call when loading is canceled. :return: If synch == True, returns the object returned by 'function'; else returns an instance of fofix.core.Loader. """ if self.logLoadings == 1: log.notice("Loading %s.%s %s" % (target.__class__.__name__, name, synch and "synchronously" or "asynchronously")) l = Loader(target, name, function, self.resultQueue, self.loaderSemaphore, onLoad = onLoad, onCancel = onCancel) if synch: l.load() return l.finish() else: self.loaders.append(l) l.start() return l
def finishGame(self): if not self.world: log.notice("GameEngine.finishGame called before World created.") return self.world.finishGame() self.world = None self.gameStarted = False self.view.pushLayer(self.mainMenu)
def __init__(self, guitarScene, configFileName, coOp = False): self.scene = guitarScene self.engine = guitarScene.engine self.layers = {} #collection of all the layers in the rockmeter self.layersForRender = {} #collection of layers that are rendered separate from any group self.layerGroups = {} #collection of layer groups self.sharedLayerGroups = {} self.sharedLayers = {} #these layers are for coOp use only self.sharedLayersForRender = {} self.sharedGroups = {} self.coOp = coOp self.config = LinedConfigParser() self.config.read(configFileName) self.themename = self.engine.data.themeLabel try: themepath = os.path.join(Version.dataPath(), "themes", self.themename) fp, pathname, description = imp.find_module("CustomRMLayers",[themepath]) self.customRMLayers = imp.load_module("CustomRMLayers", fp, pathname, description) except ImportError: self.customRMLayers = None log.notice("Custom Rockmeter layers are not available") # Build the layers for i in range(Rockmeter._layerLimit): types = [ "Image", "Text", "Circle", "Custom" ] for t in types: self.section = "layer%d:%s" % (i, t) if not self.config.has_section(self.section): continue else: if t == types[1]: self.createFont(self.section, i) elif t == types[2]: self.createCircle(self.section, i) elif t == types[3]: self.createCustom(self.section, i) else: self.createImage(self.section, i) break for i in range(Rockmeter._groupLimit): self.section = "Group%d" % i if not self.config.has_section(self.section): continue else: self.createGroup(self.section, i) self.reset()
def __init__(self, guitarScene, configFileName, coOp=False): self.scene = guitarScene self.engine = guitarScene.engine self.layers = {} #collection of all the layers in the rockmeter self.layersForRender = { } #collection of layers that are rendered separate from any group self.layerGroups = {} #collection of layer groups self.sharedLayerGroups = {} self.sharedLayers = {} #these layers are for coOp use only self.sharedLayersForRender = {} self.sharedGroups = {} self.coOp = coOp self.config = LinedConfigParser() self.config.read(configFileName) self.themename = self.engine.data.themeLabel try: themepath = os.path.join(Version.dataPath(), "themes", self.themename) fp, pathname, description = imp.find_module( "CustomRMLayers", [themepath]) self.customRMLayers = imp.load_module("CustomRMLayers", fp, pathname, description) except ImportError: self.customRMLayers = None log.notice("Custom Rockmeter layers are not available") # Build the layers for i in range(Rockmeter._layerLimit): types = ["Image", "Text", "Circle", "Custom"] for t in types: self.section = "layer%d:%s" % (i, t) if not self.config.has_section(self.section): continue else: if t == types[1]: self.createFont(self.section, i) elif t == types[2]: self.createCircle(self.section, i) elif t == types[3]: self.createCustom(self.section, i) else: self.createImage(self.section, i) break for i in range(Rockmeter._groupLimit): self.section = "Group%d" % i if not self.config.has_section(self.section): continue else: self.createGroup(self.section, i) self.reset()
def showMessage(engine, text): """ Show a message to the user. @param engine: Game engine @param text: Message text """ log.notice("%s" % text) d = MessageScreen(engine, text) _runDialog(engine, d)
def load(self, target = None, name = None, function = lambda: None, synch = False, onLoad = None): log.notice("Loading %s.%s %s" % (target.__class__.__name__, name, synch and "synchronously" or "asynchronously")) l = Loader(target, name, function, self.resultQueue, self.loaderSemaphore, onLoad = onLoad) if synch: l.load() return l.finish() else: self.loaders.append(l) l.start() return l
def load(self, target = None, name = None, function = lambda: None, synch = False, onLoad = None, onCancel = None): if self.logLoadings == 1: log.notice("Loading %s.%s %s" % (target.__class__.__name__, name, synch and "synchronously" or "asynchronously")) l = Loader(target, name, function, self.resultQueue, self.loaderSemaphore, onLoad = onLoad, onCancel = onCancel) if synch: l.load() return l.finish() else: self.loaders.append(l) l.start() return l
def finish(self): if self.canceled: return log.notice("Loaded %s.%s in %.3f seconds" % (self.target.__class__.__name__, self.name, self.time)) if self.exception: raise self.exception[0], self.exception[1], self.exception[2] if self.target and self.name: setattr(self.target, self.name, self.result) if self.onLoad: self.onLoad(self.result) return self.result
def fileName(self, *name, **args): #myfingershurt: the following should be global, and only done at startup. Not every damn time a file is loaded. songPath = self.songPath if not args.get("writable", False): for dataPath in self.dataPaths + songPath: readOnlyPath = os.path.join(dataPath, *name) # If the requested file is in the read-write path and not in the # read-only path, use the existing read-write one. if os.path.isfile(readOnlyPath): return readOnlyPath elif os.path.isdir(readOnlyPath): return readOnlyPath readWritePath = os.path.join(getWritableResourcePath(), *name) if os.path.isfile(readWritePath): return readWritePath return readOnlyPath else: for dataPath in [self.dataPaths[-1]] + songPath: readOnlyPath = os.path.join(dataPath, *name) if not (os.path.isfile(readOnlyPath) or os.path.isdir(readOnlyPath)): continue try: # First see if we can write to the original file if os.access(readOnlyPath, os.W_OK): return readOnlyPath # If the original file does not exist, see if we can write to its directory if not os.path.isfile(readOnlyPath) and os.access(os.path.dirname(readOnlyPath), os.W_OK): pass except: raise # If the resource exists in the read-only path, make a copy to the # read-write path. readWritePath = os.path.join(getWritableResourcePath(), *name) if not os.path.isfile(readWritePath) and os.path.isfile(readOnlyPath): log.notice("Copying '%s' to writable data directory." % "/".join(name)) try: os.makedirs(os.path.dirname(readWritePath)) except: pass shutil.copy(readOnlyPath, readWritePath) self.makeWritable(readWritePath) # Create directories if needed if not os.path.isdir(readWritePath) and os.path.isdir(readOnlyPath): log.notice("Creating writable directory '%s'." % "/".join(name)) os.makedirs(readWritePath) self.makeWritable(readWritePath) return readWritePath return readOnlyPath
def finish(self): if self.canceled: if self.onCancel: self.onCancel() return if self.logLoadings == 1: log.notice("Loaded %s.%s in %.3f seconds" % (self.target.__class__.__name__, self.name, self.time)) if self.exception: raise self.exception[0], self.exception[1], self.exception[2] if self.target and self.name: setattr(self.target, self.name, self.result) if self.onLoad: self.onLoad(self.result) return self.result
def getImgDrawing(self, fileName, openImage=True): imgDrawing = None for dataPath in self.resource.dataPaths: fileName1 = os.path.join(dataPath, fileName) if self.logLoadings == 1: if openImage: log.notice("Trying to load image: %s" % fileName1) else: log.notice("Checking image: %s" % fileName1) # check if fileName1 exists (has extension) if os.path.exists(fileName1): if openImage: try: imgDrawing = ImgDrawing(self.svg, fileName1) return imgDrawing except IOError: log.warn("Unable to load image file: %s" % fileName1) except OverflowError: log.warn("Unable to read image file: %s" % fileName1) else: return True else: # find extension fileName1 = os.path.splitext(fileName1)[0] # glob parses [] but those are legal chars on Windows, so we must escape them. # it must be done like this so replacements are not mangled # by other replacements. replacements = {"[": "[[]", "]": "[]]"} fileName1 = "".join( [replacements.get(c, c) for c in fileName1]) files = glob.glob('%s.*' % fileName1) if openImage: for f in files: try: imgDrawing = ImgDrawing(self.svg, f) return imgDrawing except IOError: log.warn("Unable to load image file: %s" % f) elif len(files) > 0: return True # image not found if self.logImageNotFound: log.warn("Image not found: %s" % fileName) return False
def run(self, ticks): while self.mic.get_read_available() > 1024: try: chunk = self.mic.read(1024) except IOError as e: if e.args[1] == pyaudio.paInputOverflowed: log.notice('Microphone: ignoring input buffer overflow') chunk = '\x00' * 4096 else: raise if self.passthroughStream is not None: self.passthroughQueue.append(chunk) self.analyzer.input(np.frombuffer(chunk, dtype=np.float32)) self.analyzer.process() pk = self.analyzer.getPeak() if self.detectTaps: if pk > self.tapThreshold and pk > self.lastPeak + 5.0: self.tapStatus = True self.lastPeak = pk
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()
def fileName(self, *name, **args): if not args.get("writable", False): for dataPath in self.dataPaths: readOnlyPath = os.path.join(dataPath, *name) # If the requested file is in the read-write path and not in the # read-only path, use the existing read-write one. if os.path.isfile(readOnlyPath): return readOnlyPath readWritePath = os.path.join(getWritableResourcePath(), *name) if os.path.isfile(readWritePath): return readWritePath return readOnlyPath else: readOnlyPath = os.path.join(self.dataPaths[-1], *name) try: # First see if we can write to the original file if os.access(readOnlyPath, os.W_OK): return readOnlyPath # If the original file does not exist, see if we can write to its directory if not os.path.isfile(readOnlyPath) and os.access(os.path.dirname(readOnlyPath), os.W_OK): return readOnlyPath except: raise # If the resource exists in the read-only path, make a copy to the # read-write path. readWritePath = os.path.join(getWritableResourcePath(), *name) if not os.path.isfile(readWritePath) and os.path.isfile(readOnlyPath): log.notice("Copying '%s' to writable data directory." % "/".join(name)) try: os.makedirs(os.path.dirname(readWritePath)) except: pass shutil.copy(readOnlyPath, readWritePath) self.makeWritable(readWritePath) # Create directories if needed if not os.path.isdir(readWritePath) and os.path.isdir(readOnlyPath): log.notice("Creating writable directory '%s'." % "/".join(name)) os.makedirs(readWritePath) self.makeWritable(readWritePath) return readWritePath
def getImgDrawing(self, fileName, openImage=True): imgDrawing = None for dataPath in self.resource.dataPaths: fileName1 = os.path.join(dataPath, fileName) if self.logLoadings == 1: if openImage: log.notice("Trying to load image: %s" % fileName1) else: log.notice("Checking image: %s" % fileName1) #check if fileName1 exists (has extension) if os.path.exists(fileName1): if openImage: try: imgDrawing = ImgDrawing(self.svg, fileName1) return imgDrawing except IOError: log.warn("Unable to load image file: %s" % fileName1) except OverflowError: log.warn("Unable to read image file: %s" % fileName1) else: return True else: #find extension fileName1 = os.path.splitext(fileName1)[0] files = glob.glob('%s.*' % fileName1) if openImage: for i in range(len(files)): try: imgDrawing = ImgDrawing(self.svg, files[i]) return imgDrawing except IOError: log.warn("Unable to load image file: %s" % files[i]) elif len(files) > 0: return True #image not found if self.logImageNotFound: log.debug("Image not found: %s" % fileName) return False
def _initTheme(self, themename, themepath): """ Select the source of graphics for the game. Note that currently this can only be called GameEngine on startup. :param themename: what to call this theme :type themename: str :param themepath: absolute path to theme folder :type themepath: str """ log.notice('Setting theme %s from "%s"' % (themename, themepath)) self.theme = None try: # Look for "CustomTheme.py" inside theme dir fp, pathname, description = imp.find_module( "CustomTheme", [themepath]) try: # Found it! Load it. theme = imp.load_module("CustomTheme", fp, pathname, description) self.theme = theme.CustomTheme(themepath, themename) log.notice('Theme activated using custom class "%s"' % pathname) except ImportError as e: # Unable to load module; log it, but continue with default Theme. log.error('Failed to load CustomTheme.py from "%s"' % pathname) finally: fp.close() except ImportError: # CustomTheme.py file is optional, but notify developer anyway. log.notice("No CustomTheme.py found in theme") pass if self.theme is None: self.theme = Theme(themepath, themename) log.notice("Theme activated using built-in Theme class") self.task.addTask(self.theme)
def load(self, libraryName, songName, practiceMode = False): if self.scene.coOpType: rm = os.path.join("themes", self.themename, "rockmeter_coop.ini") elif self.scene.battle: rm = os.path.join("themes", self.themename, "rockmeter_profaceoff.ini") elif self.scene.gamePlayers > 1: rm = os.path.join("themes", self.themename, "rockmeter_faceoff.ini") else: rm = os.path.join("themes", self.themename, "rockmeter.ini") if os.path.exists(os.path.join("..", "data", rm)): rockmeter = self.engine.resource.fileName(rm) else: rockmeter = self.engine.resource.fileName(os.path.join("themes", self.themename, "rockmeter.ini")) self.rockmeter = Rockmeter.Rockmeter(self.scene, rockmeter, self.scene.coOpType) # evilynux - Fixes a self.background not defined crash self.background = None #MFH - new background stage logic: if self.mode == 2: #blank / no stage self.songStage = 0 self.rotationMode = 0 elif practiceMode: #check for existing practice stage; always disable stage rotation here self.songStage = 0 self.rotationMode = 0 self.mode = 1 #separated practice stages for the instruments by k.i.d if self.scene.instruments[0].isDrum: background = "practicedrum" elif self.scene.instruments[0].isBassGuitar: background = "practicebass" else: background = "practice" if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds",background)): #MFH - must first fall back on the old practice.png before forcing blank stage mode! if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds","practice")): log.warn("No practice stage, falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode elif self.songStage == 1: #check for song-specific background test = True if not self.engine.loadImgDrawing(self, "background", os.path.join(libraryName, songName, "background")): log.notice("No song-specific stage found") # evilynux test = False if test: #does a song-specific background exist? self.rotationMode = 0 self.mode = 1 else: self.songStage = 0 #MFH - now, after the above logic, we can run the normal stage mode logic # only worrying about checking for Blank, song-specific and # practice stage modes if self.mode != 2 and self.mode != 3 and self.songStage == 0 and not practiceMode: #still need to load stage(s) #myfingershurt: assign this first if self.mode == 1: #just use Default.png if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, "default")): log.warn("No default stage; falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode ##This checks how many Stage-background we have to select from if self.mode == 0 and self.rotationMode == 0: #MFH: just display a random stage files = [] fileIndex = 0 allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass" and name != ".svn": log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: log.debug("Practice background filtered: " + name) # evilynux - improved error handling, fallback to blank background if no background are found if fileIndex == 0: log.warn("No valid stage found!") self.mode = 2; else: i = random.randint(0,len(files)-1) filename = files[i] ##End check number of Stage-backgrounds if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, filename)): self.mode = 2; elif self.rotationMode > 0 and self.mode != 2: files = [] fileIndex = 0 if self.animatedFolder == "Random": #Select one of the subfolders under stages\ to animate randomly numAniStageFolders = len(self.engine.stageFolders) if numAniStageFolders > 0: self.animatedFolder = random.choice(self.engine.stageFolders) else: self.animatedFolder = "Normal" elif self.animatedFolder == "None": self.mode = 2 if self.animatedFolder != "Normal" and self.mode != 2: #just use the base Stages folder for rotation self.path = os.path.join("themes",self.themename,"backgrounds",self.animatedFolder) self.pathfull = self.engine.getPath(self.path) self.animation = True allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[1].lower() == ".png" or os.path.splitext(name)[1].lower() == ".jpg" or os.path.splitext(name)[1].lower() == ".jpeg": if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass": log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: log.debug("Practice background filtered: " + name) files.sort() if self.rotationMode > 0 and self.mode != 2: #alarian: blank stage option is not selected #myfingershurt: just populate the image array in order, they are pulled in whatever order requested: for j in range(len(files)): self.engine.loadImgDrawing(self, "backgroundA", os.path.join(self.path, files[j])) self.imgArr.append(getattr(self, "backgroundA", os.path.join(self.path, files[j]))) if self.rotationMode > 0 and len(self.imgArr) == 0: self.rotationMode = 0
def restart(self): log.notice("Restarting.") self.engine.audio.close() self.restartRequested = True
def __init__(self): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: log.debug("Input class init (Input.py)...") Task.__init__(self) self.mouse = pygame.mouse self.mouseListeners = [] self.keyListeners = [] self.systemListeners = [] self.priorityKeyListeners = [] self.controls = Controls() self.activeGameControls = [] self.p2Nav = self.controls.p2Nav self.type1 = self.controls.type[0] self.keyCheckerMode = Config.get("game", "key_checker_mode") self.disableKeyRepeat() self.gameGuitars = 0 self.gameDrums = 0 self.gameMics = 0 self.gameBots = 0 # Initialize joysticks pygame.joystick.init() self.joystickNames = {} self.joystickAxes = {} self.joystickHats = {} self.joysticks = [ pygame.joystick.Joystick(id) for id in range(pygame.joystick.get_count()) ] for j in self.joysticks: j.init() self.joystickNames[j.get_id()] = j.get_name() self.joystickAxes[j.get_id()] = [0] * j.get_numaxes() self.joystickHats[j.get_id()] = [(0, 0)] * j.get_numhats() log.debug("%d joysticks found." % len(self.joysticks)) # Enable music events Music.setEndEvent(MusicFinished) #Music.setEndEvent() #MFH - no event required? # Custom key names self.getSystemKeyName = pygame.key.name pygame.key.name = self.getKeyName self.midi = [] if haveMidi: pygame.midi.init() for i in range(pygame.midi.get_count()): interface, name, is_input, is_output, is_opened = pygame.midi.get_device_info( i) log.debug("Found MIDI device: %s on %s" % (name, interface)) if not is_input: log.debug("MIDI device is not an input device.") continue try: self.midi.append(pygame.midi.Input(i)) log.debug("Device opened as device number %d." % len(self.midi)) except pygame.midi.MidiException: log.error("Error opening device for input.") if len(self.midi) == 0: log.debug("No MIDI input ports found.") else: log.notice( "MIDI input support is not available; install at least pygame 1.9 to get it." )
songName = arg while True: config = Config.load(Version.appName() + ".ini", setAsDefault = True) engine = GameEngine(config) menu = MainMenu(engine, songName = songName) engine.setStartupLayer(menu) try: while engine.run(): pass except KeyboardInterrupt: pass if engine.restartRequested: log.notice("Restarting.") try: # Determine whether were running from an exe or not if hasattr(sys, "frozen"): if os.name == "nt": os.execl("FretsOnFire.exe", "FretsOnFire.exe", *sys.argv[1:]) elif sys.platform == "darwin": # This exit code tells the launcher script to restart the game sys.exit(100) else: os.execl("./FretsOnFire", "./FretsOnFire", *sys.argv[1:]) else: if os.name == "nt": bin = "c:/python25/python" else:
def load(self, libraryName, songName, practiceMode = False): if self.scene.coOpType: rm = os.path.join("themes", self.themename, "rockmeter_coop.ini") elif self.scene.battle: rm = os.path.join("themes", self.themename, "rockmeter_profaceoff.ini") elif self.scene.gamePlayers > 1: rm = os.path.join("themes", self.themename, "rockmeter_faceoff.ini") else: rm = os.path.join("themes", self.themename, "rockmeter.ini") if os.path.exists(os.path.join("..", "data", rm)): rockmeter = self.engine.resource.fileName(rm) else: rockmeter = self.engine.resource.fileName(os.path.join("themes", self.themename, "rockmeter.ini")) self.rockmeter = Rockmeter.Rockmeter(self.scene, rockmeter, self.scene.coOpType) # evilynux - Fixes a self.background not defined crash self.background = None #MFH - new background stage logic: if self.mode == 2: #blank / no stage self.songStage = 0 self.rotationMode = 0 elif practiceMode: #check for existing practice stage; always disable stage rotation here self.songStage = 0 self.rotationMode = 0 self.mode = 1 #separated practice stages for the instruments by k.i.d if self.scene.instruments[0].isDrum: background = "practicedrum" elif self.scene.instruments[0].isBassGuitar: background = "practicebass" else: background = "practice" if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds",background)): #MFH - must first fall back on the old practice.png before forcing blank stage mode! if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds","practice")): log.warn("No practice stage, falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode elif self.songStage == 1: #check for song-specific background test = True if not self.engine.loadImgDrawing(self, "background", os.path.join(libraryName, songName, "background")): log.notice("No song-specific stage found") # evilynux test = False if test: #does a song-specific background exist? self.rotationMode = 0 self.mode = 1 else: self.songStage = 0 #MFH - now, after the above logic, we can run the normal stage mode logic # only worrying about checking for Blank, song-specific and # practice stage modes if self.mode != 2 and self.mode != 3 and self.songStage == 0 and not practiceMode: #still need to load stage(s) #myfingershurt: assign this first if self.mode == 1: #just use Default.png if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, "default")): log.warn("No default stage; falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode ##This checks how many Stage-background we have to select from if self.mode == 0 and self.rotationMode == 0: #MFH: just display a random stage files = [] fileIndex = 0 allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass" and name != ".git": log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: log.debug("Practice background filtered: " + name) # evilynux - improved error handling, fallback to blank background if no background are found if fileIndex == 0: log.warn("No valid stage found!") self.mode = 2; else: i = random.randint(0,len(files)-1) filename = files[i] ##End check number of Stage-backgrounds if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, filename)): self.mode = 2; elif self.rotationMode > 0 and self.mode != 2: files = [] fileIndex = 0 if self.animatedFolder == "Random": #Select one of the subfolders under stages\ to animate randomly numAniStageFolders = len(self.engine.stageFolders) if numAniStageFolders > 0: self.animatedFolder = random.choice(self.engine.stageFolders) else: self.animatedFolder = "Normal" elif self.animatedFolder == "None": self.mode = 2 if self.animatedFolder != "Normal" and self.mode != 2: #just use the base Stages folder for rotation self.path = os.path.join("themes",self.themename,"backgrounds",self.animatedFolder) self.pathfull = self.engine.getPath(self.path) self.animation = True allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[1].lower() == ".png" or os.path.splitext(name)[1].lower() == ".jpg" or os.path.splitext(name)[1].lower() == ".jpeg": if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass": log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: log.debug("Practice background filtered: " + name) files.sort() if self.rotationMode > 0 and self.mode != 2: #alarian: blank stage option is not selected #myfingershurt: just populate the image array in order, they are pulled in whatever order requested: for j in range(len(files)): self.engine.loadImgDrawing(self, "backgroundA", os.path.join(self.path, files[j])) self.imgArr.append(getattr(self, "backgroundA", os.path.join(self.path, files[j]))) if self.rotationMode > 0 and len(self.imgArr) == 0: self.rotationMode = 0
def __init__(self): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: log.debug("Input class init (Input.py)...") Task.__init__(self) self.mouse = pygame.mouse self.mouseListeners = [] self.keyListeners = [] self.systemListeners = [] self.priorityKeyListeners = [] self.controls = Controls() self.activeGameControls = [] self.p2Nav = self.controls.p2Nav self.type1 = self.controls.type[0] self.keyCheckerMode = Config.get("game","key_checker_mode") self.disableKeyRepeat() self.gameGuitars = 0 self.gameDrums = 0 self.gameMics = 0 self.gameBots = 0 # Initialize joysticks pygame.joystick.init() self.joystickNames = {} self.joystickAxes = {} self.joystickHats = {} self.joysticks = [pygame.joystick.Joystick(id) for id in range(pygame.joystick.get_count())] for j in self.joysticks: j.init() self.joystickNames[j.get_id()] = j.get_name() self.joystickAxes[j.get_id()] = [0] * j.get_numaxes() self.joystickHats[j.get_id()] = [(0, 0)] * j.get_numhats() log.debug("%d joysticks found." % len(self.joysticks)) # Enable music events Music.setEndEvent(MusicFinished) #Music.setEndEvent() #MFH - no event required? # Custom key names self.getSystemKeyName = pygame.key.name pygame.key.name = self.getKeyName self.midi = [] if haveMidi: pygame.midi.init() for i in range(pygame.midi.get_count()): interface, name, is_input, is_output, is_opened = pygame.midi.get_device_info(i) log.debug("Found MIDI device: %s on %s" % (name, interface)) if not is_input: log.debug("MIDI device is not an input device.") continue try: self.midi.append(pygame.midi.Input(i)) log.debug("Device opened as device number %d." % len(self.midi)) except pygame.midi.MidiException: log.error("Error opening device for input.") if len(self.midi) == 0: log.debug("No MIDI input ports found.") else: log.notice("MIDI input support is not available; install at least pygame 1.9 to get it.")