30 lines
1.2 KiB
Haskell
30 lines
1.2 KiB
Haskell
module Dodge.SelectUse (selectUse) where
|
|
|
|
import Control.Monad
|
|
import qualified SDL
|
|
import Control.Lens
|
|
import Data.Maybe
|
|
import Dodge.Data.World
|
|
import Dodge.Payload
|
|
|
|
-- this could just set the timer to 0?
|
|
selectUse :: Item -> Creature -> World -> World
|
|
selectUse itm _ w = fromMaybe w $ do
|
|
lbtime <- w ^? input . mouseButtons . ix SDL.ButtonLeft
|
|
guard $ lbtime == 0
|
|
itid <- itm ^? itID
|
|
pjid <- itm ^? itUse . uaParams . apLinkedProjectile . _Just
|
|
thepj <- w ^? cWorld . lWorld . projectiles . ix pjid
|
|
topupdate <- thepj ^? prjUpdates . ix 0
|
|
guard $ notdestroyed topupdate -- this assumes that "destroyed" projectiles always have the same type of update at the top
|
|
return $
|
|
w
|
|
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU (Just itid) 30] -- 69 is placeholder, should be removed
|
|
& cWorld . lWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
|
-- & itPoint . itUse . heldUse .~ HeldDoNothing
|
|
-- & itPoint . itUse . heldMods .~ DoNothingMod
|
|
& usePayload (_prjPayload thepj) (_prjPos thepj) (_prjVel thepj)
|
|
where
|
|
notdestroyed DestroyPU{} = False
|
|
notdestroyed _ = True
|