module Mischief.ECS.Resources (insertRes, res, resOrInsert) where
import Mischief.ECS.Components
import Mischief.ECS.Components.Bundle
import Mischief.ECS.Components.Spawn
import Mischief.ECS.World
import Mischief.ECS.World.Insert
import Mischief.ECS.World.Query
import Mischief.ECS.World.Query.Markers
insertRes :: forall r. (Component r, Bundle r) => r -> System ()
insertRes :: forall r. (Component r, Bundle r) => r -> System ()
insertRes r
res = do
entity <- forall c. Component c => System Entity
meta @r
insert res entity
res :: forall c. (Component c) => System (Maybe c)
res :: forall c. Component c => System (Maybe c)
res = do
meta <- forall c. Component c => System Entity
meta @c
single $ mkGet meta (C @c)
resOrInsert :: forall r. (Component r, Bundle r) => r -> System r
resOrInsert :: forall r. (Component r, Bundle r) => r -> System r
resOrInsert r
r = do
meta <- forall c. Component c => System Entity
meta @r
x <- single $ mkGet meta (C @r)
case x of
Maybe r
Nothing -> do
r -> System ()
forall r. (Component r, Bundle r) => r -> System ()
insertRes r
r
r -> System r
forall a. a -> System a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
r
Just r
r -> r -> System r
forall a. a -> System a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
r