Prop reification/splitting
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
module Dodge.Prop.Update
|
||||
where
|
||||
import Dodge.WdP2f
|
||||
import Dodge.PrWdLsLs
|
||||
import Dodge.WorldBool
|
||||
import Dodge.Data
|
||||
import Dodge.Prop.Moving
|
||||
|
||||
import Data.Foldable
|
||||
import Control.Lens
|
||||
|
||||
updateProp :: Prop -> World -> World
|
||||
updateProp pr = case _prUpdate pr of
|
||||
PropFallSmallBounceDamage -> fallSmallBounceDamage pr
|
||||
PropFallSmallBounce -> fallSmallBounce pr
|
||||
PropUpdateId -> id
|
||||
PropRotate x -> rotateProp x pr
|
||||
PropSetToggleAnd wb pu -> propSetToggleAnd wb pu pr
|
||||
PropUpdates pus -> doPropUpdates pr pus
|
||||
PropUpdateLS lsid x -> \w -> w & lightSources . ix lsid %~ doPrWdLsLs x pr w
|
||||
PropUpdatePosition x -> propUpdatePosition x pr
|
||||
PropUpdateWhen t x -> propUpdateIf t x PropUpdateId pr
|
||||
PropUpdateAnd x y -> doPropUpdates pr [x,y]
|
||||
PropUpdateIf t x y -> propUpdateIf t x y pr
|
||||
|
||||
propUpdateIf :: WdBl -> PropUpdate -> PropUpdate -> Prop -> World -> World
|
||||
propUpdateIf wb x y pr w
|
||||
| doWdBl wb w = updateProp (pr & prUpdate .~ x) w
|
||||
| otherwise = updateProp (pr & prUpdate .~ y) w
|
||||
|
||||
|
||||
|
||||
propUpdatePosition :: WdP2f -> Prop -> World -> World
|
||||
propUpdatePosition x pr w = w
|
||||
& props . ix (_prID pr) . prPos .~ fst (doWdP2f x w)
|
||||
& props . ix (_prID pr) . prRot .~ snd (doWdP2f x w)
|
||||
|
||||
doPropUpdates :: Prop -> [PropUpdate] -> World -> World
|
||||
doPropUpdates pr pus w = foldl' f w pus
|
||||
where
|
||||
f w' pu = updateProp (pr & prUpdate .~ pu) w'
|
||||
|
||||
propSetToggleAnd :: WdBl -> PropUpdate -> Prop -> World -> World
|
||||
propSetToggleAnd wb pu pr = setToggle (doWdBl wb) pr . updateProp (pr & prUpdate .~ pu)
|
||||
-- fugly
|
||||
|
||||
setToggle :: (World -> Bool) -> Prop -> World -> World
|
||||
setToggle cond pr w = w & props . ix (_prID pr) . prToggle .~ cond w
|
||||
|
||||
rotateProp :: Float -> Prop -> World -> World
|
||||
rotateProp rotAmount pr w = w
|
||||
& props . ix (_prID pr) . prRot +~ rotAmount
|
||||
|
||||
Reference in New Issue
Block a user