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

CRAB: Add Debug output for Keymaps #5416

Merged
merged 1 commit into from Nov 13, 2023

Conversation

Brakkugit
Copy link
Contributor

@Brakkugit Brakkugit commented Nov 12, 2023

Now keymap being used can be known by typing "what keymap" in the debugger console

Copy link
Contributor

coderabbitai bot commented Nov 12, 2023

Walkthrough

Walkthrough

The Crab engine's Console class has been updated with a new function named cmdWhat. This function is designed to handle the "what" command, which allows users to query and print the current key binding mode. The Console constructor has also been modified to register this new command. Additionally, there's an inclusion of a new header file for input handling in one of the diffs, suggesting enhancements to input management.

Changes

File Change Summary
.../crab/console.cpp Introduced cmdWhat function to handle "what" command and updated constructor to register this command. Included "crab/input/input.h" and added using directive for Crab::pyrodactyl::input in one of the diffs.
.../crab/console.h Added new cmdWhat function with standard command function signature (int argc, const char **argv) returning a boolean.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Comment on lines 62 to 86
bool Console::cmdWrite(int argc, const char **argv) {
using namespace Crab::pyrodactyl::input;

if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (!scumm_stricmp(argv[i], "keymap")) {

switch (g_engine->_inputManager->getKeyBindingMode()) {
case KBM_NONE:
debugPrintf("KBM_NONE\n");
break;
case KBM_GAME:
debugPrintf("KBM_GAME\n");
break;
case KBM_UI:
debugPrintf("KBM_UI\n");
break;
default:
debugPrintf("Unknown KBM\n");
break;
}
} else
debugPrintf("Valid parameters are 'keymap'\n");
return true;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The cmdWrite function is implemented correctly. It checks for the "keymap" argument and prints the current key binding mode. However, the return true; statement is inside the for loop, which means the function will return after processing the first argument, even if there are more arguments. This should be corrected.

- return true;

Move the return true; statement outside the for loop.

+ return true;

Comment on lines 62 to 86
bool Console::cmdWrite(int argc, const char **argv) {
using namespace Crab::pyrodactyl::input;

if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (!scumm_stricmp(argv[i], "keymap")) {

switch (g_engine->_inputManager->getKeyBindingMode()) {
case KBM_NONE:
debugPrintf("KBM_NONE\n");
break;
case KBM_GAME:
debugPrintf("KBM_GAME\n");
break;
case KBM_UI:
debugPrintf("KBM_UI\n");
break;
default:
debugPrintf("Unknown KBM\n");
break;
}
} else
debugPrintf("Valid parameters are 'keymap'\n");
}
}
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The cmdWrite method is implemented correctly. It checks for the "keymap" argument and prints the current key binding mode. However, it might be more user-friendly to provide a more descriptive message when the key binding mode is printed. For example, instead of just printing "KBM_GAME", you could print "The current key binding mode is KBM_GAME".

- debugPrintf("KBM_GAME\n");
+ debugPrintf("The current key binding mode is KBM_GAME.\n");

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
bool Console::cmdWrite(int argc, const char **argv) {
using namespace Crab::pyrodactyl::input;
if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (!scumm_stricmp(argv[i], "keymap")) {
switch (g_engine->_inputManager->getKeyBindingMode()) {
case KBM_NONE:
debugPrintf("KBM_NONE\n");
break;
case KBM_GAME:
debugPrintf("KBM_GAME\n");
break;
case KBM_UI:
debugPrintf("KBM_UI\n");
break;
default:
debugPrintf("Unknown KBM\n");
break;
}
} else
debugPrintf("Valid parameters are 'keymap'\n");
}
}
return true;
}
bool Console::cmdWrite(int argc, const char **argv) {
using namespace Crab::pyrodactyl::input;
if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (!scumm_stricmp(argv[i], "keymap")) {
switch (g_engine->_inputManager->getKeyBindingMode()) {
case KBM_NONE:
debugPrintf("KBM_NONE\n");
break;
case KBM_GAME:
debugPrintf("The current key binding mode is KBM_GAME.\n");
break;
case KBM_UI:
debugPrintf("KBM_UI\n");
break;
default:
debugPrintf("Unknown KBM\n");
break;
}
} else
debugPrintf("Valid parameters are 'keymap'\n");
}
}
return true;
}

}

}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

The cmdWhat method should return true on successful execution, not 0. This is because the method's return type is bool.

- return 0;
+ return true;

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
return 0;
return true;

@Brakkugit Brakkugit force-pushed the enterissuebranch branch 2 times, most recently from 3d16fc6 to a6912f6 Compare November 13, 2023 10:04
Now keymap being used can known by typing "what keymap" in the debugger
console.
Comment on lines +60 to +85
bool Console::cmdWhat(int argc, const char **argv) {
if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (!scumm_stricmp(argv[i], "keymap")) {
switch (g_engine->_inputManager->getKeyBindingMode()) {
case KBM_NONE:
debugPrintf("KBM_NONE\n");
break;

case KBM_GAME:
debugPrintf("KBM_GAME\n");
break;

case KBM_UI:
debugPrintf("KBM_UI\n");
break;

default:
debugPrintf("Unknown KBM\n");
break;
}
} else
debugPrintf("Valid parameters are 'keymap'\n");
}
}
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of the cmdWhat function appears to be correct and follows the established pattern for command functions in the ScummVM debugger console. However, the loop over argv is unnecessary if the command only supports a single argument "keymap". This could be simplified to a single check against argv[1]. Additionally, the default case in the switch statement could be enhanced by printing out the actual value of the unknown key binding mode, which would aid in debugging if new key binding modes are added in the future.

bool Console::cmdWhat(int argc, const char **argv) {
    if (argc == 2 && !scumm_stricmp(argv[1], "keymap")) {
        switch (g_engine->_inputManager->getKeyBindingMode()) {
            // ... existing cases ...
            default:
                debugPrintf("Unknown KBM: %d\n", g_engine->_inputManager->getKeyBindingMode());
                break;
        }
    } else {
        debugPrintf("Valid parameters are 'keymap'\n");
    }
    return true;
}
---end hunk 1---


<!-- This is an auto-generated comment by CodeRabbit -->

@hax0kartik
Copy link
Contributor

LGTM, merging! Thanks for the good work.

@hax0kartik hax0kartik merged commit 0a7ba01 into scummvm:master Nov 13, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants