5 from naja.attrdict import AttrDict
6 from naja.constants import DEFAULTS
12 def load_game(parser, slot_num):
14 Load a save game and store it in parser.values.game_state.
16 if not (0 <= slot_num <= 7):
17 parser.error("--load accepts a slot number from 0 to 7.")
18 from naja.scenes.load_save import SaveGameSlot
19 state = SaveGameSlot(slot_num).load()
22 "Could not load game from slot %s" % (slot_num,))
23 options.game_state = state
26 def load_deck(parser, deck):
28 Create a new game for a specific deck and store it in
29 parser.values.game_state.
31 raise optparse.OptionalValueError(
32 "Deck loading not implemented.")
37 Parse arguments and store them in the options dictionary.
39 Note: If you add arguments, you need to add an appropriate default to the
42 options.update(DEFAULTS)
44 options.debug = 'DEBUG' in os.environ
46 parser = optparse.OptionParser()
47 parser.add_option('--no-sound',
48 dest='sound', action='store_false', default=True,
49 help='Disable all sound, including music')
51 parser.add_option('--no-music',
52 dest='music', action='store_false', default=True,
53 help='Disable music (but not sound)')
55 parser.add_option("--save-location", default=_get_default_save_location(),
56 dest="save_location", help="Saved game location")
59 parser.add_option('--initial-bits', type=int,
60 help='Initial player bits')
61 parser.add_option('--cheat-enabled', default=False,
63 help='For those too lazy to type the KONAMI code')
64 parser.add_option('--deck', default=None,
65 help='Start with a new game for a specific deck')
66 parser.add_option('--load', default=None, type=int,
67 help='Start with a specific save game loaded (0-7)')
69 opts, _ = parser.parse_args(args)
72 if getattr(opts, k, None) is not None:
73 options[k] = getattr(opts, k)
75 if opts.load is not None:
76 load_game(parser, opts.load)
77 if opts.deck is not None:
78 load_deck(parser, opts.deck)
81 def _get_default_save_location():
82 """Return a default save game location."""
84 if sys.platform.startswith("win"):
85 if "APPDATA" in os.environ:
86 return os.path.join(os.environ["APPDATA"], app)
87 return os.path.join(os.path.expanduser("~"), "." + app)
88 elif 'XDG_DATA_HOME' in os.environ:
89 return os.path.join(os.environ["XDG_DATA_HOME"], app)
90 return os.path.join(os.path.expanduser("~"), ".local", "share", app)