This commit is contained in:
nek0 2018-03-01 23:33:08 +01:00
parent b7e0363647
commit c469761bd8
3 changed files with 21 additions and 0 deletions

View file

@ -55,6 +55,8 @@ load = do
mwalltsw <- createImage nvg (FileName "assets/walls/wall_t_sw.png") 0
mwalltnw <- createImage nvg (FileName "assets/walls/wall_t_nw.png") 0
mwallcross <- createImage nvg (FileName "assets/walls/wall_cross.png") 0
_ <- createFont nvg "bedstead"
(FileName "assets/font/Bedstead-Semicondensed.ttf")
let mwalls = [ mwallasc, mwalldesc,
mwallcornern, mwallcornere, mwallcorners, mwallcornerw,
mwalltne, mwalltse, mwalltsw, mwalltnw,
@ -68,6 +70,9 @@ load = do
, subsystems = subs
, assetImages = M.fromList
walls
, assetFonts = M.fromList
[ (FontBedstead, "bedstead")
]
, nano = nvg
, uuid = []
, worldState = ws

View file

@ -10,6 +10,8 @@ import Control.Monad (when, void)
import Control.Monad.IO.Class (liftIO)
import Data.Map.Strict as Map
import qualified Data.Set as S
import qualified Data.Text as T
import Data.Matrix as M (toLists, (!), Matrix, safeGet)
import Data.Ecstasy as E
@ -95,9 +97,17 @@ movePlayer _ = return ()
drawMap :: Affection UserData ()
drawMap = do
ud <- getAffection
dt <- getDelta
let matrix = mapMat (stateData ud)
mapM_ (\(i, ls) -> mapM_ (uncurry $ drawTile i) (reverse $ zip [1..] ls))
(zip [1..] (toLists matrix))
liftIO $ do
let ctx = nano ud
fontSize ctx 20
fontFace ctx (assetFonts ud Map.! FontBedstead)
textAlign ctx (S.fromList [AlignCenter,AlignTop])
fillColor ctx (rgb 255 128 0)
textBox ctx 0 0 200 ("FPS: " `T.append` (T.pack $ Prelude.take 5 $ show (1/dt)))
updateMap :: Double -> Affection UserData ()
updateMap dt = do

View file

@ -10,6 +10,7 @@ import Control.Concurrent.STM
import NanoVG hiding (V2(..), V3(..))
import qualified Data.Map.Strict as M
import qualified Data.Text as T
import Data.Matrix
import Data.Ecstasy
@ -19,6 +20,7 @@ data UserData = UserData
{ state :: State
, subsystems :: Subsystems
, assetImages :: M.Map ImgId Image
, assetFonts :: M.Map FontId T.Text
, nano :: Context
, uuid :: [UUID]
, worldState :: SystemState Entity
@ -50,6 +52,10 @@ data ImgId
| ImgWallCross
deriving (Show, Eq, Ord, Enum)
data FontId
= FontBedstead
deriving (Show, Eq, Ord, Enum)
data Direction
= N
| W