def __init__(self, resource, svg): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("Data class init (Data.py)...") self.logLoadings = Config.get("game", "log_loadings") self.logImageNotFound = Config.get("log", "log_image_not_found") self.resource = resource self.svg = svg self.sfxVolume = Config.get("audio", "SFX_volume") self.crowdVolume = Config.get("audio", "crowd_volume") # Get theme themename = Config.get("coffee", "themename") self.themeLabel = themename self.themeCoOp = False self.players = None self.players = Player.loadPlayers() # myfingershurt: check for existence of theme path themepath = os.path.join(Version.dataPath(), "themes") self.themepath = themepath self.path = Version.dataPath() if not self.checkImgDrawing(os.path.join("themes", themename, "notes", "notes.png")): # myfingershurt: here need to ensure an existing theme is selected themes = [] defaultTheme = None # myfingershurt allthemes = os.listdir(themepath) for name in allthemes: if self.checkImgDrawing(os.path.join("themes", name, "notes", "notes.png")): themes.append(name) if name == "MegaLight V4": # myfingershurt defaultTheme = name # myfingershurt if defaultTheme != "MegaLight V4": # myfingershurt defaultTheme = themes[0] # myfingershurt # not a valid theme if notes.png isn't there! Force default theme: Config.set("coffee", "themename", defaultTheme) # re-init Data with new default themename = defaultTheme self.themeLabel = themename if not os.path.exists(os.path.join(Version.dataPath(), "themes", themename, "vocals")): self.vocalPath = "vocals" else: self.vocalPath = os.path.join("themes", themename, "vocals") self.theme = 2 self.themeCoOp = True self.fontScreenBottom = ( 0.75 ) # from our current viewport's constant 3:4 aspect ratio (which is always stretched to fill the video resolution) self.loadPartImages() # myfingershurt: multi-OS compatibility file access fixes using os.path.join() # load font customization images # Worldrave - Use new defined Star3 and star4. Using star1 and star2 as a fallback. # MFH - no more custom glyphs, these are wasting memory. # MFH - but we do need these star1-4 images anyway. Leaving them loaded here in the Data object. self.loadImgDrawing(self, "star1", os.path.join("themes", themename, "star1.png"), textureSize=(128, 128)) self.loadImgDrawing(self, "star2", os.path.join("themes", themename, "star2.png"), textureSize=(128, 128)) # MFH - let's not rely on errors here if we don't have to... if not self.loadImgDrawing( self, "star3", os.path.join("themes", themename, "star3.png"), textureSize=(128, 128) ): self.star3 = self.star1 if not self.loadImgDrawing( self, "star4", os.path.join("themes", themename, "star4.png"), textureSize=(128, 128) ): self.star4 = self.star2 if self.loadImgDrawing( self, "starPerfect", os.path.join("themes", themename, "starperfect.png"), textureSize=(128, 128) ): self.perfectStars = True self.maskStars = False else: self.starPerfect = self.star2 self.fcStars = False self.starFC = self.star2 self.maskStars = True self.perfectStars = False if self.perfectStars: if self.loadImgDrawing( self, "starFC", os.path.join("themes", themename, "starfc.png"), textureSize=(128, 128) ): self.fcStars = True else: self.starFC = self.starPerfect self.fcStars = False # load misc images self.loadImgDrawing( self, "loadingImage", os.path.join("themes", themename, "loadingbg.png"), textureSize=(256, 256) ) self.loadImgDrawing(self, "optionsBG", os.path.join("themes", themename, "menu", "optionsbg.png")) if self.loadImgDrawing(self, "submenuSelect", os.path.join("themes", themename, "submenuselect.png")): subSelectImgW = self.submenuSelect.width1() self.submenuSelectFound = True self.subSelectWFactor = 640.000 / subSelectImgW self.subSelectImgH = self.submenuSelect.height1() else: self.submenuSelectFound = False self.loadImgDrawing(self, "submenuSelect", os.path.join("themes", themename, "menu", "selected.png")) self.subSelectWFactor = 0 # load all the data in parallel # asciiOnly = not bool(Language.language) or Language.language == "Custom" # reversed = _("__lefttoright__") == "__righttoleft__" and True or False asciiOnly = True reversed = False scale = 1 # evilynux - Load bigger fonts so they're nicer when scaled, scaling readjusted fontSize = [44, 132, 34, 32, 30] w, h = [int(s) for s in Config.get("video", "resolution").split("x")] aspectRatio = float(w) / float(h) self.fontList = [ ["font1", "font", "default.ttf", fontSize[4]], ["font2", "bigFont", "title.ttf", fontSize[1]], ["font3", "pauseFont", "pause.ttf", fontSize[2]], ["font4", "scoreFont", "score.ttf", fontSize[3]], ["font5", "streakFont", "streak.ttf", fontSize[3]], ["font6", "loadingFont", "loading.ttf", fontSize[3]], ["font7", "songFont", "song.ttf", fontSize[4]], ["font8", "songListFont", "songlist.ttf", fontSize[3]], ["font9", "shadowFont", "songlist.ttf", fontSize[3]], ["font10", "streakFont2", "streakphrase.ttf", fontSize[2]], ] for f in self.fontList: if self.fileExists(os.path.join("themes", themename, "fonts", f[2])): fn = resource.fileName(os.path.join("themes", themename, "fonts", f[2])) f[0] = lambda: Font( fn, f[3], scale=scale * 0.5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio, ) resource.load(self, f[1], f[0], synch=True) elif self.fileExists(os.path.join("themes", themename, "fonts", "default.ttf")): Log.debug("Theme font not found: " + f[2]) fn = resource.fileName(os.path.join("themes", themename, "fonts", "default.ttf")) f[0] = lambda: Font( fn, f[3], scale=scale * 0.5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio, ) resource.load(self, f[1], f[0], synch=True) else: Log.debug("Default theme font not found: %s - using built-in default" % str(f[2])) fn = resource.fileName(os.path.join("fonts", "default.ttf")) f[0] = lambda: Font( fn, f[3], scale=scale * 0.5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio, ) resource.load(self, f[1], f[0], synch=True) self.fontDict = { "font": self.font, "bigFont": self.bigFont, "pauseFont": self.pauseFont, "scoreFont": self.scoreFont, "streakFont": self.streakFont, "songFont": self.songFont, "streakFont2": self.streakFont2, "songListFont": self.songListFont, "shadowFont": self.shadowFont, "loadingFont": self.loadingFont, } assert self.fontDict["font"] == self.font # load sounds asynchronously resource.load(self, "screwUpsounds", self.loadScrewUpsounds) resource.load(self, "screwUpsoundsBass", self.loadScrewUpsoundsBass) resource.load(self, "screwUpsoundsDrums", self.loadScrewUpsoundsDrums) resource.load(self, "acceptSounds", self.loadAcceptSounds) resource.load(self, "cancelSounds", self.loadBackSounds) # loadSoundEffect asynchronously self.syncSounds = [ ["bassDrumSound", "bassdrum.ogg"], ["battleUsedSound", "battleused.ogg"], ["CDrumSound", "crash.ogg"], ["clapSound", "clapsound.ogg"], ["coOpFailSound", "coopfail.ogg"], # ["crowdSound","crowdcheers.ogg"], ["failSound", "failsound.ogg"], ["rescueSound", "rescue.ogg"], ["rockSound", "rocksound.ogg"], ["selectSound1", "select1.ogg"], ["selectSound2", "select2.ogg"], ["selectSound3", "select3.ogg"], ["starActivateSound", "staractivate.ogg"], ["starDeActivateSound", "stardeactivate.ogg"], ["starDingSound", "starding.ogg"], ["starLostSound", "starlost.ogg"], ["starReadySound", "starpowerready.ogg"], ["starSound", "starpower.ogg"], ["startSound", "start.ogg"], ["T1DrumSound", "tom01.ogg"], ["T2DrumSound", "tom02.ogg"], ["T3DrumSound", "tom03.ogg"], ] for self.sounds in self.syncSounds: if self.fileExists(os.path.join("themes", themename, "sounds", self.sounds[1])): self.loadSoundEffect(self, self.sounds[0], os.path.join("themes", themename, "sounds", self.sounds[1])) elif self.fileExists(os.path.join("sounds", self.sounds[1])): Log.debug("Theme sound not found: " + self.sounds[1]) self.loadSoundEffect(self, self.sounds[0], os.path.join("sounds", self.sounds[1])) else: Log.warn("File " + self.sounds[1] + " not found using default instead.") self.loadSoundEffect(self, self.sounds[0], os.path.join("sounds", "default.ogg")) # TODO: Simplify crowdSound stuff so it can join the rest of us. # MFH - fallback on sounds/crowdcheers.ogg, and then starpower.ogg. Note if the fallback crowdcheers was used or not. if self.fileExists(os.path.join("themes", themename, "sounds", "crowdcheers.ogg")): self.loadSoundEffect( self, "crowdSound", os.path.join("themes", themename, "sounds", "crowdcheers.ogg"), crowd=True ) self.cheerSoundFound = 2 elif self.fileExists(os.path.join("sounds", "crowdcheers.ogg")): self.loadSoundEffect(self, "crowdSound", os.path.join("sounds", "crowdcheers.ogg"), crowd=True) self.cheerSoundFound = 1 Log.warn(themename + "/sounds/crowdcheers.ogg not found -- using data/sounds/crowdcheers.ogg instead.") else: self.cheerSoundFound = 0 Log.warn("crowdcheers.ogg not found -- no crowd cheering.")
def __init__(self, resource, svg): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("Data class init (Data.py)...") self.logLoadings = Config.get("game", "log_loadings") self.logImageNotFound = Config.get("log", "log_image_not_found") self.resource = resource self.svg = svg self.sfxVolume = Config.get("audio", "SFX_volume") self.crowdVolume = Config.get("audio", "crowd_volume") #Get theme themename = Config.get("coffee", "themename") self.themeLabel = themename self.themeCoOp = False self.players = None self.players = Player.loadPlayers() #myfingershurt: check for existence of theme path themepath = os.path.join(Version.dataPath(), "themes") self.themepath = themepath self.path = Version.dataPath() if not self.checkImgDrawing( os.path.join("themes", themename, "notes", "notes.png")): #myfingershurt: here need to ensure an existing theme is selected themes = [] defaultTheme = None #myfingershurt allthemes = os.listdir(themepath) for name in allthemes: if self.checkImgDrawing( os.path.join("themes", name, "notes", "notes.png")): themes.append(name) if name == "MegaLight V4": #myfingershurt defaultTheme = name #myfingershurt if defaultTheme != "MegaLight V4": #myfingershurt defaultTheme = themes[0] #myfingershurt #not a valid theme if notes.png isn't there! Force default theme: Config.set("coffee", "themename", defaultTheme) #re-init Data with new default themename = defaultTheme self.themeLabel = themename if not os.path.exists( os.path.join(Version.dataPath(), "themes", themename, "vocals")): self.vocalPath = "vocals" else: self.vocalPath = os.path.join("themes", themename, "vocals") self.theme = 2 self.themeCoOp = True self.fontScreenBottom = 0.75 #from our current viewport's constant 3:4 aspect ratio (which is always stretched to fill the video resolution) self.loadPartImages() #myfingershurt: multi-OS compatibility file access fixes using os.path.join() # load font customization images #Worldrave - Use new defined Star3 and star4. Using star1 and star2 as a fallback. #MFH - no more custom glyphs, these are wasting memory. #MFH - but we do need these star1-4 images anyway. Leaving them loaded here in the Data object. self.loadImgDrawing(self, "star1", os.path.join("themes", themename, "star1.png"), textureSize=(128, 128)) self.loadImgDrawing(self, "star2", os.path.join("themes", themename, "star2.png"), textureSize=(128, 128)) #MFH - let's not rely on errors here if we don't have to... if not self.loadImgDrawing(self, "star3", os.path.join("themes", themename, "star3.png"), textureSize=(128, 128)): self.star3 = self.star1 if not self.loadImgDrawing(self, "star4", os.path.join("themes", themename, "star4.png"), textureSize=(128, 128)): self.star4 = self.star2 if self.loadImgDrawing(self, "starPerfect", os.path.join("themes", themename, "starperfect.png"), textureSize=(128, 128)): self.perfectStars = True self.maskStars = False else: self.starPerfect = self.star2 self.fcStars = False self.starFC = self.star2 self.maskStars = True self.perfectStars = False if self.perfectStars: if self.loadImgDrawing(self, "starFC", os.path.join("themes", themename, "starfc.png"), textureSize=(128, 128)): self.fcStars = True else: self.starFC = self.starPerfect self.fcStars = False # load misc images self.loadImgDrawing(self, "loadingImage", os.path.join("themes", themename, "loadingbg.png"), textureSize=(256, 256)) self.loadImgDrawing( self, "optionsBG", os.path.join("themes", themename, "menu", "optionsbg.png")) if self.loadImgDrawing( self, "submenuSelect", os.path.join("themes", themename, "submenuselect.png")): subSelectImgW = self.submenuSelect.width1() self.submenuSelectFound = True self.subSelectWFactor = 640.000 / subSelectImgW self.subSelectImgH = self.submenuSelect.height1() else: self.submenuSelectFound = False self.loadImgDrawing( self, "submenuSelect", os.path.join("themes", themename, "menu", "selected.png")) self.subSelectWFactor = 0 # load all the data in parallel # asciiOnly = not bool(Language.language) or Language.language == "Custom" # reversed = _("__lefttoright__") == "__righttoleft__" and True or False asciiOnly = True reversed = False scale = 1 # evilynux - Load bigger fonts so they're nicer when scaled, scaling readjusted fontSize = [44, 132, 34, 32, 30] w, h = [int(s) for s in Config.get("video", "resolution").split("x")] aspectRatio = float(w) / float(h) self.fontList = [ ["font1", "font", "default.ttf", fontSize[4]], ["font2", "bigFont", "title.ttf", fontSize[1]], ["font3", "pauseFont", "pause.ttf", fontSize[2]], ["font4", "scoreFont", "score.ttf", fontSize[3]], ["font5", "streakFont", "streak.ttf", fontSize[3]], ["font6", "loadingFont", "loading.ttf", fontSize[3]], ["font7", "songFont", "song.ttf", fontSize[4]], ["font8", "songListFont", "songlist.ttf", fontSize[3]], ["font9", "shadowFont", "songlist.ttf", fontSize[3]], ["font10", "streakFont2", "streakphrase.ttf", fontSize[2]] ] for f in self.fontList: if self.fileExists(os.path.join("themes", themename, "fonts", f[2])): fn = resource.fileName( os.path.join("themes", themename, "fonts", f[2])) f[0] = lambda: Font(fn, f[3], scale=scale * .5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio) resource.load(self, f[1], f[0], synch=True) elif self.fileExists( os.path.join("themes", themename, "fonts", "default.ttf")): Log.debug("Theme font not found: " + f[2]) fn = resource.fileName( os.path.join("themes", themename, "fonts", "default.ttf")) f[0] = lambda: Font(fn, f[3], scale=scale * .5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio) resource.load(self, f[1], f[0], synch=True) else: Log.debug( "Default theme font not found: %s - using built-in default" % str(f[2])) fn = resource.fileName(os.path.join("fonts", "default.ttf")) f[0] = lambda: Font(fn, f[3], scale=scale * .5, reversed=reversed, systemFont=not asciiOnly, outline=False, aspectRatio=aspectRatio) resource.load(self, f[1], f[0], synch=True) self.fontDict = {"font": self.font, "bigFont": self.bigFont, "pauseFont": self.pauseFont, "scoreFont": self.scoreFont, \ "streakFont": self.streakFont, "songFont": self.songFont, "streakFont2": self.streakFont2, \ "songListFont": self.songListFont, "shadowFont": self.shadowFont, "loadingFont": self.loadingFont} assert self.fontDict['font'] == self.font # load sounds asynchronously resource.load(self, "screwUpsounds", self.loadScrewUpsounds) resource.load(self, "screwUpsoundsBass", self.loadScrewUpsoundsBass) resource.load(self, "screwUpsoundsDrums", self.loadScrewUpsoundsDrums) resource.load(self, "acceptSounds", self.loadAcceptSounds) resource.load(self, "cancelSounds", self.loadBackSounds) # loadSoundEffect asynchronously self.syncSounds = [ ["bassDrumSound", "bassdrum.ogg"], ["battleUsedSound", "battleused.ogg"], ["CDrumSound", "crash.ogg"], ["clapSound", "clapsound.ogg"], ["coOpFailSound", "coopfail.ogg"], #["crowdSound","crowdcheers.ogg"], ["failSound", "failsound.ogg"], ["rescueSound", "rescue.ogg"], ["rockSound", "rocksound.ogg"], ["selectSound1", "select1.ogg"], ["selectSound2", "select2.ogg"], ["selectSound3", "select3.ogg"], ["starActivateSound", "staractivate.ogg"], ["starDeActivateSound", "stardeactivate.ogg"], ["starDingSound", "starding.ogg"], ["starLostSound", "starlost.ogg"], ["starReadySound", "starpowerready.ogg"], ["starSound", "starpower.ogg"], ["startSound", "start.ogg"], ["T1DrumSound", "tom01.ogg"], ["T2DrumSound", "tom02.ogg"], ["T3DrumSound", "tom03.ogg"] ] for self.sounds in self.syncSounds: if self.fileExists( os.path.join("themes", themename, "sounds", self.sounds[1])): self.loadSoundEffect( self, self.sounds[0], os.path.join("themes", themename, "sounds", self.sounds[1])) elif self.fileExists(os.path.join("sounds", self.sounds[1])): Log.debug("Theme sound not found: " + self.sounds[1]) self.loadSoundEffect(self, self.sounds[0], os.path.join("sounds", self.sounds[1])) else: Log.warn("File " + self.sounds[1] + " not found using default instead.") self.loadSoundEffect(self, self.sounds[0], os.path.join("sounds", "default.ogg")) #TODO: Simplify crowdSound stuff so it can join the rest of us. #MFH - fallback on sounds/crowdcheers.ogg, and then starpower.ogg. Note if the fallback crowdcheers was used or not. if self.fileExists( os.path.join("themes", themename, "sounds", "crowdcheers.ogg")): self.loadSoundEffect(self, "crowdSound", os.path.join("themes", themename, "sounds", "crowdcheers.ogg"), crowd=True) self.cheerSoundFound = 2 elif self.fileExists(os.path.join("sounds", "crowdcheers.ogg")): self.loadSoundEffect(self, "crowdSound", os.path.join("sounds", "crowdcheers.ogg"), crowd=True) self.cheerSoundFound = 1 Log.warn( themename + "/sounds/crowdcheers.ogg not found -- using data/sounds/crowdcheers.ogg instead." ) else: self.cheerSoundFound = 0 Log.warn("crowdcheers.ogg not found -- no crowd cheering.")