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

render scenario description as markdown #1521

Merged
merged 1 commit into from
Sep 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Swarm/Doc/Pedagogy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Swarm.Game.World.Load (loadWorlds)
import Swarm.Language.Module (Module (..))
import Swarm.Language.Pipeline (ProcessedTerm (..))
import Swarm.Language.Syntax
import Swarm.Language.Text.Markdown (findCode)
import Swarm.Language.Text.Markdown (docToText, findCode)
import Swarm.Language.Types (Polytype)
import Swarm.TUI.Controller (getTutorials)
import Swarm.Util.Effect (ignoreWarnings, simpleErrorHandle)
Expand Down Expand Up @@ -175,7 +175,7 @@ renderUsagesMarkdown (CoverageInfo (TutorialInfo (s, si) idx _sCmds dCmds) novel
intercalate
[""]
[ pure . surround "`" . T.pack $ view scenarioPath si
, pure . surround "*" . T.strip $ view scenarioDescription s
, pure . surround "*" . T.strip . docToText $ view scenarioDescription s
, renderSection "Introduced in solution" . renderCmdList $ M.keysSet novelCmds
, renderSection "Referenced in description" $ renderCmdList dCmds
]
Expand Down
6 changes: 4 additions & 2 deletions src/Swarm/Game/Scenario.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import Swarm.Game.Universe
import Swarm.Game.World.Typecheck (WorldMap)
import Swarm.Language.Pipeline (ProcessedTerm)
import Swarm.Language.Pretty (prettyText)
import Swarm.Language.Syntax (Syntax)
import Swarm.Language.Text.Markdown (Document)
import Swarm.Util (binTuples, failT)
import Swarm.Util.Effect (throwToMaybe, withThrow)
import Swarm.Util.Lens (makeLensesNoSigs)
Expand All @@ -94,7 +96,7 @@ data Scenario = Scenario
{ _scenarioVersion :: Int
, _scenarioName :: Text
, _scenarioAuthor :: Maybe Text
, _scenarioDescription :: Text
, _scenarioDescription :: Document Syntax
, _scenarioCreative :: Bool
, _scenarioSeed :: Maybe Int
, _scenarioAttrs :: [CustomAttr]
Expand Down Expand Up @@ -203,7 +205,7 @@ scenarioAuthor :: Lens' Scenario (Maybe Text)

-- | A high-level description of the scenario, shown /e.g./ in the
-- menu.
scenarioDescription :: Lens' Scenario Text
scenarioDescription :: Lens' Scenario (Document Syntax)

-- | Whether the scenario should start in creative mode.
scenarioCreative :: Lens' Scenario Bool
Expand Down
4 changes: 3 additions & 1 deletion src/Swarm/TUI/Editor/Json.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import Data.Yaml as Y
import GHC.Generics (Generic)
import Swarm.Game.Entity (Entity)
import Swarm.Game.Scenario.Topography.WorldDescription
import Swarm.Language.Syntax (Syntax)
import Swarm.Language.Text.Markdown (Document)

data SkeletonScenario = SkeletonScenario
{ version :: Int
, name :: Text
, description :: Text
, description :: Document Syntax
, creative :: Bool
, entities :: [Entity]
, world :: WorldDescriptionPaint
Expand Down
3 changes: 2 additions & 1 deletion src/Swarm/TUI/Editor/Palette.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Swarm.Game.Scenario.Topography.Navigation.Portal (Navigation (..))
import Swarm.Game.Scenario.Topography.WorldPalette
import Swarm.Game.Terrain (TerrainType, getTerrainDefaultPaletteChar)
import Swarm.Game.Universe
import Swarm.Language.Text.Markdown (fromText)
import Swarm.TUI.Editor.Json (SkeletonScenario (SkeletonScenario))
import Swarm.Util (binTuples, histogram)
import Swarm.Util qualified as U
Expand Down Expand Up @@ -116,7 +117,7 @@ constructScenario maybeOriginalScenario cellGrid =
SkeletonScenario
(maybe 1 (^. scenarioVersion) maybeOriginalScenario)
(maybe "My Scenario" (^. scenarioName) maybeOriginalScenario)
(maybe "The scenario description..." (^. scenarioDescription) maybeOriginalScenario)
(maybe (fromText "The scenario description...") (^. scenarioDescription) maybeOriginalScenario)
-- (maybe True (^. scenarioCreative) maybeOriginalScenario)
True
(M.elems $ entitiesByName customEntities)
Expand Down
2 changes: 1 addition & 1 deletion src/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ drawNewGameMenuUI (l :| ls) launchOptions = case displayedFor of
drawDescription (SICollection _ _) = txtWrap " "
drawDescription (SISingle (s, si)) =
vBox
[ txtWrap (nonBlank (s ^. scenarioDescription))
[ drawMarkdown (nonBlank (s ^. scenarioDescription))
, padTop (Pad 1) table
]
where
Expand Down
Loading