Skip to content

Commit

Permalink
Make rollex show time
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 `rollex` entity for commands but surprisingly did not show time in UI.
  • Loading branch information
xsebek committed Sep 15, 2024
1 parent 7b99e72 commit bc06667
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 bc06667

Please sign in to comment.