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

Split debug options #2094

Merged
merged 9 commits into from
Aug 8, 2024
Merged

Split debug options #2094

merged 9 commits into from
Aug 8, 2024

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Aug 4, 2024

  • replace _uiCheatMode :: Bool with _uiDebugOptions :: (Set DebugOption)
    • replace uiHideGoals with uiIsAutoPlay and debug option ShowGoalDialogsInAutoPlay
  • add command line flag --debug and make --cheat an alias for --debug=creative only
  -x,--cheat               Enable cheat mode. This is an alias for --debug=creative
  -d,--debug OPTS          Use 'all' or a comma separated list of options:
                             * creative           allow toggling creative mode on/off
                             * editor             allow toggling the world editor mode on/off
                             * cesk               allow toggling the CESK debug view on/off
                             * all_robots         list all robots (including system robots) in the robot panel
                             * robot_id           list robot IDs in the robot panel
                             * hidden_goals       show hidden objectives in the goal dialog
                             * autoplay_goals     show goal dialogs when running in autoplay
                             * testing            show Testing folder in scenarios menu

It even has shell completions:

swarm --zsh-completion-script `which swarm` > ~/.oh-my-zsh/completions/_swarm
swarm --debug  # press Tab
# all  all_robots  autoplay_goals  cesk  creative  editor  hidden_goals  robot_id  testing

@xsebek xsebek added the CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. label Aug 4, 2024
@xsebek xsebek requested review from kostmo and byorgey August 4, 2024 13:17
app/game/Main.hs Outdated Show resolved Hide resolved
xsebek added a commit that referenced this pull request Aug 4, 2024
Autopause does not work well,
let's wait for #2094 to clear things up.
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Definitely a big improvement over the status quo.

@@ -64,10 +67,11 @@ cliParser =
pausedAtStart <- paused
autoPlay <- autoplay
speed <- speedFactor
debugOptions <- debug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest something like this:

Suggested change
debugOptions <- debug
initialDebugOptions <- debug
let debugOptions = Set.union cheatMode initialDebugOptions

Then we can get rid of the lambda + record update in the final return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have underestimated the powers of ApplicativeDo after last issues. I will try this. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is not accepted by ApplicativeDo.

app/game/Main.hs:62:13: error:
    • No instance for (Monad Parser) arising from a use of ‘return’

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xsebek what about

debugOptions <- Set.union cheatMode <$> debug

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that also needs a monad. I suppose it makes sense, how else would you write it in a a <$> ... <*> ... style?

I added a comment and made the return a bit nicer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, because it's referring to cheatMode which is the result of a previous action. Actually, I now understand why let debug = Set.union cheatMode ... is not accepted either---for the same reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I don't even understand why the existing code works.

Copy link
Member Author

@xsebek xsebek Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byorgey I imagine GHC constucts a suitable a that puts everything in the right place:

(\c d o -> A (c + d) o) <$> cheat <*> debug <*> others

app/game/Main.hs Outdated Show resolved Hide resolved
src/swarm-tui/Swarm/TUI/Controller/EventHandlers/Main.hs Outdated Show resolved Hide resolved
@xsebek xsebek added the merge me Trigger the merge process of the Pull request. label Aug 8, 2024
@mergify mergify bot merged commit 0804579 into main Aug 8, 2024
12 checks passed
@mergify mergify bot deleted the task/xsebek/debug-options branch August 8, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

better name for --cheat CLI option
2 participants