Use JSON as save format
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE DeriveGeneric #-}
|
--{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE StrictData #-}
|
{-# LANGUAGE StrictData #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{-# LANGUAGE DeriveGeneric #-}
|
--{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
--{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE StrictData #-}
|
{-# LANGUAGE StrictData #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
module Dodge.Data.WorldEffect where
|
module Dodge.Data.WorldEffect where
|
||||||
|
|||||||
+19
-10
@@ -7,8 +7,10 @@ module Dodge.Save
|
|||||||
, readSaveSlot
|
, readSaveSlot
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Data.Aeson
|
||||||
import Text.Read (readMaybe)
|
import qualified Data.Aeson.Encode.Pretty as AEP
|
||||||
|
import qualified Data.ByteString.Lazy as BS
|
||||||
|
--import Text.Read (readMaybe)
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
--import Data.Maybe
|
--import Data.Maybe
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@@ -18,24 +20,31 @@ import System.Directory
|
|||||||
writeSaveSlot :: SaveSlot -> Universe -> IO ()
|
writeSaveSlot :: SaveSlot -> Universe -> IO ()
|
||||||
writeSaveSlot ss u = do
|
writeSaveSlot ss u = do
|
||||||
createDirectoryIfMissing True "saveSlot"
|
createDirectoryIfMissing True "saveSlot"
|
||||||
writeFile (saveSlotPath ss) (show $ u ^. uvWorld . cWorld)
|
BS.writeFile (saveSlotPath ss)
|
||||||
|
$ AEP.encodePretty'
|
||||||
saveSlotPath :: SaveSlot -> String
|
(AEP.Config (AEP.Spaces 2) compare AEP.Generic False)
|
||||||
saveSlotPath (SaveSlotNum i) = "saveSlot/" ++ show i
|
(u ^. uvWorld . cWorld)
|
||||||
saveSlotPath QuicksaveSlot = "saveSlot/QuickSave"
|
--writeFile (saveSlotPath ss) (show $ u ^. uvWorld . cWorld)
|
||||||
saveSlotPath LevelStartSlot = "saveSlot/LevelStartSave"
|
|
||||||
|
|
||||||
readSaveSlot :: SaveSlot -> Universe -> IO Universe
|
readSaveSlot :: SaveSlot -> Universe -> IO Universe
|
||||||
readSaveSlot ss uv = do
|
readSaveSlot ss uv = do
|
||||||
fExists <- doesFileExist $ saveSlotPath ss
|
fExists <- doesFileExist $ saveSlotPath ss
|
||||||
if fExists
|
if fExists
|
||||||
then do
|
then do
|
||||||
cwstr <- readFile $ saveSlotPath ss
|
--cwstr <- readFile $ saveSlotPath ss
|
||||||
case readMaybe cwstr of
|
--case readMaybe cwstr of
|
||||||
|
cwstr <- decodeFileStrict $ saveSlotPath ss
|
||||||
|
case cwstr of
|
||||||
Nothing -> putStrLn "loadSaveSlot failed to read saved file" >> return uv
|
Nothing -> putStrLn "loadSaveSlot failed to read saved file" >> return uv
|
||||||
Just cw -> return $ uv & uvWorld . cWorld .~ cw
|
Just cw -> return $ uv & uvWorld . cWorld .~ cw
|
||||||
else putStrLn "loadSaveSlot failed to find saved file" >> return uv
|
else putStrLn "loadSaveSlot failed to find saved file" >> return uv
|
||||||
|
|
||||||
|
saveSlotPath :: SaveSlot -> String
|
||||||
|
saveSlotPath (SaveSlotNum i) = "saveSlot/" ++ show i
|
||||||
|
saveSlotPath QuicksaveSlot = "saveSlot/QuickSave"
|
||||||
|
saveSlotPath LevelStartSlot = "saveSlot/LevelStartSave"
|
||||||
|
|
||||||
|
|
||||||
saveWorldInEmptySlot :: SaveSlot -> Universe -> Universe
|
saveWorldInEmptySlot :: SaveSlot -> Universe -> Universe
|
||||||
saveWorldInEmptySlot slot w = case M.lookup slot $ _savedWorlds w of
|
saveWorldInEmptySlot slot w = case M.lookup slot $ _savedWorlds w of
|
||||||
Nothing -> w & savedWorlds %~ M.insert slot (clearKeys (_uvWorld w))
|
Nothing -> w & savedWorlds %~ M.insert slot (clearKeys (_uvWorld w))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE DeriveGeneric #-}
|
--{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
{- |
|
{- |
|
||||||
WARNING: orphan instances concerning Aeson classes and Linear.Vx datatypes have been introduced.
|
WARNING: orphan instances concerning Aeson classes and Linear.Vx datatypes have been introduced.
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
{-# LANGUAGE StandaloneDeriving #-}
|
--{-# LANGUAGE StandaloneDeriving #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
--{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# OPTIONS_GHC -Wno-unused-imports #-}
|
{-# OPTIONS_GHC -Wno-unused-imports #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
{- |
|
{- |
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
|
||||||
{-# LANGUAGE StrictData #-}
|
{-# LANGUAGE StrictData #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
module Picture.Data
|
module Picture.Data
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
{-# LANGUAGE StandaloneDeriving #-}
|
--{-# LANGUAGE StandaloneDeriving #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
--{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
{- |
|
{- |
|
||||||
WARNING: orphan instances concerning Aeson classes and Linear.Quaternion datatypes have been introduced.
|
WARNING: orphan instances concerning Aeson classes and Linear.Quaternion datatypes have been introduced.
|
||||||
|
|||||||
Reference in New Issue
Block a user