mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2025-06-07 17:55:55 +02:00
wip: load action_set_layers in controller/layers
This commit is contained in:
parent
eaea45cabf
commit
026d00fba0
1 changed files with 58 additions and 52 deletions
|
@ -453,66 +453,72 @@ static void split_string(const std::string &s, char delim, Out result) {
|
|||
// folder "controller"
|
||||
static void load_gamecontroller_settings(Settings *settings)
|
||||
{
|
||||
std::string path = Local_Storage::get_game_settings_path() + "controller";
|
||||
std::vector<std::string> paths = Local_Storage::get_filenames_path(path);
|
||||
auto process_paths = [&](std::string path, std::map<std::string, std::map<std::string, std::pair<std::set<std::string>, std::string>>> action_sets) {
|
||||
std::vector<std::string> paths = Local_Storage::get_filenames_path(path);
|
||||
for (auto& p : paths) {
|
||||
size_t length = p.length();
|
||||
if (length < 4) continue;
|
||||
if (std::toupper(p.back()) != 'T') continue;
|
||||
if (std::toupper(p[length - 2]) != 'X') continue;
|
||||
if (std::toupper(p[length - 3]) != 'T') continue;
|
||||
if (p[length - 4] != '.') continue;
|
||||
|
||||
for (auto & p: paths) {
|
||||
size_t length = p.length();
|
||||
if (length < 4) continue;
|
||||
if ( std::toupper(p.back()) != 'T') continue;
|
||||
if ( std::toupper(p[length - 2]) != 'X') continue;
|
||||
if ( std::toupper(p[length - 3]) != 'T') continue;
|
||||
if (p[length - 4] != '.') continue;
|
||||
PRINT_DEBUG("controller config %s", p.c_str());
|
||||
std::string action_set_name = p.substr(0, length - 4);
|
||||
std::transform(action_set_name.begin(), action_set_name.end(), action_set_name.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
|
||||
PRINT_DEBUG("controller config %s", p.c_str());
|
||||
std::string action_set_name = p.substr(0, length - 4);
|
||||
std::transform(action_set_name.begin(), action_set_name.end(), action_set_name.begin(),[](unsigned char c){ return std::toupper(c); });
|
||||
std::string controller_config_path = path + PATH_SEPARATOR + p;
|
||||
std::ifstream input(std::filesystem::u8path(controller_config_path));
|
||||
if (input.is_open()) {
|
||||
common_helpers::consume_bom(input);
|
||||
std::map<std::string, std::pair<std::set<std::string>, std::string>> button_pairs;
|
||||
|
||||
std::string controller_config_path = path + PATH_SEPARATOR + p;
|
||||
std::ifstream input( std::filesystem::u8path(controller_config_path) );
|
||||
if (input.is_open()) {
|
||||
common_helpers::consume_bom(input);
|
||||
std::map<std::string, std::pair<std::set<std::string>, std::string>> button_pairs;
|
||||
|
||||
for( std::string line; getline( input, line ); ) {
|
||||
if (!line.empty() && line[line.length()-1] == '\n') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
if (!line.empty() && line[line.length()-1] == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
std::string action_name;
|
||||
std::string button_name;
|
||||
std::string source_mode;
|
||||
|
||||
std::size_t deliminator = line.find("=");
|
||||
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
|
||||
action_name = line.substr(0, deliminator);
|
||||
std::size_t deliminator2 = line.find("=", deliminator + 1);
|
||||
|
||||
if (deliminator2 != std::string::npos && deliminator2 != line.size()) {
|
||||
button_name = line.substr(deliminator + 1, deliminator2 - (deliminator + 1));
|
||||
source_mode = line.substr(deliminator2 + 1);
|
||||
} else {
|
||||
button_name = line.substr(deliminator + 1);
|
||||
source_mode = "";
|
||||
for (std::string line; getline(input, line); ) {
|
||||
if (!line.empty() && line[line.length() - 1] == '\n') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
if (!line.empty() && line[line.length() - 1] == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
std::string action_name;
|
||||
std::string button_name;
|
||||
std::string source_mode;
|
||||
|
||||
std::size_t deliminator = line.find("=");
|
||||
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
|
||||
action_name = line.substr(0, deliminator);
|
||||
std::size_t deliminator2 = line.find("=", deliminator + 1);
|
||||
|
||||
if (deliminator2 != std::string::npos && deliminator2 != line.size()) {
|
||||
button_name = line.substr(deliminator + 1, deliminator2 - (deliminator + 1));
|
||||
source_mode = line.substr(deliminator2 + 1);
|
||||
}
|
||||
else {
|
||||
button_name = line.substr(deliminator + 1);
|
||||
source_mode = "";
|
||||
}
|
||||
}
|
||||
|
||||
std::transform(action_name.begin(), action_name.end(), action_name.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
std::transform(button_name.begin(), button_name.end(), button_name.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
std::pair<std::set<std::string>, std::string> button_config = { {}, source_mode };
|
||||
split_string(button_name, ',', std::inserter(button_config.first, button_config.first.begin()));
|
||||
button_pairs[action_name] = button_config;
|
||||
PRINT_DEBUG("Added %s %s %s", action_name.c_str(), button_name.c_str(), source_mode.c_str());
|
||||
}
|
||||
|
||||
std::transform(action_name.begin(), action_name.end(), action_name.begin(),[](unsigned char c){ return std::toupper(c); });
|
||||
std::transform(button_name.begin(), button_name.end(), button_name.begin(),[](unsigned char c){ return std::toupper(c); });
|
||||
std::pair<std::set<std::string>, std::string> button_config = {{}, source_mode};
|
||||
split_string(button_name, ',', std::inserter(button_config.first, button_config.first.begin()));
|
||||
button_pairs[action_name] = button_config;
|
||||
PRINT_DEBUG("Added %s %s %s", action_name.c_str(), button_name.c_str(), source_mode.c_str());
|
||||
action_sets[action_set_name] = button_pairs;
|
||||
PRINT_DEBUG("Added %zu action names to %s", button_pairs.size(), action_set_name.c_str());
|
||||
}
|
||||
|
||||
settings->controller_settings.action_sets[action_set_name] = button_pairs;
|
||||
PRINT_DEBUG("Added %zu action names to %s", button_pairs.size(), action_set_name.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::string path = Local_Storage::get_game_settings_path() + "controller";
|
||||
std::string layers_path = path + (PATH_SEPARATOR "layers" PATH_SEPARATOR);
|
||||
process_paths(path, settings->controller_settings.action_sets);
|
||||
process_paths(layers_path, settings->controller_settings.action_set_layers);
|
||||
|
||||
settings->glyphs_directory = path + (PATH_SEPARATOR "glyphs" PATH_SEPARATOR);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue