Magnets
This commit is contained in:
+11
-1
@@ -36,12 +36,12 @@ import qualified IntMapHelp as IM
|
||||
import ListHelp
|
||||
import Color
|
||||
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.Maybe
|
||||
--import Data.List
|
||||
--import System.Random
|
||||
import Control.Lens
|
||||
|
||||
|
||||
-- | after this the item at the inventory position will no longer exist
|
||||
rmInvItem :: Int -- ^ Creature id
|
||||
-> Int -- ^ Inventory position
|
||||
@@ -51,6 +51,8 @@ rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itCons
|
||||
_ -> w & creatures . ix cid . crInv %~ f
|
||||
& creatures . ix cid . crInvSel %~ g
|
||||
& creatures . ix cid . crLeftInvSel . _Just %~ g
|
||||
& creatures . ix cid . crInvEquipped %~ IS.delete invid
|
||||
& creatures . ix cid . crInvEquipped %~ IS.map g
|
||||
where
|
||||
maxk = fmap fst $ IM.lookupMax $ _crInv $ _creatures w IM.! cid
|
||||
f inv = let (xs,ys) = IM.split invid inv
|
||||
@@ -155,6 +157,7 @@ changeSwapInvSel k w
|
||||
updatecreature = ( crInv %~ IM.swapKeys (i `mod` n) swapi )
|
||||
. (crLeftInvSel . _Just %~ updateLeftInvSel)
|
||||
. (crInvSel %~ (`mod` n) . subtract k)
|
||||
. (crInvEquipped %~ swapIntSetKeys i swapi)
|
||||
swapi = (i - k) `mod` n
|
||||
updateLeftInvSel li | i == li = swapi
|
||||
| swapi == li = i
|
||||
@@ -164,6 +167,13 @@ changeSwapInvSel k w
|
||||
n = length $ _crInv $ _creatures w IM.! _yourID w
|
||||
numCO = length $ _closeObjects w
|
||||
|
||||
swapIntSetKeys :: Int -> Int -> IS.IntSet -> IS.IntSet
|
||||
swapIntSetKeys i j is
|
||||
| i `IS.member` is && j `IS.member` is = is
|
||||
| i `IS.member` is = j `IS.insert` (i `IS.delete` is)
|
||||
| j `IS.member` is = i `IS.insert` (j `IS.delete` is)
|
||||
| otherwise = is
|
||||
|
||||
changeAugInvSel :: Int -> World -> World
|
||||
changeAugInvSel i w
|
||||
| n == 0 = w
|
||||
|
||||
Reference in New Issue
Block a user