from os import path, walk from tkinter import NSEW, ttk import xmltodict from ttkthemes import ThemedTk from classes.custom.scrollable_frame import ScrollableFrame from classes.custom.themed_frame import ThemedFrame from classes.frames.save import FrameSave from modules.utils import configGet class FrameSaves(ScrollableFrame): def __init__(self, master: ThemedTk, saves: list, **kwargs) -> None: super().__init__(master, **kwargs) master.title("Saves - Stardew Sync") self.saves = saves self.saves_local = [] for subdir, dirs, files in walk(configGet("saves_location")): try: for dir in dirs: with open(path.join(dir, "SaveGameInfo"), "r", encoding="utf-8") as file: save_dict = xmltodict.parse(file.read()) self.saves_local.append( { "id": int(save_dict["SaveGame"]["uniqueIDForThisGame"]), "user": None, "device": configGet("name"), "date": None, "data": { "farmer": save_dict["Farmer"]["name"], "money": int(save_dict["Farmer"]["money"]), "played": int(save_dict["Farmer"]["millisecondsPlayed"]), "save_time": int(save_dict["Farmer"]["saveTime"]), "year": int(save_dict["Farmer"]["yearForSaveGame"]), "season": int(save_dict["Farmer"]["seasonForSaveGame"]), "day": int(save_dict["Farmer"]["dayOfMonthForSaveGame"]), "game_version": save_dict["Farmer"]["gameVersion"] }, "file": { "name": None, "uuid": None, "path": None } } ) except: pass # Merge local and remote saves. # Maybe add something that indicates availability of an # remote update to pull or local new version to push. master.columnconfigure(1, weight=1) self.render_saves() def render_saves(self): i = 0 for save in self.saves: save_frame = FrameSave(self, save_dict=save) save_frame.grid(column=0, row=i, pady=9, padx=9, sticky=NSEW) i += 1 if i+1 != len(self.saves): divider = ttk.Separator(self, orient="horizontal") divider.grid(column=0, row=i+1, pady=9) i += 1 class FrameSavesEmpty(ThemedFrame): def __init__(self, master: ThemedTk, **kwargs) -> None: super().__init__(master, **kwargs) master.title("Saves - Stardew Sync") self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=2) master.columnconfigure(1, weight=1) self.label = ttk.Label(self, text="No saves found") self.label.grid(column=0, row=0, padx=9, pady=9)