about summary refs log tree commit diff
path: root/src/Xanthous/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Entities')
-rw-r--r--src/Xanthous/Entities/RawTypes.hs62
-rw-r--r--src/Xanthous/Entities/Raws.hs28
-rw-r--r--src/Xanthous/Entities/Raws/gormlak.yaml12
3 files changed, 102 insertions, 0 deletions
diff --git a/src/Xanthous/Entities/RawTypes.hs b/src/Xanthous/Entities/RawTypes.hs
new file mode 100644
index 000000000000..e82cb0c890c7
--- /dev/null
+++ b/src/Xanthous/Entities/RawTypes.hs
@@ -0,0 +1,62 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE DuplicateRecordFields #-}
+
+module Xanthous.Entities.RawTypes
+  ( CreatureType(..)
+  , ItemType(..)
+  , EntityRaw(..)
+
+  , HasName(..)
+  , HasDescription(..)
+  , HasLongDescription(..)
+  , HasChar(..)
+  , HasMaxHitpoints(..)
+  , HasFriendly(..)
+  , _Creature
+  ) where
+
+import Xanthous.Prelude
+import Data.Aeson.Generic.DerivingVia
+import Data.Aeson (FromJSON)
+import Data.Word
+
+import Xanthous.Data
+
+data CreatureType = CreatureType
+  { _name :: Text
+  , _description :: Text
+  , _char :: EntityChar
+  , _maxHitpoints :: Word16
+  , _friendly :: Bool
+  }
+  deriving stock (Show, Eq, Generic)
+  deriving anyclass (NFData)
+  deriving (FromJSON)
+       via WithOptions '[ FieldLabelModifier '[Drop 1] ]
+                       CreatureType
+makeFieldsNoPrefix ''CreatureType
+
+data ItemType = ItemType
+  { _name :: Text
+  , _description :: Text
+  , _longDescription :: Text
+  , _char :: EntityChar
+  }
+  deriving stock (Show, Eq, Generic)
+  deriving anyclass (NFData)
+  deriving (FromJSON)
+       via WithOptions '[ FieldLabelModifier '[Drop 1] ]
+                       ItemType
+makeFieldsNoPrefix ''ItemType
+
+data EntityRaw
+  = Creature CreatureType
+  | Item ItemType
+  deriving stock (Show, Eq, Generic)
+  deriving anyclass (NFData)
+  deriving (FromJSON)
+       via WithOptions '[ SumEnc ObjWithSingleField ]
+                       EntityRaw
+makePrisms ''EntityRaw
+
+{-# ANN module ("HLint: ignore Use newtype instead of data" :: String) #-}
diff --git a/src/Xanthous/Entities/Raws.hs b/src/Xanthous/Entities/Raws.hs
new file mode 100644
index 000000000000..4a4cba8c9a19
--- /dev/null
+++ b/src/Xanthous/Entities/Raws.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module Xanthous.Entities.Raws
+  ( raws
+  , raw
+  ) where
+
+import           Data.FileEmbed
+import qualified Data.Yaml as Yaml
+import           Xanthous.Prelude
+import           System.FilePath.Posix
+
+import           Xanthous.Entities.RawTypes
+
+rawRaws :: [(FilePath, ByteString)]
+rawRaws = $(embedDir "src/Xanthous/Entities/Raws")
+
+raws :: HashMap Text EntityRaw
+raws
+  = mapFromList
+  . map (bimap
+         (pack . takeBaseName)
+         (either (error . Yaml.prettyPrintParseException) id
+          . Yaml.decodeEither'))
+  $ rawRaws
+
+raw :: Text -> Maybe EntityRaw
+raw n = raws ^. at n
diff --git a/src/Xanthous/Entities/Raws/gormlak.yaml b/src/Xanthous/Entities/Raws/gormlak.yaml
new file mode 100644
index 000000000000..fc3215f2f451
--- /dev/null
+++ b/src/Xanthous/Entities/Raws/gormlak.yaml
@@ -0,0 +1,12 @@
+Creature:
+  name: gormlak
+  description: |
+    A chittering imp-like creature with bright yellow horns. It adores shiny objects
+    and gathers in swarms.
+  char:
+    char: g
+    style:
+      color: red
+  maxHitpoints: 5
+  speed: 120
+  friendly: false