Simplify block/wall destruction
This uses a right fold, so might be slower than a strict left fold
This commit is contained in:
@@ -13,14 +13,23 @@ import Dodge.Zoning.Base
|
||||
import Geometry.Data
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
--updateWallDamages :: World -> World
|
||||
--updateWallDamages w =
|
||||
-- let (is, w') = IM.foldlWithKey' f (mempty, w) (w ^. cWorld . lWorld . wallDamages)
|
||||
-- in updateEdgesWall is w' & cWorld . lWorld . wallDamages .~ IM.empty
|
||||
-- where
|
||||
-- f isw k dams = fromMaybe isw $ do
|
||||
-- wl <- isw ^? _2 . cWorld . lWorld . walls . ix k
|
||||
-- return $ foldl' (flip (`damageWall` wl)) isw dams
|
||||
|
||||
updateWallDamages :: World -> World
|
||||
updateWallDamages w =
|
||||
let (is, w') = IM.foldlWithKey' f (mempty, w) (w ^. cWorld . lWorld . wallDamages)
|
||||
in updateEdgesWall is w' & cWorld . lWorld . wallDamages .~ IM.empty
|
||||
updateWallDamages w = set (cWorld . lWorld . wallDamages) mempty
|
||||
. uncurry updateEdgesWall $ foldrM f w
|
||||
(IM.toList $ w ^. cWorld . lWorld . wallDamages)
|
||||
where
|
||||
f isw k dams = fromMaybe isw $ do
|
||||
wl <- isw ^? _2 . cWorld . lWorld . walls . ix k
|
||||
return $ foldl' (flip (`damageWall` wl)) isw dams
|
||||
f (k,dams) w' = fromMaybe (mempty,w') $ do
|
||||
wl <- w' ^? cWorld . lWorld . walls . ix k
|
||||
return $ foldrM (damageWall wl) w' dams
|
||||
|
||||
updateEdgesWall :: S.Set Int2 -> World -> World
|
||||
updateEdgesWall is w =
|
||||
|
||||
Reference in New Issue
Block a user