Skip to content

Commit

Permalink
Make Rolex show time (#2147)
Browse files Browse the repository at this point in the history
* show time when robot has `time` capability

Prompted by #2146, which used the fancy `rolex` entity for commands but surprisingly did not show time in UI.

You can test it with:
```sh
git cherry-pick ba8dae3  # see before and after adding rolex
cabal run swarm -O0 -- -i data/scenarios/Testing/562-lodestone.yaml --speed 2 --autoplay
```
  • Loading branch information
xsebek authored Sep 15, 2024
1 parent c37334f commit 1edf55d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/swarm-tui/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ import Data.Map qualified as M
import Data.Maybe (catMaybes, fromMaybe, isJust, mapMaybe, maybeToList)
import Data.Semigroup (sconcat)
import Data.Sequence qualified as Seq
import Data.Set qualified as Set (toList)
import Data.Set qualified as Set
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time (NominalDiffTime, defaultTimeLocale, formatTime)
import Network.Wai.Handler.Warp (Port)
import Swarm.Constant
import Swarm.Game.Device (commandCost, commandsForDeviceCaps, enabledCommands, getMap, ingredients)
import Swarm.Game.Device (commandCost, commandsForDeviceCaps, enabledCommands, getCapabilitySet, getMap, ingredients)
import Swarm.Game.Display
import Swarm.Game.Entity as E
import Swarm.Game.Ingredients
Expand Down Expand Up @@ -538,14 +538,12 @@ drawClockDisplay lgTPS gs = hBox . intersperse (txt " ") $ catMaybes [clockWidge
clockWidget = maybeDrawTime (gs ^. temporal . ticks) (gs ^. temporal . paused || lgTPS < 3) gs
pauseWidget = guard (gs ^. temporal . paused) $> txt "(PAUSED)"

-- | Check whether the currently focused robot (if any) has a clock
-- device equipped.
-- | Check whether the currently focused robot (if any) has some kind
-- of a clock device equipped.
clockEquipped :: GameState -> Bool
clockEquipped gs = case focusedRobot gs of
Nothing -> False
Just r
| countByName "clock" (r ^. equippedDevices) > 0 -> True
| otherwise -> False
Just r -> CExecute Time `Set.member` getCapabilitySet (r ^. robotCapabilities)

-- | Format a ticks count as a hexadecimal clock.
drawTime :: TickNumber -> Bool -> String
Expand Down

0 comments on commit 1edf55d

Please sign in to comment.