Skip to content

Commit

Permalink
Update FromJSON TickNumber instance to match ToJSON instance
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed May 27, 2024
1 parent d9b639a commit f3cb639
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/swarm-engine/Swarm/Game/Tick.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import Swarm.Util.WindowedCounter (Offsettable (..))
-- | A newtype representing a count of ticks (typically since the
-- start of a game).
newtype TickNumber = TickNumber {getTickNumber :: Int64}
deriving (Eq, Ord, Show, Read, Generic, FromJSON)
deriving (Eq, Ord, Show, Read, Generic)

instance ToJSON TickNumber where
toJSON = A.genericToJSON (A.defaultOptions {A.unwrapUnaryRecords = True})

instance FromJSON TickNumber where
parseJSON = A.genericParseJSON (A.defaultOptions {A.unwrapUnaryRecords = True})

-- | Add an offset to a 'TickNumber'.
addTicks :: Int -> TickNumber -> TickNumber
addTicks i (TickNumber n) = TickNumber $ n + fromIntegral i
Expand Down

0 comments on commit f3cb639

Please sign in to comment.