Write and load settings at the start of the game
This commit is contained in:
parent
af363dabfe
commit
5ca2827706
|
@ -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)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import os
|
||||
from typing import Any, Generator
|
||||
|
||||
|
||||
|
@ -64,12 +65,13 @@ 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
|
||||
"""
|
||||
if os.path.isfile("settings.json"):
|
||||
with open("settings.json", "r") as f:
|
||||
self.loads_from_string(f.read())
|
||||
|
||||
|
|
Loading…
Reference in New Issue