class TheGame::Command

Public Class Methods

_args(g, a) click to toggle source
# File lib/the_game/command.rb, line 28
def _args(g, a); a.args.inspect; end
_echo(g, a) click to toggle source
# File lib/the_game/command.rb, line 30
def _echo(g, a); a; end
_game(g, a) click to toggle source
# File lib/the_game/command.rb, line 68
def _game(g, a); g.inspect; end
_help(g, a) click to toggle source
# File lib/the_game/command.rb, line 62
def _help(g, a); "Commands available: [ #{available_methods.join(', ')} ]"; end
_items(g,a) click to toggle source
# File lib/the_game/command.rb, line 70
def _items(g,a); g.items.inspect; end
_license(g, a) click to toggle source
# File lib/the_game/command.rb, line 66
def _license(g, a); TheGame::LICENSE; end
_load(g, a) click to toggle source
# File lib/the_game/command.rb, line 76
def _load(g, a)
  pretty_rescue do
    g.load
    "Game (name => #{g.name}, saved_at => #{g.saved_at.strftime("%F %R")}) loaded."
  end
end
_lol(g, a) click to toggle source
# File lib/the_game/command.rb, line 45
def _lol(g, a)
  iteration = 0
  messages = [ "U MAD BRO?", "PROBLEM?" ]
  loop do
    message = messages[ iteration % messages.size ].center(10)
    41.upto(45) do |code|
      message.scan(/./).each do |char|  
        print "\e[#{code};39;1m"
        print char * ((rand * 1.01) + 1)
        print "\e[0m"
      end
      iteration += 1
    end
    sleep 0.005
  end
end
_quit(g, a) click to toggle source
# File lib/the_game/command.rb, line 83
def _quit(g, a); exit; end
_raise(g, a) click to toggle source
# File lib/the_game/command.rb, line 26
def _raise(g, a); raise TheGame::Exceptions::FuntimeError, a; end
_read_savefile(g, a) click to toggle source
# File lib/the_game/command.rb, line 74
def _read_savefile(g, a); pretty_rescue { g.read_savefile }; end
_save(g, a) click to toggle source
# File lib/the_game/command.rb, line 72
def _save(g, a); pretty_rescue { g.save; "Game saved." }; end
_set(g, a) click to toggle source
# File lib/the_game/command.rb, line 32
def _set(g, a)
  value = a.remove_first_word
  if value.blank?
    "Usage: set [key] [value]"
  else
    key = a.words.first.to_s.downcase
    pretty_rescue do
      g.set(key, value)
      "#{key.capitalize} set to #{value.inspect}"
    end
  end
end
_version(g, a) click to toggle source
# File lib/the_game/command.rb, line 64
def _version(g, a); "the_game v#{TheGame::Version::STRING}"; end
available_methods() click to toggle source
# File lib/the_game/command.rb, line 22
def available_methods
  methods(false).select{ |m| m.match(/^_/) }.map{ |m| m.to_s.command_sanitize }
end
method_missing(m, g, a) click to toggle source
# File lib/the_game/command.rb, line 20
def method_missing(m, g, a); "#{m.to_s.command_sanitize}: command not found"; end
send(game, input) click to toggle source
# File lib/the_game/command.rb, line 3
def send(game, input)
  input.strip!

  # Allow interpolation in the form of $(command) => output of command
  input.gsub!(/\$\((.*)\)/) { send(self, $1.to_s) }

  unless input.empty?
    # The method to send to TheGame::Command with +_+ before it
    method = input.words.first
    
    # Not an array! Use String#args to get an argument array.
    args = input.remove_first_word

    __send__("_#{method.command_sanitize.downcase}", game, args)
  end
end