Skip to content

Commit

Permalink
ControllerInterface: Rename full surface analog inputs to be more vis…
Browse files Browse the repository at this point in the history
…ually dissimilar from their underlying inputs. e.g. "Full Axis X+".
  • Loading branch information
jordan-woyak committed Mar 23, 2019
1 parent c89139d commit 6221966
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
28 changes: 26 additions & 2 deletions Source/Core/InputCommon/ControllerInterface/Device.cpp
Expand Up @@ -50,7 +50,7 @@ Device::Input* Device::FindInput(const std::string& name) const
{
for (Input* input : m_inputs)
{
if (input->GetName() == name)
if (input->IsValidName(name))
return input;
}

Expand All @@ -61,18 +61,42 @@ Device::Output* Device::FindOutput(const std::string& name) const
{
for (Output* output : m_outputs)
{
if (output->GetName() == name)
if (output->IsValidName(name))
return output;
}

return nullptr;
}

bool Device::Control::IsValidName(const std::string& name) const
{
return GetName() == name;
}

ControlState Device::FullAnalogSurface::GetState() const
{
return (1 + std::max(0.0, m_high.GetState()) - std::max(0.0, m_low.GetState())) / 2;
}

std::string Device::FullAnalogSurface::GetName() const
{
// E.g. "Full Axis X+"
return "Full " + m_high.GetName();
}

bool Device::FullAnalogSurface::IsValidName(const std::string& name) const
{
if (Control::IsValidName(name))
return true;

// Old naming scheme was "Axis X-+" which is too visually similar to "Axis X+".
// This has caused countless problems for users with mysterious misconfigurations.
// We match this old name to support old configurations.
const auto old_name = m_low.GetName() + *m_high.GetName().rbegin();

return old_name == name;
}

//
// DeviceQualifier :: ToString
//
Expand Down
9 changes: 7 additions & 2 deletions Source/Core/InputCommon/ControllerInterface/Device.h
Expand Up @@ -45,6 +45,10 @@ class Device
virtual ~Control() {}
virtual Input* ToInput() { return nullptr; }
virtual Output* ToOutput() { return nullptr; }

// May be overridden to allow multiple valid names.
// Useful for backwards-compatible configurations when names change.
virtual bool IsValidName(const std::string& name) const;
};

//
Expand Down Expand Up @@ -105,12 +109,13 @@ class Device
void AddInput(Input* const i);
void AddOutput(Output* const o);

class FullAnalogSurface : public Input
class FullAnalogSurface final : public Input
{
public:
FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {}
ControlState GetState() const override;
std::string GetName() const override { return m_low.GetName() + *m_high.GetName().rbegin(); }
std::string GetName() const override;
bool IsValidName(const std::string& name) const override;

private:
Input& m_low;
Expand Down

0 comments on commit 6221966

Please sign in to comment.