diff --git a/data/types.py b/data/types.py index bdc0263..05deea2 100644 --- a/data/types.py +++ b/data/types.py @@ -1,6 +1,8 @@ from enum import IntEnum from json import load +import paths + # The possible serialisation types the game uses and their binary value (as int) class Types(IntEnum): @@ -39,19 +41,19 @@ class Types(IntEnum): # they are not complete, considering I mostly was in it for the items and perks and so on # But still they may contain spoilers considering quite a few dialogues and so on are in # them so read it at your own risk -with open("./data/locals.json", encoding="utf8") as f: +with open(paths.locals_json, encoding="utf8") as f: id_to_name = load(f) # Generic game information -with open("./data/html/items.json", encoding="utf8") as f: +with open(paths.items_json, encoding="utf8") as f: gamedata = load(f) -with open("./data/data.json", encoding="utf8") as f: +with open(paths.data_json, encoding="utf8") as f: jsongamedata = load(f) # Load a list with default items, if those items have special attributes which would otherwise not work # (using the default item) -with open("./data/new_item_data.json", encoding="utf8") as f: +with open(paths.new_item_data_json, encoding="utf8") as f: item_fallback_data = load(f) # A example item in the case of the inventory being empty and people wanting to add items to it diff --git a/main.py b/main.py index f02f8c6..5879b40 100755 --- a/main.py +++ b/main.py @@ -21,11 +21,12 @@ import psutil import pkg_resources from packaging import version +import paths # Set up global variables and the used classes options = {} -hashes = Hashlist("./data/hashes") +hashes = Hashlist(paths.hashes) decoder = Decoder(hashes) encoder = Encoder() savefiles = {} @@ -35,21 +36,21 @@ loaded_items = {} # Load the version number of this application and already create a newversion variable for a later check for updates -with open("./data/version") as f: +with open(paths.version) as f: currentversion = f.read() newversion = currentversion # Load the information about the item version making it possible to fix bugs without having to make a new release # (when no code was changed) -with open("./data/itemversion") as f: +with open(paths.item_version) as f: currentiversion = f.read() newiversion = currentiversion # Load the settings of the settings file def load_settings(): - with open("./data/settings") as f: + with open(paths.settings) as f: global options, newversion, newiversion, web_app_options options = json.load(f) @@ -357,7 +358,7 @@ def save_json_savefile(data, shash): # If we want to dump it as html file we do so here if file.endswith(".html"): - with open('./data/html/dumpskeleton.html', 'r') as placeholderfile: + with open(paths.dump_skeleton_html) as placeholderfile: placeholder = placeholderfile.read() print("Creating HTML file at " + file) @@ -1035,7 +1036,7 @@ def set_settings(settings): if "path" in options: options["path"] = os.path.expandvars(options["path"]) - with open("./data/settings", "w") as f: + with open(paths.settings, "w") as f: json.dump(settings, f) return True diff --git a/paths.py b/paths.py new file mode 100644 index 0000000..3effa99 --- /dev/null +++ b/paths.py @@ -0,0 +1,16 @@ +import os + +own_dir = os.path.abspath(os.path.dirname(__file__)) +data_dir = os.path.join(own_dir, 'data') +html_dir = os.path.join(data_dir, 'html') + +version = os.path.join(data_dir, 'version') +item_version = os.path.join(data_dir, 'itemversion') +hashes = os.path.join(data_dir, 'hashes') +settings = os.path.join(data_dir, 'settings') +locals_json = os.path.join(data_dir, 'locals.json') +data_json = os.path.join(data_dir, 'data.json') +new_item_data_json = os.path.join(data_dir, 'new_item_data.json') + +dump_skeleton_html = os.path.join(html_dir, 'dumpskeleton.html') +items_json = os.path.join(html_dir, 'items.json')