Hate 0.1.4.2 → 0.1.4.3
raw patch · 3 files changed
+58/−1 lines, 3 filesdep +hpp
Dependencies added: hpp
Files
- Hate.cabal +4/−1
- samples/Vec2Lens.hs +20/−0
- src/Hate/Util.hs +34/−0
Hate.cabal view
@@ -3,7 +3,7 @@ -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.4.2+version: 0.1.4.3 synopsis: A small 2D game framework. description: A small 2D game framework. stability: experimental@@ -46,6 +46,7 @@ Hate.Graphics.Backend.Modern Hate.Graphics.Backend.Modern.Shaders Hate.Graphics.Backend.Modern.Types+ Hate.Util hs-source-dirs: .,src@@ -55,6 +56,7 @@ -- Other library packages from which modules are imported. build-depends: base >= 4.6 && < 4.9, GLFW-b >= 1.4 && < 1.4.7,+ hpp, GLUtil >= 0.7, OpenGL > 2.9.1, transformers,@@ -97,6 +99,7 @@ executable sample_sprite main-is: sample_sprite.hs hs-source-dirs: samples + other-modules: Vec2Lens build-depends: base >= 4.6 && < 4.9, GLFW-b >= 1.4 && < 1.4.7, GLUtil >= 0.7,
+ samples/Vec2Lens.hs view
@@ -0,0 +1,20 @@+module Vec2Lens(x,y) where + +import Data.Vect.Float +import Control.Lens + +x :: Simple Lens Vec2 Float +x = lens getX setX + +y :: Simple Lens Vec2 Float +y = lens getY setY + +getX :: Vec2 -> Float +getX (Vec2 x' _) = x' +getY :: Vec2 -> Float +getY (Vec2 _ y') = y' + +setX :: Vec2 -> Float -> Vec2 +setX (Vec2 _ y') nx = Vec2 nx y' +setY :: Vec2 -> Float -> Vec2 +setY (Vec2 x' _) ny = Vec2 x' ny
+ src/Hate/Util.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE Trustworthy #-}++{-|+Module : Util+Description : Various utilities used by Hate framework+License : MIT+Maintainer : bananu7@o2.pl+Stability : stable+Portability : full++This module contains various utilities missing from @Prelude@+or @Control.Monad@.+-}++module Hate.Util where++import Control.Monad (unless)++-- |A "functional" if-statement.+bool :: Bool -> a -> a -> a+bool b falseRes trueRes = if b then trueRes else falseRes++-- |Monad "unless" that automatically extracts the value from the action.+unless' :: Monad m => m Bool -> m () -> m ()+unless' action falseAction = do+ b <- action+ unless b falseAction++-- |A bit cleaner "maybe".+maybe' :: Maybe a -> b -> (a -> b) -> b+maybe' m nothingRes f = case m of+ Nothing -> nothingRes+ Just x -> f x+