Files
loop/src/Dodge/Placement/Instance/LightSource/Flicker.hs
T
2022-07-23 20:53:00 +01:00

34 lines
1.1 KiB
Haskell

module Dodge.Placement.Instance.LightSource.Flicker where
import Dodge.LevelGen.Data
import Dodge.Data
import qualified IntMapHelp as IM
import Data.Maybe
import Control.Lens
import System.Random
-- Supposes the orginal placement is a light source, adds a flicker
flickerMod :: Placement -> Maybe Placement
flickerMod pl = Just $ sps0 $ PutMod $ ModIDTimerPoint3Bool
{ _mdID = 0
, _mdExternalID = fromJust $ _plMID pl
, _mdUpdate = MdFlickerUpdate
, _mdTimer = 10
, _mdPoint3 = 0.8
, _mdBool = True
}
flickerUpdate :: Modification -> World -> World
flickerUpdate md w
| _mdTimer md > 0 = w & modifications . ix mdid . mdTimer -~ 1
| otherwise = w & lightSources . ix lsid . lsParam . lsCol .~ mdcol
& modifications . ix mdid
%~ ( (mdTimer .~ newtime) . (mdPoint3 .~ lscol) . (mdBool %~ not) )
where
mdcol = _mdPoint3 md
lscol = _lsCol $ _lsParam $ _lightSources w IM.! lsid
lsid = _mdExternalID md
mdid = _mdID md
timerange
| _mdBool md = (2,10)
| otherwise = (2,30)
(newtime,_) = randomR timerange $ _randGen w