module Dodge.WorldEvent.Cloud
    where

import Dodge.Data
import Dodge.Base
import Geometry.Data
import Picture
--import qualified IntMapHelp as IM

import Control.Lens

makeCloudAt 
    :: (Cloud -> Picture) -- ^ draw function
    -> Float    -- ^ radius
    -> Int      -- ^ timer
    -> Float    -- ^ resting altitude
    -> Point3   -- start position
    -> World 
    -> World
makeCloudAt drawFunc rad t alt p w = w & clouds %~ (theCloud :)
  where 
    theCloud = Cloud 
        { _clPos = p
        , _clVel = V3 0 0 0
        , _clPict = drawFunc
        , _clRad = rad
        , _clAlt = alt
        , _clTimer = t
        , _clType = SmokeCloud
        , _clEffect = const id
        }

smokeCloudAt 
    :: Color  
    -> Float    -- ^ radius
    -> Int      -- ^ timer
    -> Float    -- ^ resting altitude
    -> Point3   -- start position
    -> World 
    -> World
smokeCloudAt col = makeCloudAt (drawCloudWith (4/3) 800 col)

drawCloudWith :: Float -> Float -> Color -> Cloud -> Picture
drawCloudWith radMult fadet col cl 
    = setLayer 2 
    . setDepth 25
    $ circleSolidCol (withAlpha 0 col) (withAlpha a col) (radMult * _clRad cl)
  where 
    a = min 1 $ fromIntegral (_clTimer cl) / fadet

makeThickSmokeAt :: Point3 -> World -> World
makeThickSmokeAt = makeCloudAt (drawCloudWith 4 50 black) 3 50 30

makeThinSmokeAt :: Point3 -> World -> World
makeThinSmokeAt = makeCloudAt (drawCloudWith 4 400 (withAlpha 0.05 black)) 5 400 50

makeStartCloudAt :: Point3 -> World -> World
--makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5))
makeStartCloudAt = makeCloudAt (drawCloudWith 2 800 white) 10 400 5

shellTrailCloud :: Point3 -> World -> World
----makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5))
shellTrailCloud = makeCloudAt (drawCloudWith (4/3) 800 (greyN 0.5)) 15 400 40

makeFlamerSmokeAt :: Float -> Point3 -> World -> World
makeFlamerSmokeAt x = makeCloudAt (drawCloudWith 4 300 (greyN x)) 6 200 40

spawnSmokeAtCursor :: World -> World
spawnSmokeAtCursor w = shellTrailCloud (V3 x y 20) w
  where
    V2 x y = mouseWorldPos w
