36 lines
1011 B
Haskell
36 lines
1011 B
Haskell
module Dodge.StartNewGame (
|
|
startNewGameInSlot,
|
|
startSeedGame,
|
|
) where
|
|
|
|
import Dodge.Menu.Loading
|
|
import Dodge.Concurrent
|
|
--import Dodge.Menu.Option
|
|
import LensHelp
|
|
import Dodge.Data.Universe
|
|
import Dodge.LevelGen
|
|
import Dodge.Save
|
|
import System.Random
|
|
|
|
startNewGameInSlot :: Int -> Universe -> Universe
|
|
startNewGameInSlot slot u = startSeedGame slot i u
|
|
where
|
|
i = fst $ randomR (0, maxBound) (_randGen (_uvWorld u))
|
|
|
|
|
|
blockingLoad :: String -> IO (Universe -> Maybe Universe) -> Universe -> Universe
|
|
blockingLoad str f u = u & uvScreenLayers .:~ loadingScreen str
|
|
& addSideEffect f str
|
|
|
|
startSeedGame :: Int -> Int -> Universe -> Universe
|
|
startSeedGame _ i = blockingLoad "LOADING" (startSeedGameConc i)
|
|
|
|
startSeedGameConc :: Int -> IO (Universe -> Maybe Universe)
|
|
startSeedGameConc seed = do
|
|
w <- generateWorldFromSeed seed
|
|
writeFile "saveSlot/seed" $ show seed
|
|
return $ Just
|
|
. saveWorldInSlot (LevelStartSlot 0)
|
|
. (uvScreenLayers .~ [])
|
|
. (uvWorld .~ w)
|