lib/gamefic/user/tty.rb in gamefic-1.6.0 vs lib/gamefic/user/tty.rb in gamefic-1.7.0

- old
+ new

@@ -9,46 +9,30 @@ # @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. # class User::Tty < User::Base - def update state - print Gamefic::Text::Html::Conversions.html_to_ansi(state[:output]) + def update + unless character.state[:options].nil? + list = '<ol class="multiple_choice">' + character.state[:options].each { |o| + list += "<li><a href=\"#\" rel=\"gamefic\" data-command=\"#{o}\">#{o}</a></li>" + } + list += "</ol>" + character.tell list + end + print Gamefic::Text::Html::Conversions.html_to_ansi(character.state[:output]) end def save filename, snapshot - json = JSON.generate snapshot - if json.nil? - @character.tell "Nothing to save." + File.open(filename, 'w') do |file| + file << snapshot.to_json 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 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 + json = File.read(filename) + snapshot = JSON.parse(json, symbolize_names: true) + engine.plot.restore snapshot end end end