Cleanup and fix selection section cursor position bug

This commit is contained in:
2023-05-19 19:29:37 +01:00
parent 03b793802f
commit 17c79e7cee
6 changed files with 35 additions and 37 deletions
+19 -17
View File
@@ -5,11 +5,9 @@ module Dodge.Reloading (
tryStartLoading,
) where
import Dodge.Data.Item.Use.Consumption.LoadAction
import Control.Lens
import Dodge.Data.Creature
import Data.Maybe
--import qualified IntMapHelp as IM
import Dodge.Data.Creature
crCancelReloading :: Creature -> Creature
crCancelReloading cr =
@@ -19,7 +17,9 @@ crCancelReloading cr =
where
updateProgress = fromMaybe id $ do
InInventory (SelItem i _) <- cr ^? crManipulation . manObject
return $ crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress %~ const Nothing
return $
crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress
%~ const Nothing
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
@@ -35,7 +35,7 @@ stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem i _) -> case cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress . _Just . ix 0 of
Just (SelItem i _) -> case cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress . _Just . ix 0 of
Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
Just la ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
@@ -50,28 +50,30 @@ crUpdateLoadSource cr = case cr ^? crManipulation . manObject . inInventory . is
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
as <- cr ^? crInv . ix i . itUse . heldConsumption . laSource
case as of
InternalSource ia -> return $ startLoading ia cr
AboveSource -> return cr
ia <- cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource
return $ startLoading ia cr
-- case as of
-- InternalSource ia -> return $ startLoading ia cr
-- AboveSource -> return cr
startLoading :: InternalAmmo -> Creature -> Creature
startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of
Just la -> cr & startLoadingStep la
Nothing -> case ic ^? iaCycle of
Nothing -> cr
Just [] -> error "item has empty load cycle"
Just _ | _iaLoaded ic >= _iaMax ic -> cr
Just (la : las) -> fromMaybe (error "item loading error") $ do
Nothing -> case ic ^. iaCycle of
[] -> error "item has empty load cycle"
_ | _iaLoaded ic >= _iaMax ic -> cr
(la : las) -> fromMaybe (error "item loading error") $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ cr & startLoadingStep la
& crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress ?~ (la : las)
return $
cr & startLoadingStep la
& crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress ?~ (la : las)
startLoadingStep :: LoadAction -> Creature -> Creature
startLoadingStep la cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la
rotateActionProgress :: InternalAmmo -> InternalAmmo
rotateActionProgress ic = case ic ^? iaProgress . _Just of
rotateActionProgress ic = case ic ^. iaProgress of
Just (_ : la : las) -> ic & iaProgress . _Just .~ (la : las)
_ | _iaLoaded ic < _iaMax ic -> ic & iaProgress ?~ _iaCycle ic
_ -> ic & iaProgress .~ Nothing