Core

class afc.core.node.Node(parent=None, children=_Nothing.NOTHING, locals=_Nothing.NOTHING, index=_Nothing.NOTHING, my_var=0, *, guid=_Nothing.NOTHING, uid=None)

The Node class represents a basic building block of a story or scene tree. Each Node has a unique identifier (guid), a public name (uid), an optional parent Node, a local variables store, and can have multiple child Nodes. It includes methods for managing its relationships and recursively evaluating its namespace with variables cascaded from parents, super-classes, and collection-level metadata.

Variables:
  • guid (UUID) – A unique identifier for this Node.

  • uid (str) – A short identifier derived from a template name or its guid.

  • parent (Node) – The parent Node of this Node.

  • path (str) – The path from the root Node to this Node.

  • root (Node) – The root Node of this Node’s tree.

  • index (Index) – The Index object that contains this Node.

  • locals (dict) – The local variables associated with the Node.

  • children (dict) – A dictionary of child Nodes.

Node is designed to be extended with various Mixin classes. These Mixins add functionality to the Node, such as rendering, runtime evaluation, conditional application, trading, and traversal.

Mixin Classes:

  • RenderableMixin: Adds a rendering handler to the Node.

  • RuntimeMixin: Adds a runtime evaluation handler to the Node.

  • ConditionalApplyableMixin: Adds conditions and effects to the Node.

  • TraderMixin: Adds Node-trading functionality to the Node.

  • TraversableMixin: Adds graph traversal functionality to the Node.

  • AutomorphicMixin: Adds methods for converting a Node to and from a dictionary with dynamic subclass casting.

Relies on attrs <https://www.attrs.org> initialization for attributes.

Examples:

>>> root = Node(uid="root")
>>> child1 = Node(uid="child1")
>>> root.add_child(child1)

Note: Detailed descriptions of the methods can be found in their respective docstrings.

Raises: KeyError: If a child with the same guid already exists in the children dictionary.

_uid

A short identifier for this Node, derived from a template name or its guid.

guid

Unique private identifier UUID for this Node.

my_var

The local variables associated with the Node.

property uid

Public name or partial guid for this Node.

class afc.core.tree_index.Index

A collection of all nodes in the story tree.

Provides easy access to and lookup of nodes. Nodes can be added or removed from the index, and found by their unique identifiers or and uid-path.

class afc.core.tree_index.IndexedTreeMixin(parent=None, children=_Nothing.NOTHING, index=_Nothing.NOTHING, *, guid=_Nothing.NOTHING, uid=None)