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
+2 -11
View File
@@ -13,7 +13,6 @@ import Dodge.Default
import Dodge.Machine
import Dodge.SoundLogic
import Dodge.Terminal
import Dodge.WorldEvent.Explosion
import Color
import Geometry
import ShapePicture
@@ -33,27 +32,20 @@ putTerminal'' mc tm mcf = ps0PushPS (PutTerminal tm)
$ \tmpl -> Just $ ps0PushPS (PutButton termButton)
$ \btpl -> Just $ pt0 (PutMachine (reverse $ square 10)
(mc & mcUpdate %~ (\fmu mc' -> mcf (fromJust $ _plMID btpl) mc' . fmu mc') . machineAddSound fridgeHumS
& mcDeath %~ (\fd mc' -> mcKillTerm mc' . (buttons . at (fromJust (_plMID btpl)) .~ Nothing) . fd mc')
& mcMounts . at ObButton ?~ fromJust (_plMID btpl)
) )
$ \mcpl -> Just $ sps0 $ PutWorldUpdate $ const (setids tmpl btpl mcpl)
where
setids tmpl btpl mcpl w = w
& terminals . ix tmid . tmButtonID .~ btid
& terminals . ix tmid . tmMachineID .~ mcid
& machines . ix mcid . mcTermMID ?~ tmid
& machines . ix mcid . mcMounts . at ObTerminal ?~ tmid
& buttons . ix btid . btTermMID ?~ tmid
where
tmid = fromJust (_plMID tmpl)
btid = fromJust (_plMID btpl)
mcid = fromJust (_plMID mcpl)
mcKillTerm :: Machine -> World -> World
mcKillTerm mc w = fromMaybe w $ do
tmid <- _mcTermMID mc
tm <- w ^? terminals . ix tmid
return $ w
& _tmDeathEffect tm tm
putTerminal'
:: Color
-> Terminal
@@ -72,7 +64,6 @@ putTerminal col f = putTerminal'' (mc & mcColor .~ col) f (\_ -> basicMachineUpd
mc = defaultMachine
{ _mcDraw = terminalSPic
, _mcHP = 100
, _mcDeath = makeExplosionAt . _mcPos
}
termButton :: Button