Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Set instead of a list for entity properties, for sortability #794

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Swarm/Game/Entity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import Data.Map (Map)
import Data.Map qualified as M
import Data.Maybe (fromMaybe, isJust, listToMaybe)
import Data.Set (Set)
import Data.Set qualified as Set (fromList)
import Data.Set.Lens (setOf)
import Data.Text (Text)
import Data.Text qualified as T
Expand Down Expand Up @@ -219,7 +220,7 @@ data Entity = Entity
-- grabbed.
_entityYields :: Maybe Text
, -- | Properties of the entity.
_entityProperties :: [EntityProperty]
_entityProperties :: Set EntityProperty
, -- | Capabilities provided by this entity.
_entityCapabilities :: [Capability]
, -- | Inventory of other entities held by this entity.
Expand Down Expand Up @@ -274,7 +275,7 @@ mkEntity ::
[Capability] ->
Entity
mkEntity disp nm descr props caps =
rehashEntity $ Entity 0 disp nm Nothing descr Nothing Nothing Nothing props caps empty
rehashEntity $ Entity 0 disp nm Nothing descr Nothing Nothing Nothing (Set.fromList props) caps empty

------------------------------------------------------------
-- Entity map
Expand Down Expand Up @@ -330,7 +331,7 @@ instance FromJSON Entity where
<*> v .:? "orientation"
<*> v .:? "growth"
<*> v .:? "yields"
<*> v .:? "properties" .!= []
<*> v .:? "properties" .!= mempty
<*> v .:? "capabilities" .!= []
<*> pure empty
)
Expand Down Expand Up @@ -431,7 +432,7 @@ entityYields :: Lens' Entity (Maybe Text)
entityYields = hashedLens _entityYields (\e x -> e {_entityYields = x})

-- | The properties enjoyed by this entity.
entityProperties :: Lens' Entity [EntityProperty]
entityProperties :: Lens' Entity (Set EntityProperty)
entityProperties = hashedLens _entityProperties (\e x -> e {_entityProperties = x})

-- | Test whether an entity has a certain property.
Expand Down
3 changes: 2 additions & 1 deletion src/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import Data.Map qualified as M
import Data.Maybe (catMaybes, fromMaybe, mapMaybe, maybeToList)
import Data.Semigroup (sconcat)
import Data.Sequence qualified as Seq
import Data.Set qualified as Set (toList)
import Data.String (fromString)
import Data.Text (Text)
import Data.Text qualified as T
Expand Down Expand Up @@ -956,7 +957,7 @@ explainFocusedItem s = case focusedItem s of
explainEntry :: AppState -> Entity -> Widget Name
explainEntry s e =
vBox
[ displayProperties (e ^. entityProperties)
[ displayProperties $ Set.toList (e ^. entityProperties)
, displayParagraphs (e ^. entityDescription)
, explainRecipes s e
]
Expand Down