From a4794437d561a01c8bea12d59502e4cc72acfbea Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 27 Apr 2024 00:40:24 +0300 Subject: separate settings from hiscore --- src/sliceitoff/hiscores/hiscores.py | 56 +++++++++++++------------------------ 1 file changed, 20 insertions(+), 36 deletions(-) (limited to 'src/sliceitoff/hiscores/hiscores.py') diff --git a/src/sliceitoff/hiscores/hiscores.py b/src/sliceitoff/hiscores/hiscores.py index bcf41a0..d963605 100644 --- a/src/sliceitoff/hiscores/hiscores.py +++ b/src/sliceitoff/hiscores/hiscores.py @@ -1,32 +1,16 @@ """ hiscores.hiscores - high socres: loading, saving, converting to string """ -import os -from pathlib import Path -from .static import INITIAL_HIGHSCORES, MAX_HIGHSCORES +from sliceitoff.settings import settings +from .static import MAX_HIGHSCORES class HiScores: """ Keeps track of high scores """ - def __init__(self, filename = None): + def __init__(self): """ On creation load high scores from config file """ self.table=[] - if filename: - self.config_filename = filename - else: - if os.name == 'nt': - self.config_filename = (Path.home().resolve() - .joinpath('sliceitoff.cfg')) - else: - self.config_filename = (Path.home().resolve() - .joinpath('.config').joinpath('sliceitoffrc')) - if not self.config_filename.is_file(): - self.table=INITIAL_HIGHSCORES[:] - return - with open(self.config_filename, "r", encoding="utf-8") as config_file: - for line in config_file: - option, *value = line.split('=') - if option == 'hiscore' and value: - score, name = value[0].split('!') - self.add(int(score.strip()),name.strip()) + for value in settings.get_values("hiscore"): + score, name = value.split('!') + self.add(int(score.strip()),name.strip()) if len(self.table)