module Dodge.Save
    ( storeLevel
    , loadStoredLevel
    , doQuicksave
    )
  where
import Dodge.Data

import Data.Maybe
import Control.Lens
import qualified Data.Set as S

storeLevel :: World -> World
storeLevel w = case _storedLevel w of
    Nothing -> w & storedLevel ?~ clearKeys w
    _       -> w

loadStoredLevel :: World -> World
loadStoredLevel w = fromMaybe w $ _storedLevel w <&> quicksaveLevel .~ _quicksaveLevel w

doQuicksave :: World -> World
doQuicksave w = w & quicksaveLevel ?~ clearKeys w

clearKeys :: World -> World
clearKeys = (keys .~ S.empty) . (mouseButtons .~ S.empty)
