Generalise weapon character modes
This commit is contained in:
@@ -1,2 +1,42 @@
|
||||
module Dodge.Item.Attachment
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Item.Attachment.Data
|
||||
|
||||
import Control.Lens hiding ((|>),(<|))
|
||||
import Data.Sequence
|
||||
import Data.Maybe (fromJust)
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
|
||||
incCharMode' :: ItAttachment -> ItAttachment
|
||||
incCharMode' = itCharMode %~ cycleL
|
||||
where
|
||||
cycleL (x :<| xs) = xs |> x
|
||||
cycleL xs = xs
|
||||
decCharMode' :: ItAttachment -> ItAttachment
|
||||
decCharMode' = itCharMode %~ cycleR
|
||||
where
|
||||
cycleR (xs :|> x) = x <| xs
|
||||
cycleR xs = xs
|
||||
|
||||
incCharMode
|
||||
:: Int -- ^ Inventory selection
|
||||
-> World
|
||||
-> World
|
||||
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ incCharMode'
|
||||
decCharMode
|
||||
:: Int -- ^ Inventory selection
|
||||
-> World
|
||||
-> World
|
||||
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ decCharMode'
|
||||
|
||||
charFiringStrat
|
||||
:: [(Char, Int -> World -> World)] -- ^ Different firing effects for different characters
|
||||
-> Int -- ^ Creature id
|
||||
-> World
|
||||
-> World
|
||||
charFiringStrat strats cid w =
|
||||
let Just (c :<| _) = w ^? creatures . ix cid . crInv
|
||||
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment
|
||||
. _Just . itCharMode
|
||||
in fromJust (Prelude.lookup c strats) cid w
|
||||
|
||||
Reference in New Issue
Block a user