aztecs 0.17.0 → 0.17.1
raw patch · 5 files changed
+4/−127 lines, 5 filesdep ~basedep ~mtldep ~vectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, mtl, vector
API changes (from Hackage documentation)
+ Aztecs.ECS.Access.Internal: instance Control.Monad.Trans.Class.MonadTrans Aztecs.ECS.Access.Internal.Access
Files
- aztecs.cabal +1/−27
- examples/ECS.hs +0/−30
- examples/Lifecycle.hs +0/−30
- examples/Observers.hs +0/−40
- src/Aztecs/ECS/Access/Internal.hs +3/−0
aztecs.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: aztecs -version: 0.17.0 +version: 0.17.1 license: BSD-3-Clause license-file: LICENSE maintainer: matt@hunzinger.me @@ -67,32 +67,6 @@ containers >=0.6, mtl >=2, vector >=0.12 - -executable ecs - main-is: examples/ECS.hs - default-language: Haskell2010 - ghc-options: -Wall - build-depends: - base, - aztecs - -executable lifecycle - main-is: examples/Lifecycle.hs - default-language: Haskell2010 - ghc-options: -Wall - build-depends: - base, - aztecs - -executable observers - main-is: examples/Observers.hs - default-language: Haskell2010 - ghc-options: -Wall - build-depends: - base, - aztecs, - mtl, - vector test-suite aztecs-test type: exitcode-stdio-1.0
− examples/ECS.hs
@@ -1,30 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}--module Main where--import Aztecs.ECS-import Control.Monad.IO.Class--newtype Position = Position Int deriving (Show)--instance (Monad m) => Component m Position--newtype Velocity = Velocity Int deriving (Show)--instance (Monad m) => Component m Velocity--move :: (Monad m) => Query m Position-move = queryMapWith go query- where- go (Velocity v) (Position p) = Position $ p + v--app :: Access IO ()-app = do- spawn_ $ bundle (Position 0) <> bundle (Velocity 1)- positions <- system $ runQuery move- liftIO $ print positions--main :: IO ()-main = runAccess_ app
− examples/Lifecycle.hs
@@ -1,30 +0,0 @@-{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE TypeApplications #-} - -module Main where - -import Aztecs.ECS -import Control.Monad.IO.Class - -newtype X = X Int deriving (Show) - -instance Component IO X where - componentOnInsert = exampleHook "insert" - componentOnChange e _ = exampleHook "change" e - componentOnRemove = exampleHook "remove" - -exampleHook :: String -> EntityID -> X -> Access IO () -exampleHook s e x = liftIO . putStrLn $ s ++ " " ++ show e ++ ": " ++ show x - -addTen :: Query IO X -addTen = queryMap (\(X n) -> X (n + 10)) - -app :: Access IO () -app = do - e <- spawn $ bundle (X 1) - _ <- system $ runQuery addTen - _ <- remove @IO @X e - return () - -main :: IO () -main = runAccess_ app
− examples/Observers.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE TypeApplications #-} - -module Main where - -import Aztecs.ECS -import Control.Monad.IO.Class - -newtype Health = Health Int - deriving (Show) - -instance Component IO Health - -heal :: Query IO Health -heal = queryMap (\(Health h) -> Health (h + 10)) - -run :: Access IO () -run = do - -- Spawn a player with health - player <- spawn . bundle $ Health 100 - - -- Spawn observers that react to lifecycle events on the player's Health component - _ <- spawn . bundle . observer @IO @(OnInsert Health) player $ \e (OnInsert h) -> - observe "insert" e h - _ <- spawn . bundle . observer @IO @(OnChange Health) player $ \e change -> - liftIO . putStrLn $ "change " ++ show e ++ ": old=" ++ show (onChangeOld change) ++ ", new=" ++ show (onChangeNew change) - _ <- spawn . bundle . observer @IO @(OnRemove Health) player $ \e (OnRemove h) -> - observe "remove" e h - - -- Trigger events by inserting, changing, and removing the Health component - _ <- insert player . bundle $ Health 150 - _ <- system $ runQuery heal - _ <- remove @_ @Health player - - return () - where - observe s e h = liftIO . putStrLn $ s ++ " " ++ show e ++ ": " ++ show h - -main :: IO () -main = runAccess_ run
src/Aztecs/ECS/Access/Internal.hs view
@@ -38,6 +38,9 @@ newtype Access m a = Access {unAccess :: StateT (World m) m a} deriving (Functor, Applicative, Monad, MonadFix, MonadIO) +instance MonadTrans Access where + lift = Access . lift + -- | Run an `Access` with a given `World`, returning the result and updated world. runAccessWith :: Access m a -> World m -> m (a, World m) runAccessWith a = runStateT (unAccess a)