-
Notifications
You must be signed in to change notification settings - Fork 53
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
Hide robots for two seconds #802
Conversation
xsebek
commented
Oct 29, 2022
- closes A way to "peek" under the robots #761
Co-authored-by: Restyled.io <commits@restyled.io>
Otherwise they aren't hidden until the next time the world gets redrawn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me after the small fix I pushed. Take a look and see what you think.
src/Swarm/TUI/Controller.hs
Outdated
@@ -261,7 +261,8 @@ handleMainEvent ev = do | |||
MetaKey 'h' -> do | |||
t <- liftIO $ getTime Monotonic | |||
uiState . uiHideRobotsUntil .= t + TimeSpec 2 0 -- hide for two seconds | |||
-- pausing and stepping | |||
invalidateCacheEntry WorldCache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xsebek I wondered why it took up to a second or so for robots to disappear after I hit M-h. Then I figured it out --- we try hard NOT to redraw the world on every event because it is slow. So when the world actually needs to be redrawn we have to signal it explicitly. I fixed it by calling invalidateCacheEntry WorldCache
here.
I also realized we should do the same fix for Ctrl-v. Don't know whether you want to just include that fix with this PR or put it in a separate one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I originally had code to not change anything for one second.
Might as well include it again if some player decides to hold down the H key. 😅
robots = | ||
if showRobots | ||
then map (view robotDisplay) (robotsAtLocation (W.coordsToLoc coords) g) | ||
else [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much cleaner than my original code, thanks. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STAN shows me warnings about unsafe functions in HLS and in this case, it got me thinking about refactoring to use the NonEmpty
list constructor instead of fromList
.
I usually just ignore them (they are not intrusive) but here it worked nicely. 😁
Co-authored-by: Restyled.io <commits@restyled.io>