#!/usr/bin/env python
#
# Copyright 2010, 2011 Westley Martinez
#
# This file is part of Anikom15's Computer Game (ACG).
# ACG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# ACG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ACG.  If not, see <http://www.gnu.org/licenses/>.
"""Usage: anikom15 [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -r FREQUENCY, --audio-frequency=FREQUENCY
                        set audio frequency
  -s SIZE, --audio-size=SIZE
                        set the audio bit depth
  -c CHANNELS, --audio-channels=CHANNELS
                        set the audio to stereo or mono
  -b SIZE, --audio-buffersize=SIZE
                        set the audio buffer size
  -f, --fullscreen      play in fullscreen mode
  -a, --hardware-acceleration
                        use hardware acceleration in fullscreen mode
  -d, --double-buffer   use double buffering in fullscreen mode
  -z FPS, --frame-rate=FPS
                        set frame rate

"""

import sys
import optparse

import acg

def opt_to_dict(options):
    """Converts optparse 'Values' class to a standard dictionary."""
    return {'afrequency': options.afrequency,
            'asize': options.asize,
            'achannels': options.achannels,
            'abuffersize': options.abuffersize,
            'fullscreen': options.fullscreen,
            'hwsurface': options.hwsurface,
            'doublebuf': options.doublebuf,
            'frame_rate': options.frame_rate}


def main():
    version = '%prog ' + acg.DATA['version'] + '''
Copyright (C) 2010, 2011 Westley Martinez
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Westley Martinez'''
    parser = optparse.OptionParser(version=version)
    parser.add_option('-r', '--audio-frequency', action='store', type='int',
                      dest='afrequency', default=44100, metavar='FREQUENCY',
                      help='set audio frequency')
    parser.add_option('-s', '--audio-size', action='store', type='int',
                      dest='asize', default=-16, metavar='SIZE',
                      help='set the audio bit depth')
    parser.add_option('-c', '--audio-channels', action='store', type='int',
                      dest='achannels', default=2, metavar='CHANNELS',
                      help='set the audio to stereo or mono')
    parser.add_option('-b', '--audio-buffersize', action='store', type='int',
                      dest='abuffersize', default=4096, metavar='SIZE',
                      help='set the audio buffer size')
    parser.add_option('-f', '--fullscreen', action='store_true',
                      dest='fullscreen', default=False,
                      help='play in fullscreen mode')
    parser.add_option('-a', '--hardware-acceleration', action='store_true',
                      dest='hwsurface', default=False,
                      help='use hardware acceleration in fullscreen mode')
    parser.add_option('-d', '--double-buffer', action='store_true',
                      dest='doublebuf', default=False,
                      help='use double buffering in fullscreen mode')
    parser.add_option('-z', '--frame-rate', action='store', type='int',
                      dest='frame_rate', default=60, metavar='FPS',
                      help='set frame rate')
    options, args = parser.parse_args()
    acg.set_options(opt_to_dict(options))
    acg.init()
    acg.preface()
    op = acg.title()
    while op != 'quit':
        acg.run(op)
        op = acg.title()
    acg.shutdown()
    return 0


if __name__ == '__main__':
    sys.exit(main())
