module Dodge.Update.WallDamage where
import Dodge.Wall.Damage
import Dodge.Data

import qualified Data.IntMap.Strict as IM
import Control.Lens
import Data.Maybe

updateWallDamages :: World -> World
updateWallDamages w = w
    & wallDamages .~ IM.empty
    & flip (IM.foldrWithKey f) (_wallDamages w)
  where
    f k dams w' = fromMaybe w' $ do
        wl <- w' ^? walls . ix k
        return $ foldr (`damageWall` wl) w' dams
