From ecbd51135b204cfe63451ef0f62bca81e92797da Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 5 Nov 2024 19:14:09 +0000 Subject: [PATCH] Add sounds when connecting/disconnecting items --- ghcidOutput | 2 +- src/Dodge/Data/SoundOrigin.hs | 1 + src/Dodge/Inventory.hs | 14 ++++++++------ src/Dodge/Inventory/Location.hs | 13 ++++++++----- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index 771e6e29a..6c826e637 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1 +1 @@ -All good (594 modules, at 18:20:01) +All good (594 modules, at 19:11:58) diff --git a/src/Dodge/Data/SoundOrigin.hs b/src/Dodge/Data/SoundOrigin.hs index b03972c87..959d85cb9 100644 --- a/src/Dodge/Data/SoundOrigin.hs +++ b/src/Dodge/Data/SoundOrigin.hs @@ -11,6 +11,7 @@ import Dodge.Data.Material data SoundOrigin = InventorySound + | InventoryConnectSound | BackgroundSound | OnceSound | CrSound Int diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index 6243404c8..2897623ff 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -189,7 +189,8 @@ swapInvItems f i w = fromMaybe w $ do Just (0, j) | j == i -> hud . hudElement . diSelection . _Just . _2 .~ k _ -> id return $ - w & checkdisconnect k + w + & checkconnect k InventorySound disconnectItemS & cWorld . lWorld . creatures . ix 0 %~ updatecreature k & updateselection & worldEventFlags . at InventoryChange ?~ () @@ -197,14 +198,15 @@ swapInvItems f i w = fromMaybe w $ do & setInvPosFromSS & cWorld . lWorld %~ crUpdateItemLocations 0 -- the double application is inefficient, but necessary without further changes -- a rethink is maybe in order + & checkconnect k InventoryConnectSound connectItemS where cpos = fromMaybe 0 $ w ^? cWorld . lWorld . creatures . ix 0 . crPos - checkdisconnect k - | a || b = soundStart InventorySound cpos disconnectItemS Nothing - | otherwise = id + checkconnect k stype s w' + | p (i+1) || p (i-1) + || p (k+1) || p (k-1) = soundStart stype cpos s Nothing w' + | otherwise = w' where - a = maybe False not $ w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix i . itLocation . ilIsRoot - b = maybe False not $ w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix k . itLocation . ilIsRoot + p j = maybe False not $ w' ^? cWorld . lWorld . creatures . ix 0 . crInv . ix j . itLocation . ilIsRoot updatecreature k = (crInv %~ IM.safeSwapKeys i k) . (crManipulation . manObject . imSelectedItem .~ k) diff --git a/src/Dodge/Inventory/Location.hs b/src/Dodge/Inventory/Location.hs index 14d035bc5..547049b88 100644 --- a/src/Dodge/Inventory/Location.hs +++ b/src/Dodge/Inventory/Location.hs @@ -6,6 +6,7 @@ module Dodge.Inventory.Location ( import Control.Applicative import Control.Lens +import Data.IntMap.Merge.Strict import qualified Data.IntSet as IS import Data.Maybe import Dodge.Base.You @@ -13,7 +14,6 @@ import Dodge.Data.Item.Use.Consumption.LoadAction import Dodge.Data.World import Dodge.Item.Grammar import qualified IntMapHelp as IM -import Data.IntMap.Merge.Strict import NewInt -- assumes all item locations inside the items are correct @@ -48,10 +48,13 @@ crUpdateItemLocations crid lw = fromMaybe lw $ do crSetRoots :: Int -> LWorld -> LWorld crSetRoots cid w = fromMaybe w $ do inv <- w ^? creatures . ix cid . crInv --- invRootTrees inv - return $ w & creatures . ix cid . crInv %~ merge dropMissing preserveMissing - (zipWithMatched f) - (invRootTrees inv) + return $ + w & creatures . ix cid . crInv + %~ merge + dropMissing + preserveMissing + (zipWithMatched f) + (invRootTrees inv) where f _ _ = itLocation . ilIsRoot .~ True