This commit is contained in:
2024-12-19 22:10:18 +00:00
parent 3da9490dd4
commit 2b5a81fd11
5 changed files with 81 additions and 94 deletions
+11 -11
View File
@@ -2,10 +2,6 @@ module Dodge.Creature.YourControl (
yourControl, yourControl,
) where ) where
import Dodge.Data.ComposedItem
import Dodge.HeldUse
import Dodge.Data.DoubleTree
import Dodge.Item.Grammar
import Control.Monad import Control.Monad
import Data.Foldable import Data.Foldable
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
@@ -13,9 +9,13 @@ import Data.Maybe
import Dodge.Base.Coordinate import Dodge.Base.Coordinate
import Dodge.Creature.Impulse.Movement import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Impulse.UseItem import Dodge.Creature.Impulse.UseItem
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.World import Dodge.Data.World
import Dodge.HeldUse
import Dodge.Hotkey import Dodge.Hotkey
import Dodge.InputFocus import Dodge.InputFocus
import Dodge.Item.Grammar
import Dodge.WASD import Dodge.WASD
import Geometry import Geometry
import LensHelp import LensHelp
@@ -43,16 +43,15 @@ yourControl _ w
handleHotkeys :: World -> World handleHotkeys :: World -> World
handleHotkeys w handleHotkeys w
-- | SDL.ButtonRight `M.member` _mouseButtons (_input w)
| SDL.ScancodeLShift `M.member` _pressedKeys (_input w) | SDL.ScancodeLShift `M.member` _pressedKeys (_input w)
|| SDL.ScancodeRShift `M.member` _pressedKeys (_input w) || SDL.ScancodeRShift `M.member` _pressedKeys (_input w) =
= foldl' tryAssignHotkey w allHotkeys foldl' tryAssignHotkey w allHotkeys
| otherwise = foldl' useHotKey w (M.intersection thehotkeys (w ^. input . pressedKeys)) | otherwise = foldl' useHotkey w (M.intersection thehotkeys (w ^. input . pressedKeys))
where where
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
useHotKey :: World -> Int -> World useHotkey :: World -> Int -> World
useHotKey w invid = fromMaybe w $ do useHotkey w invid = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT itmloc <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT
return $ heldEffectNoHammerCheck (bimap (^. iatType) (^. _1) itmloc) cr w return $ heldEffectNoHammerCheck (bimap (^. iatType) (^. _1) itmloc) cr w
@@ -132,7 +131,8 @@ wasdTwist cr
(TwoHandOver, 0) -> (TwoHandOver, 0) ->
return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
_ -> Nothing _ -> Nothing
| otherwise = cr | otherwise =
cr
& crDir +~ _crTwist cr & crDir +~ _crTwist cr
& crTwist .~ 0 --remove twistk & crTwist .~ 0 --remove twistk
where where
+15 -7
View File
@@ -1,14 +1,15 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
--{-# LANGUAGE StrictData #-} --{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.DoubleTree
where module Dodge.Data.DoubleTree where
import Control.Lens import Control.Lens
import Data.Aeson import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
import Data.Bifunctor import Data.Bifunctor
--import qualified Data.Map.Strict as M --import qualified Data.Map.Strict as M
data DoubleTreeNodeType data DoubleTreeNodeType
@@ -36,12 +37,16 @@ data DoubleTree a = DT {_dtValue :: a,_dtLeft :: [DoubleTree a],_dtRight :: [Dou
-- ,_fldtID :: Int -- ,_fldtID :: Int
-- ,_fldtChildren = -- ,_fldtChildren =
data LabelDoubleTree b a = LDT {_ldtValue :: a, _ldtLeft :: [(b,LabelDoubleTree b a)] data LabelDoubleTree b a = LDT
,_ldtRight :: [(b,LabelDoubleTree b a)]} { _ldtValue :: a
, _ldtLeft :: [(b, LabelDoubleTree b a)]
, _ldtRight :: [(b, LabelDoubleTree b a)]
}
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
-- I am not sure about the double use of records here -- I am not sure about the double use of records here
data ContextLDT b a = TopLDT data ContextLDT b a
= TopLDT
| LeftwardLDT | LeftwardLDT
{ _cldtUp :: ContextLDT b a { _cldtUp :: ContextLDT b a
, _cldtCloseLeft :: [(b, LabelDoubleTree b a)] , _cldtCloseLeft :: [(b, LabelDoubleTree b a)]
@@ -75,7 +80,10 @@ instance Functor (LabelDoubleTree b) where
instance Bifunctor LabelDoubleTree where instance Bifunctor LabelDoubleTree where
second = fmap second = fmap
first f (LDT x l r) = LDT x (map (bimap f (first f)) l) first f (LDT x l r) =
LDT
x
(map (bimap f (first f)) l)
(map (bimap f (first f)) r) (map (bimap f (first f)) r)
makeLenses ''DoubleTree makeLenses ''DoubleTree
+38
View File
@@ -7,6 +7,7 @@ module Dodge.HeldUse (
mcUseHeld, mcUseHeld,
) where ) where
import NewInt
import Dodge.Luse import Dodge.Luse
import Dodge.Creature.Action.Blink import Dodge.Creature.Action.Blink
import Dodge.RadarSweep import Dodge.RadarSweep
@@ -565,3 +566,40 @@ createProjectile magtree muz itmtree cr = fromMaybe failsound $ do
-- ps' = replicateM 4 randOnUnitSphere & evalState $ _randGen w -- ps' = replicateM 4 randOnUnitSphere & evalState $ _randGen w
-- pos = addZ 10 $ _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm) -- pos = addZ 10 $ _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
---- , withSmoke 1 black 20 200 5 ---- , withSmoke 1 black 20 200 5
useStopWatch :: Item -> Creature -> World -> World
useStopWatch itm _ =
timeFlow
.~ PausedTimeFlow
{ _timeFlowCharge = 100
, _scrollItemID = _itID itm
}
useTimeScrollGun :: Item -> Creature -> World -> World
useTimeScrollGun itm _ =
timeFlow
.~ ItemScrollTimeFlow
{ _scrollSmoothing = 0
--, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
, _reverseAmount = 100
, _futureWorlds = []
, _scrollItemID = _itID itm
}
useRewindGun :: NewInt ItmInt -> World -> World
useRewindGun i =
timeFlow
.~ RewindLeftClick
-- { _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
{ _reverseAmount = 100
, _scrollItemID = i
}
--useRewindGun _ _ w = case w ^. cwTime . rewindWorlds of
-- [w'] -> w & cwTime . maybeWorld .~ Just' w'
-- (w' : ws) -> w
-- & cwTime . maybeWorld
-- .~ Just' w'
-- & cwTime . rewindWorlds .~ ws
-- _ -> w
-3
View File
@@ -9,9 +9,6 @@ import Dodge.Euse
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
doInvEffect iie = case iie of doInvEffect iie = case iie of
NoInvEffect -> const $ const id NoInvEffect -> const $ const id
-- ChargeIfEquipped -> chargeIfEquipped
-- ChargeIfInInventory -> chargeIfInInventory
-- SetCharge i -> setItemCharge i
EffectRootNotroot f g -> rootNotrootEff f g EffectRootNotroot f g -> rootNotrootEff f g
CreateShieldWall -> createShieldWall CreateShieldWall -> createShieldWall
RemoveShieldWall -> removeShieldWall RemoveShieldWall -> removeShieldWall
-56
View File
@@ -1,56 +0,0 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Luse (
-- useL,
useRewindGun,
useStopWatch,
useTimeScrollGun
) where
import NewInt
import Dodge.Data.World
--import Dodge.Item.Weapon.TriggerType
import LensHelp
--useL :: Luse -> Item -> Creature -> World -> World
--useL = \case
-- LDoNothing -> const $ const id
-- LRewind -> useRewindGun
-- LTimePause -> hammerCheckL useStopWatch
-- LTimeScroll -> hammerCheckL useTimeScrollGun
useStopWatch :: Item -> Creature -> World -> World
useStopWatch itm _ =
timeFlow
.~ PausedTimeFlow
{ _timeFlowCharge = 100
, _scrollItemID = _itID itm
}
useTimeScrollGun :: Item -> Creature -> World -> World
useTimeScrollGun itm _ =
timeFlow
.~ ItemScrollTimeFlow
{ _scrollSmoothing = 0
--, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
, _reverseAmount = 100
, _futureWorlds = []
, _scrollItemID = _itID itm
}
useRewindGun :: NewInt ItmInt -> World -> World
useRewindGun i =
timeFlow
.~ RewindLeftClick
-- { _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
{ _reverseAmount = 100
, _scrollItemID = i
}
--useRewindGun _ _ w = case w ^. cwTime . rewindWorlds of
-- [w'] -> w & cwTime . maybeWorld .~ Just' w'
-- (w' : ws) -> w
-- & cwTime . maybeWorld
-- .~ Just' w'
-- & cwTime . rewindWorlds .~ ws
-- _ -> w