""" hiscores.hiscores - high socres: loading, saving, converting to string """ import os from pathlib import Path from .static import INITIAL_HIGHSCORES, MAX_HIGHSCORES class HiScores: """ Keeps track of high scores """ def __init__(self, filename = None): """ On creation load high scores from config file """ self.table=[] if filename: self.config_filename = filename else: if os.name == 'nt': self.config_filename = os.path.join( Path.home(), "sliceitoff.cfg") else: self.config_filename = os.path.join( Path.home(), ".config", "sliceitoffrc") if not os.path.isfile(self.config_filename): 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()) if len(self.table)