module Dodge.StartNewGame where
import Dodge.Data
import Dodge.LevelGen
import Control.Lens
import System.Random

startNewGame :: Universe -> Universe
startNewGame u = startSeedGame i u
  where
    i = fst $ randomR (0,maxBound) (_randGen (_uvWorld u))

startSeedGame :: Int -> Universe -> Universe
startSeedGame i u = u
    & menuLayers .~ [WaitScreen (const "GENERATING...") 1]
    & uvWorld . sideEffects .~ \_ -> do 
        w <- generateWorldFromSeed i
        return $ u & menuLayers .~ [] & uvWorld .~ w
            & savedWorlds . at LevelStartSlot ?~ w
