mischief-ecs
Safe HaskellNone
LanguageGHC2024

Mischief.ECS.World.Query.Pipe

Synopsis

Impure

qtraverse :: (Entity -> a -> m b) -> Query m a -> Query m b Source #

Map Query m a to Query m b with side effects.

Example

[q|Name, Position|]
  & qtraverse (\e (name, pos) -> do
    [i|The name of entity #{e} is #{name}|]
    pure pos
  )
  & query

qtap :: (Entity -> a -> m b) -> Query m a -> Query m a Source #

Apply a side effect over a query.

Example

[q|Name, Position|]
  & qtraverse (\e (name, pos) -> do
    [i|The name of entity #{e} is #{name}|]
  )
  & query

Mapping

qmap :: forall w (m :: Type -> Type) a b. MonadSystem w m => (a -> b) -> Query m a -> Query m b Source #

Maps Query m a to Query m b. Same as fmap.

Example

[q|Name, Position|]
  & qmap (\(name, _) -> name)
  & query

qmapM :: MonadSystem w m => (Entity -> a -> m b) -> Query m a -> Query m b Source #

qmap with side effects. Same as qtraverse.

qmapMaybe :: forall w (m :: Type -> Type) a b. MonadSystem w m => (a -> Maybe b) -> Query m a -> Query m b Source #

Possibly maps each element from Query m a to an element from Query m b. If Nothing, will filter this Entity out of the Query.

Example

f :: Name -> Maybe Name
[q|Name|]
  & qmapMaybe f
  & query

qmapMaybeM :: MonadSystem w m => (Entity -> a -> m (Maybe b)) -> Query m a -> Query m b Source #

qmapMaybe with side effects.

Filtering

qfilter :: forall w (m :: Type -> Type) a. MonadSystem w m => (a -> Bool) -> Query m a -> Query m a Source #

Filter the entities of a query.

Example

[q|Name|]
  & qfilter (== Name Florian)
  & query

qfilterM :: (Entity -> a -> m Bool) -> Query m a -> Query m a Source #

Filter the entities of a query with possible side effects.

Example

[q|Position|]
  & qfilterM (\e _ -> changed @Position e)
  & query

Insertion

qinsert :: Bundle b => (a -> b) -> Query System a -> Query System a Source #

Insert the values obtained from a mapping function.

Example

q[|Position, Velocity|]
  & qinsert (\(Position p, Velocity v) -> Position (p + v))
  & query

qinsertNew :: Bundle b => (a -> b) -> Query System a -> Query System a Source #

Same as qinsert but only inserts components that aren't already on the entity.

qinsertIfNeq :: BundleEq b => (a -> b) -> Query System a -> Query System a Source #

Same as qinsert but only inserts components that are new or different than the ones already on the entity. Avoids triggering false change detection.

qmodify :: Bundle b => (a -> b) -> Query System a -> Query System b Source #

Same as qinsert but will also propagate the mapped elements. Equivalent to qinsert id . qmap f.

qmodifyNew :: Bundle b => (a -> b) -> Query System a -> Query System b Source #

Same as qinsertNew but will also propagate the mapped elements. Equivalent to qinsertNew id . qmap f.

qmodifyIfNeq :: BundleEq b => (a -> b) -> Query System a -> Query System b Source #

Same as qinsertIfNeq but will also propagate the mapped elements. Equivalent to qinsertIfNeq id . qmap f.

Expansion

qextend :: forall w (m :: Type -> Type) qd out a c. (MonadSystem w m, Queryable qd out) => qd -> (a -> out -> c) -> Query m a -> Query m c Source #

Filter the entities of a query with a dedicated query filter.

Example

[q|Position|]
  & qcheck [qf|Changed Position, !Added Position|]
  & query

qcheck :: (MonadSystem w m) => QueryFilter EntityFilter -> Query m a -> Query m a qcheck !f = qfilterM ((!e) _ -> check f e) {-# INLINE [1] qcheck #-}

Extends the query with new elements.

Example

[q|Name|]
  & qextend qd|Position|
  & query

qentity :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a -> Query m (Entity, a) Source #

Traversal

qrelateOne :: (MonadSystem w m, Queryable qd out) => (Entity -> m (Maybe Entity)) -> qd -> (a -> From out -> c) -> Query m a -> Query m c Source #

Grab a Query Data from an entity resulting from a traversal and map it into the current data wrapped in a From:

Example

[q|Name|]
  & qrelateOne (Tree.root @Like) [qd|Name|] (,)
  & query_

qrelateMany :: (MonadSystem w m, Queryable (E, qd) (Entity, out)) => (Entity -> m [Entity]) -> qd -> (a -> [From out] -> c) -> Query m a -> Query m c Source #

Same as qrelateOne but takes a traversal that returns a list of entities.

qjoin :: forall w (m :: Type -> Type) a b c. MonadSystem w m => (a -> Query m b) -> (a -> [From b] -> c) -> Query m a -> Query m c Source #

Monad

qpure :: forall w (m :: Type -> Type). MonadSystem w m => Entity -> Query m () Source #

qrefocus :: forall (m :: Type -> Type) a. Entity -> Query m a -> Query m a Source #

qres :: forall c (m :: Type -> Type) w. (MonadSystem w m, Component c) => Query m c Source #

qget :: forall w (m :: Type -> Type) qd out. (MonadSystem w m, Queryable qd out) => Entity -> qd -> Query m out Source #

qgetAll :: forall w (m :: Type -> Type) qd out. (MonadSystem w m, Queryable qd out) => [Entity] -> qd -> Query m out Source #

qcollect :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a -> Query m [From a] Source #

qmaybe :: forall w (m :: Type -> Type) a. MonadSystem w m => Maybe a -> Query m a Source #

qstopIf :: forall w (m :: Type -> Type). MonadSystem w m => Bool -> Query m () Source #

qstop :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a Source #

qiter :: forall w (m :: Type -> Type) a. MonadSystem w m => [From a] -> Query m a Source #

qiterE :: forall w (m :: Type -> Type). MonadSystem w m => [Entity] -> Query m Entity Source #

qlift :: MonadSystem w m => m a -> Query m a Source #

qlift_ :: MonadSystem w m => m a -> Query m () Source #

Logging

qinfo :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a Source #

Logs an INFO message.

qwarn :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a Source #

Logs a WARNING message.

qerr :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a Source #

Logs an ERROR message.

Other

Parallelism

qpar :: forall w (m :: Type -> Type) a. MonadSystem w m => Query ParSystem a -> Query m a Source #