Now maps are in JSON format
This commit is contained in:
parent
88e2522ab9
commit
3f88d88ad7
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"map" : [
|
||||
|
||||
"#########################",
|
||||
"####......#####....######",
|
||||
"###.........###.....#####",
|
||||
"##....#......###....#####",
|
||||
"##...###......##.....####",
|
||||
"##..######....##......###",
|
||||
"##..######....###.....###",
|
||||
"#...########..#####....##",
|
||||
"#....#######..######...##",
|
||||
"#....#####.......###....#",
|
||||
"##...####...#.....##....#",
|
||||
"###........######.###...#",
|
||||
"###.......##......###...#",
|
||||
"###...#..###.########...#",
|
||||
"##...#######.......###..#",
|
||||
"#....#############.#....#",
|
||||
"#.....####.###.....##..##",
|
||||
"#.........########.....##",
|
||||
"##...##############....##",
|
||||
"###...###..###.######..##",
|
||||
"###.......##....####...##",
|
||||
"####.#####......###...###",
|
||||
"#..###................###",
|
||||
"#..................######",
|
||||
"#########################"
|
||||
|
||||
]
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#########################
|
||||
####......#####....######
|
||||
###.........###.....#####
|
||||
##....#......###....#####
|
||||
##...###......##.....####
|
||||
##..######....##......###
|
||||
##..######....###.....###
|
||||
#...########..#####....##
|
||||
#....#######..######...##
|
||||
#....#####.......###....#
|
||||
##...####...#.....##....#
|
||||
###........######.###...#
|
||||
###.......##......###...#
|
||||
###...#..###.########...#
|
||||
##...#######.......###..#
|
||||
#....#############.#....#
|
||||
#.....####.###.....##..##
|
||||
#.........########.....##
|
||||
##...##############....##
|
||||
###...###..###.######..##
|
||||
###.......##....####...##
|
||||
####.#####......###...###
|
||||
#..###................###
|
||||
#..................######
|
||||
#########################
|
|
@ -29,4 +29,7 @@ executable roguelike
|
|||
unordered-containers,
|
||||
microlens-th,
|
||||
microlens,
|
||||
linear
|
||||
linear,
|
||||
aeson,
|
||||
bytestring,
|
||||
utf8-string
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Dungeon where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Types
|
||||
import Data.Matrix
|
||||
import Linear.V2
|
||||
import Data.Tuple
|
||||
|
@ -25,10 +28,16 @@ instance Show Dungeon where
|
|||
|
||||
makeDungeonFromFile :: String -> IO Dungeon
|
||||
makeDungeonFromFile f = do
|
||||
contents <- readFile f
|
||||
--contents <- readFile f
|
||||
ef <- eitherDecodeFileStrict f :: IO (Either String Object)
|
||||
let obj = case ef of (Right o) -> o
|
||||
(Left l) -> error l
|
||||
let stringMap = case parse (.: "map") obj :: Result [String] of
|
||||
(Success m) -> m
|
||||
(Error s) -> error s
|
||||
let cellMappingR = map swap cellMapping
|
||||
charToCell c = fromMaybe (error "Invalid cell in the .map file") (c `lookup` cellMappingR)
|
||||
cellLists = map charToCell <$> lines contents
|
||||
cellLists = map charToCell <$> stringMap
|
||||
return . Dungeon . fromLists $ cellLists
|
||||
|
||||
dungeonToLists :: Dungeon -> [[Cell]]
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
module Dungeon.Loader where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.ByteString.Lazy.UTF8 (fromString)
|
||||
|
||||
loadDungeon :: String -> IO (Either String Object)
|
||||
loadDungeon = eitherDecodeFileStrict
|
|
@ -19,7 +19,7 @@ makeLenses ''Game
|
|||
|
||||
newGame :: IO Game
|
||||
newGame = do
|
||||
dun <- makeDungeonFromFile "maps/test.map"
|
||||
dun <- makeDungeonFromFile "maps/test.json"
|
||||
return $ Game dun (Player $ V2 1 24)
|
||||
|
||||
runAction :: Action -> Game -> Maybe Game
|
||||
|
|
Loading…
Reference in New Issue