MobHierarchyMixin¶
Qualified name: algan.animatable\_base.mob\_hierarchy.MobHierarchyMixin
- class MobHierarchyMixin[source]¶
Bases:
objectParent, child and descendant management, mixed into
Mob.A Mob’s children follow its transforms: move, rotate, scale or recolor a parent and the change propagates down. Use
add_children()to build a hierarchy, or aGroupwhen you just want to handle several Mobs as one.The hierarchy is a graph, not a tree: a Mob may have several parents and then accumulates all of their changes, which is what lets two overlapping Groups each arrange the same member. It is read when an animation is recorded, not when it plays, so re-parenting between two recorded animations leaves the first one alone – see Grouping Mobs.
Methods
Attach Mobs as children, so they follow this Mob's transforms.
Attach this Mob to another as one of its children.
Get this Mob's children, optionally reaching further down the hierarchy.
Get every Mob at or below this one, flattened into one list.
Detach a child so it stops following this Mob's transforms.
Detach this Mob from one of its parents, so it stops following that Mob's transforms.
Swap out this Mob's children for a different set.
- add_children(*mobs)[source]¶
Attach Mobs as children, so they follow this Mob’s transforms.
Once attached, moving, rotating, scaling or recoloring this Mob carries the children along. Adding a Mob that is already a child does nothing.
Animation
Not animated: the hierarchy changes immediately, and only affects animations recorded from here on. Children keep their own spawn state – attaching an unspawned Mob does not spawn it.
- Parameters:
*mobs – Mobs to attach. Nested iterables are flattened, so
mob.add_children([a, b])andmob.add_children(a, b)are the same.- Returns:
This Mob, so calls can be chained.
- Return type:
- Raises:
TypeError – If any item is not an
Animatable.HierarchyError – If a Mob appears twice, is its own child, belongs to another Scene, or the change would create a cycle.
- add_parent(other_mob)[source]¶
Attach this Mob to another as one of its children.
The mirror image of
add_children()called from the child’s side:child.add_parent(parent)andparent.add_children(child)build the same link, so this Mob followsother_mob’s transforms from here on. A Mob may have several parents, and then accumulates every one of their changes. Re-adding an existing parent does nothing.Animation
Not animated: the hierarchy changes immediately, and only affects animations recorded from here on.
- Parameters:
other_mob (Mob) – The Mob to become a parent of this one.
- Returns:
This Mob, so calls can be chained.
- Return type:
- Raises:
TypeError – If
other_mobis not anAnimatable..HierarchyError – If
other_mobis this Mob, belongs to another Scene, or is already somewhere below it – any of which would make the graph a cycle.
- get_children(generation=0, include_components=True)[source]¶
Get this Mob’s children, optionally reaching further down the hierarchy.
- Parameters:
generation (int) – How many levels down to collect:
0for direct children,1for grandchildren, and so on – each level replaces the one above rather than adding to it. Defaults to0.include_components (bool) – Whether to include children that are structural components of the Mob (the parts a shape builds itself from) as opposed to Mobs you added. Defaults to True.
- Returns:
The children at that generation. The Mobs are live, not copies.
- Return type:
list[
Mob]
See also
get_descendants()Every level at once, flattened.
- get_descendants(include_self=True)[source]¶
Get every Mob at or below this one, flattened into one list.
- Parameters:
include_self (bool) – Whether this Mob is the first element of the list. Defaults to True.
- Returns:
This Mob (unless excluded) followed by its children, their children, and so on. The Mobs are live, not copies.
- Return type:
list[
Mob]
- remove_child(mob)[source]¶
Detach a child so it stops following this Mob’s transforms.
The child stays in the scene and keeps its own state; it is simply no longer driven by this Mob. Any other parents it has are untouched, so it goes on following those.
Animation
Not animated: the hierarchy changes immediately, and only affects animations recorded from here on.
- remove_parent(other_mob)[source]¶
Detach this Mob from one of its parents, so it stops following that Mob’s transforms.
The reverse of
add_parent(), and drops both halves of the link – this Mob leavesother_mob’s children as well. Any other parents it has are untouched, and it stays in the scene with its own state. Removing a Mob that is not a parent does nothing.Animation
Not animated: the hierarchy changes immediately, and only affects animations recorded from here on.
- replace_children(mobs, *, link_parents=True)[source]¶
Swap out this Mob’s children for a different set.
Children that are not in the new set have their link to this Mob dropped, so they stop following its transforms; they are not despawned and remain in the scene on their own.
Animation
Not animated: the hierarchy changes immediately, and only affects animations recorded from here on. Already-recorded animation is unchanged.
- Parameters:
mobs – The new children. Nested iterables are flattened, so a list of Groups is accepted.
link_parents (bool) – Whether to maintain the children’s upward links to this Mob. Defaults to True; pass False only when the caller manages those links itself.
- Returns:
This Mob, so calls can be chained.
- Return type:
- Raises:
TypeError – If any item is not an
Animatable.HierarchyError – If a Mob appears twice, is its own child, belongs to another Scene, or the change would create a cycle.