Top Level Namespace

Defined Under Namespace

Modules: Dialogue, Gardner, Planter Classes: Sapling

Constant Summary collapse

SKELE_TRUNK_TEXT =

The default trunk text of a new tree

'Welcome to the Sapling Editor. For details, please see the
documentation!'.freeze
SKELE_BRANCH_TEXT =

The default first-branch text of a new tree

'The first branch is always shown by default. It should act
as the introduction to the story. From here, the user enters your world!'.freeze
SKELE_LEAF_TEXT =

The default first-leaf text of the first branch of a new tree. The leaf points to it’s own branch. The only way out of the program is to either force-quit or reply with option 0.

'Each branch can have any number of leaves, which represent
the options a user has on that branch. Each leaf points to another branch, or
can point to branch 0 to immediately exit.'.freeze
SKELETON_TREE =

The final tree

[
  { 'trunk' => SKELE_TRUNK_TEXT.to_s },
  { 'branch' => {
    'number' => 1,
    'text' => SKELE_BRANCH_TEXT.to_s,
    'leaf' => [{
      'text' => SKELE_LEAF_TEXT.to_s,
      'branch' => 1
    }]
  } }
].freeze

Instance Method Summary collapse

Instance Method Details

#verify_tree(file) ⇒ Boolean

Verify that a file is a dialogue tree file.

Parameters:

  • file (File)

    The provided file

Returns:

  • (Boolean)

    True if the file is a tree; false otherwise



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sapling/utility.rb', line 41

def verify_tree(file)
  results = []
  begin
    tree = YAML.load_file(file)
    results << tree[0].keys.include?('trunk')
    results << tree[1]['branch'].keys.include?('number')
    results << tree[1]['branch'].keys.include?('text')
    results << tree[1]['branch'].keys.include?('leaf')
  rescue
    puts "Sorry chummer, I don't think this is a tree."
    puts 'Verify your YAML file is formatted properly.'
    results << false
  end

  results.include?(false) ? false : true
end