about summary refs log tree commit diff
path: root/users/grfn/xanthous/src
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-11-20T21·43-0500
committergrfn <grfn@gws.fyi>2021-11-22T19·12+0000
commit3a01398672d50aa768f926776cb04ef6f5f6f75e (patch)
treec14f01225d309d13b780178a724a207235d97064 /users/grfn/xanthous/src
parentccb918ae975a61c43b95f1b4dce7a72c3ad98b67 (diff)
refactor(gs/xanthous): Define local field lens aliases in AI r/3080
This slightly improves how the module reads imo

Change-Id: Ib1efcbbd5392ece6b46461e8075162f03846d421
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3886
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'users/grfn/xanthous/src')
-rw-r--r--users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs21
1 files changed, 13 insertions, 8 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
index 629798da3c52..c75c6d9163ec 100644
--- a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
+++ b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
@@ -88,21 +88,21 @@ stepGormlak ticks pe@(Positioned pos creature) = do
 
   dest <- maybe (selectDestination pos creature) pure
          . mfilter (\(Destination p _) -> p /= pos)
-         $ creature ^. field @"_hippocampus" . destination
+         $ creature ^. hippocampus . destination
   let progress' =
         dest ^. destinationProgress
-        + creatureType ^. Raw.speed . invertedRate |*| ticks
+        + creature ^. creatureType . Raw.speed . invertedRate |*| ticks
   if progress' < 1
     then pure
          $ pe'
-         & positioned . field @"_hippocampus" . destination
+         & positioned . hippocampus . destination
          ?~ (dest & destinationProgress .~ progress')
     else do
       let newPos = dest ^. destinationPosition
           remainingSpeed = progress' - 1
       newDest <- selectDestination newPos creature
                 <&> destinationProgress +~ remainingSpeed
-      let pe'' = pe' & positioned . field @"_hippocampus" . destination ?~ newDest
+      let pe'' = pe' & positioned . hippocampus . destination ?~ newDest
       collisionAt newPos >>= \case
         Nothing -> pure $ pe'' & position .~ newPos
         Just Stop -> pure pe''
@@ -111,10 +111,9 @@ stepGormlak ticks pe@(Positioned pos creature) = do
           when (any (entityIs @Character) ents) attackCharacter
           pure pe'
   where
-    creatureType = creature ^. field @"_creatureType"
     vision = visionRadius creature
     attackCharacter = do
-      attack <- choose $ creatureType ^. attacks
+      attack <- choose $ creature ^. creatureType . attacks
       attackDescription <- Messages.render (attack ^. Raw.description)
                           $ object []
       say ["combat", "creatureAttack"]
@@ -123,13 +122,13 @@ stepGormlak ticks pe@(Positioned pos creature) = do
                  ]
       character %= Character.damage (attack ^. Raw.damage)
 
-    yellAtCharacter = for_ (creature ^. field @"_creatureType" . language)
+    yellAtCharacter = for_ (creature ^. creatureType . language)
       $ \lang -> do
           utterance <- fmap (<> "!") . word $ getLanguage lang
           creatureSaysText pe utterance
 
     creatureGreeted :: Lens' entity Bool
-    creatureGreeted = field @"_hippocampus" . greetedCharacter
+    creatureGreeted = hippocampus . greetedCharacter
 
 
 -- | A creature sends some text
@@ -166,6 +165,12 @@ instance (IsCreature entity) => Brain (GormlakBrain entity) where
     . fmap _unGormlakBrain
   entityCanMove = const True
 
+hippocampus :: HasField "_hippocampus" s t a b => Lens s t a b
+hippocampus = field @"_hippocampus"
+
+creatureType :: HasField "_creatureType" s t a b => Lens s t a b
+creatureType = field @"_creatureType"
+
 --------------------------------------------------------------------------------
 
 -- instance Brain Creature where