packages feed

mischief-ecs-0.2.1.0: src/Mischief/ECS/Relationships/ChildOf.hs

module Mischief.ECS.Relationships.ChildOf where

import Mischief.ECS.Components
import Mischief.ECS.Entities
import Mischief.ECS.Relationships.Graph
import Mischief.ECS.World

data ChildOf = ChildOf deriving (Show)

instance Component ChildOf where
  type IsExclusiveRel ChildOf = True

parent :: forall m w. (MonadSystem w m) => Entity -> m (Maybe Entity)
parent !entity = do
  !p <- outgoing' @ChildOf entity
  pure $ case p of
    [!p] -> Just p
    _ -> Nothing

children :: forall m w. (MonadSystem w m) => Entity -> m [Entity]
children = incoming @ChildOf