diff --git a/lib/sapling.rb b/lib/sapling.rb index 901094b..721455a 100644 --- a/lib/sapling.rb +++ b/lib/sapling.rb @@ -1,5 +1,7 @@ #!/usr/bin/env ruby +# frozen string literal: true +require 'rack' require 'thor' require 'yaml' @@ -7,6 +9,7 @@ Dir[File.join(__dir__, 'sapling', '*.rb')].each { |file| require file } # The main Sapling interface. class Sapling < Thor + # CLI-based options desc 'read TREE', 'Load and traverse the TREE' def read(file) puts 'Welcome to Sapling, a Dialogue Tree Utility.' @@ -30,10 +33,16 @@ class Sapling < Thor gardner.plant end + # Web-based options desc 'serve TREE', 'Load TREE in a web-based interface' - def serve(tree) - exit unless verify_tree(tree) - puts 'Sinatra will be cool.' + def serve(file) + exit unless verify_tree(file) + tree = Gardner::Plot.new(YAML.load_file(file)) + Rack::Server.new( + app: Greenhouse.new(tree), + server: 'webrick', + Port: 9000 + ).start end desc 'export TREE', 'Save a portable HTML version of TREE' @@ -41,4 +50,15 @@ class Sapling < Thor exit unless verify_tree(tree) puts 'Cool feature, bro!' end + + # Miscellaneous options + desc 'example', 'Play Example Quest!' + def example + file = File.join(__dir__, '..', 'var', 'trees', 'example_quest.yaml') + puts 'Welcome to Sapling, a Dialogue Tree Utility.' + exit unless verify_tree(file) + tree = Gardner::Plot.new(YAML.load_file(file)) + speaker = Dialogue::Speaker.new(tree, false) + speaker.conversation + end end