Implemented Input Binding Serialisation #304

Merged
mushgunAX merged 4 commits from SP3-10-input-management into main 2023-01-09 16:56:59 +08:00
2 changed files with 6 additions and 19 deletions
Showing only changes of commit 4123e76a7d - Show all commits

View File

@ -102,6 +102,8 @@ namespace SHADE
//The Binding File format presently goes as such: //The Binding File format presently goes as such:
/* /*
* Binding count
* (For each binding:)
* Name * Name
Binding Type Enum Binding Type Enum
Inverted Bool Inverted Bool
@ -121,7 +123,7 @@ namespace SHADE
void SHInputManager::SaveBindings(std::string const& targetFile) noexcept void SHInputManager::SaveBindings(std::string const& targetFile) noexcept
{ {
std::ofstream file; std::ofstream file;
file.open("../../Assets/Bindings.SHConfig"); file.open(targetFile);
//File cannot be written to //File cannot be written to
if (!file) return; if (!file) return;
@ -165,7 +167,7 @@ namespace SHADE
void SHInputManager::LoadBindings(std::string const& sourceFile) noexcept void SHInputManager::LoadBindings(std::string const& sourceFile) noexcept
{ {
std::ifstream file; std::ifstream file;
file.open("../../Assets/Bindings.SHConfig"); file.open(sourceFile);
//Check //Check
if (!file) return; if (!file) return;
@ -185,82 +187,67 @@ namespace SHADE
{ {
//Name //Name
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Binding Name: {}", read);
bindingName = read; bindingName = read;
AddBinding(bindingName); AddBinding(bindingName);
//Type //Type
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Binding Type: {}", read);
SetBindingType(bindingName, static_cast<SH_BINDINGTYPE>(std::stoi(read))); SetBindingType(bindingName, static_cast<SH_BINDINGTYPE>(std::stoi(read)));
//Inversion //Inversion
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Inversion: {}", read);
SetBindingInverted(bindingName, static_cast<bool>(std::stoi(read))); SetBindingInverted(bindingName, static_cast<bool>(std::stoi(read)));
//Gravity //Gravity
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Gravity: {}", read);
SetBindingGravity(bindingName, std::stod(read)); SetBindingGravity(bindingName, std::stod(read));
//Dead //Dead
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Dead: {}", read);
SetBindingDead(bindingName, std::stod(read)); SetBindingDead(bindingName, std::stod(read));
//Sensitivity //Sensitivity
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Sensitivity: {}", read);
SetBindingSensitivity(bindingName, std::stod(read)); SetBindingSensitivity(bindingName, std::stod(read));
//Snap //Snap
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Snap: {}", read);
SetBindingSnap(bindingName, static_cast<bool>(std::stoi(read))); SetBindingSnap(bindingName, static_cast<bool>(std::stoi(read)));
int count = 0; int count = 0;
//Positive Key Codes //Positive Key Codes
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Positive Key Count: {}", read);
count = std::stoi(read); count = std::stoi(read);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Positive Key: {}", read);
AddBindingPositiveKeyCode(bindingName, static_cast<SH_KEYCODE>(std::stoi(read))); AddBindingPositiveKeyCode(bindingName, static_cast<SH_KEYCODE>(std::stoi(read)));
} }
//Negative Key Codes //Negative Key Codes
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Negative Key Count: {}", read);
count = std::stoi(read); count = std::stoi(read);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Negative Key: {}", read);
AddBindingNegativeKeyCode(bindingName, static_cast<SH_KEYCODE>(std::stoi(read))); AddBindingNegativeKeyCode(bindingName, static_cast<SH_KEYCODE>(std::stoi(read)));
} }
//Positive Controller Codes //Positive Controller Codes
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Positive Controller Count: {}", read);
count = std::stoi(read); count = std::stoi(read);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Positive Controller: {}", read);
AddBindingPositiveControllerCode(bindingName, static_cast<SH_CONTROLLERCODE>(std::stoi(read))); AddBindingPositiveControllerCode(bindingName, static_cast<SH_CONTROLLERCODE>(std::stoi(read)));
} }
//Negative Controller Codes //Negative Controller Codes
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Negative Controller Count: {}", read);
count = std::stoi(read); count = std::stoi(read);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
std::getline(file, read); std::getline(file, read);
SHLOGV_CRITICAL("Negative Controller: {}", read);
AddBindingNegativeControllerCode(bindingName, static_cast<SH_CONTROLLERCODE>(std::stoi(read))); AddBindingNegativeControllerCode(bindingName, static_cast<SH_CONTROLLERCODE>(std::stoi(read)));
} }
} }

View File

@ -686,11 +686,11 @@ namespace SHADE
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
//Save bindings registered into a file //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 //Load and register bindings from a file
//The current list of bindings will be overwritten, so save them somewhere else before loading //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 */ /* Binding Functions */