Skip to content

Commit

Permalink
Merge pull request #71 from eviltwo/parent-path
Browse files Browse the repository at this point in the history
Changed to use the parent path if the image cannot be found.
  • Loading branch information
eviltwo authored Dec 9, 2024
2 parents 8410dbe + 4a71272 commit 9301f92
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions InputGlyphs/Assets/InputGlyphs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## [1.2.2] - Development
### Modified
- Supported `DISABLESTEAMWORKS` Assembly Definition.
- Changed to use the parent path if the image cannot be found.
- Example: `leftStick/x` -> `leftStick`

## [1.2.1] - 2024-10-31
### Modified
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if INPUT_SYSTEM && ENABLE_INPUT_SYSTEM
using System.Collections.Generic;
using InputGlyphs.Utils;
using UnityEngine;
using UnityEngine.InputSystem;

Expand Down Expand Up @@ -45,7 +46,16 @@ public static bool LoadGlyph(Texture2D texture, IReadOnlyList<InputDevice> activ
return true;
}
}
return false;

var parentPath = InputLayoutPathUtility.GetParent(inputLayoutPath);
if (string.IsNullOrEmpty(parentPath))
{
return false;
}
else
{
return LoadGlyph(texture, activeDevices, parentPath);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public static string RemoveRoot(string inputControlPath)
return inputControlPath.Substring(separationIndex + 1);
}

/// <summary>
/// Get the parent path of the input layout path.
/// </summary>
/// <remarks>
/// Example: /leftStick/x -> /leftStick
/// </remarks>
public static string GetParent(string inputLayoutPath)
{
if (string.IsNullOrEmpty(inputLayoutPath))
{
return string.Empty;
}
var lastSeparatorIndex = inputLayoutPath.LastIndexOf(InputControlPath.Separator);
if (lastSeparatorIndex == -1)
{
return string.Empty;
}
return inputLayoutPath.Substring(0, lastSeparatorIndex);
}

/// <summary>
/// Searches for bindings within actions that match the control scheme and returns the effective paths.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ public void RemoveRoot(string input, string expected)
var result = InputLayoutPathUtility.RemoveRoot(input);
Assert.AreEqual(expected, result);
}

[TestCase("/leftStick/x", "/leftStick")]
[TestCase("/leftStick", "")]
[TestCase("/leftStick/x/y", "/leftStick/x")]
[TestCase("leftStick/x", "leftStick")]
[TestCase("leftStick", "")]
[TestCase("leftStick/x/y", "leftStick/x")]
[TestCase("", "")]
public void GetParent(string input, string expected)
{
var result = InputLayoutPathUtility.GetParent(input);
Assert.AreEqual(expected, result);
}
}
}

0 comments on commit 9301f92

Please sign in to comment.