Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support markdown in achievement descriptions #1508

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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