gardner.rb: Refactor

- Remove functionality that doesn't belong in this module:
  - Move printing of trunk to the dialogue class
  - Remove tree generation entirely; let other modules generate trees as
  they need them
- Style formatting
This commit is contained in:
Bill Niblock 2017-05-07 23:49:12 -04:00
parent e27cd43e7c
commit a2dd7e3b1c

View file

@ -2,11 +2,10 @@ require 'yaml'
# Gardner is the module for working with a dialogue tree file
module Gardner
# Parse the branch
# Parse the tree array into an array of numbered branches, and ordered leaves.
#
# @param tree [Array] The dialogue tree
# @return [Array] The array of options on the branch.
# @return [Array] An array of numbered branches, with numbered leaves
def self.prune_branches(tree)
branches = { 0 => { "desc" => "Thanks for using Sapling!" } }
tree.each do |b|
@ -16,13 +15,12 @@ module Gardner
end
return branches
end
# Parse the options
# Parse the leaves of a branch into a numbered hash of options.
#
# @param leaves [Array] The option of leaf hashes
# @return [Hash] A has of options
# @return [Hash] A numbered hash of options
def self.prune_leaves(leaves)
x = 1
options = {}
@ -35,34 +33,15 @@ module Gardner
end
return options
end
# Parse the trunk
# The trunk is like the introduction to the tree.
# Parse the trunk of the tree.
#
# @param tree [Hash] The entire tree
# @return [Hash] The tree without the trunk
# @return [Array] The trunk, and the remainder of the tree
def self.prune_trunk(tree)
trunk = tree.shift
40.times { print "-" }
puts "\n#{trunk["trunk"]}"
40.times { print "-" }
puts "\n"
return tree
return [trunk,tree]
end
# The main method for Sapling. From here, the tree is grown.
#
# @param tree [File] The dialogue tree file
# @return [Hash] The final, constructed data set
def self.grow(tree)
trunk = Gardner.prune_trunk(tree)
branches = Gardner.prune_branches(trunk)
return branches
end
end