Ignore:
Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r15 r16  
    11SCREEN = (800, 600)
    22FPS = 40
     3DEFAULTS = dict(
     4    debug=False,
     5    sound=True,
     6)
  • nagslang/options.py

    r10 r14  
     1import optparse
     2import os
     3
     4from nagslang.constants import DEFAULTS
     5
     6
     7class AttrDict(dict):
     8    '''A dict with attribute access'''
     9    def __getattr__(self, attr):
     10        return self[attr]
     11
     12
     13options = AttrDict()
     14
     15
    116def parse_args(args):
    2     #TODO
    3     return
     17    '''
     18    Parse arguments and store them in the options dictionary.
     19
     20    Note: If you add arguments, you need to add an appropriate default to the
     21    DEFAULTS dict.
     22    '''
     23    options.update(DEFAULTS)
     24
     25    options.debug = 'DEBUG' in os.environ
     26
     27    parser = optparse.OptionParser()
     28    parser.add_option('--no-sound',
     29                      dest='sound', action='store_false', default=True,
     30                      help='Disable sound')
     31    if options.debug:
     32        parser.add_option('--area', help='Initial area')
     33
     34    opts, _ = parser.parse_args(args)
     35
     36    for k in DEFAULTS:
     37        if getattr(opts, k, None) is not None:
     38            options[k] = getattr(opts, k)
Note: See TracChangeset for help on using the changeset viewer.