From 6622dd301860765ed16f29f74c9d1348d3aa0d41 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 22 Dec 2019 23:22:25 -0500 Subject: Add a wield command Add a Wield command, which prompts for a wieldable item, if any, to take out of the character's inventory and put in their right hand. Eventually we should support other hands, but for now hardcoding the right hand should be fine. --- src/Xanthous/Util.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/Xanthous/Util.hs') diff --git a/src/Xanthous/Util.hs b/src/Xanthous/Util.hs index 814f9371150f..b8b789e1b1ea 100644 --- a/src/Xanthous/Util.hs +++ b/src/Xanthous/Util.hs @@ -25,17 +25,19 @@ module Xanthous.Util -- ** Bag sequence algorithms , takeWhileInclusive , smallestNotIn + , removeVectorIndex -- * Type-level programming utils , KnownBool(..) ) where -------------------------------------------------------------------------------- -import Xanthous.Prelude hiding (foldr) +import Xanthous.Prelude hiding (foldr) -------------------------------------------------------------------------------- -import Test.QuickCheck.Checkers -import Data.Foldable (foldr) -import Data.Monoid -import Data.Proxy +import Test.QuickCheck.Checkers +import Data.Foldable (foldr) +import Data.Monoid +import Data.Proxy +import qualified Data.Vector as V -------------------------------------------------------------------------------- newtype EqEqProp a = EqEqProp a @@ -210,6 +212,12 @@ smallestNotIn xs = case uniq $ sort xs of | otherwise -> snd . headEx . filter (uncurry (/=)) $ zip (xs' ++ [minBound]) [minBound..] +-- | Remove the element at the given index, if any, from the given vector +removeVectorIndex :: Int -> Vector a -> Vector a +removeVectorIndex idx vect = + let (before, after) = V.splitAt idx vect + in before <> fromMaybe Empty (tailMay after) + -------------------------------------------------------------------------------- -- | This class gives a boolean associated with a type-level bool, a'la -- cgit 1.4.1