Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverShadowStar committed Oct 15, 2024
1 parent 0853180 commit bb165e8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from kivy.app import App
from kivy.storage.jsonstore import JsonStore
from kivy.utils import platform
from kivy.logger import Logger
import json

class Config:
def __init__(self):
self.store = JsonStore('game_config.json')
self.default_config = {
'display' : {
'orientation' : 'portrait',
'fullscreen' : True,
},
'audio' : {
'master_volume' : 1.0,
'music_volume' : 0.7,
'sfx_volume' : 0.5
},
'gameplay' : {
'difficulty' : 'normal',
'language' : 'en'
},
'controls' : {
'touch_sensitivity' : 0.5,
'vibration_enabled' : True
}
}

def load_config(self):
if not self.store.exists('config'):
self.store.put('config', **self.default_config)

def get_config(self, *keys):
config = self.store.get('config')
for key in keys:
if key in config:
config = config[key]
else:
return None
return config

def set_config(self, *keys, value):
config = self.store.get('config')
temp = config
for key in keys[:-1]:
if key not in temp:
temp[key] = {}
temp = temp[key]
temp[keys[-1]] = value
self.store.put('config', **config)

def reset_config(self):
self.store.put('config', **self.default_config)

0 comments on commit bb165e8

Please sign in to comment.