File: RuleKind.hs

package info (click to toggle)
haskell-lambdahack 0.11.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,064 kB
  • sloc: haskell: 45,636; makefile: 223
file content (73 lines) | stat: -rw-r--r-- 2,673 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- | The type of game rules and assorted game data.
module Game.LambdaHack.Content.RuleKind
  ( RuleContent(..), emptyRuleContent, makeData
#ifdef EXPOSE_INTERNAL
    -- * Internal operations
  , emptyRuleContentRaw, validateSingle
#endif
  ) where

import Prelude ()

import Game.LambdaHack.Core.Prelude

import qualified Data.Ini as Ini
import qualified Data.Ini.Types as Ini
import           Data.Version

import Game.LambdaHack.Content.ItemKind
  (ItemSymbolsUsedInEngine, emptyItemSymbolsUsedInEngine)
import Game.LambdaHack.Definition.Defs

-- | The type of game rules and assorted game data.
data RuleContent = RuleContent
  { rtitle            :: String    -- ^ title of the game (not lib)
  , rWidthMax         :: X         -- ^ maximum level width
  , rHeightMax        :: Y         -- ^ maximum level height
  , rexeVersion       :: Version   -- ^ version of the game
  , rcfgUIName        :: FilePath  -- ^ name of the UI config file
  , rcfgUIDefault     :: (Text, Ini.Config)
                                   -- ^ the default UI settings config file
  , rwriteSaveClips   :: Int       -- ^ game saved that often (not on browser)
  , rleadLevelClips   :: Int       -- ^ server switches leader level that often
  , rscoresFileName   :: FilePath  -- ^ name of the scores file
  , rnearby           :: Int       -- ^ what is a close distance between actors
  , rstairWordCarried :: [Text]    -- ^ words that can't be dropped from stair
                                   --   name as it goes through levels
  , ritemSymbols      :: ItemSymbolsUsedInEngine
                                   -- ^ item symbols treated specially in engine
  }

emptyRuleContentRaw :: RuleContent
emptyRuleContentRaw = RuleContent
  { rtitle = ""
  , rWidthMax = 5
  , rHeightMax = 2
  , rexeVersion = makeVersion []
  , rcfgUIName = ""
  , rcfgUIDefault = ("", Ini.emptyConfig)
  , rwriteSaveClips = 0
  , rleadLevelClips = 0
  , rscoresFileName = ""
  , rnearby = 0
  , rstairWordCarried = []
  , ritemSymbols = emptyItemSymbolsUsedInEngine
  }

emptyRuleContent :: RuleContent
emptyRuleContent = assert (null $ validateSingle emptyRuleContentRaw)
                          emptyRuleContentRaw

-- | Catch invalid rule kind definitions.
validateSingle :: RuleContent -> [Text]
validateSingle RuleContent{..} =
  [ "rWidthMax < 5" | rWidthMax < 5 ]  -- indented (4 prop spaces) text
  ++ [ "rHeightMax < 2" | rHeightMax < 2 ]  -- or 4 tiles of sentinel wall

makeData :: RuleContent -> RuleContent
makeData rc =
  let singleOffenders = validateSingle rc
  in assert (null singleOffenders
             `blame` "Rule Content not valid"
             `swith` singleOffenders)
     rc