Skip to content

Commit

Permalink
Very first step towards handling Event
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Apr 26, 2020
1 parent a8b21de commit ca6147e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ai/src/Card.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ creatureUI2CreatureCore Creature {creatureId, hp, attack, moral, victoryPoints,
card2Creature :: Card p -> Maybe (Creature p)
card2Creature =
\case
CreatureCard creature -> Just $ creature
CreatureCard creature -> Just creature
NeutralCard _ -> Nothing
ItemCard _ -> Nothing

Expand Down
41 changes: 21 additions & 20 deletions ai/ui/MainUi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pictureSize picture =
data Assets
= Assets
{ backgroundPics :: NE.NonEmpty Picture,
creaturePics :: Map.Map CreatureID Picture
creaturePics :: Map.Map CreatureID Picture,
cardOverlay :: Picture
}

getOrThrow ::
Expand All @@ -84,30 +85,25 @@ getOrThrow ma e =
Nothing -> throw e
Just a -> return a

loadOrThrowJuicyPNG :: (MonadIO m, MonadThrow m) => FilePath -> m Picture
loadOrThrowJuicyPNG filepath = do
maybePic <- liftIO $ loadJuicyPNG filepath
pic :: Picture <- getOrThrow maybePic $ LoadException filepath
return pic

loadBackgrounds ::
(MonadIO m, MonadThrow m) =>
m (NE.NonEmpty Picture)
loadBackgrounds = do
let pics = NE.map loadBackground backgrounds
let pics = NE.map loadOrThrowJuicyPNG backgrounds
traverse Prelude.id pics
where
loadBackground :: (MonadIO m, MonadThrow m) => FilePath -> m Picture
loadBackground filepath = do
maybePic <- liftIO $ loadJuicyPNG filepath
pic :: Picture <- getOrThrow maybePic $ LoadException filepath
return pic

loadCreature ::
(MonadIO m, MonadThrow m) =>
CreatureID ->
m Picture
loadCreature creatureID = do
maybePic <- liftIO $ loadJuicyPNG path
case maybePic of
Nothing -> throw $ CreatureLoadException path creatureID
Just pic -> return pic
where
path = creatureID2FilePath creatureID
loadCreature creatureID =
loadOrThrowJuicyPNG $ creatureID2FilePath creatureID

-- | Loads backgrounds and creatures assets from disk
loadAssets ::
Expand All @@ -117,7 +113,12 @@ loadAssets ::
loadAssets uiData = do
bgs <- loadBackgrounds
assocList <- liftIO $ traverse entryMaker uiData
return $ Assets bgs $ Map.fromListWith handleDuplicate assocList
cardOverlay <- loadOrThrowJuicyPNG $ assetsGenPath ++ "/" ++ "card-overlay.png"
return $
Assets
bgs
(Map.fromListWith handleDuplicate assocList)
cardOverlay
where
entryMaker :: CreatureID -> IO (CreatureID, Picture)
entryMaker id = do
Expand All @@ -129,9 +130,9 @@ loadAssets uiData = do
pictureBoard ::
HasCallStack =>
Assets ->
Board ->
(Board, Maybe Event) ->
Picture
pictureBoard assets board =
pictureBoard assets (board, maybeEvent) =
mconcat (bg : cards')
where
bg :: Picture = NE.head $ backgroundPics assets
Expand Down Expand Up @@ -202,7 +203,7 @@ mainPlay assets cards =
liftIO $ play display' white fps world drawer eventHandler stepper
where
board = exampleBoard cards
boardPicture = pictureBoard assets board
boardPicture = pictureBoard assets (board, Nothing)
world = World board
(framex, framey) = pictureSize boardPicture
display' = InWindow gameName (round framex, round framey) (0, 0)
Expand All @@ -217,7 +218,7 @@ mainUI ::
[Card UI] ->
m ()
mainUI assets cards = do
let pic = pictureBoard assets board
let pic = pictureBoard assets (board, Nothing)
pic' = Scale 0.66 0.66 pic
picSize = pictureSize pic'
liftIO $ display (InWindow gameName (both ceiling picSize) (0, 0)) white pic'
Expand Down
Binary file added assets/card-overlay.xcf
Binary file not shown.

0 comments on commit ca6147e

Please sign in to comment.