summaryrefslogtreecommitdiff
path: root/src/Sequence
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sequence')
-rw-r--r--src/Sequence/Types.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Sequence/Types.hs b/src/Sequence/Types.hs
index 3d95b9a..02389a1 100644
--- a/src/Sequence/Types.hs
+++ b/src/Sequence/Types.hs
@@ -3,7 +3,7 @@
3module Sequence.Types 3module Sequence.Types
4 ( GameState, gEntities, gEntityNames, gFocus, gNextId' 4 ( GameState, gEntities, gEntityNames, gFocus, gNextId'
5 , Faction, faction, faction' 5 , Faction, faction, faction'
6 , SeqVal(..), seqVal 6 , SeqVal(..), seqVal, seqVal'
7 , Entity(..), eFaction, eSeqVal, eStats 7 , Entity(..), eFaction, eSeqVal, eStats
8 , EntityName(..), entityName 8 , EntityName(..), entityName
9 , EntityIdentifier(..), entityId, entityId' 9 , EntityIdentifier(..), entityId, entityId'
@@ -61,8 +61,13 @@ faction' = lens (CI.original . fromMaybe unaligned . view faction) (\s a -> s {
61 61
62newtype SeqVal = SeqVal { _seqVal :: Int } 62newtype SeqVal = SeqVal { _seqVal :: Int }
63 deriving (Show, Ord, Eq, Num, Integral, Enum, Real) 63 deriving (Show, Ord, Eq, Num, Integral, Enum, Real)
64makeLenses ''SeqVal 64
65 65seqVal :: Integral a => Iso' a SeqVal
66seqVal = iso (SeqVal . fromIntegral) (fromIntegral . _seqVal)
67
68seqVal' :: Prism' String SeqVal
69seqVal' = _Show . seqVal
70
66 71
67data Entity = Entity 72data Entity = Entity
68 { _eSeqVal :: Maybe SeqVal 73 { _eSeqVal :: Maybe SeqVal
@@ -90,11 +95,12 @@ entityName = iso (EntityName . CI.mk) (CI.original . _entityName)
90newtype EntityIdentifier = EntityIdentifier { _entityId :: Integer } 95newtype EntityIdentifier = EntityIdentifier { _entityId :: Integer }
91 deriving (Show, Eq, Ord, Enum) 96 deriving (Show, Eq, Ord, Enum)
92 97
93entityId :: Iso' Integer EntityIdentifier 98entityId :: Integral a => Iso' a EntityIdentifier
94entityId = iso EntityIdentifier _entityId 99entityId = iso (EntityIdentifier . fromIntegral) (fromIntegral . _entityId)
95 100
96entityId' :: Prism' String EntityIdentifier 101entityId' :: Prism' String EntityIdentifier
97entityId' = prism' (show . _entityId) (fmap EntityIdentifier . readMaybe) 102entityId' = _Show . entityId
103
98 104
99data GameState = GameState 105data GameState = GameState
100 { _gEntities :: Map EntityIdentifier Entity 106 { _gEntities :: Map EntityIdentifier Entity
@@ -118,7 +124,7 @@ inhabitedFactions = to $ nub . sort . Map.elems . fmap (view eFaction) . view gE
118priorityQueue :: Getter GameState [(SeqVal, EntityIdentifier)] 124priorityQueue :: Getter GameState [(SeqVal, EntityIdentifier)]
119priorityQueue = to priorityQueue' 125priorityQueue = to priorityQueue'
120 where 126 where
121 priorityQueue' (Map.toAscList . view gEntities -> entities) = sortBy (comparing $ Down . snd) . concat . map filter . map (over _1 $ view eSeqVal) . map swap $ entities 127 priorityQueue' (Map.toAscList . view gEntities -> entities) = sortBy (comparing $ Down . fst) . concat . map filter . map (over _1 $ view eSeqVal) . map swap $ entities
122 filter (Nothing, _) = mempty 128 filter (Nothing, _) = mempty
123 filter (Just val, id) = pure (val, id) 129 filter (Just val, id) = pure (val, id)
124 130