From 4123e76a7d991add7f03f57b2b6ba9512b5f92b0 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sun, 8 Jan 2023 21:36:19 +0800 Subject: [PATCH] Checking Input Binding I/O --- SHADE_Engine/src/Input/SHInputManager.cpp | 21 ++++----------------- SHADE_Engine/src/Input/SHInputManager.h | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index a94b66d4..b8f329b9 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -102,6 +102,8 @@ namespace SHADE //The Binding File format presently goes as such: /* + * Binding count + * (For each binding:) * Name Binding Type Enum Inverted Bool @@ -121,7 +123,7 @@ namespace SHADE void SHInputManager::SaveBindings(std::string const& targetFile) noexcept { std::ofstream file; - file.open("../../Assets/Bindings.SHConfig"); + file.open(targetFile); //File cannot be written to if (!file) return; @@ -165,7 +167,7 @@ namespace SHADE void SHInputManager::LoadBindings(std::string const& sourceFile) noexcept { std::ifstream file; - file.open("../../Assets/Bindings.SHConfig"); + file.open(sourceFile); //Check if (!file) return; @@ -185,82 +187,67 @@ namespace SHADE { //Name std::getline(file, read); - SHLOGV_CRITICAL("Binding Name: {}", read); bindingName = read; AddBinding(bindingName); //Type std::getline(file, read); - SHLOGV_CRITICAL("Binding Type: {}", read); SetBindingType(bindingName, static_cast(std::stoi(read))); //Inversion std::getline(file, read); - SHLOGV_CRITICAL("Inversion: {}", read); SetBindingInverted(bindingName, static_cast(std::stoi(read))); //Gravity std::getline(file, read); - SHLOGV_CRITICAL("Gravity: {}", read); SetBindingGravity(bindingName, std::stod(read)); //Dead std::getline(file, read); - SHLOGV_CRITICAL("Dead: {}", read); SetBindingDead(bindingName, std::stod(read)); //Sensitivity std::getline(file, read); - SHLOGV_CRITICAL("Sensitivity: {}", read); SetBindingSensitivity(bindingName, std::stod(read)); //Snap std::getline(file, read); - SHLOGV_CRITICAL("Snap: {}", read); SetBindingSnap(bindingName, static_cast(std::stoi(read))); int count = 0; //Positive Key Codes std::getline(file, read); - SHLOGV_CRITICAL("Positive Key Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Positive Key: {}", read); AddBindingPositiveKeyCode(bindingName, static_cast(std::stoi(read))); } //Negative Key Codes std::getline(file, read); - SHLOGV_CRITICAL("Negative Key Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Negative Key: {}", read); AddBindingNegativeKeyCode(bindingName, static_cast(std::stoi(read))); } //Positive Controller Codes std::getline(file, read); - SHLOGV_CRITICAL("Positive Controller Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Positive Controller: {}", read); AddBindingPositiveControllerCode(bindingName, static_cast(std::stoi(read))); } //Negative Controller Codes std::getline(file, read); - SHLOGV_CRITICAL("Negative Controller Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Negative Controller: {}", read); AddBindingNegativeControllerCode(bindingName, static_cast(std::stoi(read))); } } diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 977a2d08..01ef6c42 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -686,11 +686,11 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Save bindings registered into a file - static void SaveBindings(std::string const& targetFile = "Assets/InputBindings.SHConfig") noexcept; + static void SaveBindings(std::string const& targetFile = "../../Assets/Bindings.SHConfig") noexcept; //Load and register bindings from a file //The current list of bindings will be overwritten, so save them somewhere else before loading - static void LoadBindings(std::string const& sourceFile = "Assets/InputBindings.SHConfig") noexcept; + static void LoadBindings(std::string const& sourceFile = "../../Assets/Bindings.SHConfig") noexcept; /*------------------------------------------------------------------------*/ /* Binding Functions */