diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index 4584f6a39..cbd2495c2 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -7,6 +7,8 @@ import Dodge.Inventory import Dodge.Reloading import qualified Data.IntMap.Strict as IM +import qualified Data.Map.Strict as M +import qualified SDL --import qualified Data.IntSet as IS import Control.Lens import Data.Maybe @@ -22,7 +24,7 @@ useItem cr' w = fromMaybe (f w) $ do itemEffect :: Creature -> Item -> World -> World itemEffect cr it w = case it ^? itUse of Just RightUse {_rUse = eff,_useMods = usemods} - -> hammerTest $ foldr ($) eff usemods it cr + -> hammerTest $ tryClickReload cr it w $ foldr ($) eff usemods it cr Just LeftUse {} -> doequipmentchange Just EquipUse{} -> doequipmentchange -- ConsumeUse will cause problems if the item is not selected @@ -37,6 +39,17 @@ itemEffect cr it w = case it ^? itUse of doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr . activateEquipmentAt (_rbOptions w) cr) +tryClickReload :: Creature -> Item -> World -> (World -> World) -> World -> World +tryClickReload cr it w f + | _crID cr == _yourID w && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False + = crToggleReloading cr + | otherwise = f + +itNeedsLoading :: Item -> Bool +itNeedsLoading it = _laLoaded ic == 0 || not (_laPrimed ic) + where + ic = _itConsumption it + activateEquipmentAt :: RightButtonOptions -> Creature -> World -> World activateEquipmentAt rbo cr = creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of (Just i,_) -> crLeftInvSel ?~ i diff --git a/src/Dodge/Event.hs b/src/Dodge/Event.hs index 5ba985f19..4edb8dbd8 100644 --- a/src/Dodge/Event.hs +++ b/src/Dodge/Event.hs @@ -68,11 +68,9 @@ handleMouseMotionEvent mmev u = Just $ u & uvWorld . mousePos .~ V2 handleMouseButtonEvent :: MouseButtonEventData -> World -> World handleMouseButtonEvent mbev = case mouseButtonEventMotion mbev of Released -> mouseButtons . at thebutton .~ Nothing - Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton %~ f) + Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton ?~ False) where thebutton = mouseButtonEventButton mbev - f Nothing = Just False - f _ = Just True {- | Sets window position in config. -} handleWindowMoveEvent :: WindowMovedEventData -> Universe -> Maybe Universe diff --git a/src/Dodge/Initialisation.hs b/src/Dodge/Initialisation.hs index 705f942d2..0add8af5e 100644 --- a/src/Dodge/Initialisation.hs +++ b/src/Dodge/Initialisation.hs @@ -41,12 +41,5 @@ initialWorld = defaultWorld } testStringInit :: World -> [String] -testStringInit = const [] -- map (show . _mcTermMID) . IM.elems . _machines ---testStringInit w = [show $ _cameraZoom w] ---testStringInit = (:[]) . show . _testFloat ---testStringInit = map (concatMap $ \(_,ct,_,_) -> show ct) . invertListInvMult . yourInv ---testStringInit w = fmap (show . _crHammerPosition) . IM.elems $ _creatures w --- w = [show $ f $ _roomClipping w] --- where --- f (x:xs) = any (convexPolysOverlap x) xs || f xs --- f [] = False +testStringInit = map show . M.toList . _mouseButtons +--testStringInit = const [] diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 64f674e92..5f9bff37c 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -133,7 +133,7 @@ ammoCheckI eff item cr w -- hammer is down? ammoHammerCheck :: ChainEffect ammoHammerCheck eff it cr w - | _laLoaded ic <= 0 || _laPrimed ic == False = w -- fromMaybe w (startReloadingWeapon cr w) + | _laLoaded ic <= 0 || not (_laPrimed ic) = w -- fromMaybe w (startReloadingWeapon cr w) & setHammerDown | otherwise = case it ^? itUse . useHammer . hammerPosition of Just HammerUp -> eff it cr $ setHammerDown w & creatures . ix (_crID cr) %~ crCancelReloading diff --git a/src/Dodge/Reloading/Action.hs b/src/Dodge/Reloading/Action.hs index 27cf8aae3..92a820803 100644 --- a/src/Dodge/Reloading/Action.hs +++ b/src/Dodge/Reloading/Action.hs @@ -6,7 +6,7 @@ loadInsert :: Int -> LoadAction loadInsert x = LoadInsert x insertS loadPartialInsert :: Int -> Int -> LoadAction -loadPartialInsert x y = LoadAdd x insertOneS y +loadPartialInsert x = LoadAdd x insertOneS loadEject :: Int -> LoadAction loadEject x = LoadEject x ejectS diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 40a41a1bf..ea740a88e 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -53,6 +53,7 @@ updateUniverse u = case _menuLayers u of functionalUpdate :: Configuration -> World -> World functionalUpdate cfig w = checkEndGame -- . updateRandGen + . (mouseButtons . each .~ True) . (worldClock +~ 1) . doRewind . (doubleMouseHammer %~ moveHammerUp)