34 lines
992 B
Haskell
34 lines
992 B
Haskell
module Dodge.HeldScroll (
|
|
doHeldScroll,
|
|
) where
|
|
|
|
--import Dodge.Base.You
|
|
import Control.Lens hiding ((<|), (|>))
|
|
import Data.Sequence
|
|
import Dodge.Data.Creature
|
|
import Dodge.Data.World
|
|
import Data.Maybe
|
|
--import LensHelp hiding ((|>), (<|))
|
|
-- should be able to just import data.item
|
|
|
|
doHeldScroll :: HeldScroll -> Float -> Creature -> World -> World
|
|
doHeldScroll hs = case hs of
|
|
HeldScrollDoNothing -> const . const id
|
|
HeldScrollZoom -> const . const id
|
|
HeldScrollCharMode{} -> overYourItem $ \x _ -> itUse . heldScroll . hsCharMode %~ cycleSignum x
|
|
where
|
|
overYourItem f x cr w = fromMaybe w $ do
|
|
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
|
return $ w & cWorld . lWorld . creatures . ix 0 . crInv . ix i %~ f x cr
|
|
|
|
cycleSignum :: Float -> Seq a -> Seq a
|
|
cycleSignum x
|
|
| x > 0 = cycleL
|
|
| otherwise = cycleR
|
|
|
|
cycleL, cycleR :: Seq a -> Seq a
|
|
cycleL (x :<| xs) = xs |> x
|
|
cycleL xs = xs
|
|
cycleR (xs :|> x) = x <| xs
|
|
cycleR xs = xs
|