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

Added in feature to assign keyboard or gamepad with the -N or -R option #5230

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ namespace UserConfigParams

PARAM_PREFIX bool m_race_now PARAM_DEFAULT( false );

PARAM_PREFIX int m_default_keyboard PARAM_DEFAULT( -1 );

PARAM_PREFIX int m_default_gamepad PARAM_DEFAULT( -1 );

PARAM_PREFIX bool m_enforce_current_player PARAM_DEFAULT( false );

PARAM_PREFIX bool m_enable_sound PARAM_DEFAULT( true );
Expand Down
33 changes: 28 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,21 @@ void setupRaceStart()

InputDevice *device;

// Use keyboard 0 by default in --no-start-screen
device = input_manager->getDeviceManager()->getKeyboard(0);
// Assign the player a device; check the command line params for preferences; by default use keyboard 0

// Create player and associate player with keyboard
if(UserConfigParams::m_default_keyboard > -1) {
device = input_manager->getDeviceManager()->getKeyboard(UserConfigParams::m_default_keyboard);
}
else if(UserConfigParams::m_default_gamepad > -1) {
// getGamePad(int) returns a GamePadDevice which is a subclass of InputDevice
// However, the compiler doesn't like it so it has to be manually casted in
device = (InputDevice *) input_manager->getDeviceManager()->getGamePad(UserConfigParams::m_default_gamepad);
}
else {
device = input_manager->getDeviceManager()->getKeyboard(0);
}

// Create player and associate player with device
StateManager::get()->createActivePlayer(
PlayerManager::get()->getPlayer(0), device);

Expand Down Expand Up @@ -557,10 +568,14 @@ void cmdLineHelp()
"menu.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase"
" and the music.\n"
" --use-keyboard=N Used in conjunction with the -N or -R option, will assign the player to the specified"
" keyboard. Is zero indexed.\n"
" --use-gamepad=N Used in conjunction with the -N or -R option, will assign the player to the specified"
" gamepad. Is zero indexed.\n"
" -t, --track=NAME Start track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n"
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n"
"in config.xml under additional_gp_directory. Use\n"
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved"
"in config.xml under additional_gp_directory. Use"
"--add-gp-dir=\"\" to unset.\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
Expand Down Expand Up @@ -1675,6 +1690,14 @@ int handleCmdLine(bool has_server_config, bool has_parent_process)
UserConfigParams::m_race_now = true;
} // --race-now

if(CommandLine::has( "--use-keyboard",&n)) {
UserConfigParams::m_default_keyboard = n;
} //--use-keyboard

if(CommandLine::has( "--use-gamepad",&n)) {
UserConfigParams::m_default_gamepad = n;
} //--use-gamepad

if(CommandLine::has("--laps", &s))
{
int laps = atoi(s.c_str());
Expand Down
Loading