module Dodge.PreloadData where
import Dodge.Data
--import Dodge.Base
--import Dodge.Base.Window
--import Dodge.Creature.Action
--import Dodge.SoundLogic
--import Dodge.Inventory
--import Geometry
import Preload.Update
--import qualified IntMapHelp as IM

import Control.Lens

sideEffectUpdatePreload :: Int -> Int -> Int -> (Universe -> IO Universe) -> Universe -> IO Universe
sideEffectUpdatePreload divRes x y f u =  do
    pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData u)
    f $ u & preloadData .~ pdata

updatePreload :: Int -> Int -> Int -> Universe -> IO Universe
updatePreload divRes x y u =  do
    pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData u)
    return $ u & preloadData .~ pdata

updateFramebufferSize :: Universe -> IO Universe
updateFramebufferSize u = updatePreload divRes x y u
  where 
    (x,y) = (round $ _windowX cfig, round $ _windowY cfig)
    cfig = _config u
    divRes = resFactorNum $ u ^. config . graphics_resolution_factor
