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
+3 -3
View File
@@ -10,13 +10,13 @@ import Control.Lens
drawButton :: Button -> SPic
drawButton bt = case bt ^. btEvent of
ButtonPress {_bpColor = col} -> defaultDrawButton col bt
ButtonSimpleSwith {_bssColor1 = col1, _bssColor2 = col2} -> drawSwitch col1 col2 bt
ButtonSwitch {_bsColor1 = col1, _bsColor2 = col2} -> drawSwitch col1 col2 bt
ButtonAccessTerminal -> mempty
ButtonDoNothing -> mempty
drawSwitch :: Color -> Color -> Button -> SPic
drawSwitch col1 col2 bt
| _btState bt == BtOff = flick $ pi / 4
| bt ^? btEvent . btOn == Just False = flick $ pi / 4
| otherwise = flick (negate (pi / 4))
where
flick a = noPic
@@ -33,6 +33,6 @@ defaultDrawButton col bt = noPic
)
where
buttonGeometry
| _btState bt == BtOff = rectNSWE 10 (-1) (- width) width
| bt ^? btEvent . btOn == Just False = rectNSWE 10 (-1) (- width) width
| otherwise = rectNSWE 2 (-1) (- width) width
width = 8
+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