Apply side effects to universe not world

This commit is contained in:
2021-11-28 11:43:17 +00:00
parent 24480bbe52
commit d6fb6adc66
4 changed files with 52 additions and 28 deletions
+10 -5
View File
@@ -159,11 +159,16 @@ pauseMenuOptions =
startNewGame :: World -> Maybe World
startNewGame w = Just $ w
& menuLayers .~ [WaitScreen (const "GENERATING...") 1]
& sideEffects .~ const (generateWorldFromSeed i <&> keyConfig .~ _keyConfig w <&> config .~ _config w
<&> preloadData .~ _preloadData w) -- this kills save games etc...
& sideEffects .~ uvWorld (uvWorldSideEffects i w)
where
i = fst $ random (_randGen w)
uvWorldSideEffects :: Int -> World -> b -> IO World
uvWorldSideEffects i w = const (generateWorldFromSeed i <&> keyConfig .~ _keyConfig w <&> config .~ _config w
<&> preloadData .~ _preloadData w)
-- this kills save games etc...
-- | hacky
scodeToChar :: Scancode -> Char
scodeToChar = toEnum . (+ 61) . fromIntegral . toNumber
@@ -176,10 +181,10 @@ updateFramebufferSize w = w & sideEffects %~ up
where
(x,y) = (round $ getWindowX w, round $ getWindowY w)
divRes = w ^. config . resolution_factor
up :: (World -> IO World) -> World -> IO World
up :: (Universe -> IO Universe) -> Universe -> IO Universe
up f w' = do
pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData w')
f $ w' & preloadData .~ pdata
pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData (_uvWorld w'))
f $ w' & uvWorld . preloadData .~ pdata
--levelMenu :: Int -> ScreenLayer
--levelMenu x = OptionScreen