update JSL (DualSense Edge support)

add ability to update controller bindings
This commit is contained in:
minenice55 2024-01-30 22:31:20 -05:00
parent 664d55e7a9
commit b294c64852
11 changed files with 178 additions and 61 deletions

View file

@ -29,8 +29,11 @@ public static class JSL
public const int ButtonMaskPS = 16;
public const int ButtonMaskCapture = 17;
public const int ButtonMaskTouchpadClick = 17;
public const int ButtonMaskSL = 18;
public const int ButtonMaskSR = 19;
public const int ButtonMaskMic = 18;
public const int ButtonMaskSL = 19;
public const int ButtonMaskSR = 20;
public const int ButtonMaskFnL = 19;
public const int ButtonMaskFnR = 20;
public const int TypeJoyConLeft = 1;
public const int TypeJoyConRight = 2;

View file

@ -17,31 +17,33 @@
#define JS_SPLIT_TYPE_RIGHT 2
#define JS_SPLIT_TYPE_FULL 3
#define JSMASK_UP 0x00001
#define JSMASK_DOWN 0x00002
#define JSMASK_LEFT 0x00004
#define JSMASK_RIGHT 0x00008
#define JSMASK_PLUS 0x00010
#define JSMASK_OPTIONS 0x00010
#define JSMASK_MINUS 0x00020
#define JSMASK_SHARE 0x00020
#define JSMASK_LCLICK 0x00040
#define JSMASK_RCLICK 0x00080
#define JSMASK_L 0x00100
#define JSMASK_R 0x00200
#define JSMASK_ZL 0x00400
#define JSMASK_ZR 0x00800
#define JSMASK_S 0x01000
#define JSMASK_E 0x02000
#define JSMASK_W 0x04000
#define JSMASK_N 0x08000
#define JSMASK_HOME 0x10000
#define JSMASK_PS 0x10000
#define JSMASK_CAPTURE 0x20000
#define JSMASK_TOUCHPAD_CLICK 0x20000
#define JSMASK_MIC 0x40000
#define JSMASK_SL 0x40000
#define JSMASK_SR 0x80000
#define JSMASK_UP 0x000001
#define JSMASK_DOWN 0x000002
#define JSMASK_LEFT 0x000004
#define JSMASK_RIGHT 0x000008
#define JSMASK_PLUS 0x000010
#define JSMASK_OPTIONS 0x000010
#define JSMASK_MINUS 0x000020
#define JSMASK_SHARE 0x000020
#define JSMASK_LCLICK 0x000040
#define JSMASK_RCLICK 0x000080
#define JSMASK_L 0x000100
#define JSMASK_R 0x000200
#define JSMASK_ZL 0x000400
#define JSMASK_ZR 0x000800
#define JSMASK_S 0x001000
#define JSMASK_E 0x002000
#define JSMASK_W 0x004000
#define JSMASK_N 0x008000
#define JSMASK_HOME 0x010000
#define JSMASK_PS 0x010000
#define JSMASK_CAPTURE 0x020000
#define JSMASK_TOUCHPAD_CLICK 0x020000
#define JSMASK_MIC 0x040000
#define JSMASK_SL 0x080000
#define JSMASK_SR 0x100000
#define JSMASK_FNL 0x200000
#define JSMASK_FNR 0x400000
#define JSOFFSET_UP 0
#define JSOFFSET_DOWN 1
@ -66,8 +68,10 @@
#define JSOFFSET_CAPTURE 17
#define JSOFFSET_TOUCHPAD_CLICK 17
#define JSOFFSET_MIC 18
#define JSOFFSET_SL 18
#define JSOFFSET_SR 19
#define JSOFFSET_SL 19
#define JSOFFSET_SR 20
#define JSOFFSET_FNL 21
#define JSOFFSET_FNR 22
// PS5 Player maps for the DS Player Lightbar
#define DS5_PLAYER_1 4

View file

@ -107,7 +107,7 @@ namespace HeavenStudio.InputSystem
"Joy-Con (R)",
"Pro Controller",
"DualShock 4",
"DualSense"
"DualSense/Edge" // jsl doesn't expose a new device ID for DSE
};
static readonly int[] dsPlayerColours = new[]
@ -228,6 +228,7 @@ namespace HeavenStudio.InputSystem
"X",
"Home",
"Capture",
"", // mic on playstation, unused here
"SL",
"SR",
"Stick Up",
@ -256,6 +257,7 @@ namespace HeavenStudio.InputSystem
"Triangle",
"PS",
"Touchpad Click",
"Mic",
};
static readonly string[] ps5ButtonNames = new[]
@ -279,6 +281,10 @@ namespace HeavenStudio.InputSystem
"PS",
"Create",
"Mic",
"Left Grip",
"Right Grip",
"Left Function",
"Right Function",
};
static readonly float debounceTime = 1f / 90f;
@ -599,6 +605,7 @@ namespace HeavenStudio.InputSystem
break;
}
binds.PointerSensitivity = 3;
binds.version = 1;
return binds;
}
@ -617,20 +624,45 @@ namespace HeavenStudio.InputSystem
currentBindings = newBinds;
}
public override ControlBindings UpdateBindings(ControlBindings lastBinds)
{
if (lastBinds.version == 0)
{
switch (type)
{
case TypeProController:
case TypeDualShock4:
case TypeDualSense:
return lastBinds;
case TypeJoyConLeft:
case TypeJoyConRight:
for (int i = 0; i < lastBinds.Pad.Length; i++)
{
if (lastBinds.Pad[i] is 18 or 19)
lastBinds.Pad[i] = lastBinds.Pad[i] + 1;
}
return lastBinds;
}
}
return lastBinds;
}
public override int GetBindingsVersion()
{
return 1;
}
public override bool GetIsActionUnbindable(int action, ControlStyles style)
{
if (otherHalf == null)
{
switch (splitType)
if (splitType is SplitLeft or SplitRight)
{
case SplitLeft:
case SplitRight:
switch (style)
{
case ControlStyles.Pad:
return action is 0 or 1 or 2 or 3;
}
break;
switch (style)
{
case ControlStyles.Pad:
return action is 0 or 1 or 2 or 3;
}
}
}
return false;
@ -721,7 +753,7 @@ namespace HeavenStudio.InputSystem
case InputAxis.AxisRStickY:
return joyBtStateCurrent.stickRY;
case InputAxis.PointerX: //isn't updated for now, so always returns 0f
//return joyTouchStateCurrent.t0X;
//return joyTouchStateCurrent.t0X;
case InputAxis.PointerY:
//return joyTouchStateCurrent.t0Y;
default:

View file

@ -131,6 +131,16 @@ namespace HeavenStudio.InputSystem
currentBindings = newBinds;
}
public override ControlBindings UpdateBindings(ControlBindings lastBinds)
{
return lastBinds;
}
public override int GetBindingsVersion()
{
return 0;
}
public override bool GetIsActionUnbindable(int action, ControlStyles style)
{
return false;

View file

@ -259,6 +259,16 @@ namespace HeavenStudio.InputSystem
currentBindings = newBinds;
}
public override ControlBindings UpdateBindings(ControlBindings lastBinds)
{
return lastBinds;
}
public override int GetBindingsVersion()
{
return 0;
}
public override bool GetIsActionUnbindable(int action, ControlStyles style)
{
return action is 0;

View file

@ -141,6 +141,7 @@ namespace HeavenStudio.InputSystem
[System.Serializable]
public struct ControlBindings
{
public int version;
public int[] Pad;
public int[] Baton;
public int[] Touch;
@ -184,7 +185,19 @@ namespace HeavenStudio.InputSystem
string json = File.ReadAllText(path);
if (json is not null or "")
{
currentBindings = JsonUtility.FromJson<ControlBindings>(json);
try
{
currentBindings = JsonUtility.FromJson<ControlBindings>(json);
if (currentBindings.version != GetBindingsVersion())
{
currentBindings = UpdateBindings(currentBindings);
SaveBindings();
}
}
catch (System.Exception)
{
ResetBindings();
}
}
else
{
@ -220,6 +233,19 @@ namespace HeavenStudio.InputSystem
/// <param name="newBinds"></param>
public abstract void SetCurrentBindings(ControlBindings newBinds);
/// <summary>
/// updates controller bindings to new versions
/// </summary>
/// <param name="lastBinds">bindings of a previous version</param>
/// <returns></returns>
public abstract ControlBindings UpdateBindings(ControlBindings lastBinds);
/// <summary>
/// gets the current bindings version for this controller
/// </summary>
/// <returns></returns>
public abstract int GetBindingsVersion();
/// <summary>
/// Whether a given action can have be rebount
/// </summary>

View file

@ -32,27 +32,44 @@ namespace HeavenStudio.Editor
if (File.Exists(Application.persistentDataPath + "/editorTheme.json"))
{
string json = File.ReadAllText(Application.persistentDataPath + "/editorTheme.json");
theme = JsonConvert.DeserializeObject<Theme>(json);
// Naive way of doing it? Possibly, but we should have a theme editor in the future.
if (defaultTheme.properties.LayerColors != null)
if (json == "")
{
theme.properties.LayerColors = new string[]
PersistentDataManager.SaveTheme(ThemeTXT.text);
theme = defaultTheme;
theme.SetLayersGradient();
return;
}
try
{
theme = JsonConvert.DeserializeObject<Theme>(json);
// Naive way of doing it? Possibly, but we should have a theme editor in the future.
if (defaultTheme.properties.LayerColors != null)
{
theme.properties.Layer1Col,
theme.properties.Layer2Col,
theme.properties.Layer3Col,
theme.properties.Layer4Col,
theme.properties.Layer5Col
};
// Create a function for this in the future.
var savedTheme = JsonConvert.SerializeObject(theme, Formatting.Indented, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None,
NullValueHandling = NullValueHandling.Include,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});
PersistentDataManager.SaveTheme(savedTheme);
theme.properties.LayerColors = new string[]
{
theme.properties.Layer1Col,
theme.properties.Layer2Col,
theme.properties.Layer3Col,
theme.properties.Layer4Col,
theme.properties.Layer5Col
};
// Create a function for this in the future.
var savedTheme = JsonConvert.SerializeObject(theme, Formatting.Indented, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None,
NullValueHandling = NullValueHandling.Include,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});
PersistentDataManager.SaveTheme(savedTheme);
}
}
catch
{
PersistentDataManager.SaveTheme(ThemeTXT.text);
theme = defaultTheme;
theme.SetLayersGradient();
return;
}
}
else

View file

@ -67,7 +67,22 @@ namespace HeavenStudio.Common
if (File.Exists(Application.persistentDataPath + "/settings.json"))
{
string json = File.ReadAllText(Application.persistentDataPath + "/settings.json");
gameSettings = JsonUtility.FromJson<GameSettings>(json);
if (json == "")
{
GlobalGameManager.IsFirstBoot = true;
CreateDefaultSettings();
return;
}
try
{
gameSettings = JsonConvert.DeserializeObject<GameSettings>(json);
}
catch (Exception e)
{
Debug.LogError($"Error while loading settings, creating default settings;\n{e.Message}");
GlobalGameManager.IsFirstBoot = true;
CreateDefaultSettings();
}
}
else
{