-----------------------------------------------------------------------------
{-# LANGUAGE LambdaCase #-}
-----------------------------------------------------------------------------
-- | https://threejs.org/docs/index.html#api/en/constants/CustomBlendingEquations
module THREE.Constants.CustomBlendingEquations.DestinationFactors
  ( -- * Types
    DestinationFactors (..)
  ) where
-----------------------------------------------------------------------------
import           Miso
-----------------------------------------------------------------------------

-- same as SourceFactors, w/o SrcAlphaSaturateFactor

data DestinationFactors
  = ZeroFactor 
  | OneFactor 
  | SrcColorFactor
  | OneMinusSrcColorFactor 
  | SrcAlphaFactor
  | OneMinusSrcAlphaFactor 
  | DstAlphaFactor
  | OneMinusDstAlphaFactor 
  | DstColorFactor
  | OneMinusDstColorFactor 
  | ConstantColorFactor
  | OneMinusConstantColorFactor
  | ConstantAlphaFactor
  | OneMinusConstantAlphaFactor

instance ToJSVal DestinationFactors where
  toJSVal :: DestinationFactors -> IO JSVal
toJSVal = Int -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal (Int -> IO JSVal)
-> (DestinationFactors -> Int) -> DestinationFactors -> IO JSVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DestinationFactors -> Int
go
    where
      go :: DestinationFactors -> Int
      go :: DestinationFactors -> Int
go = \case
        DestinationFactors
ZeroFactor                    -> Int
200
        DestinationFactors
OneFactor                     -> Int
201
        DestinationFactors
SrcColorFactor                -> Int
202
        DestinationFactors
OneMinusSrcColorFactor        -> Int
203
        DestinationFactors
SrcAlphaFactor                -> Int
204
        DestinationFactors
OneMinusSrcAlphaFactor        -> Int
205
        DestinationFactors
DstAlphaFactor                -> Int
206
        DestinationFactors
OneMinusDstAlphaFactor        -> Int
207
        DestinationFactors
DstColorFactor                -> Int
208
        DestinationFactors
OneMinusDstColorFactor        -> Int
209
        DestinationFactors
ConstantColorFactor           -> Int
211
        DestinationFactors
OneMinusConstantColorFactor   -> Int
212
        DestinationFactors
ConstantAlphaFactor           -> Int
213
        DestinationFactors
OneMinusConstantAlphaFactor   -> Int
214

instance FromJSVal DestinationFactors where
  fromJSVal :: JSVal -> IO (Maybe DestinationFactors)
fromJSVal = (Maybe Int -> Maybe DestinationFactors)
-> IO (Maybe Int) -> IO (Maybe DestinationFactors)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Int
-> (Int -> Maybe DestinationFactors) -> Maybe DestinationFactors
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Maybe DestinationFactors
go) (IO (Maybe Int) -> IO (Maybe DestinationFactors))
-> (JSVal -> IO (Maybe Int))
-> JSVal
-> IO (Maybe DestinationFactors)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> IO (Maybe Int)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal
    where
      go :: Int -> Maybe DestinationFactors
      go :: Int -> Maybe DestinationFactors
go = \case
        Int
200 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
ZeroFactor
        Int
201 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneFactor
        Int
202 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
SrcColorFactor
        Int
203 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusSrcColorFactor
        Int
204 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
SrcAlphaFactor
        Int
205 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusSrcAlphaFactor
        Int
206 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
DstAlphaFactor
        Int
207 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusDstAlphaFactor
        Int
208 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
DstColorFactor
        Int
209 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusDstColorFactor
        Int
211 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
ConstantColorFactor
        Int
212 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusConstantColorFactor
        Int
213 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
ConstantAlphaFactor
        Int
214 -> DestinationFactors -> Maybe DestinationFactors
forall a. a -> Maybe a
Just DestinationFactors
OneMinusConstantAlphaFactor
        Int
_ -> Maybe DestinationFactors
forall a. Maybe a
Nothing

-----------------------------------------------------------------------------