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:
/*
* 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<SH_BINDINGTYPE>(std::stoi(read)));
//Inversion
std::getline(file, read);
SHLOGV_CRITICAL("Inversion: {}", read);
SetBindingInverted(bindingName, static_cast<bool>(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<bool>(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<SH_KEYCODE>(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<SH_KEYCODE>(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<SH_CONTROLLERCODE>(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<SH_CONTROLLERCODE>(std::stoi(read)));
}
}

View File

@ -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 */