lib/gamefic/engine/tty.rb in gamefic-0.6.1 vs lib/gamefic/engine/tty.rb in gamefic-1.0.0
- old
+ new
@@ -1,9 +1,10 @@
require 'gamefic/engine'
require 'rexml/document'
require 'gamefic/ansi'
require 'gamefic/html'
+require 'json'
begin
require 'io/console'
rescue LoadError
puts "This version of Ruby does not support io/console. Text may not wrap correctly."
@@ -29,11 +30,16 @@
@stream.ansi = val
end
def ansi
@stream.ansi
end
- def save filename, json
+ def save filename, snapshot
+ data = {
+ :metadata => @character.plot.metadata,
+ :entities => snapshot
+ }
+ json = JSON.generate data
if json.nil?
@character.tell "Nothing to save."
end
if filename.nil?
stream.select "Enter the filename to save:"
@@ -51,14 +57,20 @@
stream.select "Enter the filename to restore:"
filename = stream.queue.pop
end
if filename != ''
if File.exists?(filename)
- return File.read(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[:entities]
+ end
else
@character.tell "File \"#{filename}\" not found."
end
end
+ nil
end
end
class UserStream < Gamefic::UserStream
include Ansi
include Ansi::Code