Game now knows the abs path of the program

This commit is contained in:
Marcin Kostrzewski 2020-04-06 12:30:03 +02:00
parent c080816908
commit 479c6eece7
2 changed files with 8 additions and 5 deletions

5
Run.py
View File

@ -1,3 +1,6 @@
from pathlib import Path
from src.game.Game import Game from src.game.Game import Game
game = Game() programPath = Path(".").resolve()
game = Game(programPath)

View File

@ -12,12 +12,12 @@ from src.game.Timer import Timer
class Game: class Game:
def __init__(self): def __init__(self, filesPath):
self.running = True self.running = True
print("Loading configuration...", end=" ") print("Loading configuration...", end=" ")
try: try:
configFolder = Path("../data/config/") configFolder = Path(str(filesPath) + "/data/config/")
configFile = configFolder / "mainConfig.json" configFile = configFolder / "mainConfig.json"
self.config = json.loads(configFile.read_text()) self.config = json.loads(configFile.read_text())
@ -47,8 +47,8 @@ class Game:
self.screen = Screen(self, self.config["window"]) self.screen = Screen(self, self.config["window"])
print("OK") print("OK")
self.mapDataFolder = path.dirname("../data/mapdata/") mapFile = Path(str(filesPath) + "/data/mapdata/")
self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen) self.map = Map(path.join(mapFile, 'map.txt'), self.screen)
self.player = Player((6, 2), self.map.tileSize) self.player = Player((6, 2), self.map.tileSize)
self.map.addEntity(self.player) self.map.addEntity(self.player)
self.eventManager = EventManager(self, self.player) self.eventManager = EventManager(self, self.player)