Class: Gamefic::User::Tty

Inherits:
Base
  • Object
show all
Defined in:
lib/gamefic/user/tty.rb

Overview

Note:

Due to their dependency on io/console, User::Tty and Engine::Tty are not included in the core Gamefic library. ‘require gamefic/tty` if you need them.

Extend User::Base to convert HTML into ANSI text.

Instance Method Summary collapse

Instance Method Details

#restore(filename) ⇒ Object



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

def restore filename
  if filename.nil?
    stream.select "Enter the filename to restore:"
    filename = stream.queue.pop
  end
  if filename != ''
    if File.exists?(filename)
      data = JSON.parse File.read(filename), symbolize_names: true
      #if (data[:metadata] != @character.plot.metadata)
      #  @character.tell "The save file is not compatible with this version of the game."
      #else
        return data
      #end
    else
      @character.tell "File \"#{filename}\" not found."
    end
  end
  nil
end

#save(filename, snapshot) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gamefic/user/tty.rb', line 18

def save filename, snapshot
  json = JSON.generate snapshot
  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
  end
end

#update(state) ⇒ Object



14
15
16
# File 'lib/gamefic/user/tty.rb', line 14

def update state
  print Gamefic::Text::Html::Conversions.html_to_ansi(state[:output])
end