Skip to content

Commit

Permalink
Merge branch 'new-kbm'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaposfos13 committed Nov 14, 2024
2 parents e215530 + 9c81f8e commit e38e75b
Show file tree
Hide file tree
Showing 7 changed files with 1,049 additions and 762 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ set(IMGUI src/imgui/imgui_config.h

set(INPUT src/input/controller.cpp
src/input/controller.h
src/input/input_handler.cpp
src/input/input_handler.h
)

set(EMULATOR src/emulator.cpp
Expand Down
111 changes: 111 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,115 @@ void setDefaultValues() {
gpuId = -1;
}

std::string_view getDefaultKeyboardConfig() {
static std::string_view default_config =
R"(#This is the default keybinding config
#To change per-game configs, modify the CUSAXXXXX.ini files
#To change the default config that applies to new games without already existing configs, modify default.ini
#If you don't like certain mappings, delete, change or comment them out.
#You can add any amount of KBM keybinds to a single controller input,
#but you can use each KBM keybind for one controller input.
#Keybinds used by the emulator (these are unchangeable):
#F11 : fullscreen
#F10 : FPS counter
#F9 : toggle mouse-to-joystick input
# (it overwrites everything else to that joystick, so this is required)
#F8 : reparse keyboard input(this)
#This is a mapping for Bloodborne, inspired by other Souls titles on PC.
#Specifies which joystick the mouse movement controls.
mouse_to_joystick = right;
#Use healing item, change status in inventory
triangle = f;
#Dodge, back in inventory
circle = space;
#Interact, select item in inventory
cross = e;
#Use quick item, remove item in inventory
square = r;
#Emergency extra bullets
up = w, lalt;
up = mousewheelup;
#Change quick item
down = s, lalt;
down = mousewheeldown;
#Change weapon in left hand
left = a, lalt;
left = mousewheelleft;
#Change weapon in right hand
right = d, lalt;
right = mousewheelright;
#Change into 'inventory mode', so you don't have to hold lalt every time you go into menus
modkey_toggle = i, lalt;
#Menu
options = escape;
#Gestures
touchpad = g;
#Transform
l1 = rightbutton, lshift;
#Shoot
r1 = leftbutton;
#Light attack
l2 = rightbutton;
#Heavy attack
r2 = leftbutton, lshift;
#Does nothing
l3 = x;
#Center cam, lock on
r3 = q;
r3 = middlebutton;
#Axis mappings
#Move
axis_left_x_minus = a;
axis_left_x_plus = d;
axis_left_y_minus = w;
axis_left_y_plus = s;
#Change to 'walk mode' by holding the following key:
leftjoystick_halfmode = lctrl;
)";
return default_config;
}
std::filesystem::path getFoolproofKbmConfigFile(const std::string& game_id) {
// 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 even the folder is missing, we start with that.

const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "kbmConfig";
const auto config_file = config_dir / (game_id + ".ini");
const auto default_config_file = config_dir / "default.ini";

// Ensure the config directory exists
if (!std::filesystem::exists(config_dir)) {
std::filesystem::create_directories(config_dir);
}

// Check if the default config exists
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 empty, we only need to execute the function up until this point
if(game_id.empty()) {
return default_config_file;
}

// If game-specific config doesn't exist, create it from the default config
if (!std::filesystem::exists(config_file)) {
std::filesystem::copy(default_config_file, config_file);
}
return config_file;
}

} // namespace Config
3 changes: 3 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ std::string getEmulatorLanguage();

void setDefaultValues();

// todo: name and function location pending
std::filesystem::path getFoolproofKbmConfigFile(const std::string& game_id = "");

// settings
u32 GetLanguage();
}; // namespace Config
Loading

0 comments on commit e38e75b

Please sign in to comment.