Code cleanup and sound consolidation.

This commit is contained in:
Storm Dragon
2025-03-22 17:34:35 -04:00
parent 3a478d15d5
commit a17a4c6f15
10 changed files with 732 additions and 986 deletions

View File

@ -13,10 +13,10 @@ from xdg import BaseDirectory
class Config:
"""Configuration management class for Storm Games."""
def __init__(self, gameTitle):
"""Initialize configuration system for a game.
Args:
gameTitle (str): Title of the game
"""
@ -24,19 +24,19 @@ class Config:
self.globalPath = os.path.join(BaseDirectory.xdg_config_home, "storm-games")
self.gamePath = os.path.join(self.globalPath,
str.lower(str.replace(gameTitle, " ", "-")))
# Create game directory if it doesn't exist
if not os.path.exists(self.gamePath):
os.makedirs(self.gamePath)
# Initialize config parsers
self.localConfig = configparser.ConfigParser()
self.globalConfig = configparser.ConfigParser()
# Load existing configurations
self.read_local_config()
self.read_global_config()
def read_local_config(self):
"""Read local configuration from file."""
try:
@ -44,7 +44,7 @@ class Config:
self.localConfig.read_file(configFile)
except:
pass
def read_global_config(self):
"""Read global configuration from file."""
try:
@ -52,12 +52,12 @@ class Config:
self.globalConfig.read_file(configFile)
except:
pass
def write_local_config(self):
"""Write local configuration to file."""
with open(os.path.join(self.gamePath, "config.ini"), 'w') as configFile:
self.localConfig.write(configFile)
def write_global_config(self):
"""Write global configuration to file."""
with open(os.path.join(self.globalPath, "config.ini"), 'w') as configFile:
@ -71,7 +71,7 @@ globalPath = ""
def write_config(writeGlobal=False):
"""Write configuration to file.
Args:
writeGlobal (bool): If True, write to global config, otherwise local (default: False)
"""
@ -84,7 +84,7 @@ def write_config(writeGlobal=False):
def read_config(readGlobal=False):
"""Read configuration from file.
Args:
readGlobal (bool): If True, read global config, otherwise local (default: False)
"""