5 from naja.attrdict import AttrDict
6 from naja.constants import DEFAULTS
12 def check_min_max(option, value, min_value, max_value):
14 Check value lies between min and max and raise OptionValueError if it does
17 if not (min_value <= value <= max_value):
18 raise optparse.OptionValueError(
19 "Value of %s should be between %s and %s but got: %r"
20 % (option.dest, min, max, value))
23 def load_game(option, opt_str, value, parser):
25 Load a save game and store it in parser.values.game_state.
27 check_min_max(option, value, 0, 7)
28 # madness takes its toll ...
29 options.save_location = parser.values.save_location
30 from naja.scenes.load_save import SaveGameSlot
31 state = SaveGameSlot(value).load()
33 raise optparse.OptionValueError(
34 "Could not load game from slot %s" % (value,))
35 parser.values.game_state = state
38 def load_deck(option, opt_str, value, parser):
40 Create a new game for a specific deck and store it in
41 parser.values.game_state.
43 raise optparse.OptionalValueError(
44 "Deck loading not implemented.")
49 Parse arguments and store them in the options dictionary.
51 Note: If you add arguments, you need to add an appropriate default to the
54 options.update(DEFAULTS)
56 options.debug = 'DEBUG' in os.environ
58 parser = optparse.OptionParser()
59 parser.add_option('--no-sound',
60 dest='sound', action='store_false', default=True,
61 help='Disable all sound, including music')
63 parser.add_option('--no-music',
64 dest='music', action='store_false', default=True,
65 help='Disable music (but not sound)')
67 parser.add_option("--save-location", default=_get_default_save_location(),
68 dest="save_location", help="Saved game location")
71 parser.add_option('--initial-bits', type=int,
72 help='Initial player bits')
73 parser.add_option('--cheat-enabled', default=False,
75 help='For those too lazy to type the KONAMI code')
76 parser.add_option('--deck', default=None, action="callback",
78 help='Start with a new game for a specific deck')
79 parser.add_option('--load', default=None, type=int, action="callback",
81 help='Start with a specific save game loaded (0-7)')
83 opts, _ = parser.parse_args(args)
86 if getattr(opts, k, None) is not None:
87 options[k] = getattr(opts, k)
90 def _get_default_save_location():
91 """Return a default save game location."""
93 if sys.platform.startswith("win"):
94 if "APPDATA" in os.environ:
95 return os.path.join(os.environ["APPDATA"], app)
96 return os.path.join(os.path.expanduser("~"), "." + app)
97 elif 'XDG_DATA_HOME' in os.environ:
98 return os.path.join(os.environ["XDG_DATA_HOME"], app)
99 return os.path.join(os.path.expanduser("~"), ".local", "share", app)