Allow pausable reloads with discrete progess steps
This commit is contained in:
@@ -5,9 +5,10 @@ import Sound.Data
|
||||
import Dodge.Item.Data
|
||||
import Control.Lens
|
||||
data LoadAction
|
||||
= Eject {_actionTime :: Int, _actionSound :: SoundID}
|
||||
| Insert {_actionTime :: Int, _actionSound :: SoundID, _insertMax :: Maybe Int }
|
||||
| Prime {_actionTime :: Int, _actionSound :: SoundID}
|
||||
= LoadEject {_actionTime :: Int, _actionSound :: SoundID}
|
||||
| LoadInsert {_actionTime :: Int, _actionSound :: SoundID}
|
||||
| LoadAdd {_actionTime :: Int, _actionSound :: SoundID, _insertMax :: Int }
|
||||
| LoadPrime {_actionTime :: Int, _actionSound :: SoundID}
|
||||
deriving (Eq,Ord,Show)
|
||||
data InvSel = InvSel {_iselPos :: Int, _iselAction :: InvSelAction }
|
||||
data InvSelAction
|
||||
|
||||
@@ -87,7 +87,7 @@ handlePressedKeyInGame scode w = case scode of
|
||||
ScancodeP -> pauseGame $ escapeMap w
|
||||
ScancodeF -> youDropItem w
|
||||
ScancodeM -> toggleMap w
|
||||
ScancodeR -> crStartReloading (you w) w
|
||||
ScancodeR -> crToggleReloading (you w) w
|
||||
ScancodeT -> testEvent w
|
||||
ScancodeX -> w & hud . hudElement %~ toggleTweakInv
|
||||
ScancodeC -> toggleCombineInv w
|
||||
|
||||
@@ -55,14 +55,14 @@ showSelectedConsumption cr ic = case ic of
|
||||
|
||||
showReloadProgress :: Creature -> ItemConsumption -> String
|
||||
showReloadProgress cr ic = case cr ^?! crInvSel . iselAction of
|
||||
ReloadAction i la _ -> show i ++ showLoadActionType la
|
||||
ReloadAction i la _ -> show i ++ showLoadActionType la (_laLoaded ic)
|
||||
_ -> case ic ^? laProgress . _Just . ix 0 of
|
||||
Nothing -> show $ _laLoaded ic
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la (_laLoaded ic)
|
||||
|
||||
showLoadProgress :: Int -> Maybe [LoadAction] -> String
|
||||
showLoadProgress x mlas = case mlas ^? _Just . ix 0 of
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la x
|
||||
Nothing -> show x
|
||||
|
||||
showConsumption :: ItemConsumption -> String
|
||||
@@ -71,11 +71,12 @@ showConsumption ic = case ic of
|
||||
am@ChargeableAmmo{} -> show $ _wpCharge am
|
||||
x@ItemItselfConsumable{} -> show (_icAmount x)
|
||||
NoConsumption -> ""
|
||||
showLoadActionType :: LoadAction -> String
|
||||
showLoadActionType la = case la of
|
||||
Eject {} -> "E"
|
||||
Insert {} -> "L"
|
||||
Prime {} -> "P"
|
||||
showLoadActionType :: LoadAction -> Int -> String
|
||||
showLoadActionType la x = case la of
|
||||
LoadEject {} -> "E"
|
||||
LoadInsert {} -> "L"
|
||||
LoadAdd {} -> "A" ++ show x
|
||||
LoadPrime {} -> "P"
|
||||
|
||||
-- & itInvDisplay .~ \it -> head (basicItemDisplay it) :
|
||||
-- ["*FIRERATE:" ++ fromMaybe "" (maybeRateStatus it)
|
||||
|
||||
@@ -149,7 +149,7 @@ repeater :: Item
|
||||
repeater = rifle
|
||||
& itType . iyModules . at ModRifleMag ?~ EMPTYMODULE
|
||||
& itType . iyBase .~ REPEATER
|
||||
& itConsumption . laCycle .~ [loadEject 5, loadInsert 15 ,loadPrime 15]
|
||||
& itConsumption . laCycle .~ [loadEject 20, loadInsert 20 ,loadPrime 20]
|
||||
& itConsumption . laMax .~ 15
|
||||
& itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape
|
||||
<> makeTinClipAt 0 (V3 10 (-2) 0) it
|
||||
|
||||
+41
-59
@@ -1,14 +1,13 @@
|
||||
module Dodge.Reloading
|
||||
( crCancelReloading
|
||||
, crStartReloading
|
||||
, crToggleReloading
|
||||
, stepReloading
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base.Arithmetic
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
import Dodge.Hammer
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
|
||||
crCancelReloading :: Creature -> Creature
|
||||
crCancelReloading cr = cr
|
||||
@@ -17,75 +16,58 @@ crCancelReloading cr = cr
|
||||
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^?! crInvSel . iselAction of
|
||||
ReloadAction _ _ (HasHammer HammerUp) -> cr & crInvSel . iselAction .~ NoInvSelAction
|
||||
ReloadAction x la _
|
||||
| x > 0 -> cr & crInvSel . iselAction . actionProgress -~ 1
|
||||
| otherwise -> cr & completeLoadAction la
|
||||
& crInvSel . iselAction . actionHammer . hammerPosition %~ moveHammerUp
|
||||
| otherwise -> cr
|
||||
& crInvSel . iselAction . actionHammer . hammerPosition %~ moveHammerUp
|
||||
& crInv . ix (crSel cr) . itConsumption %~ doLoadAction la
|
||||
& crInv . ix (crSel cr) . itConsumption %~ rotateActionProgress
|
||||
& tryNextLoadAction
|
||||
_ -> cr
|
||||
|
||||
crStartReloading :: Creature -> World -> World
|
||||
crStartReloading cr w = fromMaybe w $ w
|
||||
& creatures . ix (_crID cr) %%~ tryStartLoading
|
||||
tryNextLoadAction :: Creature -> Creature
|
||||
tryNextLoadAction cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just . ix 0 of
|
||||
Nothing -> cr & crInvSel . iselAction .~ NoInvSelAction
|
||||
Just la -> cr & crInvSel . iselAction . actionProgress .~ _actionTime la
|
||||
& crInvSel . iselAction . reloadAction .~ la
|
||||
|
||||
tryStartLoading :: Creature -> Maybe Creature
|
||||
tryStartLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress of
|
||||
Just Nothing -> Just . startLoadAction $ cr
|
||||
& crInv . ix (crSel cr) . itConsumption %~ setLoadCycle
|
||||
Just (Just (a:_)) -> Just . startNextLoadAction a $ cr
|
||||
Just (Just []) -> Nothing
|
||||
_ -> Nothing
|
||||
-- Just (Just _) -> Just . continueLoading $ cr
|
||||
-- Nothing -> Nothing
|
||||
|
||||
startLoadAction :: Creature -> Creature
|
||||
startLoadAction cr = continueLoading $ cr
|
||||
& crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer
|
||||
crToggleReloading :: Creature -> World -> World
|
||||
crToggleReloading cr w = case cr ^?! crInvSel . iselAction of
|
||||
ReloadAction {} -> w & creatures . ix (_crID cr) . crInvSel . iselAction .~ NoInvSelAction
|
||||
_ -> w & creatures . ix (_crID cr) %~ tryStartLoading
|
||||
|
||||
tryStartLoading :: Creature -> Creature
|
||||
tryStartLoading cr = case ic ^? laProgress . _Just . ix 0 of
|
||||
Just la -> cr & startLoadAction la
|
||||
Nothing -> case ic ^? laCycle of
|
||||
Nothing -> cr
|
||||
Just [] -> error ("item has empty load cycle" ++ show (cr ^?! crInv . ix (crSel cr) . itType))
|
||||
Just (la:las) -> cr & startLoadAction la
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress ?~ (la:las)
|
||||
where
|
||||
la = cr ^?! crInv . ix (crSel cr) . itConsumption . laProgress . _Just . ix 0
|
||||
ic = cr ^?! crInv . ix (crSel cr) . itConsumption
|
||||
|
||||
setLoadCycle :: ItemConsumption -> ItemConsumption
|
||||
setLoadCycle ic = ic & laProgress ?~ _laCycle ic
|
||||
startLoadAction :: LoadAction -> Creature -> Creature
|
||||
startLoadAction la cr = cr & crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer
|
||||
|
||||
startNextLoadAction :: LoadAction -> Creature -> Creature
|
||||
startNextLoadAction la cr = cr
|
||||
& crInvSel . iselAction .~ ReloadAction (_actionTime la) la NoHammer
|
||||
|
||||
continueLoading :: Creature -> Creature
|
||||
continueLoading cr = case cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just of
|
||||
Just (la:_) -> cr & crInvSel . iselAction . reloadAction .~ la
|
||||
& crInvSel . iselAction . actionProgress .~ _actionTime la
|
||||
Just [] -> case cr ^?! crInv . ix (crSel cr) . itConsumption of
|
||||
ic | _laLoaded ic < _laMax ic -> continueLoading $ cr
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress ?~ _laCycle ic
|
||||
_ -> cr & crInvSel . iselAction .~ NoInvSelAction
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress .~ Nothing
|
||||
_ -> cr & crInvSel . iselAction .~ NoInvSelAction
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress .~ Nothing
|
||||
|
||||
completeLoadAction :: LoadAction -> Creature -> Creature
|
||||
completeLoadAction la cr = continueLoading $ cr
|
||||
& crInv . ix (crSel cr) . itConsumption . laProgress . _Just %~ tail
|
||||
& crInv . ix (crSel cr) . itConsumption %~ doLoadAction la
|
||||
rotateActionProgress :: ItemConsumption -> ItemConsumption
|
||||
rotateActionProgress ic = case ic ^? laProgress . _Just of
|
||||
Just (_:la:las) -> ic & laProgress . _Just .~ (la:las)
|
||||
_ | _laLoaded ic < _laMax ic -> ic & laProgress ?~ _laCycle ic
|
||||
_ -> ic & laProgress .~ Nothing
|
||||
|
||||
|
||||
-- Just LoadFinished
|
||||
-- | _laLoaded ic >= _laMax ic -> Nothing
|
||||
-- | otherwise -> Just $ ic & laProgress
|
||||
-- .~ LoadUnderway (_actionTime (head (_laCycle ic))) (_laCycle ic)
|
||||
-- Just (LoadUnderway _ []) -> Just $ ic & laProgress .~ LoadFinished
|
||||
-- Just (LoadUnderway t (a:_))
|
||||
-- | t > 0 -> Just $ ic & laProgress . actionProgress -~ 1
|
||||
-- | otherwise -> Just $ ic & doLoadAction a
|
||||
-- & laProgress . futureActions %~ tail
|
||||
-- & laProgress . actionProgress .~ _actionTime a
|
||||
-- Just (LoadPaused (a:as)) -> Just $ ic & laProgress .~ LoadUnderway (_actionTime a) (a:as)
|
||||
-- Just (LoadPaused []) -> Just $ ic & laProgress .~ LoadFinished
|
||||
-- Nothing -> Nothing
|
||||
|
||||
doLoadAction :: LoadAction -> ItemConsumption -> ItemConsumption
|
||||
doLoadAction la ic = case la of
|
||||
Eject {} -> ic & laLoaded .~ 0
|
||||
Insert {_insertMax = mx} -> ic & laLoaded +~ maybe id min mx (_laMax ic - _laLoaded ic)
|
||||
Prime {} -> ic
|
||||
LoadEject {} -> ic & laLoaded .~ 0
|
||||
LoadInsert {} -> ic & laLoaded .~ _laMax ic
|
||||
LoadAdd {_insertMax = x}
|
||||
-> ic & laLoaded +~ min x (_laMax ic - _laLoaded ic)
|
||||
LoadPrime {} -> ic
|
||||
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
|
||||
@@ -3,13 +3,13 @@ import Dodge.SoundLogic.ExternallyGeneratedSounds
|
||||
import Dodge.Data.LoadAction
|
||||
|
||||
loadInsert :: Int -> LoadAction
|
||||
loadInsert x = Insert x insertS Nothing
|
||||
loadInsert x = LoadInsert x insertS
|
||||
|
||||
loadPartialInsert :: Int -> Int -> LoadAction
|
||||
loadPartialInsert x y = Insert x insertOneS (Just y)
|
||||
loadPartialInsert x y = LoadAdd x insertOneS y
|
||||
|
||||
loadEject :: Int -> LoadAction
|
||||
loadEject x = Eject x ejectS
|
||||
loadEject x = LoadEject x ejectS
|
||||
|
||||
loadPrime :: Int -> LoadAction
|
||||
loadPrime x = Prime x primeS
|
||||
loadPrime x = LoadPrime x primeS
|
||||
|
||||
Reference in New Issue
Block a user