Sha256: 8def0d3400a87b3ae04673f6c884252acf6503416168b0d293f978cf663b3038

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module Gamefic

	module Node
		def children
			if @children == nil
				@children = Array.new
			end
			@children.clone
		end
		def flatten
			array = Array.new
			children.each { |child|
				array = array + recurse_flatten(child)
			}
			return array
		end
		protected
		def add_child(node)
			children
			@children.push(node)
		end
		def rem_child(node)
			children
			@children.delete(node)
		end
		def concat_children(children)
			children
			@children.concat(children)
		end
		private
		def recurse_flatten(node)
			array = Array.new
			array.push(node)
			node.children.each { |child|
				array = array + recurse_flatten(child)
			}
			return array
		end
	end
	
	module Branch
		include Node
		def parent
			@parent
		end
		def parent=(node)
			if node == self
				raise "Entity cannot be its own parent"
			end
			if @parent != node
				if @parent != nil
					@parent.send(:rem_child, self)
				end
				@parent = node
				if @parent != nil
					@parent.send(:add_child, self)
				end
			end
		end
	end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gamefic-0.2.0 lib/gamefic/node.rb
gamefic-0.1.1 lib/gamefic/node.rb
gamefic-0.0.5 lib/gamefic/node.rb
gamefic-0.0.4 lib/gamefic/node.rb
gamefic-0.0.3 lib/gamefic/node.rb
gamefic-0.0.2 lib/gamefic/node.rb
gamefic-0.0.1 lib/gamefic/node.rb