diff --git a/src/api/udev/JoystickInterfaceUdev.cpp b/src/api/udev/JoystickInterfaceUdev.cpp index 4aedf988..ecb3ae80 100644 --- a/src/api/udev/JoystickInterfaceUdev.cpp +++ b/src/api/udev/JoystickInterfaceUdev.cpp @@ -118,12 +118,12 @@ bool CJoystickInterfaceUdev::ScanForJoysticks(JoystickVector& joysticks) const ButtonMap& CJoystickInterfaceUdev::GetButtonMap() { auto& dflt = m_buttonMap["game.controller.default"]; - dflt[CJoystickUdev::MOTOR_STRONG].SetPrimitive(ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_STRONG)); - dflt[CJoystickUdev::MOTOR_WEAK].SetPrimitive(ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_WEAK)); + dflt[CJoystickUdev::MOTOR_STRONG].SetPrimitive(JOYSTICK_MOTOR_PRIMITIVE, ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_STRONG)); + dflt[CJoystickUdev::MOTOR_WEAK].SetPrimitive(JOYSTICK_MOTOR_PRIMITIVE, ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_WEAK)); auto& ps = m_buttonMap["game.controller.ps"]; - ps[CJoystickUdev::MOTOR_STRONG].SetPrimitive(ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_STRONG)); - ps[CJoystickUdev::MOTOR_WEAK].SetPrimitive(ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_WEAK)); + ps[CJoystickUdev::MOTOR_STRONG].SetPrimitive(JOYSTICK_MOTOR_PRIMITIVE, ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_STRONG)); + ps[CJoystickUdev::MOTOR_WEAK].SetPrimitive(JOYSTICK_MOTOR_PRIMITIVE, ADDON::DriverPrimitive::CreateMotor(CJoystickUdev::MOTOR_WEAK)); return m_buttonMap; } diff --git a/src/buttonmapper/ControllerTransformer.cpp b/src/buttonmapper/ControllerTransformer.cpp index 347f215d..581846f1 100644 --- a/src/buttonmapper/ControllerTransformer.cpp +++ b/src/buttonmapper/ControllerTransformer.cpp @@ -74,25 +74,26 @@ bool CControllerTransformer::AddControllerMap(const std::string& controllerFrom, { if (fromFeature.Type() == feature.Type()) { + return fromFeature.Primitives() == feature.Primitives(); switch (feature.Type()) { case JOYSTICK_FEATURE_TYPE_SCALAR: case JOYSTICK_FEATURE_TYPE_MOTOR: { - return fromFeature.Primitive() == feature.Primitive(); + return fromFeature.Primitive(JOYSTICK_SCALAR_PRIMITIVE) == feature.Primitive(JOYSTICK_SCALAR_PRIMITIVE); } case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: { - return fromFeature.Up() == feature.Up() && - fromFeature.Down() == feature.Down() && - fromFeature.Right() == feature.Right() && - fromFeature.Left() == feature.Left(); + return fromFeature.Primitive(JOYSTICK_ANALOG_STICK_UP) == feature.Primitive(JOYSTICK_ANALOG_STICK_UP) && + fromFeature.Primitive(JOYSTICK_ANALOG_STICK_DOWN) == feature.Primitive(JOYSTICK_ANALOG_STICK_DOWN) && + fromFeature.Primitive(JOYSTICK_ANALOG_STICK_RIGHT) == feature.Primitive(JOYSTICK_ANALOG_STICK_RIGHT) && + fromFeature.Primitive(JOYSTICK_ANALOG_STICK_LEFT) == feature.Primitive(JOYSTICK_ANALOG_STICK_LEFT); } case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: { - return fromFeature.PositiveX() == feature.PositiveX() && - fromFeature.PositiveY() == feature.PositiveY() && - fromFeature.PositiveZ() == feature.PositiveZ(); + return fromFeature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_X) == feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_X) && + fromFeature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Y) == feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Y) && + fromFeature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Z) == feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Z); } default: break; diff --git a/src/storage/xml/ButtonMapXml.cpp b/src/storage/xml/ButtonMapXml.cpp index b04b971d..522211b2 100644 --- a/src/storage/xml/ButtonMapXml.cpp +++ b/src/storage/xml/ButtonMapXml.cpp @@ -264,42 +264,42 @@ bool CButtonMapXml::Serialize(const FeatureVector& features, TiXmlElement* pElem { case JOYSTICK_FEATURE_TYPE_SCALAR: { - SerializePrimitive(featureElem, feature.Primitive()); + SerializePrimitive(featureElem, feature.Primitive(JOYSTICK_SCALAR_PRIMITIVE)); break; } case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: { - if (!SerializePrimitiveTag(featureElem, feature.Up(), BUTTONMAP_XML_ELEM_UP)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ANALOG_STICK_UP), BUTTONMAP_XML_ELEM_UP)) return false; - if (!SerializePrimitiveTag(featureElem, feature.Down(), BUTTONMAP_XML_ELEM_DOWN)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ANALOG_STICK_DOWN), BUTTONMAP_XML_ELEM_DOWN)) return false; - if (!SerializePrimitiveTag(featureElem, feature.Right(), BUTTONMAP_XML_ELEM_RIGHT)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ANALOG_STICK_RIGHT), BUTTONMAP_XML_ELEM_RIGHT)) return false; - if (!SerializePrimitiveTag(featureElem, feature.Left(), BUTTONMAP_XML_ELEM_LEFT)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ANALOG_STICK_LEFT), BUTTONMAP_XML_ELEM_LEFT)) return false; break; } case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: { - if (!SerializePrimitiveTag(featureElem, feature.PositiveX(), BUTTONMAP_XML_ELEM_POSITIVE_X)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_X), BUTTONMAP_XML_ELEM_POSITIVE_X)) return false; - if (!SerializePrimitiveTag(featureElem, feature.PositiveY(), BUTTONMAP_XML_ELEM_POSITIVE_Y)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Y), BUTTONMAP_XML_ELEM_POSITIVE_Y)) return false; - if (!SerializePrimitiveTag(featureElem, feature.PositiveZ(), BUTTONMAP_XML_ELEM_POSITIVE_Z)) + if (!SerializePrimitiveTag(featureElem, feature.Primitive(JOYSTICK_ACCELEROMETER_POSITIVE_Z), BUTTONMAP_XML_ELEM_POSITIVE_Z)) return false; break; } case JOYSTICK_FEATURE_TYPE_MOTOR: { - SerializePrimitive(featureElem, feature.Primitive()); + SerializePrimitive(featureElem, feature.Primitive(JOYSTICK_MOTOR_PRIMITIVE)); break; } @@ -313,43 +313,13 @@ bool CButtonMapXml::Serialize(const FeatureVector& features, TiXmlElement* pElem bool CButtonMapXml::IsValid(const ADDON::JoystickFeature& feature) { - bool bIsValid = false; - - switch (feature.Type()) - { - case JOYSTICK_FEATURE_TYPE_SCALAR: - case JOYSTICK_FEATURE_TYPE_MOTOR: - { - if (feature.Primitive().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN) - bIsValid = true; - break; - } - case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: - { - if (feature.Up().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN || - feature.Down().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN || - feature.Right().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN || - feature.Left().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN) - { - bIsValid = true; - } - break; - } - case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: + auto itValid = std::find_if(feature.Primitives().begin(), feature.Primitives().end(), + [](const ADDON::DriverPrimitive& primitive) { - if (feature.PositiveX().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN || - feature.PositiveY().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN || - feature.PositiveZ().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN) - { - bIsValid = true; - } - break; - } - default: - break; - } + return primitive.Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN; + }); - return bIsValid; + return itValid != feature.Primitives().end(); } bool CButtonMapXml::SerializePrimitiveTag(TiXmlElement* pElement, const ADDON::DriverPrimitive& primitive, const char* tagName) @@ -480,7 +450,7 @@ bool CButtonMapXml::Deserialize(const TiXmlElement* pElement, FeatureVector& fea { case JOYSTICK_FEATURE_TYPE_SCALAR: { - feature.SetPrimitive(primitive); + feature.SetPrimitive(JOYSTICK_SCALAR_PRIMITIVE, primitive); break; } case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: @@ -519,10 +489,10 @@ bool CButtonMapXml::Deserialize(const TiXmlElement* pElement, FeatureVector& fea if (!bSuccess) return false; - feature.SetUp(up); - feature.SetDown(down); - feature.SetRight(right); - feature.SetLeft(left); + feature.SetPrimitive(JOYSTICK_ANALOG_STICK_UP, up); + feature.SetPrimitive(JOYSTICK_ANALOG_STICK_DOWN, down); + feature.SetPrimitive(JOYSTICK_ANALOG_STICK_RIGHT, right); + feature.SetPrimitive(JOYSTICK_ANALOG_STICK_LEFT, left); break; } @@ -555,9 +525,9 @@ bool CButtonMapXml::Deserialize(const TiXmlElement* pElement, FeatureVector& fea if (!bSuccess) return false; - feature.SetPositiveX(positiveX); - feature.SetPositiveY(positiveY); - feature.SetPositiveZ(positiveZ); + feature.SetPrimitive(JOYSTICK_ACCELEROMETER_POSITIVE_X, positiveX); + feature.SetPrimitive(JOYSTICK_ACCELEROMETER_POSITIVE_Y, positiveY); + feature.SetPrimitive(JOYSTICK_ACCELEROMETER_POSITIVE_Z, positiveZ); break; }