Skip to content

Commit

Permalink
support 'orientationMap' (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo authored Jan 22, 2023
1 parent adab34a commit d96405b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion data/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ a key-value mapping described by the following table.
| Key | Default? | Type | Description |
|------------------|----------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `char` | `' '` | `string` | The default character that should be used to draw the robot or entity. |
| `orientationMap` | `{}` | | TODO currently unused |
| `orientationMap` | `{}` | | A map to override display character for any of the (lowercase) cardinal directions |
| `curOrientation` | `null` | | TODO currently unused |
| `attr` | `entity` | `string` | The name of the attribute that should be used to style the robot or entity. A list of currently valid attributes can be found at https://github.com/swarm-game/swarm/blob/main/src/Swarm/TUI/Attr.hs. |
| `priority` | `1` | `int` | When multiple entities and robots occupy the same cell, the one with the highest priority is drawn. By default, entities have priority `1`, and robots have priority `10`. |
Expand Down
12 changes: 10 additions & 2 deletions src/Swarm/Language/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ module Swarm.Language.Syntax (
import Control.Arrow (Arrow ((&&&)))
import Control.Lens (Plated (..), Traversal', (%~))
import Data.Aeson.Types
import Data.Char qualified as C (toLower)
import Data.Data (Data)
import Data.Data.Lens (uniplate)
import Data.Hashable (Hashable)
import Data.List qualified as L (tail)
import Data.Map qualified as M
import Data.Set qualified as S
import Data.String (IsString (fromString))
Expand All @@ -103,11 +105,17 @@ import Witch.From (from)
data AbsoluteDir = DNorth | DSouth | DEast | DWest
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON, Enum, Bounded)

cardinalDirectionKeyOptions :: JSONKeyOptions
cardinalDirectionKeyOptions =
defaultJSONKeyOptions
{ keyModifier = map C.toLower . L.tail
}

instance ToJSONKey AbsoluteDir where
toJSONKey = genericToJSONKey defaultJSONKeyOptions
toJSONKey = genericToJSONKey cardinalDirectionKeyOptions

instance FromJSONKey AbsoluteDir where
fromJSONKey = genericFromJSONKey defaultJSONKeyOptions
fromJSONKey = genericFromJSONKey cardinalDirectionKeyOptions

-- | A relative direction is one which is defined with respect to the
-- robot's frame of reference; no special capability is needed to
Expand Down

0 comments on commit d96405b

Please sign in to comment.