Class: Gamefic::User::Tty

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

Overview

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

Instance Method Summary collapse

Methods inherited from Base

#send

Instance Method Details

#flushObject



48
49
50
# File 'lib/gamefic/user/tty.rb', line 48

def flush
  Gamefic::Text::Html::Conversions.html_to_ansi(super)
end

#restore(filename) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gamefic/user/tty.rb', line 28

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.)
        @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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gamefic/user/tty.rb', line 10

def save filename, snapshot
  data = snapshot.merge(:metadata => @character.plot.)
  json = JSON.generate data
  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