Module: Gamefic::Node

Included in:
Entity
Defined in:
lib/gamefic/node.rb

Overview

Parent/child relationships for objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentNode?

The object’s parent.

Returns:



16
17
18
# File 'lib/gamefic/node.rb', line 16

def parent
  @parent
end

Instance Method Details

#accessible?Boolean

Determine if external objects can interact with this object’s children. For example, a game can designate that the contents of a bowl are accessible, while the contents of a locked safe are not.

Returns:

  • (Boolean)


50
51
52
# File 'lib/gamefic/node.rb', line 50

def accessible?
  true
end

#childrenArray<Node>

An array of the object’s children.

Returns:



21
22
23
# File 'lib/gamefic/node.rb', line 21

def children
  child_set.to_a.freeze
end

#flattenArray<Node>

Get a flat array of all descendants.

Returns:



28
29
30
# File 'lib/gamefic/node.rb', line 28

def flatten
  children.flat_map { |child| [child] + child.flatten }
end

#has?(other) ⇒ Boolean

True if this node is the other’s parent.

Parameters:

Returns:

  • (Boolean)


57
58
59
# File 'lib/gamefic/node.rb', line 57

def has?(other)
  other.parent == self
end