sapling.rb: Multiple fixes

- Add logic for Planter, the editor module
- Add logic for catching a bad switch, and reporting accordingly
- Add logic for when no tree is included when required, and reporting
  accordingly
- Move YAML file loading from Dialogue/Gardner to here
This commit is contained in:
Bill Niblock 2017-05-07 16:51:00 -04:00
parent adecc3b193
commit 4570ee37e6

View file

@ -6,6 +6,7 @@ require 'yaml'
require_relative 'sapling/dialogue' require_relative 'sapling/dialogue'
require_relative 'sapling/gardner' require_relative 'sapling/gardner'
require_relative 'sapling/planter' require_relative 'sapling/planter'
require_relative 'sapling/utility'
# Sapling is the main module for the program. From here, the rest of the world # Sapling is the main module for the program. From here, the rest of the world
# starts building. # starts building.
@ -31,29 +32,50 @@ module Sapling
"Begin traversing the provided dialogue tree") do "Begin traversing the provided dialogue tree") do
if ARGV.empty? if ARGV.empty?
puts "No tree file provided. Please provide a tree file."
puts opt_parser puts opt_parser
exit exit
end end
unless Gardner.verify_tree(ARGV[0]) unless verify_tree(ARGV[0])
puts "\n#{opt}\n" puts "\n#{opt}\n"
exit exit
end end
puts "Welcome to Sapling, a Dialogue Tree Utility.\n"
speaker = Dialogue::Speaker.new speaker = Dialogue::Speaker.new
speaker.file = ARGV speaker.file = YAML.load_file(ARGV[0])
speaker.conversation speaker.conversation
end end
opt.on("-e", "--edit", opt.on("-e", "--edit",
"Create or edit a dialogue tree") do "Create or edit a dialogue tree") do
puts "We gonna make a tree!"
if ARGV.empty?
puts "Creating a new tree."
tree = SKELETON_TREE
else
puts "Using tree at #{ARGV[0]}."
unless verify_tree(ARGV[0])
puts "\n#{opt}\n"
exit
end
tree = YAML.load_file(ARGV[0])
end
puts "Welcome to Sapling, a Dialogue Tree Utility.\n"
gardner = Planter::Spade.new
gardner.file = tree
gardner.plant
end end
end end
opt_parser.parse!(options)
if ARGV.empty? # Hacky way of dealing with bad options
begin
opt_parser.parse!(options)
rescue OptionParser::InvalidOption
puts "Invalid option."
puts opt_parser puts opt_parser
exit exit
end end