2018-06-08 23:17:03 +00:00
|
|
|
module Load where
|
|
|
|
|
|
|
|
import Affection as A
|
|
|
|
|
2018-06-15 13:39:08 +00:00
|
|
|
import qualified SDL
|
2018-06-16 17:34:17 +00:00
|
|
|
import Graphics.Rendering.OpenGL.GL.FlushFinish (finish)
|
2018-06-15 13:39:08 +00:00
|
|
|
|
2018-06-08 23:17:03 +00:00
|
|
|
import Control.Concurrent (forkIO)
|
|
|
|
import Control.Concurrent.MVar
|
|
|
|
import Control.Monad (when)
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2018-07-19 02:51:07 +00:00
|
|
|
import qualified Data.Text as T
|
2018-06-08 23:17:03 +00:00
|
|
|
import Data.Ecstasy
|
|
|
|
import Data.Maybe
|
|
|
|
|
|
|
|
import System.Exit (exitFailure)
|
|
|
|
|
|
|
|
import NanoVG hiding (V2(..))
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
2018-06-28 19:07:58 +00:00
|
|
|
import MainGame.WorldMap
|
2018-06-08 23:17:03 +00:00
|
|
|
import Util
|
|
|
|
|
|
|
|
loadLoad :: Affection UserData ()
|
|
|
|
loadLoad = do
|
2018-07-06 15:17:12 +00:00
|
|
|
ad <- A.get
|
2018-06-08 23:17:03 +00:00
|
|
|
ud <- getAffection
|
2018-07-19 02:51:07 +00:00
|
|
|
progress <- liftIO $ newMVar (0, "Starting up")
|
2018-06-08 23:17:03 +00:00
|
|
|
future <- liftIO $ newEmptyMVar
|
2018-06-15 13:39:08 +00:00
|
|
|
_ <- liftIO $ createFont (nano ud) "bedstead"
|
|
|
|
(FileName "assets/font/Bedstead-Semicondensed.ttf")
|
|
|
|
_ <- liftIO $ forkIO $
|
|
|
|
loadFork
|
|
|
|
(worldState ud)
|
2018-07-03 14:19:27 +00:00
|
|
|
(fromJust $ window ud)
|
|
|
|
(fromJust $ threadContext ud)
|
2018-06-15 13:39:08 +00:00
|
|
|
(nano ud)
|
|
|
|
future
|
|
|
|
progress
|
2018-07-06 15:17:12 +00:00
|
|
|
SDL.glMakeCurrent (fromJust $ window ud) (glContext ad)
|
2018-06-08 23:17:03 +00:00
|
|
|
putAffection ud
|
|
|
|
{ stateMVar = future
|
|
|
|
, stateProgress = progress
|
|
|
|
, state = Load
|
2018-06-15 13:39:08 +00:00
|
|
|
, assetFonts = M.fromList
|
|
|
|
[ (FontBedstead, "bedstead")
|
|
|
|
]
|
2018-06-08 23:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadFork
|
|
|
|
:: (SystemState Entity IO)
|
2018-07-03 14:19:27 +00:00
|
|
|
-> SDL.Window
|
|
|
|
-> SDL.GLContext
|
2018-06-08 23:17:03 +00:00
|
|
|
-> Context
|
|
|
|
-> MVar (SystemState Entity IO, StateData)
|
2018-07-19 02:51:07 +00:00
|
|
|
-> MVar (Float, T.Text)
|
2018-06-08 23:17:03 +00:00
|
|
|
-> IO ()
|
2018-07-03 14:19:27 +00:00
|
|
|
loadFork ws win glc nvg future progress = do
|
2018-07-30 12:34:46 +00:00
|
|
|
let stateSteps = 25
|
2018-06-08 23:17:03 +00:00
|
|
|
increment = 1 / stateSteps
|
2018-06-15 13:39:08 +00:00
|
|
|
SDL.glMakeCurrent win glc
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_asc\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallasc <- createImage nvg (FileName "assets/walls/wall_asc.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_desc\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwalldesc <- createImage nvg (FileName "assets/walls/wall_desc.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_corner_n\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallcornern <- createImage nvg (FileName "assets/walls/wall_corner_n.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_corner_e\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallcornere <- createImage nvg (FileName "assets/walls/wall_corner_e.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_corner_s\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallcorners <- createImage nvg (FileName "assets/walls/wall_corner_s.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_corner_w\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallcornerw <- createImage nvg (FileName "assets/walls/wall_corner_w.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_t_ne\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwalltne <- createImage nvg (FileName "assets/walls/wall_t_ne.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_t_se\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwalltse <- createImage nvg (FileName "assets/walls/wall_t_se.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_t_sw\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwalltsw <- createImage nvg (FileName "assets/walls/wall_t_sw.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_t_nw\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwalltnw <- createImage nvg (FileName "assets/walls/wall_t_nw.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_cross\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mwallcross <- createImage nvg (FileName "assets/walls/wall_cross.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"box1\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmiscbox1 <- createImage nvg (FileName "assets/misc/box1.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"table1\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmisctable1 <- createImage nvg (FileName "assets/misc/table1.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"table2\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmisctable2 <- createImage nvg (FileName "assets/misc/table2.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"table3\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmisctable3 <- createImage nvg (FileName "assets/misc/table3.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"wall_table4\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmisctable4 <- createImage nvg (FileName "assets/misc/table4.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading asset \"tableCorner\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
mmisctableC <- createImage nvg (FileName "assets/misc/tableCorner.png") 0
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"intruder: standing\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
let mimgs = [ mwallasc, mwalldesc,
|
|
|
|
mwallcornern, mwallcornere, mwallcorners, mwallcornerw,
|
|
|
|
mwalltne, mwalltse, mwalltsw, mwalltnw, mwallcross,
|
|
|
|
mmiscbox1,
|
|
|
|
mmisctable1, mmisctable2, mmisctable3, mmisctable4, mmisctableC
|
|
|
|
]
|
|
|
|
when (any isNothing mimgs) $ do
|
|
|
|
liftIO $logIO Error "Failed to load image assets"
|
|
|
|
exitFailure
|
|
|
|
-- playerImgs <- loadPlayerSprite "assets/intruder.png" 64 74 nvg
|
|
|
|
-- (zipWith (\a b -> (a, [b])) [0..] $ [ImgIntrE .. ImgIntrN] ++ [ImgIntrNE])
|
2018-07-21 04:43:26 +00:00
|
|
|
let imgs = zipWith (\a b -> (a, fromJust b))
|
|
|
|
[ ImgWallAsc
|
|
|
|
, ImgWallDesc
|
|
|
|
, ImgWallCornerN
|
|
|
|
, ImgWallCornerE
|
|
|
|
, ImgWallCornerS
|
|
|
|
, ImgWallCornerW
|
|
|
|
, ImgWallTNE
|
|
|
|
, ImgWallTSE
|
|
|
|
, ImgWallTSW
|
|
|
|
, ImgWallTNW
|
|
|
|
, ImgWallCross
|
|
|
|
, ImgMiscBox1
|
|
|
|
, ImgMiscTable1
|
|
|
|
, ImgMiscTable2
|
|
|
|
, ImgMiscTable3
|
|
|
|
, ImgMiscTable4
|
|
|
|
, ImgMiscTableCorner
|
|
|
|
]
|
|
|
|
mimgs
|
2018-06-08 23:17:03 +00:00
|
|
|
directions = [E .. N] ++ [NE]
|
2018-06-16 17:34:17 +00:00
|
|
|
standIds var = map (AnimId var "standing") directions
|
|
|
|
walkIds var = map (AnimId var "walking") directions
|
2018-06-08 23:17:03 +00:00
|
|
|
standConfigs = map
|
2018-07-21 04:43:26 +00:00
|
|
|
(\i -> AnimationConfig (0, i * 74) (64, 74) (64, 0) 1 0 APLoop)
|
|
|
|
[0 .. length (standIds "intruder") - 1]
|
2018-06-08 23:17:03 +00:00
|
|
|
walkConfigs = map
|
2018-07-21 04:43:26 +00:00
|
|
|
(\i -> AnimationConfig (64, i * 74) (64, 74) (64, 0) 6 1.5 APLoop)
|
|
|
|
[0 .. length (walkIds "intruder") - 1]
|
2018-06-08 23:17:03 +00:00
|
|
|
playerStanding <- loadAnimationSprites "assets/intruder.png" nvg
|
2018-07-21 04:43:26 +00:00
|
|
|
(zip (standIds "intruder") standConfigs)
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"intruder: walking\""
|
|
|
|
)))
|
2018-06-08 23:17:03 +00:00
|
|
|
playerWalking <- loadAnimationSprites "assets/intruder.png" nvg
|
2018-07-21 04:43:26 +00:00
|
|
|
(zip (walkIds "intruder") walkConfigs)
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"jdoem: standing\""
|
|
|
|
)))
|
2018-06-16 17:34:17 +00:00
|
|
|
jdoemStanding <- loadAnimationSprites "assets/jdoem.png" nvg
|
2018-07-21 04:43:26 +00:00
|
|
|
(zip (standIds "jdoem") standConfigs)
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"jdoem: walking\""
|
|
|
|
)))
|
2018-06-16 17:34:17 +00:00
|
|
|
jdoemWalking <- loadAnimationSprites "assets/jdoem.png" nvg
|
2018-07-21 04:43:26 +00:00
|
|
|
(zip (walkIds "jdoem") walkConfigs)
|
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"copier: stand\""
|
|
|
|
)))
|
|
|
|
copierStand <- loadAnimationSprites "assets/misc/copier.png" nvg $ zip
|
|
|
|
(map (\name -> AnimId "copier" name N) ["closed", "open"])
|
|
|
|
(map
|
|
|
|
(\i -> AnimationConfig (0, i * 74) (64, 74) (0, 0) 1 0 APLoop)
|
|
|
|
[0, 1]
|
|
|
|
)
|
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"copier: copy\""
|
|
|
|
)))
|
2018-07-30 12:34:46 +00:00
|
|
|
copierCopy <- loadAnimationSprites "assets/misc/copier.png" nvg
|
2018-07-21 04:43:26 +00:00
|
|
|
[ ( AnimId "copier" "copy" N
|
2018-07-22 20:30:17 +00:00
|
|
|
, AnimationConfig (64, 0) (64, 74) (64, 0) 4 1 APLoop
|
2018-07-21 04:43:26 +00:00
|
|
|
)
|
|
|
|
]
|
2018-07-30 12:34:46 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Loading Animation \"computer: off\""
|
|
|
|
)))
|
|
|
|
computerOff <- loadAnimationSprites "assets/misc/tableCornerComputer.png" nvg
|
|
|
|
[ ( AnimId "computer" "off" N
|
|
|
|
, AnimationConfig (0, 0) (64, 74) (64, 0) 2 2 APLoop
|
|
|
|
)
|
|
|
|
]
|
2018-07-19 02:51:07 +00:00
|
|
|
modifyMVar_ progress (return . (\(p, _) ->
|
|
|
|
( p + increment
|
|
|
|
, "Handing over"
|
|
|
|
)))
|
2018-06-16 17:34:17 +00:00
|
|
|
finish
|
2018-06-08 23:17:03 +00:00
|
|
|
putMVar future
|
|
|
|
( ws
|
|
|
|
, LoadData
|
|
|
|
{ loadAssetImages = M.fromList imgs
|
|
|
|
, loadAssetAnims = M.fromList
|
2018-07-21 04:43:26 +00:00
|
|
|
( playerStanding ++
|
|
|
|
playerWalking ++
|
|
|
|
jdoemStanding ++
|
|
|
|
jdoemWalking ++
|
|
|
|
copierStand ++
|
2018-07-30 12:34:46 +00:00
|
|
|
copierCopy ++
|
|
|
|
computerOff
|
2018-07-21 04:43:26 +00:00
|
|
|
)
|
2018-06-08 23:17:03 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
drawLoad :: Affection UserData ()
|
|
|
|
drawLoad = do
|
|
|
|
ud <- getAffection
|
|
|
|
progress <- liftIO $ readMVar (stateProgress ud)
|
2018-06-15 13:39:08 +00:00
|
|
|
liftIO $ do
|
|
|
|
logIO A.Verbose ("LoadProgress: " ++ show progress)
|
|
|
|
drawLoadScreen ud progress
|
2018-06-08 23:17:03 +00:00
|
|
|
|
|
|
|
updateLoad :: Double -> Affection UserData ()
|
|
|
|
updateLoad _ = do
|
|
|
|
ud <- getAffection
|
|
|
|
mwsld <- liftIO $ tryTakeMVar (stateMVar ud)
|
|
|
|
case mwsld of
|
|
|
|
Just (_, ld) -> do
|
|
|
|
liftIO $ logIO A.Debug "loaded assets, entering menu"
|
|
|
|
putAffection ud
|
|
|
|
{ assetImages = loadAssetImages ld
|
|
|
|
, assetAnimations = loadAssetAnims ld
|
2018-06-28 19:07:58 +00:00
|
|
|
, state = Main WorldMap
|
2018-06-08 23:17:03 +00:00
|
|
|
, stateData = None
|
|
|
|
}
|
|
|
|
loadMap
|
2018-07-03 14:19:27 +00:00
|
|
|
Nothing ->
|
2018-06-08 23:17:03 +00:00
|
|
|
return ()
|