Simplify buttons

This commit is contained in:
2025-06-25 21:37:32 +01:00
parent 6e9d4918a1
commit a9cae4d409
13 changed files with 130 additions and 140 deletions
+10 -13
View File
@@ -9,26 +9,23 @@ import Dodge.WorldEffect
doButtonEvent :: ButtonEvent -> Button -> World -> World
doButtonEvent be = case be of
ButtonDoNothing -> const id
ButtonPress newstate newevent thesound f c -> \b ->
ButtonPress True _ _ -> const id
ButtonPress False f _ -> \b ->
doWdWd f
. set (cWorld . lWorld . buttons . ix (_btID b) . btState) newstate
. set (cWorld . lWorld . buttons . ix (_btID b) . btEvent) newevent
. soundStart (LeverSound 0) (_btPos b) thesound Nothing
--ButtonSwitch onstate onevent onsound oneff offstate offevent offsound offeff -> undefined
ButtonSimpleSwith oneff offeff _ _ -> flipSwitch oneff offeff
. set (cWorld . lWorld . buttons . ix (_btID b) . btEvent . btOn) True
. soundStart (LeverSound 0) (_btPos b) click1S Nothing
ButtonSwitch oneff offeff _ _ _ -> flipSwitch oneff offeff
ButtonAccessTerminal -> accessTerminal . _btTermMID
flipSwitch :: WdWd -> WdWd -> Button -> World -> World
flipSwitch oneff offeff bt
| _btState bt == BtOff =
doWdWd oneff . dosound
. over (cWorld . lWorld . buttons . ix (_btID bt)) turnon
| otherwise =
| _btOn (_btEvent bt) =
doWdWd offeff . dosound
. over (cWorld . lWorld . buttons . ix (_btID bt)) turnoff
. set (cWorld . lWorld . buttons . ix (_btID bt) . btEvent . btOn) False
| otherwise =
doWdWd oneff . dosound
. set (cWorld . lWorld . buttons . ix (_btID bt) . btEvent . btOn) True
where
turnon = (btState .~ BtOn)
turnoff = (btState .~ BtOff)
dosound = soundWithStatus ToStart (LeverSound 0) (_btPos bt) click1S Nothing
-- switchEffect b = case _btState b of