Пример #1
0
int ConfigurationFile::AutoBind(const string& directory, const string& file)
{
  ConfigurationFile refConfigFile;

  int ret = refConfigFile.ReadConfigFile(directory, file);

  if(ret >= 0)
  {
    for(int i=0; i<MAX_CONTROLLERS; ++i)
    {
      Controller* refController = refConfigFile.GetController(i);
      Controller* modController = GetController(i);
      for(int j=0; j<MAX_PROFILES; ++j)
      {
        Profile* refConfig = refController->GetProfile(j);
        Profile* modConfig = modController->GetProfile(j);

        modConfig->SetTrigger(*refConfig->GetTrigger());
        modConfig->SetIntensityList(*refConfig->GetIntensityList());

        AutoBindMappers<ControlMapper>(refConfig->GetButtonMapperList(), modConfig->GetButtonMapperList());

        AutoBindMappers<ControlMapper>(refConfig->GetAxisMapperList(), modConfig->GetAxisMapperList());
      }
    }
  }

  return ret;
}
Пример #2
0
void ConfigurationFile::GetLabels(list<string>& button_labels, list<string>& axis_labels)
{
  for(int i=0; i<MAX_CONTROLLERS; ++i)
  {
    Controller* controller = GetController(i);

    for(int k=0; k<MAX_PROFILES; ++k)
    {
      Profile* config = controller->GetProfile(k);

      list<ControlMapper>* buttonMappers = config->GetButtonMapperList();

      for(list<ControlMapper>::iterator itButtonMappers = buttonMappers->begin(); itButtonMappers!=buttonMappers->end(); ++itButtonMappers)
      {
        string label = itButtonMappers->GetLabel();
        if(!label.empty())
        {
          list<string> tokens = split(label, ',');
          for(list<string>::iterator tk_it = tokens.begin(); tk_it != tokens.end(); ++tk_it)
          {
            if(!tk_it->empty() && *tk_it != "not found" && *tk_it != "duplicate")
            {
              string tk = *tk_it;
              transform(tk.begin(), tk.end(), tk.begin(), (int(*)(int)) tolower);
              list<string>::iterator bl_it;
              for(bl_it = button_labels.begin(); bl_it != button_labels.end(); ++bl_it)
              {
                string bl = *bl_it;
                transform(bl.begin(), bl.end(), bl.begin(), (int(*)(int)) tolower);
                if(tk == bl)
                {
                  break;
                }
              }
              if(bl_it == button_labels.end())
              {
                button_labels.push_back(*tk_it);
              }
            }
          }
        }
      }

      list<ControlMapper>* axisMappers = config->GetAxisMapperList();

      for(list<ControlMapper>::iterator itControlMappers = axisMappers->begin(); itControlMappers!=axisMappers->end(); ++itControlMappers)
      {
        string label = itControlMappers->GetLabel();
        if(!label.empty())
        {
          list<string> tokens = split(label, ',');
          for(list<string>::iterator tk_it = tokens.begin(); tk_it != tokens.end(); ++tk_it)
          {
            if(!tk_it->empty() && *tk_it != "not found" && *tk_it != "duplicate")
            {
              string tk = *tk_it;
              transform(tk.begin(), tk.end(), tk.begin(), (int(*)(int)) tolower);
              list<string>::iterator al_it;
              for(al_it = axis_labels.begin(); al_it != axis_labels.end(); ++al_it)
              {
                string al = *al_it;
                transform(al.begin(), al.end(), al.begin(), (int(*)(int)) tolower);
                if(al == tk)
                {
                  break;
                }
              }
              if(al_it == axis_labels.end())
              {
                axis_labels.push_back(*tk_it);
              }
            }
          }
        }
      }
    }
  }
}