better JSON direction representation (#1359)

This commit is contained in:
Karl Ostmo 2023-07-11 07:55:46 -07:00 committed by GitHub
parent a30b6ed0c9
commit 7daa64b9c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 23 deletions

View File

@ -39,34 +39,34 @@ world:
- src: tetromino
offset: [9, -2]
orient:
up: "DEast"
up: east
- src: tetromino
offset: [17, -2]
orient:
up: "DSouth"
up: south
- src: tetromino
offset: [23, -2]
orient:
up: "DWest"
up: west
- src: tetromino
offset: [3, -9]
orient:
up: "DNorth"
up: north
flip: true
- src: tetromino
offset: [9, -9]
orient:
up: "DEast"
up: east
flip: true
- src: tetromino
offset: [17, -9]
orient:
up: "DSouth"
up: south
flip: true
- src: tetromino
offset: [23, -9]
orient:
up: "DWest"
up: west
flip: true
map: |
┌──────────────────────────────┐

View File

@ -93,35 +93,35 @@ world:
- src: tunnel
offset: [3, -21]
orient:
up: "DWest"
up: west
- src: tunnel
offset: [71, -21]
orient:
up: "DEast"
up: east
- src: road segment
offset: [6, -22]
orient:
up: "DSouth"
up: south
flip: true
- src: road segment
offset: [12, -22]
orient:
up: "DSouth"
up: south
flip: true
- src: road segment
offset: [18, -22]
orient:
up: "DSouth"
up: south
flip: true
- src: road segment
offset: [24, -22]
orient:
up: "DSouth"
up: south
flip: true
- src: road segment
offset: [30, -22]
orient:
up: "DSouth"
up: south
flip: true
- src: intersection
offset: [36, -22]
@ -138,29 +138,29 @@ world:
- src: road segment
offset: [36, -28]
orient:
up: "DEast"
up: east
- src: road segment
offset: [36, -34]
orient:
up: "DEast"
up: east
- src: road segment
offset: [36, -40]
orient:
up: "DEast"
up: east
- src: road segment
offset: [36, -16]
orient:
up: "DWest"
up: west
flip: true
- src: road segment
offset: [36, -10]
orient:
up: "DWest"
up: west
flip: true
- src: road segment
offset: [36, -4]
orient:
up: "DWest"
up: west
flip: true
upperleft:
- -18

View File

@ -137,12 +137,27 @@ maxStrideRange = 64
-- Do not alter this ordering, as there exist functions that depend on it
-- (e.g. "nearestDirection" and "relativeTo").
data AbsoluteDir = DEast | DNorth | DWest | DSouth
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON, Enum, Bounded)
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, Enum, Bounded)
directionJsonModifier :: String -> String
directionJsonModifier = map C.toLower . L.tail
directionJsonOptions :: Options
directionJsonOptions =
defaultOptions
{ constructorTagModifier = directionJsonModifier
}
instance FromJSON AbsoluteDir where
parseJSON = genericParseJSON directionJsonOptions
instance ToJSON AbsoluteDir where
toJSON = genericToJSON directionJsonOptions
cardinalDirectionKeyOptions :: JSONKeyOptions
cardinalDirectionKeyOptions =
defaultJSONKeyOptions
{ keyModifier = map C.toLower . L.tail
{ keyModifier = directionJsonModifier
}
instance ToJSONKey AbsoluteDir where
@ -160,7 +175,13 @@ data RelativeDir = DPlanar PlanarRelativeDir | DDown
-- | Caution: Do not alter this ordering, as there exist functions that depend on it
-- (e.g. "nearestDirection" and "relativeTo").
data PlanarRelativeDir = DForward | DLeft | DBack | DRight
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON, Enum, Bounded)
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, Enum, Bounded)
instance FromJSON PlanarRelativeDir where
parseJSON = genericParseJSON directionJsonOptions
instance ToJSON PlanarRelativeDir where
toJSON = genericToJSON directionJsonOptions
-- | The type of directions. Used /e.g./ to indicate which way a robot
-- will turn.