From 50fbc7d779fa3ee321600da42875de206b53ba9f Mon Sep 17 00:00:00 2001 From: mandaw2014 Date: Wed, 20 Jul 2022 20:59:05 +0100 Subject: [PATCH] Fixed file loading while building --- UrsinaAchievements/__init__.py | 9 +++++---- car.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/UrsinaAchievements/__init__.py b/UrsinaAchievements/__init__.py index a85c1c1..714e900 100644 --- a/UrsinaAchievements/__init__.py +++ b/UrsinaAchievements/__init__.py @@ -8,14 +8,15 @@ import os from direct.stdpy import thread -_path = os.path.dirname(os.path.abspath(__file__)) +_path = os.path.dirname(sys.argv[0]) +achievements_json = os.path.join(_path, "./UrsinaAchievements/achievements.json") _achievements_list = [] try: - with open(f"{_path}/achievements.json", "r", encoding="utf-8") as save_file: + with open(achievements_json, "r") as save_file: _achievements_got = json.load(save_file)["achievements_got_names"].copy() except FileNotFoundError: - with open(f"{_path}/achievements.json", "w", encoding="utf-8") as save_file: + with open(achievements_json, "w") as save_file: _achievements_got = [] json.dump({"achievements_got_names": []}, save_file, indent=4) @@ -37,7 +38,7 @@ def create_achievement(name:str, unlock_condition, icon:str=None, ringtone:str=" def _save_achievements(): - with open(f"{_path}/achievements.json", "w", encoding="utf-8") as save_file: + with open(achievements_json, "w") as save_file: json.dump({"achievements_got_names": _achievements_got.copy()}, save_file, indent=2) diff --git a/car.py b/car.py index 83df3b3..9d74c56 100644 --- a/car.py +++ b/car.py @@ -121,7 +121,7 @@ def __init__(self, position = (0, 0, 4), rotation = (0, 0, 0), topspeed = 30, ac self.camera_shake_option = True # Get highscore from json file - path = os.path.dirname(os.path.abspath(__file__)) + path = os.path.dirname(sys.argv[0]) self.highscore_path = os.path.join(path, "./highscore/highscore.json") try: