#!/usr/bin/env ruby require 'optparse' require_relative '../lib/gemwarrior/game' require_relative '../lib/gemwarrior/version' GAME_NAME = 'Gem Warrior' def parse_options_cli options = { :beast_mode => false, :debug_mode => false, :god_mode => false, :new_game => false, :sound => false, :use_wordnik => false, :extra_command => nil } optparse = OptionParser.new do |opts| opts.on('-b', '--beast', 'Enable debug[beastmode]') do options[:beast_mode] = true end opts.on('-d', '--debug', 'Enable debug commands in-game') do options[:debug_mode] = true end opts.on('-g', '--god', 'Enable debug[godmode]') do options[:god_mode] = true end opts.on('-n', '--new', 'Immediately start a new game, skipping main menu') do options[:new_game] = true end opts.on('-s', '--sound', 'Enable sound (experimental)') do options[:sound] = true end opts.on('-v', '--version', 'Display version number and exit') do puts "#{GAME_NAME} v#{Gemwarrior::VERSION}" exit end opts.on('-w', '--wordnik', 'Enable Wordnik to generate more diverse, dynamic descriptors of entities') do options[:use_wordnik] = true end opts.on('-x', '--extra COMMAND', 'Run a command immediately upon beginning the game') do |xc| options[:extra_command] = xc.to_s end end optparse.parse!() return options end def print_error(error) case error when OptionParser::InvalidOption puts "#{$GAME_NAME}: illegal option #{error.args.join(' ')}" else puts "An unexpected error occurred while running #{$GAME_NAME}:" puts " #{error}\n" end end def get_options_file_path "#{Dir.home}/.gemwarrior_options" end def read_options_file options = [] if File.exist?(get_options_file_path) File.open(get_options_file_path).readlines.each do |line| options << line.chomp.split(':') end return options end nil end begin options = parse_options_cli options_file = read_options_file unless options_file.nil? sound_option = options_file[0][1].eql?('false') ? false : true wordnik_option = options_file[1][1].eql?('false') ? false : true options[:sound] = sound_option options[:use_wordnik] = wordnik_option end Gemwarrior::Game.new(options) rescue => error print_error(error) exit(false) end