cache scenario preview widget (#2143)

Fixes the lag issue noted in #1515.

# Demo

1. First, launch a toplevel scenario:
    ```
    scripts/play.sh -i data/scenarios/blank.yaml
    ```
2. Then use <kbd>Ctrl</kbd>+<kbd>q</kbd> to quit to the scenario selection menu.
3. Notice when using up-arrow to select the "Classic" and "Creative" scenarios, there is a delay as the preview is computed for the first time.
4. Finally, when subsequently selecting back and forth between the two again, notice that the lag is gone, as the cache is being used.
This commit is contained in:
Karl Ostmo 2024-09-10 07:25:43 -07:00 committed by GitHub
parent 9270ff8eb9
commit 7b99e721a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -92,6 +92,8 @@ data Name
InventoryList
| -- | The inventory item position in the InventoryList.
InventoryListItem Int
| -- | Cacheable scenario preview
ScenarioPreview FilePath
| -- | The list of main menu choices.
MenuList
| -- | The list of achievements.

View File

@ -17,9 +17,6 @@ module Swarm.TUI.View (
drawModalMenu,
drawKeyCmd,
-- * World
drawWorldPane,
-- * Robot panel
drawRobotPanel,
drawItem,
@ -255,7 +252,9 @@ drawNewGameMenuUI (l :| ls) launchOptions = case displayedFor of
drawDescription (SISingle (s, si)) =
vBox
[ drawMarkdown (nonBlank (s ^. scenarioOperation . scenarioDescription))
, hCenter . padTop (Pad 1) . vLimit 6 $ hLimitPercent 60 worldPeek
, cached (ScenarioPreview $ si ^. scenarioPath) $
hCenter . padTop (Pad 1) . vLimit 6 $
hLimitPercent 60 worldPeek
, padTop (Pad 1) table
]
where