Skip to content

Commit

Permalink
Add Robot instances
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Jun 26, 2022
1 parent c9586ff commit e99b7db
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Swarm/Game/Robot.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
Expand All @@ -7,6 +9,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module : Swarm.Game.Robot
Expand Down Expand Up @@ -71,6 +74,7 @@ module Swarm.Game.Robot (
) where

import Control.Lens hiding (contains)
import Data.Aeson (FromJSON, ToJSON)
import Data.Hashable (hashWithSalt)
import Data.Int (Int64)
import Data.Maybe (isNothing)
Expand All @@ -79,6 +83,7 @@ import qualified Data.Sequence as Seq
import Data.Set (Set)
import Data.Set.Lens (setOf)
import Data.Text (Text)
import GHC.Generics (Generic)
import Linear
import System.Clock (TimeSpec)

Expand Down Expand Up @@ -109,7 +114,7 @@ data RobotContext = RobotContext
-- definitions.
_defStore :: Store
}
deriving (Show)
deriving (Show, Generic, FromJSON, ToJSON)

makeLenses ''RobotContext

Expand All @@ -122,7 +127,7 @@ data LogEntry = LogEntry
, -- | The time at which the entry was created.
_leTime :: Integer
}
deriving (Show)
deriving (Show, Generic, FromJSON, ToJSON)

makeLenses ''LogEntry

Expand Down Expand Up @@ -150,8 +155,14 @@ data RobotR f = RobotR
, _tickSteps :: Int
, _robotCreatedAt :: TimeSpec
}
deriving (Generic)

deriving instance Show (f RID) => Show (RobotR f)
deriving instance FromJSON (f RID) => FromJSON (RobotR f)
deriving instance ToJSON (f RID) => ToJSON (RobotR f)

deriving instance FromJSON TimeSpec
deriving instance ToJSON TimeSpec

-- See https://byorgey.wordpress.com/2021/09/17/automatically-updated-cached-views-with-lens/
-- for the approach used here with lenses.
Expand Down

0 comments on commit e99b7db

Please sign in to comment.