mischief-ecs
Safe HaskellNone
LanguageGHC2024

Mischief.ECS.HooksRel

Synopsis

Documentation

addOther :: (Component a, Component b) => (a -> b) -> HookRel a Source #

Relationship Hook for Component a.

Takes a a -> b. If a is a relationship from x to y, this hook will add the corresponding b from y to x.

Example usage:

data After = After
data Before = Before

instance Component Before where
  onAddRel = [addOther (const After)]

instance Component After where
  onAddRel = [addOther (const Before)]

removeOther :: forall {k} (a :: k) b. Component b => HookRel a Source #

Relationship Hook for Component a.

Removes b from the target entity of a relationship.

Example usage:

data Likes = Likes
data LikedBy = LikedBy deriving (Component)

instance Component Likes where
  onAddRel = [addOther (const Likes)]
  onRemoveRel = [removeOther @Likes]

`

addDespawnCleaner :: Component a => HookRel a Source #

Relationship Hook for Component a.

Adds a cleaner that will despawn this relationship's entity if the target of the relationship is despawned.

Note that one component can have only one cleaner at a time.

addRemoveCleaner :: Component a => HookRel a Source #

Relationship Hook for Component a.

Adds a cleaner that will remove this relationship if the target is despawned.

Note that one component can have only one cleaner at a time.

addCleaner :: Component a => (CleanupRequest -> System ()) -> HookRel a Source #

removeCleaner :: Component a => HookRel a Source #

Relationship Hook for Component a.

Removes the cleaner associated to this component, if any.