Sapling: Add functionality for web and demo
- Web: Add `serve` functionality, which starts a simple Rack application to serve a template page. Template still needs work. - Demo: add `example` option, which starts the CLI using the "Example Quest!" tree
This commit is contained in:
parent
522c23b206
commit
ed521bfbcd
1 changed files with 23 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue