Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+22 -17
View File
@@ -1,37 +1,42 @@
{- | Controls a walls response to external damage.
- Indestructible walls may still produce sparks, dust etc
-}
module Dodge.Wall.Damage
( damageBlocksBy
, damageWall
) where
import Dodge.Data
-}
module Dodge.Wall.Damage (
damageBlocksBy,
damageWall,
) where
import Dodge.Block
import LensHelp
import Dodge.Data.World
import Dodge.Wall.DamageEffect
import LensHelp
damageWall :: Damage -> Wall -> World -> World
damageWall dt wl w = case _wlStructure wl of
MachinePart mcid -> fst . defaultWallDamage dt wl $ w
& cWorld . machines . ix mcid . mcDamage .:~ dt
BlockPart blid -> let (w',x) = defaultWallDamage dt wl w
in w' & cWorld . blocks . ix blid . blHP -~ x & maybeDestroyBlock blid
DoorPart drid -> let (w',x) = defaultWallDamage dt wl w
in w' & cWorld . doors . ix drid . drHP -~ x & maybeDestroyDoor drid
_ -> fst $ defaultWallDamage dt wl w
MachinePart mcid ->
fst . defaultWallDamage dt wl $
w
& cWorld . machines . ix mcid . mcDamage .:~ dt
BlockPart blid ->
let (w', x) = defaultWallDamage dt wl w
in w' & cWorld . blocks . ix blid . blHP -~ x & maybeDestroyBlock blid
DoorPart drid ->
let (w', x) = defaultWallDamage dt wl w
in w' & cWorld . doors . ix drid . drHP -~ x & maybeDestroyDoor drid
_ -> fst $ defaultWallDamage dt wl w
-- block destruction is convoluted...
maybeDestroyBlock :: Int -> World -> World
maybeDestroyBlock blid w = case w ^? cWorld . blocks . ix blid of
Just bl | _blHP bl < 1 -> destroyBlock bl w
Just bl | _blHP bl < 1 -> destroyBlock bl w
_ -> w
maybeDestroyDoor :: Int -> World -> World
maybeDestroyDoor drid w = case w ^? cWorld . doors . ix drid of
Just dr | _drHP dr < 1 -> destroyDoor dr w
Just dr | _drHP dr < 1 -> destroyDoor dr w
_ -> w
damageBlocksBy :: Int -> Wall -> World -> World
damageBlocksBy x wl = case wl ^? wlStructure . wsBlock of
Just blid -> cWorld . blocks . ix blid . blHP -~ x
Nothing -> id
Nothing -> id