order KeyMap and JoyMap when saving

This commit is contained in:
thrust26 2020-04-21 16:20:37 +02:00
parent 98d42cfd94
commit db51de1bde
2 changed files with 48 additions and 4 deletions

View File

@ -185,9 +185,35 @@ JoyMap::JoyMappingArray JoyMap::getEventMapping(const Event::Type event, const E
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string JoyMap::saveMapping(const EventMode mode) const
{
using MapType = std::pair<JoyMapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());
std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.second != b.second)
return a.second < b.second;
if(a.first.button != b.first.button)
return a.first.button < b.first.button;
if(a.first.axis != b.first.axis)
return a.first.axis < b.first.axis;
if(a.first.adir != b.first.adir)
return a.first.adir < b.first.adir;
if(a.first.hat != b.first.hat)
return a.first.hat < b.first.hat;
return a.first.hdir < b.first.hdir;
}
);
ostringstream buf;
for (auto item : myMap)
for (auto item : sortedMap)
{
if (item.first.mode == mode)
{

View File

@ -16,6 +16,7 @@
//============================================================================
#include "KeyMap.hxx"
#include <map>
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KeyMap::add(const Event::Type event, const Mapping& mapping)
@ -170,9 +171,26 @@ KeyMap::MappingArray KeyMap::getEventMapping(const Event::Type event, const Even
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string KeyMap::saveMapping(const EventMode mode) const
{
using MapType = std::pair<Mapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());
std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.second != b.second)
return a.second < b.second;
if(a.first.key != b.first.key)
return a.first.key < b.first.key;
return a.first.mod < b.first.mod;
}
);
ostringstream buf;
for (auto item : myMap)
for (auto item : sortedMap)
{
if (item.first.mode == mode)
{