Remove yourID -- you are simply at 0

This commit is contained in:
2022-10-28 21:26:14 +01:00
parent 32744d7cb3
commit d496c4c523
8 changed files with 18 additions and 24 deletions
+1 -2
View File
@@ -5,8 +5,7 @@ import qualified IntMapHelp as IM
import Control.Lens import Control.Lens
you :: World -> Creature you :: World -> Creature
--you w = _creatures (_cWorld w) IM.! _yourID (_cWorld w) you w = w ^?! cWorld . lWorld . creatures . ix 0
you w = w ^?! cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID)
yourItem :: World -> Maybe Item yourItem :: World -> Maybe Item
yourItem w = _crInv (you w) IM.!? crSel (you w) yourItem w = _crInv (you w) IM.!? crSel (you w)
+1 -1
View File
@@ -51,7 +51,7 @@ itemEffect cr it w = case it ^. itUse of
tryReload :: Creature -> Item -> World -> (World -> World) -> World -> World tryReload :: Creature -> Item -> World -> (World -> World) -> World -> World
tryReload cr it w f tryReload cr it w f
| _crID cr == (w ^. cWorld . lWorld . yourID) && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False = | _crID cr == 0 && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False =
crToggleReloading cr crToggleReloading cr
| otherwise = | otherwise =
(runIdentity . pointerToItemLocation (_itLocation it) (return . (itUse . heldHammer .~ HammerDown))) (runIdentity . pointerToItemLocation (_itLocation it) (return . (itUse . heldHammer .~ HammerDown)))
-1
View File
@@ -141,7 +141,6 @@ data LWorld = LWorld
, _floorItems :: IM.IntMap FloorItem , _floorItems :: IM.IntMap FloorItem
, _floorTiles :: [(Point3, Point3)] , _floorTiles :: [(Point3, Point3)]
, _modifications :: IM.IntMap Modification , _modifications :: IM.IntMap Modification
, _yourID :: Int
, _worldEvents :: [WdWd] , _worldEvents :: [WdWd]
, _delayedEvents :: [(Int, WdWd)] , _delayedEvents :: [(Int, WdWd)]
, _pressPlates :: IM.IntMap PressPlate , _pressPlates :: IM.IntMap PressPlate
-1
View File
@@ -111,7 +111,6 @@ defaultLWorld =
, _wlZoning = IM.empty --Zoning IM.empty wlZoneSize zoneOfWall , _wlZoning = IM.empty --Zoning IM.empty wlZoneSize zoneOfWall
, _floorItems = IM.empty , _floorItems = IM.empty
, _floorTiles = [] , _floorTiles = []
, _yourID = 0
, _worldEvents = [] , _worldEvents = []
, _delayedEvents = [] , _delayedEvents = []
, _pressPlates = IM.empty , _pressPlates = IM.empty
+10 -12
View File
@@ -169,7 +169,7 @@ updateCloseObjects :: World -> World
updateCloseObjects w = updateCloseObjects w =
w w
& cWorld . lWorld . closeObjects .~ unionBy closeObjEq oldCloseFiltered currentClose & cWorld . lWorld . closeObjects .~ unionBy closeObjEq oldCloseFiltered currentClose
& cWorld . lWorld . creatures . ix (_yourID (_lWorld (_cWorld w))) . crInvSel . iselPos %~ updateinvsel & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ updateinvsel
where where
updateinvsel curinvsel updateinvsel curinvsel
| length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1 | length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1
@@ -319,16 +319,16 @@ changeInvSel i w
| n == 0 = w | n == 0 = w
| yourInvSel w < n = | yourInvSel w < n =
w w
& cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvSel . iselPos %~ (`mod` n) . subtract i & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
& cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvSel . iselAction .~ NoInvSelAction & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
| otherwise = | otherwise =
w w
& cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvSel . iselPos %~ ((+ n) . (`mod` numCO) . subtract (i + n)) & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ ((+ n) . (`mod` numCO) . subtract (i + n))
& cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvSel . iselAction .~ NoInvSelAction & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
where where
-- arguably this should jump the invpos into the inventory proper -- arguably this should jump the invpos into the inventory proper
n = length $ _crInv $ _creatures (_lWorld (_cWorld w)) IM.! _yourID (_lWorld (_cWorld w)) n = length $ w ^?! cWorld . lWorld . creatures . ix 0 . crInv
numCO = length $ w ^. cWorld . lWorld . closeObjects numCO = length $ w ^. cWorld . lWorld . closeObjects
changeSwapInvSel :: Int -> World -> World changeSwapInvSel :: Int -> World -> World
@@ -336,13 +336,12 @@ changeSwapInvSel k w
| n == 0 = w | n == 0 = w
| yourInvSel w < n = | yourInvSel w < n =
w w
& cWorld . lWorld . creatures . ix yid %~ updatecreature & cWorld . lWorld . creatures . ix 0 %~ updatecreature
| otherwise = | otherwise =
w w
& cWorld . lWorld . creatures . ix yid . crInvSel . iselPos .~ ico' & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos .~ ico'
& cWorld . lWorld . closeObjects %~ swapIndices (i - n) (ico' - n) & cWorld . lWorld . closeObjects %~ swapIndices (i - n) (ico' - n)
where where
yid = w ^. cWorld . lWorld . yourID
updatecreature = updatecreature =
(crInv %~ IM.safeSwapKeys (i `mod` n) swapi) (crInv %~ IM.safeSwapKeys (i `mod` n) swapi)
. (crLeftInvSel . _Just %~ updateLeftInvSel) . (crLeftInvSel . _Just %~ updateLeftInvSel)
@@ -369,10 +368,9 @@ changeAugInvSel i w
| n == 0 = w | n == 0 = w
| otherwise = | otherwise =
w w
& cWorld . lWorld . creatures . ix yid . crInvSel . iselPos %~ (`mod` n) . subtract i & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
& cWorld . lWorld . creatures . ix yid . crInvSel . iselAction .~ NoInvSelAction & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
where where
yid = w ^. cWorld . lWorld . yourID
n = length (yourInv w) + length (w ^. cWorld . lWorld . closeObjects) n = length (yourInv w) + length (w ^. cWorld . lWorld . closeObjects)
bestCloseObjectIndex :: World -> Maybe Int bestCloseObjectIndex :: World -> Maybe Int
+1 -1
View File
@@ -51,5 +51,5 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
-- Just j -> w' & itemPositions . ix j .~ InInv cid invid -- Just j -> w' & itemPositions . ix j .~ InInv cid invid
createPutItem :: Item -> World -> (Maybe Int, World) createPutItem :: Item -> World -> (Maybe Int, World)
createPutItem it w = createPutItem it w =
uncurry (putItemInInvID (_yourID (_lWorld (_cWorld w)))) $ uncurry (putItemInInvID 0) $
copyItemToFloorID (_crPos $ you w) (applyModules it) w copyItemToFloorID (_crPos $ you w) (applyModules it) w
+2 -2
View File
@@ -26,7 +26,7 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
DisplayInventory NoSubInventory DisplayInventory NoSubInventory
-- functions that modify the inventory should be centralised so that -- functions that modify the inventory should be centralised so that
-- this lock can be sensibly applied, perhaps -- this lock can be sensibly applied, perhaps
| w ^?! cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvLock -> w | w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w
| rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of
(_, EquipOptions{}) -> scrollRBOption y w (_, EquipOptions{}) -> scrollRBOption y w
(Nothing, _) -> closeObjScrollDir y w (Nothing, _) -> closeObjScrollDir y w
@@ -93,7 +93,7 @@ changeTweakParam mi i w = fromMaybe w $ do
params <- yourItem w ^? _Just . itTweaks . tweakParams . ix paramid params <- yourItem w ^? _Just . itTweaks . tweakParams . ix paramid
let x = (_tweakVal params + i) `mod` _tweakMax params let x = (_tweakVal params + i) `mod` _tweakMax params
return $ return $
w & cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInv . ix (crSel (you w)) w & cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (you w))
%~ ( (itTweaks . tweakParams . ix paramid . tweakVal .~ x) %~ ( (itTweaks . tweakParams . ix paramid . tweakVal .~ x)
. doTweak (_tweakType params) x . doTweak (_tweakType params) x
) )
+3 -4
View File
@@ -55,7 +55,7 @@ pressedMBEffectsNoInventory pkeys w
useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown
| justPressedDown ButtonLeft && inTopInv | justPressedDown ButtonLeft && inTopInv
&& w ^?! hammers . ix DoubleMouseHam == HammerUp = && w ^?! hammers . ix DoubleMouseHam == HammerUp =
useLeftItem (w ^. cWorld . lWorld . yourID) w useLeftItem 0 w
| isDown ButtonLeft && inTopInv = | isDown ButtonLeft && inTopInv =
w & hammers . ix DoubleMouseHam .~ HammerDown w & hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonRight && inTopInv = w | isDown ButtonRight && inTopInv = w
@@ -81,10 +81,9 @@ doCombine i w = case combineItemListYou w ^? ix i of
-- set (hud . hudElement) (DisplayInventory NoSubInventory) -- set (hud . hudElement) (DisplayInventory NoSubInventory)
selectinv --enterCombineInv selectinv --enterCombineInv
. createPutItem it . createPutItem it
$ foldr (rmInvItem yid) w (sort is) $ foldr (rmInvItem 0) w (sort is)
where where
yid = w ^. cWorld . lWorld . yourID selectinv (Just i', w') = w' & cWorld . lWorld . creatures . ix 0 . crInvSel .~ InvSel i' NoInvSelAction
selectinv (Just i', w') = w' & cWorld . lWorld . creatures . ix yid . crInvSel .~ InvSel i' NoInvSelAction
selectinv (Nothing, w') = w' selectinv (Nothing, w') = w'
updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World