change load function to use Config stored variables

This commit is contained in:
2024-04-04 20:36:05 +02:00
parent f3d85922ed
commit b460480e2b
5 changed files with 18 additions and 22 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ class Map:
def load_from_file(cls, file_options): def load_from_file(cls, file_options):
LOGGING.debug(f"Loading from file: {file_options}") LOGGING.debug(f"Loading from file: {file_options}")
if os.path.exists(file_options["path"]): if os.path.exists(file_options["path"]):
with open(file_options["path"], "rb") as f: with open(f'{file_options["path"]}/{file_options["name"]}', "rb") as f:
data = my_pickle.load(f, file_options['compression'], None) data = my_pickle.load(f, file_options['compression'], None)
new_class = cls(file_options["path"]) new_class = cls(file_options["path"])
+1 -1
View File
@@ -52,7 +52,7 @@ class SavedState:
def load_from_file(cls, file_options): def load_from_file(cls, file_options):
LOGGING.debug(f"Loading from file: {file_options}") LOGGING.debug(f"Loading from file: {file_options}")
if os.path.exists(file_options["path"]): if os.path.exists(file_options["path"]):
with open(file_options["path"], "rb") as f: with open(f'{file_options["path"]}/{file_options["name"]}', "rb") as f:
data = my_pickle.load(f, file_options['compression'], None) data = my_pickle.load(f, file_options['compression'], None)
new_class = cls() new_class = cls()
+13 -9
View File
@@ -1,13 +1,17 @@
{ {
"map_file": { "file": {
"path": "./GameData", "map": {
"filename": "map.pkl.lzma.encrypted", "path": "./GameData",
"encryption_key": "" "name": "map",
}, "extension": "pkl.lzma.encrypted",
"save_file": { "encryption_key": ""
"path": "./GameData/Save", },
"filename": "The-Adventure-AutoSaveGame.pkl.lzma.encrypted", "save": {
"encryption_key": "" "path": "./GameData/Save",
"name": "The-Adventure-AutoSaveGame",
"extension": "pkl.lzma.encrypted",
"encryption_key": ""
}
}, },
"logging": { "logging": {
+2 -10
View File
@@ -13,16 +13,8 @@ if __name__ == '__main__':
logging.basicConfig(filename=f"{CONFIG['logging']['file']['path']}/{CONFIG['logging']['file']['name']}", encoding='utf-8', level=logging.DEBUG) logging.basicConfig(filename=f"{CONFIG['logging']['file']['path']}/{CONFIG['logging']['file']['name']}", encoding='utf-8', level=logging.DEBUG)
LOGGING = logging.getLogger(__name__) LOGGING = logging.getLogger(__name__)
SAVE_STATE_FILE = { SAVE_STATE_FILE = CONFIG.get_file_path("file/save", add_to_dictionary={"compression": lzma, "key": CONFIG['file']["save"]["encryption_key"]})
"path": f"{CONFIG['save_file']['path']}/{CONFIG['save_file']['filename']}", MAP_FILE = CONFIG.get_file_path("file/map", add_to_dictionary={"compression": lzma, "key": CONFIG['file']["map"]["encryption_key"]})
"compression": lzma,
"key": CONFIG["save_file"]["encryption_key"]
}
MAP_FILE = {
"path": f"{CONFIG['map_file']['path']}/{CONFIG['map_file']['filename']}",
"compression": lzma,
"key": CONFIG["map_file"]["encryption_key"]
}
game_board = GameBoard(CONFIG, SAVE_STATE_FILE, MAP_FILE) game_board = GameBoard(CONFIG, SAVE_STATE_FILE, MAP_FILE)
game_board.find_game_state(store_state=not DEBUG) game_board.find_game_state(store_state=not DEBUG)