Class: Gamefic::Tty::User

Inherits:
User
  • Object
show all
Defined in:
lib/gamefic/engine/tty.rb

Instance Attribute Summary

Attributes inherited from User

#character, #state, #story

Instance Method Summary collapse

Methods inherited from User

#initialize, #quit, #refresh, #stream

Constructor Details

This class inherits a constructor from Gamefic::User

Instance Method Details

#ansiObject



31
32
33
# File 'lib/gamefic/engine/tty.rb', line 31

def ansi
  @stream.ansi
end

#ansi=(val) ⇒ Object



28
29
30
# File 'lib/gamefic/engine/tty.rb', line 28

def ansi=(val)
  @stream.ansi = val
end

#post_initializeObject



24
25
26
27
# File 'lib/gamefic/engine/tty.rb', line 24

def post_initialize
  @stream = Tty::UserStream.new
  @state = UserState.new self
end

#restore(filename) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gamefic/engine/tty.rb', line 49

def restore filename
  if filename.nil?
    stream.select "Enter the filename to restore:"
    filename = stream.queue.pop
  end
  if filename != ''
    if File.exists?(filename)
      return File.read(filename)
    else
      @character.tell "File \"#{filename}\" not found."
    end
  end
end

#save(filename, json) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gamefic/engine/tty.rb', line 34

def save filename, json
  if json.nil?
    @character.tell "Nothing to save."
  end
  if filename.nil?
    stream.select "Enter the filename to save:"
    filename = stream.queue.pop
  end
  if filename != ''
    File.open(filename, 'w') do |f|
      f.write json
    end
    @character.tell "Game saved."
  end
end