From 0b30950ff855a97dde41e9ae7df898e5f172d723 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Sat, 29 May 2021 22:30:12 -0400 Subject: [PATCH] save file now stored in home directory --- pocket_friends/game_files/game.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index f3f1465..d272e74 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -8,9 +8,20 @@ import os import pygame from pygame.locals import * from ..hardware.gpio_handler import Constants, GPIOHandler +from pathlib import Path +# FPS for the entire game to run at. game_fps = 16 + +# Gets the directory of the script for importing and the save directory script_dir = os.path.dirname(__file__) +save_dir = os.path.join(Path.home(), '.pocket_friends') + +# Tries to make the save directory. Does nothing if it already exists. +try: + os.mkdir(save_dir) +except FileExistsError: + pass class FileHandler: @@ -33,7 +44,7 @@ class FileHandler: """ Writes attributes of class to "save.json" file. """ - with open(script_dir + '/save.json', 'w') as save_file: + with open(save_dir + '/save.json', 'w') as save_file: json.dump(self.attributes, save_file) save_file.close() @@ -43,7 +54,7 @@ class FileHandler: """ # Open up the save file and read it into self.attributes. try: - with open(script_dir + '/save.json', 'r') as save_file: + with open(save_dir + '/save.json', 'r') as save_file: self.attributes = json.load(save_file) save_file.close()