From 6c1bf920825235a81b6f63830d58cb39d0898ee2 Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 7 Apr 2022 09:29:11 +0100 Subject: [PATCH] Add file --- src/Dodge/Item/Location.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Dodge/Item/Location.hs diff --git a/src/Dodge/Item/Location.hs b/src/Dodge/Item/Location.hs new file mode 100644 index 000000000..3b0b92982 --- /dev/null +++ b/src/Dodge/Item/Location.hs @@ -0,0 +1,23 @@ +module Dodge.Item.Location where +import Dodge.Data +import qualified IntMapHelp as IM + +import Control.Lens +import Data.Maybe + +setHeldItemPos :: Creature -> World -> World +setHeldItemPos cr = fst . getHeldItemPos cr + +getHeldItemPos :: Creature -> World -> (World,Int) +getHeldItemPos cr w = case maybeitid of + Nothing -> + ( w & creatures . ix cid . crInv . ix j . itID ?~ newitid + & itemPositions %~ IM.insert newitid (InInv cid j) + , itid) + _ -> (w, itid) + where + cid = _crID cr + j = _crInvSel cr + newitid = IM.newKey $ _itemPositions w + maybeitid = cr ^? crInv . ix j . itID . _Just + itid = fromMaybe newitid maybeitid