1
0
Fork 0
mirror of https://github.com/Detanup01/gbe_fork.git synced 2025-06-07 09:45:55 +02:00

wip: load action_set_layers in controller/layers

This commit is contained in:
faith 2025-06-05 17:38:02 +08:00
parent eaea45cabf
commit 026d00fba0

View file

@ -453,66 +453,72 @@ static void split_string(const std::string &s, char delim, Out result) {
// folder "controller" // folder "controller"
static void load_gamecontroller_settings(Settings *settings) static void load_gamecontroller_settings(Settings *settings)
{ {
std::string path = Local_Storage::get_game_settings_path() + "controller"; 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); 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) { PRINT_DEBUG("controller config %s", p.c_str());
size_t length = p.length(); std::string action_set_name = p.substr(0, length - 4);
if (length < 4) continue; std::transform(action_set_name.begin(), action_set_name.end(), action_set_name.begin(), [](unsigned char c) { return std::toupper(c); });
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 controller_config_path = path + PATH_SEPARATOR + p;
std::string action_set_name = p.substr(0, length - 4); std::ifstream input(std::filesystem::u8path(controller_config_path));
std::transform(action_set_name.begin(), action_set_name.end(), action_set_name.begin(),[](unsigned char c){ return std::toupper(c); }); 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; for (std::string line; getline(input, line); ) {
std::ifstream input( std::filesystem::u8path(controller_config_path) ); if (!line.empty() && line[line.length() - 1] == '\n') {
if (input.is_open()) { line.pop_back();
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 = "";
} }
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); }); action_sets[action_set_name] = button_pairs;
std::transform(button_name.begin(), button_name.end(), button_name.begin(),[](unsigned char c){ return std::toupper(c); }); PRINT_DEBUG("Added %zu action names to %s", button_pairs.size(), action_set_name.c_str());
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());
} }
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); settings->glyphs_directory = path + (PATH_SEPARATOR "glyphs" PATH_SEPARATOR);
} }