Move machine destruction to external function

This commit is contained in:
2022-07-14 12:48:52 +01:00
parent 79791d0df2
commit f05d284312
7 changed files with 57 additions and 23 deletions
+27
View File
@@ -0,0 +1,27 @@
module Dodge.Machine.Destroy where
import Dodge.Wall.Delete
import Dodge.Data
import Dodge.WorldEvent.Explosion
import LensHelp
import Data.Maybe
import qualified Data.IntMap.Strict as IM
destroyMachine :: Machine -> World -> World
destroyMachine mc = (machines %~ IM.delete (_mcID mc))
. deleteWallIDs (_mcWallIDs mc)
. makeExplosionAt (_mcPos mc)
. mcKillTerm mc
. mcKillBut mc
mcKillTerm :: Machine -> World -> World
mcKillTerm mc w = fromMaybe w $ do
tmid <- mc ^? mcMounts . ix ObTerminal
tm <- w ^? terminals . ix tmid
return $ w
& _tmDeathEffect tm tm
mcKillBut :: Machine -> World -> World
mcKillBut mc w = fromMaybe w $ do
btid <- mc ^? mcMounts . ix ObButton
return $ w & buttons . at btid .~ Nothing