From 4d270712aecf1b61249086718852b96968de2bd8 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 2 Sep 2019 13:56:25 -0400 Subject: Add raws, loaded statically from a folder Add raw types with support for both creatures and items, loaded statically from a "raws" folder just like in the Rust version. --- src/Xanthous/Orphans.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/Xanthous/Orphans.hs') diff --git a/src/Xanthous/Orphans.hs b/src/Xanthous/Orphans.hs index d2e378cd28..3efe1f1264 100644 --- a/src/Xanthous/Orphans.hs +++ b/src/Xanthous/Orphans.hs @@ -18,6 +18,7 @@ import Text.Mustache.Type ( showKey ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NonEmpty import Data.Aeson +import Graphics.Vty.Attributes instance forall s a. ( Cons s s a a @@ -152,3 +153,31 @@ instance Function Text where deriving anyclass instance NFData Node deriving anyclass instance NFData Template + +instance FromJSON Color where + parseJSON = withText "Color" $ \case + "black" -> pure black + "red" -> pure red + "green" -> pure green + "yellow" -> pure yellow + "blue" -> pure blue + "magenta" -> pure magenta + "cyan" -> pure cyan + "white" -> pure white + _ -> fail "Invalid color" + +instance ToJSON Color where + toJSON color + | color == black = "black" + | color == red = "red" + | color == green = "green" + | color == yellow = "yellow" + | color == blue = "blue" + | color == magenta = "magenta" + | color == cyan = "cyan" + | color == white = "white" + | otherwise = error "unimplemented" + +instance (Eq a, Show a, Read a, FromJSON a) => FromJSON (MaybeDefault a) where + parseJSON Null = pure Default + parseJSON x = SetTo <$> parseJSON x -- cgit 1.4.1