-- |
-- Module      :  Games.ECS.Slot
-- Description : ECS Slots
-- Copyright   :  (C) 2020 Sophie Taylor
-- License     :  AGPL-3.0-or-later
-- Maintainer  :  Sophie Taylor <sophie@spacekitteh.moe>
-- Stability   :  experimental
-- Portability: GHC
-- 
-- Slots are /logical/ places in a `Games.ECS.Component.Store.ComponentStore`.

module Games.ECS.Slot where

import Control.Lens
-- | A helper class for a generic "has" `Control.Lens.Type.Lens'`.
class HasType a s where
  {-# MINIMAL typed | getTyped, setTyped #-}
  -- | A 'Lens'' for accessing a well-known contained type.
  typed :: Lens' s a
  typed = (s -> a) -> (s -> a -> s) -> Lens' s a
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall a s. HasType a s => s -> a
getTyped @a) ((a -> s -> s) -> s -> a -> s
forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall a s. HasType a s => a -> s -> s
setTyped @a))
  -- | A getter for accesing a well-known contained type.
  {-# INLINE typed #-}
  getTyped :: s -> a
  getTyped s
s = s
s s -> Getting a s a -> a
forall s a. s -> Getting a s a -> a
^. forall a s. HasType a s => Lens' s a
typed @a
  {-# INLINE getTyped #-}
  -- | A setter for a well-known contained type.
  setTyped :: a -> s -> s
  setTyped a
a s
s = s
s s -> (s -> s) -> s
forall a b. a -> (a -> b) -> b
& (forall a s. HasType a s => Lens' s a
typed @a) ((a -> Identity a) -> s -> Identity s) -> a -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
a
  {-# INLINE setTyped #-}