Fix inventory swapping equipment bug
This commit is contained in:
+10
-3
@@ -3,9 +3,11 @@ module IntMapHelp
|
||||
, newKey
|
||||
, insertNewKey
|
||||
, insertWithNewKeys
|
||||
, swapKeys
|
||||
, unsafeSwapKeys
|
||||
, safeSwapKeys
|
||||
, findIndex
|
||||
) where
|
||||
import LensHelp
|
||||
--import Data.List hiding (foldr,insert)
|
||||
import Data.IntMap.Strict
|
||||
{- | Find a key value one higher than any key in the map, or zero if the map is
|
||||
@@ -21,8 +23,13 @@ insertNewKey x m = case lookupMax m of
|
||||
insertWithNewKeys :: [a] -> IntMap a -> IntMap a
|
||||
insertWithNewKeys xs m = union m $ fromList $ zip [newKey m..] xs
|
||||
{- | Swaps two keys. Unsafe: assumes both keys exist. -}
|
||||
swapKeys :: Int -> Int -> IntMap a -> IntMap a
|
||||
swapKeys i j m = insert i (m ! j) $ insert j (m ! i) m
|
||||
unsafeSwapKeys :: Int -> Int -> IntMap a -> IntMap a
|
||||
unsafeSwapKeys i j m = insert i (m ! j) $ insert j (m ! i) m
|
||||
|
||||
safeSwapKeys :: Int -> Int -> IntMap a -> IntMap a
|
||||
safeSwapKeys i j m = m
|
||||
& at i .~ (m ^? ix j)
|
||||
& at j .~ (m ^? ix i)
|
||||
|
||||
-- ideally this should short circuit, I am not sure whether it does or not
|
||||
-- though
|
||||
|
||||
Reference in New Issue
Block a user