diff options
author | Griffin Smith <root@gws.fyi> | 2019-11-30T03·59-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-11-30T03·59-0500 |
commit | 8a1235c3dcf7fe69b2e2ea3eea326858d26d38b9 (patch) | |
tree | 398c6dce549602c9890fbded64e3bdf2646b2a1f /src/Xanthous/Game/Prompt.hs | |
parent | 7d8ce026a2acc5a4d208110750be188f0ce5591c (diff) |
Use menus for combat and picking up items
Refactor a bunch of stuff around to allow for polymorphically surfacing an EntityChar for all entities, and use this to write a generic `entityMenu` function, which generates a menu from the chars of a list of entities - and use that to fully implement (removing `undefined`) menus for both attacking and picking things up when there are multiple entities on the relevant tile.
Diffstat (limited to 'src/Xanthous/Game/Prompt.hs')
-rw-r--r-- | src/Xanthous/Game/Prompt.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Xanthous/Game/Prompt.hs b/src/Xanthous/Game/Prompt.hs index 6c3629f31055..8e9ec04ccb33 100644 --- a/src/Xanthous/Game/Prompt.hs +++ b/src/Xanthous/Game/Prompt.hs @@ -1,6 +1,8 @@ +{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE DeriveFunctor #-} -------------------------------------------------------------------------------- module Xanthous.Game.Prompt ( PromptType(..) @@ -25,6 +27,7 @@ import Xanthous.Prelude import Brick.Widgets.Edit (Editor, editorText, getEditContents) import Test.QuickCheck import Test.QuickCheck.Arbitrary.Generic +import Control.Comonad -------------------------------------------------------------------------------- import Xanthous.Util (smallestNotIn) import Xanthous.Data (Direction, Position) @@ -159,9 +162,13 @@ instance CoArbitrary (PromptState ('Menu a)) where deriving stock instance Show (PromptState pt) data MenuOption a = MenuOption Text a - deriving stock (Eq, Generic) + deriving stock (Eq, Generic, Functor) deriving anyclass (NFData, CoArbitrary, Function) +instance Comonad MenuOption where + extract (MenuOption _ x) = x + extend cok mo@(MenuOption text _) = MenuOption text (cok mo) + mkMenuItems :: (MonoFoldable f, Element f ~ (Char, MenuOption a)) => f -> Map Char (MenuOption a) |