{-# LANGUAGE DeriveGeneric #-}
module Game.LambdaHack.Definition.Flavour
(
Flavour(Flavour)
,
zipPlain, zipFancy, zipLiquid, zipGlassPlain, zipGlassFancy
,
flavourToColor, flavourToName
, colorToPlainName, colorToFancyName, colorToTeamName
#ifdef EXPOSE_INTERNAL
, FancyName, colorToLiquidName, colorToGlassPlainName, colorToGlassFancyName
#endif
) where
import Prelude ()
import Game.LambdaHack.Core.Prelude
import Data.Binary
import Data.Bits (unsafeShiftL, unsafeShiftR, (.&.))
import Data.Hashable (Hashable (hashWithSalt), hashUsing)
import GHC.Generics (Generic)
import Game.LambdaHack.Definition.Color
data FancyName = Plain | Fancy | Liquid | GlassPlain | GlassFancy
deriving (Show, Eq, Ord, Enum, Bounded, Generic)
data Flavour = Flavour
{ fancyName :: FancyName
, baseColor :: Color
}
deriving (Show, Eq, Ord, Generic)
instance Enum Flavour where
fromEnum Flavour{..} =
unsafeShiftL (fromEnum fancyName) 8 + fromEnum baseColor
toEnum n = Flavour (toEnum $ unsafeShiftR n 8)
(toEnum $ n .&. (2 ^ (8 :: Int) - 1))
instance Hashable Flavour where
hashWithSalt = hashUsing fromEnum
instance Binary Flavour where
put = put . (fromIntegral :: Int -> Word16) . fromEnum
get = fmap (toEnum . (fromIntegral :: Word16 -> Int)) get
zipPlain, zipFancy, zipLiquid, zipGlassPlain, zipGlassFancy :: [Color] -> [Flavour]
zipPlain = map (Flavour Plain)
zipFancy = map (Flavour Fancy)
zipLiquid = map (Flavour Liquid)
zipGlassPlain = map (Flavour GlassPlain)
zipGlassFancy = map (Flavour GlassFancy)
flavourToColor :: Flavour -> Color
flavourToColor Flavour{baseColor} = baseColor
flavourToName :: Flavour -> Text
flavourToName Flavour{fancyName=Plain, ..} = colorToPlainName baseColor
flavourToName Flavour{fancyName=Fancy, ..} = colorToFancyName baseColor
flavourToName Flavour{fancyName=Liquid, ..} = colorToLiquidName baseColor
flavourToName Flavour{fancyName=GlassPlain, ..} =
colorToGlassPlainName baseColor
flavourToName Flavour{fancyName=GlassFancy, ..} =
colorToGlassFancyName baseColor
colorToPlainName :: Color -> Text
colorToPlainName Black = "black"
colorToPlainName Red = "red"
colorToPlainName Green = "green"
colorToPlainName Brown = "brown"
colorToPlainName Blue = "blue"
colorToPlainName Magenta = "purple"
colorToPlainName Cyan = "cyan"
colorToPlainName White = "ivory"
colorToPlainName AltWhite = error "colorToPlainName: illegal color"
colorToPlainName BrBlack = "gray"
colorToPlainName BrRed = "coral"
colorToPlainName BrGreen = "lime"
colorToPlainName BrYellow = "yellow"
colorToPlainName BrBlue = "azure"
colorToPlainName BrMagenta = "pink"
colorToPlainName BrCyan = "aquamarine"
colorToPlainName BrWhite = "white"
colorToFancyName :: Color -> Text
colorToFancyName Black = "smoky-black"
colorToFancyName Red = "apple-red"
colorToFancyName Green = "forest-green"
colorToFancyName Brown = "mahogany"
colorToFancyName Blue = "royal-blue"
colorToFancyName Magenta = "indigo"
colorToFancyName Cyan = "teal"
colorToFancyName White = "silver-gray"
colorToFancyName AltWhite = error "colorToFancyName: illegal color"
colorToFancyName BrBlack = "charcoal"
colorToFancyName BrRed = "salmon"
colorToFancyName BrGreen = "emerald"
colorToFancyName BrYellow = "amber"
colorToFancyName BrBlue = "sky-blue"
colorToFancyName BrMagenta = "magenta"
colorToFancyName BrCyan = "turquoise"
colorToFancyName BrWhite = "ghost-white"
colorToLiquidName :: Color -> Text
colorToLiquidName Black = "tarry"
colorToLiquidName Red = "bloody"
colorToLiquidName Green = "moldy"
colorToLiquidName Brown = "muddy"
colorToLiquidName Blue = "oily"
colorToLiquidName Magenta = "swirling"
colorToLiquidName Cyan = "bubbling"
colorToLiquidName White = "cloudy"
colorToLiquidName AltWhite = error "colorToLiquidName: illegal color"
colorToLiquidName BrBlack = "pitchy"
colorToLiquidName BrRed = "red-speckled"
colorToLiquidName BrGreen = "sappy"
colorToLiquidName BrYellow = "golden"
colorToLiquidName BrBlue = "blue-speckled"
colorToLiquidName BrMagenta = "hazy"
colorToLiquidName BrCyan = "misty"
colorToLiquidName BrWhite = "shining"
colorToGlassPlainName :: Color -> Text
colorToGlassPlainName color = colorToPlainName color <+> "glass"
colorToGlassFancyName :: Color -> Text
colorToGlassFancyName color = colorToFancyName color <+> "crystal"
colorToTeamName :: Color -> Text
colorToTeamName BrBlack = "black"
colorToTeamName BrRed = "red"
colorToTeamName BrGreen = "green"
colorToTeamName BrYellow = "yellow"
colorToTeamName BrBlue = "blue"
colorToTeamName BrMagenta = "pink"
colorToTeamName BrCyan = "cyan"
colorToTeamName BrWhite = "white"
colorToTeamName c = colorToFancyName c