diff --git a/Assets/Plugins/JoyShockLibrary/JoyShockLibrary.cs b/Assets/Plugins/JoyShockLibrary/JoyShockLibrary.cs index ac12b5723..677c9d4c8 100644 --- a/Assets/Plugins/JoyShockLibrary/JoyShockLibrary.cs +++ b/Assets/Plugins/JoyShockLibrary/JoyShockLibrary.cs @@ -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; diff --git a/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.dll b/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.dll index b99f671e5..f83c1226b 100644 Binary files a/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.dll and b/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.dll differ diff --git a/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.h b/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.h index 21b2f88cf..2258b00a9 100644 --- a/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.h +++ b/Assets/Plugins/JoyShockLibrary/Plugins/JoyShockLibrary.h @@ -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 diff --git a/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.dylib b/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.dylib index 783efd22a..405204e45 100644 Binary files a/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.dylib and b/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.dylib differ diff --git a/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.so b/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.so index 3ad61ac1c..e37994c4d 100644 Binary files a/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.so and b/Assets/Plugins/JoyShockLibrary/Plugins/libJoyShockLibrary.so differ diff --git a/Assets/Scripts/InputSystem/ControllerTypes/InputJoyshock.cs b/Assets/Scripts/InputSystem/ControllerTypes/InputJoyshock.cs index 921307980..d72125586 100644 --- a/Assets/Scripts/InputSystem/ControllerTypes/InputJoyshock.cs +++ b/Assets/Scripts/InputSystem/ControllerTypes/InputJoyshock.cs @@ -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: diff --git a/Assets/Scripts/InputSystem/ControllerTypes/InputKeyboard.cs b/Assets/Scripts/InputSystem/ControllerTypes/InputKeyboard.cs index bb52b9d05..0cbcccb19 100644 --- a/Assets/Scripts/InputSystem/ControllerTypes/InputKeyboard.cs +++ b/Assets/Scripts/InputSystem/ControllerTypes/InputKeyboard.cs @@ -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; diff --git a/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs b/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs index 094055487..4d3d3c54f 100644 --- a/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs +++ b/Assets/Scripts/InputSystem/ControllerTypes/InputMouse.cs @@ -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; diff --git a/Assets/Scripts/InputSystem/InputController.cs b/Assets/Scripts/InputSystem/InputController.cs index 4f2a50b3e..d3fb41f9b 100644 --- a/Assets/Scripts/InputSystem/InputController.cs +++ b/Assets/Scripts/InputSystem/InputController.cs @@ -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(json); + try + { + currentBindings = JsonUtility.FromJson(json); + if (currentBindings.version != GetBindingsVersion()) + { + currentBindings = UpdateBindings(currentBindings); + SaveBindings(); + } + } + catch (System.Exception) + { + ResetBindings(); + } } else { @@ -220,6 +233,19 @@ namespace HeavenStudio.InputSystem /// public abstract void SetCurrentBindings(ControlBindings newBinds); + /// + /// updates controller bindings to new versions + /// + /// bindings of a previous version + /// + public abstract ControlBindings UpdateBindings(ControlBindings lastBinds); + + /// + /// gets the current bindings version for this controller + /// + /// + public abstract int GetBindingsVersion(); + /// /// Whether a given action can have be rebount /// diff --git a/Assets/Scripts/LevelEditor/EditorTheme.cs b/Assets/Scripts/LevelEditor/EditorTheme.cs index dc79c4120..b201f2da4 100644 --- a/Assets/Scripts/LevelEditor/EditorTheme.cs +++ b/Assets/Scripts/LevelEditor/EditorTheme.cs @@ -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(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(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 diff --git a/Assets/Scripts/PersistentDataManager.cs b/Assets/Scripts/PersistentDataManager.cs index e0df0eb14..1c1508a0c 100644 --- a/Assets/Scripts/PersistentDataManager.cs +++ b/Assets/Scripts/PersistentDataManager.cs @@ -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(json); + if (json == "") + { + GlobalGameManager.IsFirstBoot = true; + CreateDefaultSettings(); + return; + } + try + { + gameSettings = JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + Debug.LogError($"Error while loading settings, creating default settings;\n{e.Message}"); + GlobalGameManager.IsFirstBoot = true; + CreateDefaultSettings(); + } } else {