diff options
Diffstat (limited to 'src/Sequence')
-rw-r--r-- | src/Sequence/Types.hs | 20 |
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 @@ | |||
3 | module Sequence.Types | 3 | module 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 | ||
62 | newtype SeqVal = SeqVal { _seqVal :: Int } | 62 | newtype SeqVal = SeqVal { _seqVal :: Int } |
63 | deriving (Show, Ord, Eq, Num, Integral, Enum, Real) | 63 | deriving (Show, Ord, Eq, Num, Integral, Enum, Real) |
64 | makeLenses ''SeqVal | 64 | |
65 | 65 | seqVal :: Integral a => Iso' a SeqVal | |
66 | seqVal = iso (SeqVal . fromIntegral) (fromIntegral . _seqVal) | ||
67 | |||
68 | seqVal' :: Prism' String SeqVal | ||
69 | seqVal' = _Show . seqVal | ||
70 | |||
66 | 71 | ||
67 | data Entity = Entity | 72 | data Entity = Entity |
68 | { _eSeqVal :: Maybe SeqVal | 73 | { _eSeqVal :: Maybe SeqVal |
@@ -90,11 +95,12 @@ entityName = iso (EntityName . CI.mk) (CI.original . _entityName) | |||
90 | newtype EntityIdentifier = EntityIdentifier { _entityId :: Integer } | 95 | newtype EntityIdentifier = EntityIdentifier { _entityId :: Integer } |
91 | deriving (Show, Eq, Ord, Enum) | 96 | deriving (Show, Eq, Ord, Enum) |
92 | 97 | ||
93 | entityId :: Iso' Integer EntityIdentifier | 98 | entityId :: Integral a => Iso' a EntityIdentifier |
94 | entityId = iso EntityIdentifier _entityId | 99 | entityId = iso (EntityIdentifier . fromIntegral) (fromIntegral . _entityId) |
95 | 100 | ||
96 | entityId' :: Prism' String EntityIdentifier | 101 | entityId' :: Prism' String EntityIdentifier |
97 | entityId' = prism' (show . _entityId) (fmap EntityIdentifier . readMaybe) | 102 | entityId' = _Show . entityId |
103 | |||
98 | 104 | ||
99 | data GameState = GameState | 105 | data 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 | |||
118 | priorityQueue :: Getter GameState [(SeqVal, EntityIdentifier)] | 124 | priorityQueue :: Getter GameState [(SeqVal, EntityIdentifier)] |
119 | priorityQueue = to priorityQueue' | 125 | priorityQueue = 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 | ||