Move machine destruction to external function
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user