X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Foptions.py;h=5c80b1b32f3cd834fb7ebc5ea4391964a22ade2c;hb=d6b587d8325492b436c4e19f8842f5ae7fccf6a4;hp=cf5715dde1faa36d7dcf81628648458434c3b3fc;hpb=39f49f9579bdee2ad449246d1370a0be27186ed9;p=naja.git diff --git a/naja/options.py b/naja/options.py index cf5715d..5c80b1b 100644 --- a/naja/options.py +++ b/naja/options.py @@ -1,15 +1,11 @@ import optparse import os +import sys +from naja.attrdict import AttrDict from naja.constants import DEFAULTS -class AttrDict(dict): - '''A dict with attribute access''' - def __getattr__(self, attr): - return self[attr] - - options = AttrDict() @@ -33,8 +29,30 @@ def parse_args(args): dest='music', action='store_false', default=True, help='Disable music (but not sound)') + parser.add_option("--save-location", default=_get_default_save_location(), + dest="save_location", help="Saved game location") + + if options.debug: + parser.add_option('--initial-bits', type=int, + help='Initial player bits') + parser.add_option('--cheat-enabled', default=False, + action='store_true', + help='For those too lazy to type the KONAMI code') + opts, _ = parser.parse_args(args) for k in DEFAULTS: if getattr(opts, k, None) is not None: options[k] = getattr(opts, k) + + +def _get_default_save_location(): + """Return a default save game location.""" + app = "naja" + if sys.platform.startswith("win"): + if "APPDATA" in os.environ: + return os.path.join(os.environ["APPDATA"], app) + return os.path.join(os.path.expanduser("~"), "." + app) + elif 'XDG_DATA_HOME' in os.environ: + return os.path.join(os.environ["XDG_DATA_HOME"], app) + return os.path.join(os.path.expanduser("~"), ".local", "share", app)