Write and load settings at the start of the game

This commit is contained in:
Yohann D'ANELLO 2020-11-06 14:59:27 +01:00
parent af363dabfe
commit 5ca2827706
2 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,6 @@
from .interfaces import Map
from .mapdisplay import MapDisplay
from .settings import Settings
from .term_manager import TermManager
@ -8,6 +9,9 @@ class Game:
def init(self) -> None:
Game.INSTANCE = self
self.settings = Settings()
self.settings.load_settings()
self.settings.write_settings()
with TermManager() as term_manager:
self._start_game(term_manager.screen)

View File

@ -1,4 +1,5 @@
import json
import os
from typing import Any, Generator
@ -64,14 +65,15 @@ class Settings:
d = dict()
for key in self.settings_keys:
d[key] = getattr(self, key)
return json.dumps(d)
return json.dumps(d, indent=4)
def load_settings(self) -> None:
"""
Loads the settings from a file
"""
with open("settings.json", "r") as f:
self.loads_from_string(f.read())
if os.path.isfile("settings.json"):
with open("settings.json", "r") as f:
self.loads_from_string(f.read())
def write_settings(self) -> None:
"""