changed parser parameters to make it possible to use it from the gui

This commit is contained in:
kalaposfos13 2024-10-18 18:04:43 +02:00
parent 942c1d8471
commit 52ad7e0a96
2 changed files with 16 additions and 10 deletions

View File

@ -204,6 +204,7 @@ std::map<KeyBinding, u32> button_map = {};
std::map<KeyBinding, AxisMapping> axis_map = {}; std::map<KeyBinding, AxisMapping> axis_map = {};
std::map<SDL_Keycode, std::pair<SDL_Keymod, bool>> key_to_modkey_toggle_map = {}; std::map<SDL_Keycode, std::pair<SDL_Keymod, bool>> key_to_modkey_toggle_map = {};
// i wrapped it in a function so I can collapse it // i wrapped it in a function so I can collapse it
std::string getDefaultKeyboardConfig() { std::string getDefaultKeyboardConfig() {
std::string default_config = std::string default_config =
@ -272,6 +273,8 @@ axis_left_y_plus = s;
return default_config; return default_config;
} }
// Flags and values for varying purposes // Flags and values for varying purposes
int mouse_joystick_binding = 0; int mouse_joystick_binding = 0;
float mouse_deadzone_offset = 0.5, mouse_speed = 1, mouse_speed_offset = 0.125; float mouse_deadzone_offset = 0.5, mouse_speed = 1, mouse_speed_offset = 0.125;
@ -308,13 +311,12 @@ SDL_Keymod KeyBinding::getCustomModState() {
return state; return state;
} }
void parseInputConfig() { void parseInputConfig(const std::string game_id = "") {
// Read configuration file of the game, and if it doesn't exist, generate it from default // Read configuration file of the game, and if it doesn't exist, generate it from default
// If that doesn't exist either, generate that from getDefaultConfig() and try again // If that doesn't exist either, generate that from getDefaultConfig() and try again
// If even the folder is missing, we start with that. // If even the folder is missing, we start with that.
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "kbmConfig"; const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "kbmConfig";
const auto config_file = const auto config_file = config_dir / (game_id + ".ini");
config_dir / (std::string(Common::ElfInfo::Instance().GameSerial()) + ".ini");
const auto default_config_file = config_dir / "default.ini"; const auto default_config_file = config_dir / "default.ini";
// Ensure the config directory exists // Ensure the config directory exists
@ -327,7 +329,7 @@ void parseInputConfig() {
// If game-specific config doesn't exist, check for the default config // If game-specific config doesn't exist, check for the default config
if (!std::filesystem::exists(default_config_file)) { if (!std::filesystem::exists(default_config_file)) {
// If the default config is also missing, create it from getDefaultConfig() // If the default config is also missing, create it from getDefaultConfig()
const auto default_config = getDefaultKeyboardConfig(); const auto default_config = getDefaultKeyboardConfig();
std::ofstream default_config_stream(default_config_file); std::ofstream default_config_stream(default_config_file);
if (default_config_stream) { if (default_config_stream) {
default_config_stream << default_config; default_config_stream << default_config;
@ -335,10 +337,14 @@ void parseInputConfig() {
} }
// If default config now exists, copy it to the game-specific config file // If default config now exists, copy it to the game-specific config file
if (std::filesystem::exists(default_config_file)) { if (std::filesystem::exists(default_config_file) && !game_id.empty()) {
std::filesystem::copy(default_config_file, config_file); std::filesystem::copy(default_config_file, config_file);
} }
} }
// if we just called the function to generate the directory and the default .ini
if(game_id.empty()) {
return;
}
// we reset these here so in case the user fucks up or doesn't include this we can fall back to // we reset these here so in case the user fucks up or doesn't include this we can fall back to
// default // default
@ -467,14 +473,14 @@ void parseInputConfig() {
file.close(); file.close();
} }
} // namespace KBMConfig }
namespace Frontend { namespace Frontend {
using Libraries::Pad::OrbisPadButtonDataOffset; using Libraries::Pad::OrbisPadButtonDataOffset;
using namespace KBMConfig; using namespace KBMConfig;
using KBMConfig::AxisMapping;
using KBMConfig::KeyBinding; using KBMConfig::KeyBinding;
using KBMConfig::AxisMapping;
// modifiers are bitwise or-d together, so we need to check if ours is in that // modifiers are bitwise or-d together, so we need to check if ours is in that
template <typename T> template <typename T>
@ -615,7 +621,7 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, Input::GameController* controller_
window_info.render_surface = SDL_Metal_GetLayer(SDL_Metal_CreateView(window)); window_info.render_surface = SDL_Metal_GetLayer(SDL_Metal_CreateView(window));
#endif #endif
// initialize kbm controls // initialize kbm controls
parseInputConfig(); parseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
// Start polling the mouse // Start polling the mouse
if (mouse_polling_id == 0) { if (mouse_polling_id == 0) {
mouse_polling_id = SDL_AddTimer(33, mousePolling, (void*)this); mouse_polling_id = SDL_AddTimer(33, mousePolling, (void*)this);
@ -721,7 +727,7 @@ void WindowSDL::onKeyboardMouseEvent(const SDL_Event* event) {
if (event->type == SDL_EVENT_KEY_DOWN) { if (event->type == SDL_EVENT_KEY_DOWN) {
// Reparse kbm inputs // Reparse kbm inputs
if (binding.key == SDLK_F8) { if (binding.key == SDLK_F8) {
parseInputConfig(); parseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
} }
// Toggle mouse capture and movement input // Toggle mouse capture and movement input
else if (binding.key == SDLK_F9) { else if (binding.key == SDLK_F9) {

View File

@ -19,7 +19,7 @@ class GameController;
namespace KBMConfig { namespace KBMConfig {
std::string getDefaultKeyboardConfig(); std::string getDefaultKeyboardConfig();
void parseInputConfig(); void parseInputConfig(const std::string game_id);
class KeyBinding { class KeyBinding {
public: public: