Skip to content

Commit

Permalink
Support markdown in achievement descriptions (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 10, 2023
1 parent f9a1c31 commit 318b939
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Swarm/Game/Achievement/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Swarm.Game.Achievement.Definitions (
import Data.Aeson
import Data.Text (Text)
import GHC.Generics (Generic)
import Swarm.Language.Syntax (Syntax)
import Swarm.Language.Text.Markdown (Document)
import Swarm.Util

-- | How hard do we expect the achievement to be?
Expand All @@ -39,7 +41,7 @@ data Quotation = Quotation
-- | Flavor text to spice up the description of an achievement, either
-- freeform text or a quotation.
data FlavorText
= Freeform Text
= Freeform (Document Syntax)
| FTQuotation Quotation
deriving (Eq, Show, Generic, FromJSON, ToJSON)

Expand All @@ -58,7 +60,7 @@ data AchievementInfo = AchievementInfo
-- ^ Explain the reference, e.g. in the form of a full quote
-- from a movie, or something you might find
-- in a fortune cookie
, attainmentProcess :: Text
, attainmentProcess :: Document Syntax
-- ^ Precisely what must be done to obtain this achievement.
, effort :: ExpectedEffort
-- ^ How hard the achievement is expected to be.
Expand Down
2 changes: 1 addition & 1 deletion src/Swarm/Game/Achievement/Description.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ describe = \case
"Lil Jon"
"Fire up that loud / Another round of shots / Turn down for what?"
)
"'turn down' without a compass. Congratulations, you are 'disoriented'. How are you supposed to move now?"
"`turn down` without a compass. Congratulations, you are \"disoriented\". How are you supposed to move now?"
Easy
True
10 changes: 5 additions & 5 deletions src/Swarm/TUI/View/Achievement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Swarm.Game.Achievement.Description
import Swarm.TUI.Model
import Swarm.TUI.Model.UI
import Swarm.TUI.View.Attribute.Attr
import Swarm.TUI.View.Util (drawMarkdown)
import Text.Wrap

padAllEvenly :: Int -> Widget Name -> Widget Name
Expand Down Expand Up @@ -66,7 +67,7 @@ singleAchievementDetails attainedMap x =
wasAttained = M.member x attainedMap

renderFlavorTextWidget :: FlavorText -> Widget Name
renderFlavorTextWidget (Freeform t) = txtWrap t
renderFlavorTextWidget (Freeform t) = drawMarkdown t
renderFlavorTextWidget (FTQuotation (Quotation author quoteContent)) =
vBox
[ txtWrap quoteContent
Expand All @@ -79,10 +80,9 @@ singleAchievementDetails attainedMap x =
innerContent =
vBox
[ maybe emptyWidget (padAllEvenly 2 . renderFlavorTextWidget) $ humorousElaboration details
, txtWrap $
if wasAttained || not (isObfuscated details)
then attainmentProcess details
else "???"
, if wasAttained || not (isObfuscated details)
then drawMarkdown $ attainmentProcess details
else txt "???"
, case M.lookup x attainedMap of
Nothing -> emptyWidget
Just attainment ->
Expand Down

0 comments on commit 318b939

Please sign in to comment.