Permalink
Browse files

add a command to dump current configuration; close #30

Also rewritten the default config file to make diffing with dumps easier.
  • Loading branch information...
1 parent 447b0fc commit 208fc62c1a11340313c7a46b86a31fe27c69fa93 @Mikolaj Mikolaj committed Mar 2, 2011
Showing with 33 additions and 14 deletions.
  1. +8 −0 src/Actions.hs
  2. +1 −0 src/Command.hs
  3. +10 −1 src/Config.hs
  4. +13 −13 src/LambdaHack.config.default
  5. +1 −0 src/Turn.hs
View
@@ -36,6 +36,14 @@ displayHistory =
messageOverlayConfirm "" (unlines hst)
abort
+dumpConfig :: Action ()
+dumpConfig =
+ do
+ config <- gets sconfig
+ let fn = "LambdaHack.config.dump"
+ liftIO $ Config.dump fn config
+ abortWith $ "Current configuration dumped to file " ++ fn ++ "."
+
saveGame :: Action ()
saveGame =
do
View
@@ -27,6 +27,7 @@ saveCommand = Described "save and quit the game" saveGame
quitCommand = Described "quit without saving" quitGame
cancelCommand = Described "cancel current action" cancelCurrent
historyCommand = Described "display previous messages" displayHistory
+dumpCommand = Described "dump current configuration" dumpConfig
heroCommand = Described "cycle among heroes on level" cycleHero -- TODO: should take 0 turns! When it does, use in Turn.hs.
moveDirCommand = Described "move in direction" move
View
@@ -1,8 +1,9 @@
module Config
- (CP, defaultCP, config, getOption, get, getFile) where
+ (CP, defaultCP, config, getOption, get, getFile, dump) where
import System.Directory
import System.FilePath
+import System.IO
import Control.Monad.Error
import qualified Data.ConfigFile as CF
@@ -92,3 +93,11 @@ getFile config dflt s o =
appData <- getAppUserDataDirectory "LambdaHack"
let path = getOption config s o
return $ maybe (combine current dflt) (combine appData) path
+
+dump :: FilePath -> CP -> IO ()
+dump fn (CP config) =
+ do
+ current <- getCurrentDirectory
+ let path = combine current fn
+ dump = CF.to_string config
+ writeFile path dump
@@ -9,27 +9,27 @@
; In this way, you won't accidentally commit your private high scores
; (nor your save files) to LambdaHack git repository.
-; paths to various game files; relative to ~/.LambdaHack/
-; (or analogous prefixes for other OSes, see getAppUserDataDirectory)
-[files]
-saveGame: LambdaHack.save
-highScores: LambdaHack.scores
+[dungeon]
+; the hardcoded default for levels with no specified layout:
+LambdaCave_1: rogueRoom
+; access to stairs may be blocked, so only suitable for the last level:
+LambdaCave_10: noiseRoom
+LambdaCave_3: bigRoom
+depth: 10
[engine]
fovMode: shadow
;fovMode: digital
;fovMode: permissive
fovRadius: 40
+; paths to various game files; relative to ~/.LambdaHack/
+; (or analogous prefixes for other OSes, see getAppUserDataDirectory)
+[files]
+highScores: LambdaHack.scores
+saveGame: LambdaHack.save
+
[heroes]
baseHp: 50
extraHeroes: 0
firstDeathEnds: False
-
-[dungeon]
-depth: 10
-LambdaCave_3: bigRoom
-; access to stairs may be blocked, so only suitable for the last level:
-LambdaCave_10: noiseRoom
-; the hardcoded default for levels with no specified layout:
-LambdaCave_1: rogueRoom
View
@@ -264,6 +264,7 @@ stdKeybindings = Keybindings
-- information for the player
(K.Char 'v', Undescribed $ abortWith version),
(K.Char 'M', historyCommand),
+ (K.Char 'D', dumpCommand),
(K.Char '?', helpCommand),
(K.Return , helpCommand)
]

0 comments on commit 208fc62

Please sign in to comment.