Skip to content

Commit

Permalink
Fix exception logging, missing variable, and leaky global.
Browse files Browse the repository at this point in the history
Global vars at the top were leaking into the rest of the file; and this
hid an error with an undefined var.
  • Loading branch information
wrzwicky committed Oct 19, 2017
1 parent 58b7d18 commit ddfb8b2
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions fofix/core/GameEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,38 @@
# evilynux - Grab name and version from Version class.
version = "%s v%s" % ( Version.PROGRAM_NAME, Version.version() )

##Alarian: Get unlimited themes by foldername
themepath = os.path.join(Version.dataPath(), "themes")
themes = []
defaultTheme = None #myfingershurt
allthemes = os.listdir(themepath)
for name in allthemes:
if os.path.exists(os.path.join(themepath,name,"notes","notes.png")):
themes.append(name)
if name == "MegaLight V4":
defaultTheme = name

i = len(themes)
if i == 0:
if os.name == 'posix':
log.error("No valid theme found!\n" +
"Make sure theme files are properly cased " +
"e.g. notes.png works, Notes.png doesn't\n")
else:
log.error("No valid theme found!")
sys.exit(1)

if defaultTheme is None:
defaultTheme = themes[0] #myfingershurt

#myfingershurt: default theme must be an existing one!
Config.define("coffee", "themename", str, defaultTheme, text = _("Theme"), options = dict([(str(themes[n]),themes[n]) for n in range(0, i)]), tipText = _("Sets the overall graphical feel of the game. You can find and download many more at fretsonfire.net"))

##Alarian: End Get unlimited themes by foldername
Player.loadControls()
def _init_allthemes():
""" Alarian: Get unlimited themes by foldername """
# this global code is in a function to hide vars from rest of file

themepath = os.path.join(Version.dataPath(), "themes")
themes = []
defaultTheme = None #myfingershurt
allthemes = os.listdir(themepath)
for name in allthemes:
if os.path.exists(os.path.join(themepath,name,"notes","notes.png")):
themes.append(name)
if name == "MegaLight V4":
defaultTheme = name

i = len(themes)
if i == 0:
if os.name == 'posix':
log.error("No valid theme found!\n" +
"Make sure theme files are properly cased " +
"e.g. notes.png works, Notes.png doesn't\n")
else:
log.error("No valid theme found!")
sys.exit(1)

if defaultTheme is None:
defaultTheme = themes[0] #myfingershurt

#myfingershurt: default theme must be an existing one!
Config.define("coffee", "themename", str, defaultTheme, text = _("Theme"), options = dict([(str(themes[n]),themes[n]) for n in range(0, i)]), tipText = _("Sets the overall graphical feel of the game. You can find and download many more at fretsonfire.net"))
_init_allthemes()

Player.loadControls()


class FullScreenSwitcher(KeyListener):
Expand Down Expand Up @@ -349,7 +351,8 @@ def _initTheme(self, themename, themepath):
finally:
fp.close()
except ImportError:
# CustomTheme is optional; no need to complain.
# CustomTheme.py file is optional, but notify developer anyway.
log.notice("No CustomTheme.py found in theme")
pass

if self.theme is None:
Expand All @@ -368,6 +371,7 @@ def _initStages(self):

self.stageFolders = []
currentTheme = self.theme.name
themepath = self.theme.path

stagespath = os.path.join(themepath, "backgrounds")
if os.path.exists(stagespath):
Expand Down

0 comments on commit ddfb8b2

Please sign in to comment.