diff --git a/core/Rpg.py b/core/Rpg.py index 6d83006..b98b563 100644 --- a/core/Rpg.py +++ b/core/Rpg.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from core import command_factory, fight +from core import command_factory, fight, config from models.player import player from models.Model import Model from models.area import area @@ -25,10 +25,26 @@ def __init__(self, debug=False): self._player = player() self._debug = debug self._action = None + self._initNexus() fight.fight.stopFight() area.resetChangedAreas() container.resetChangedContainers() + def _initNexus(self): + """ + Method to init the nexus file, containing the different saved game info + """ + + nexusDir = os.path.dirname(config.nexusDb) + if not os.path.isdir(nexusDir): + os.makedirs(nexusDir) + + if os.path.isfile(config.nexusDb) is False: + saved_game.saved_game.initFile( + config.nexusDb, + config.nexusDbStructure + ) + def initWorld(self, world): """ Method to init the Rpg's world. diff --git a/core/config.py b/core/config.py index e4a24ba..d3a77dc 100644 --- a/core/config.py +++ b/core/config.py @@ -12,6 +12,9 @@ externalPath = rootPath + '/externals' localesDir = rootPath + '/locales' +nexusDb = os.path.expanduser('~') + '/.rrpg/nexus.db' +nexusDbStructure = rootPath + '/database/nexus.sql' + generator = {} generator['dungeon'] = { 'path': externalPath + '/dungeon-generator', diff --git a/models/saved_game.py b/models/saved_game.py index 16a0196..fac9a02 100644 --- a/models/saved_game.py +++ b/models/saved_game.py @@ -18,6 +18,18 @@ def loadById(savedGameId): return None return savedGame + @staticmethod + def initFile(fileName, dbStructure): + db = sqlite3.connect(fileName) + c = db.cursor() + f = open(dbStructure, 'r') + print(f) + sql = f.read() + c.executescript(sql) + f.close() + db.commit() + db.close() + @staticmethod def updateSavedGame(saveId, data): model.update(data, ('id_saved_game = ?', [saveId]))