Skip to content

Commit

Permalink
nexus created if it does not exist when the engine is started
Browse files Browse the repository at this point in the history
  • Loading branch information
padawin committed Apr 18, 2016
1 parent 6ff183a commit 929201d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/Rpg.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions models/saved_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 929201d

Please sign in to comment.