Skip to content

Commit 8cfffd5

Browse files
committed
Fix KeyAxis.Equals comparison.
1 parent 1da06c5 commit 8cfffd5

7 files changed

Lines changed: 64 additions & 34 deletions

File tree

AdvancedControlsMod/Axes/KeyAxis.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ public override bool Equals(InputAxis other)
271271
this.Gravity == cast.Gravity &&
272272
this.Snap == cast.Snap &&
273273
this.Raw == cast.Raw &&
274-
this.PositiveBind.ID == cast.PositiveBind.ID &&
275-
this.NegativeBind.ID == cast.NegativeBind.ID;
274+
this.PositiveBind == cast.PositiveBind &&
275+
this.NegativeBind == cast.NegativeBind;
276276
}
277277
}
278278
}
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
1-
namespace Lench.AdvancedControls.Input
1+
#pragma warning disable CS0660, CS0661
2+
namespace Lench.AdvancedControls.Input
23
{
34
/// <summary>
45
/// Button interface for mapping in Input axes.
56
/// </summary>
6-
public interface Button
7+
public abstract class Button
78
{
89
/// <summary>
910
/// Identifier string containing full information.
1011
/// </summary>
11-
string ID { get; }
12+
public abstract string ID { get; }
1213

1314
/// <summary>
1415
/// Button's display name.
1516
/// </summary>
16-
string Name { get; }
17+
public abstract string Name { get; }
1718

1819
/// <summary>
1920
/// Button value is 1 if pressed and 0 if released.
2021
/// Analog buttons can take values in between.
2122
/// </summary>
22-
float Value { get; }
23+
public abstract float Value { get; }
24+
25+
/// <summary>
26+
/// Compares buttons a and b by values.
27+
/// </summary>
28+
/// <param name="a"></param>
29+
/// <param name="b"></param>
30+
/// <returns></returns>
31+
public static bool operator ==(Button a, Button b)
32+
{
33+
if ((object)a == null && (object)b == null)
34+
return true;
35+
if (((object)a == null) != ((object)b == null))
36+
return false;
37+
if (a.GetType() != b.GetType())
38+
return false;
39+
return a.ID == b.ID;
40+
}
41+
42+
/// <summary>
43+
/// Compares buttons a and b by values.
44+
/// </summary>
45+
/// <param name="a"></param>
46+
/// <param name="b"></param>
47+
/// <returns></returns>
48+
public static bool operator !=(Button a, Button b)
49+
{
50+
return !(a == b);
51+
}
2352

2453
#pragma warning disable CS1591
25-
bool IsDown { get; }
26-
bool Pressed { get; }
27-
bool Released { get; }
28-
bool Connected { get; }
54+
public abstract bool IsDown { get; }
55+
public abstract bool Pressed { get; }
56+
public abstract bool Released { get; }
57+
public abstract bool Connected { get; }
2958
}
3059
}

AdvancedControlsMod/Input/HatButton.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class HatButton : Button
2121
/// Hat button identifying string of the following format:
2222
/// hat:[index]:[down_state_byte]:[device_guid]
2323
/// </summary>
24-
public string ID { get { return "hat:" + index + ":" + down_state + ":" + guid; } }
24+
public override string ID { get { return "hat:" + index + ":" + down_state + ":" + guid; } }
2525

2626
/// <summary>
2727
/// Guid of the associated controller.
@@ -47,12 +47,12 @@ public int Index
4747
}
4848

4949
#pragma warning disable CS1591
50-
public bool IsDown { get { return down; } }
51-
public bool Pressed { get { return pressed; } }
52-
public bool Released { get { return released; } }
53-
public float Value { get { return down ? 1 : 0; } }
54-
public string Name { get { return controller != null ? controller.HatNames[index] + " - " + direction : "<color=#FF0000>Unknown hat</color>"; } }
55-
public bool Connected { get { return controller != null && controller.Connected; } }
50+
public override bool IsDown { get { return down; } }
51+
public override bool Pressed { get { return pressed; } }
52+
public override bool Released { get { return released; } }
53+
public override float Value { get { return down ? 1 : 0; } }
54+
public override string Name { get { return controller != null ? controller.HatNames[index] + " - " + direction : "<color=#FF0000>Unknown hat</color>"; } }
55+
public override bool Connected { get { return controller != null && controller.Connected; } }
5656
#pragma warning restore CS1591
5757

5858
/// <summary>

AdvancedControlsMod/Input/JoystickButton.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class JoystickButton : Button
1919
/// Joystick button identifying string of the following format:
2020
/// joy:[index]:[device_guid]
2121
/// </summary>
22-
public string ID { get { return "joy:" + index + ":" + guid; } }
22+
public override string ID { get { return "joy:" + index + ":" + guid; } }
2323

2424
/// <summary>
2525
/// Guid of the associated controller.
@@ -45,12 +45,12 @@ public int Index
4545
}
4646

4747
#pragma warning disable CS1591
48-
public bool IsDown { get { return down; } }
49-
public bool Pressed { get { return pressed; } }
50-
public bool Released { get { return released; } }
51-
public float Value { get { return down ? 1 : 0; } }
52-
public string Name { get { return controller != null ? controller.ButtonNames[index] : "<color=#FF0000>Unknown button</color>"; } }
53-
public bool Connected { get { return controller != null && controller.Connected; } }
48+
public override bool IsDown { get { return down; } }
49+
public override bool Pressed { get { return pressed; } }
50+
public override bool Released { get { return released; } }
51+
public override float Value { get { return down ? 1 : 0; } }
52+
public override string Name { get { return controller != null ? controller.ButtonNames[index] : "<color=#FF0000>Unknown button</color>"; } }
53+
public override bool Connected { get { return controller != null && controller.Connected; } }
5454
#pragma warning restore CS1591
5555

5656
/// <summary>

AdvancedControlsMod/Input/Key.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public class Key : Button
1414
/// Keyboard button identifying string of the following format:
1515
/// key:[UnityEngine.KeyCode]
1616
/// </summary>
17-
public string ID { get { return "key:" + keycode.ToString(); } }
17+
public override string ID { get { return "key:" + keycode.ToString(); } }
1818

1919
#pragma warning disable CS1591
20-
public bool IsDown { get { return UnityEngine.Input.GetKey(keycode); } }
21-
public bool Pressed { get { return UnityEngine.Input.GetKeyDown(keycode); } }
22-
public bool Released { get { return UnityEngine.Input.GetKeyUp(keycode); } }
23-
public float Value { get { return IsDown ? 1 : 0; } }
24-
public string Name { get { return keycode.ToString(); } }
25-
public bool Connected { get; } = true;
20+
public override bool IsDown { get { return UnityEngine.Input.GetKey(keycode); } }
21+
public override bool Pressed { get { return UnityEngine.Input.GetKeyDown(keycode); } }
22+
public override bool Released { get { return UnityEngine.Input.GetKeyUp(keycode); } }
23+
public override float Value { get { return IsDown ? 1 : 0; } }
24+
public override string Name { get { return keycode.ToString(); } }
25+
public override bool Connected { get; } = true;
2626
#pragma warning restore CS1591
2727

2828
/// <summary>

AdvancedControlsMod/MachineData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal static void Load(MachineInfo machineInfo)
1414
try
1515
{
1616
AxisManager.MachineAxes.Clear();
17+
ControlManager.Blocks.Clear();
1718

1819
// read mod version
1920
if (!machineInfo.MachineData.HasKey("ac-version")) return;

AdvancedControlsMod/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.4.3.0")]
36-
[assembly: AssemblyFileVersion("1.4.3.0")]
35+
[assembly: AssemblyVersion("1.4.6.0")]
36+
[assembly: AssemblyFileVersion("1.4.6.0")]

0 commit comments

Comments
 (0)