Implement moving mounted lights

This commit is contained in:
2022-03-10 14:43:41 +00:00
parent c583d33b57
commit 907cca0ef0
8 changed files with 80 additions and 21 deletions
+9 -6
View File
@@ -16,16 +16,18 @@ import qualified Data.IntMap.Strict as IM
putDoubleDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> Placement
putDoubleDoor pathing col cond a b speed
= putDoubleDoorThen pathing col cond a b speed (const $ const Nothing)
= putDoubleDoorThen pathing col cond 1 a b speed (const $ const Nothing)
putDoubleDoorThen :: Bool -> Color -> (World -> Bool)
-> Point2 -> Point2 -> Float
-> Float -> Point2 -> Point2 -> Float
-> (Placement -> Placement -> Maybe Placement)
-> Placement
putDoubleDoorThen pathing col cond a b speed cont = pt0 (PutSlideDr pathing col cond a half speed)
$ \pl1 -> Just $ Placement (PS (V2 0 0) 0) ( PutSlideDr pathing col cond b half speed) Nothing
putDoubleDoorThen pathing col cond soff a b speed cont
= doorbetween a half
$ \pl1 -> Just $ doorbetween b half
$ \pl2 -> cont pl1 pl2
where
doorbetween pa pb = pt0 $ PutSlideDr pathing col cond soff pa pb speed
half = 0.5 *.* (a +.+ b)
putAutoDoor :: Point2 -> Point2 -> Placement
@@ -39,8 +41,9 @@ putAutoDoor a b = PlacementUsingPos (addZ 0 a)
switchDoor :: Point2 -> Float -> Point2 -> Point2 -> Color -> Placement
switchDoor btpos btrot dra drb col = pContID (PS btpos btrot) (PutButton $ makeSwitch col red id id)
$ \btid -> jsps0J (PutSlideDr False col (cond btid) dra drc 2)
$ sps0 (PutSlideDr False col (cond btid) drb drc 2)
$ \btid -> jsps0J (doorbetween btid dra drc)
$ sps0 (doorbetween btid drb drc)
where
doorbetween btid a b = PutSlideDr False col (cond btid) 1 a b 2
drc = 0.5 *.* (dra +.+ drb)
cond btid w' = _btState (_buttons w' IM.! btid) == BtOn
@@ -11,8 +11,44 @@ import Dodge.Default
import Dodge.RandomHelp
import Color
import Shape
import ShapePicture
import Control.Lens
import Data.Maybe
propLSThen :: (Prop -> World -> World)
-> (Prop -> World -> LightSource -> LightSource)
-> LightSource
-> Prop
-> (Placement -> Placement -> Maybe Placement) -- ^ continuation, access to ls and prop placements
-> Placement
propLSThen propf lsf ls prop cont = pt0 (PutLS $ ls)
$ \lspl -> Just $ pt0 (PutProp $ prop & pjUpdate .~ theupdate (fromJust $ _plMID lspl))
$ cont lspl
where
theupdate lsid pr w = propf pr w & lightSources . ix lsid %~ lsf pr w
moveLSThen :: (World -> (Point2,Float))
-> Point3 -- ^ light source offset
-> Shape
-> (Placement -> Placement -> Maybe Placement)
-> Placement
moveLSThen posf off sh = propLSThen propupdate lsupdate thels theprop
where
propupdate pr w = w
& props . ix (_pjID pr) . pjPos .~ fst (posf w)
& props . ix (_pjID pr) . pjRot .~ snd (posf w)
lsupdate _ w = lsParam . lsPos .~ addZ 0 (fst (posf w)) +.+.+ rotate3z (snd (posf w)) off
thels = defaultLS
theprop = ShapeProp
{ _pjPos = 0
, _pjID = 0
, _pjRot = 0
, _pjUpdate = const id
, _prDraw = \pr -> noPic $ uncurryV translateSHf (_pjPos pr) $ rotateSH (_pjRot pr) sh
, _prToggle = True
}
-- | mount a light source on a shape
mntLSOn