| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Mischief.ECS.World.Query.Pipe
Synopsis
- qtraverse :: (Entity -> a -> m b) -> Query m a -> Query m b
- qtap :: (Entity -> a -> m b) -> Query m a -> Query m a
- qmap :: forall w (m :: Type -> Type) a b. MonadSystem w m => (a -> b) -> Query m a -> Query m b
- qmapM :: MonadSystem w m => (Entity -> a -> m b) -> Query m a -> Query m b
- qmapMaybe :: forall w (m :: Type -> Type) a b. MonadSystem w m => (a -> Maybe b) -> Query m a -> Query m b
- qmapMaybeM :: MonadSystem w m => (Entity -> a -> m (Maybe b)) -> Query m a -> Query m b
- qfilter :: forall w (m :: Type -> Type) a. MonadSystem w m => (a -> Bool) -> Query m a -> Query m a
- qfilterM :: (Entity -> a -> m Bool) -> Query m a -> Query m a
- qinsert :: Bundle b => (a -> b) -> Query System a -> Query System a
- qinsertNew :: Bundle b => (a -> b) -> Query System a -> Query System a
- qinsertIfNeq :: BundleEq b => (a -> b) -> Query System a -> Query System a
- qmodify :: Bundle b => (a -> b) -> Query System a -> Query System b
- qmodifyNew :: Bundle b => (a -> b) -> Query System a -> Query System b
- qmodifyIfNeq :: BundleEq b => (a -> b) -> Query System a -> Query System b
- 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
- qentity :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a -> Query m (Entity, a)
- qrelateOne :: (MonadSystem w m, Queryable qd out) => (Entity -> m (Maybe Entity)) -> qd -> (a -> From out -> c) -> Query m a -> Query m c
- qrelateMany :: (MonadSystem w m, Queryable (E, qd) (Entity, out)) => (Entity -> m [Entity]) -> qd -> (a -> [From out] -> c) -> Query m a -> Query m c
- 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
- qpure :: forall w (m :: Type -> Type). MonadSystem w m => Entity -> Query m ()
- qrefocus :: forall (m :: Type -> Type) a. Entity -> Query m a -> Query m a
- qres :: forall c (m :: Type -> Type) w. (MonadSystem w m, Component c) => Query m c
- qget :: forall w (m :: Type -> Type) qd out. (MonadSystem w m, Queryable qd out) => Entity -> qd -> Query m out
- qgetAll :: forall w (m :: Type -> Type) qd out. (MonadSystem w m, Queryable qd out) => [Entity] -> qd -> Query m out
- qcollect :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a -> Query m [From a]
- qmaybe :: forall w (m :: Type -> Type) a. MonadSystem w m => Maybe a -> Query m a
- qstopIf :: forall w (m :: Type -> Type). MonadSystem w m => Bool -> Query m ()
- qstop :: forall w (m :: Type -> Type) a. MonadSystem w m => Query m a
- qiter :: forall w (m :: Type -> Type) a. MonadSystem w m => [From a] -> Query m a
- qiterE :: forall w (m :: Type -> Type). MonadSystem w m => [Entity] -> Query m Entity
- qlift :: MonadSystem w m => m a -> Query m a
- qlift_ :: MonadSystem w m => m a -> Query m ()
- qinfo :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a
- qwarn :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a
- qerr :: forall w (m :: Type -> Type) a. (HasCallStack, MonadSystem w m) => (a -> Text) -> Query m a -> Query m a
- qdespawn :: Query System a -> Query System a
- qpar :: forall w (m :: Type -> Type) a. MonadSystem w m => Query ParSystem a -> Query m a
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
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 #
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
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 #
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.