mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Added per-game config
This commit is contained in:
parent
2c51aeef1c
commit
e0b288ac68
@ -15,6 +15,7 @@
|
|||||||
#include <SDL3/SDL_video.h>
|
#include <SDL3/SDL_video.h>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
|
#include "common/elf_info.h"
|
||||||
#include "common/io_file.h"
|
#include "common/io_file.h"
|
||||||
#include "common/path_util.h"
|
#include "common/path_util.h"
|
||||||
#include "common/version.h"
|
#include "common/version.h"
|
||||||
@ -210,6 +211,7 @@ std::string getDefaultKeyboardConfig() {
|
|||||||
## SPDX-License-Identifier: GPL-2.0-or-later
|
## SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#Default controller button mappings
|
#Default controller button mappings
|
||||||
|
#I will update this later
|
||||||
|
|
||||||
#Taken keys:
|
#Taken keys:
|
||||||
#F11 : fullscreen
|
#F11 : fullscreen
|
||||||
@ -339,25 +341,36 @@ typename std::map<KeyBinding, T>::const_iterator FindKeyAllowingOnlyNoModifiers(
|
|||||||
return map.end(); // Return end if no match is found
|
return map.end(); // Return end if no match is found
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowSDL::parseInputConfig(const std::string& filename) {
|
void WindowSDL::parseInputConfig() {
|
||||||
// Read configuration file.
|
// Read configuration file of the game, and if it doesn't exist, generate it from default
|
||||||
const auto config_file = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / filename;
|
// If that doesn't exist either, generate that from getDefaultConfig() and try again
|
||||||
if (!std::filesystem::exists(config_file)) {
|
// If even the folder is missing, we start with that.
|
||||||
// create it
|
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "kbmConfig";
|
||||||
std::ofstream file;
|
const auto config_file =
|
||||||
file.open(config_file, std::ios::out);
|
config_dir / (std::string(Common::ElfInfo::Instance().GameSerial()) + ".ini");
|
||||||
if (file.is_open()) {
|
const auto default_config_file = config_dir / "default.ini";
|
||||||
file << getDefaultKeyboardConfig();
|
|
||||||
file.close();
|
// Ensure the config directory exists
|
||||||
std::cout << "Config file generated.\n";
|
if (!std::filesystem::exists(config_dir)) {
|
||||||
} else {
|
std::filesystem::create_directories(config_dir);
|
||||||
std::cerr << "Error creating file!\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
std::ifstream file(config_file);
|
|
||||||
if (!file.is_open()) {
|
// Try loading the game-specific config file
|
||||||
std::cerr << "Error opening file: " << filename << std::endl;
|
if (!std::filesystem::exists(config_file)) {
|
||||||
return;
|
// If game-specific config doesn't exist, check for the default config
|
||||||
|
if (!std::filesystem::exists(default_config_file)) {
|
||||||
|
// If the default config is also missing, create it from getDefaultConfig()
|
||||||
|
const auto default_config = getDefaultKeyboardConfig();
|
||||||
|
std::ofstream default_config_stream(default_config_file);
|
||||||
|
if (default_config_stream) {
|
||||||
|
default_config_stream << default_config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If default config now exists, copy it to the game-specific config file
|
||||||
|
if (std::filesystem::exists(default_config_file)) {
|
||||||
|
std::filesystem::copy(default_config_file, config_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@ -369,6 +382,8 @@ void WindowSDL::parseInputConfig(const std::string& filename) {
|
|||||||
axis_map.clear();
|
axis_map.clear();
|
||||||
key_to_modkey_toggle_map.clear();
|
key_to_modkey_toggle_map.clear();
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
|
|
||||||
|
std::ifstream file(config_file);
|
||||||
std::string line = "";
|
std::string line = "";
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
lineCount++;
|
lineCount++;
|
||||||
@ -600,7 +615,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("keyboardInputConfig.ini");
|
parseInputConfig();
|
||||||
// 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);
|
||||||
@ -706,7 +721,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("keyboardInputConfig.ini");
|
parseInputConfig();
|
||||||
}
|
}
|
||||||
// Toggle mouse capture and movement input
|
// Toggle mouse capture and movement input
|
||||||
else if (binding.key == SDLK_F9) {
|
else if (binding.key == SDLK_F9) {
|
||||||
|
@ -103,7 +103,7 @@ private:
|
|||||||
static Uint32 keyRepeatCallback(void* param, Uint32 id, Uint32 interval);
|
static Uint32 keyRepeatCallback(void* param, Uint32 id, Uint32 interval);
|
||||||
static Uint32 mousePolling(void* param, Uint32 id, Uint32 interval);
|
static Uint32 mousePolling(void* param, Uint32 id, Uint32 interval);
|
||||||
|
|
||||||
void parseInputConfig(const std::string& filename);
|
void parseInputConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
s32 width;
|
s32 width;
|
||||||
|
Loading…
Reference in New Issue
Block a user