Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PlasticBand-Unity to v0.3.0 #353

Merged
merged 3 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Assets/Script/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using YARG.Input;
using YARG.Settings;
using YARG.Song;

Expand Down Expand Up @@ -58,6 +59,8 @@ private void Awake() {

AudioManager = gameObject.AddComponent<BassAudioManager>();
AudioManager.Initialize();

StageKitHapticsManager.Initialize();
}

private void Start() {
Expand Down
20 changes: 20 additions & 0 deletions Assets/Script/Input/InputStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using PlasticBand.Haptics;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
Expand All @@ -14,6 +15,7 @@ public abstract class InputStrategy {
protected int botChartIndex;

private InputDevice _inputDevice;
private ISantrollerHaptics _haptics;
public InputDevice InputDevice {
get => _inputDevice;
set {
Expand All @@ -23,6 +25,9 @@ public InputDevice InputDevice {
}

_inputDevice = value;
if (_inputDevice is ISantrollerHaptics haptics) {
_haptics = haptics;
}

if (enabled) {
Enable();
Expand Down Expand Up @@ -254,5 +259,20 @@ protected void NavigationHoldableForMapping(MenuAction action, string mapping) {
Navigator.Instance.EndNavigationHold(action, this);
}
}

public void SendStarPowerFill(float fill)
=> _haptics?.SetStarPowerFill(fill);

public void SendStarPowerActive(bool enabled)
=> _haptics?.SetStarPowerActive(enabled);

public void SendMultiplier(uint multiplier)
=> _haptics?.SetMultiplier(multiplier);

public void SendSolo(bool enabled)
=> _haptics?.SetSolo(enabled);

public virtual void ResetHaptics()
=> _haptics?.ResetHaptics();
}
}
42 changes: 8 additions & 34 deletions Assets/Script/Input/RealGuitarInputStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using PlasticBand.Devices;
using UnityEngine;
using UnityEngine.InputSystem.Controls;
using YARG.Data;
using YARG.PlayMode;

Expand Down Expand Up @@ -31,8 +30,8 @@ public static StrumFlag StrumFlagFromInt(int str) {

private List<NoteInfo> botChart;

private int[] fretCache = new int[6];
private float[] velocityCache = new float[6];
private int[] fretCache = new int[ProGuitar.StringCount];
private float[] velocityCache = new float[ProGuitar.StringCount];

private float? stringGroupingTimer = null;
private StrumFlag stringGroupingFlag = StrumFlag.NONE;
Expand Down Expand Up @@ -60,17 +59,17 @@ protected override void UpdatePlayerMode() {
}

// Update frets
for (int i = 0; i < 6; i++) {
int fret = GetFret(input, i).ReadValue();
for (int i = 0; i < ProGuitar.StringCount; i++) {
int fret = input.GetFret(i).ReadValue();
if (fret != fretCache[i]) {
FretChangeEvent?.Invoke(i, fret);
fretCache[i] = fret;
}
}

// Update strums
for (int i = 0; i < 6; i++) {
float vel = GetVelocity(input, i).ReadValue();
for (int i = 0; i < ProGuitar.StringCount; i++) {
float vel = input.GetVelocity(i).ReadValue();
if (vel != velocityCache[i]) {
stringGroupingFlag |= StrumFlagFromInt(i);
velocityCache[i] = vel;
Expand All @@ -84,31 +83,6 @@ protected override void UpdatePlayerMode() {
CallStarpowerEvent();
}

// TODO: Ideally these should be directly implemented in PlasticBand
private IntegerControl GetFret(ProGuitar input, int i) {
return i switch {
0 => input.fret1,
1 => input.fret2,
2 => input.fret3,
3 => input.fret4,
4 => input.fret5,
5 => input.fret6,
_ => null
};
}

private AxisControl GetVelocity(ProGuitar input, int i) {
return i switch {
0 => input.velocity1,
1 => input.velocity2,
2 => input.velocity3,
3 => input.velocity4,
4 => input.velocity5,
5 => input.velocity6,
_ => null
};
}

public override void InitializeBotMode(object rawChart) {
botChart = (List<NoteInfo>) rawChart;
}
Expand All @@ -125,7 +99,7 @@ protected override void UpdateBotMode() {
var note = botChart[botChartIndex];

// Press correct frets
for (int i = 0; i < 6; i++) {
for (int i = 0; i < ProGuitar.StringCount; i++) {
int fret = note.stringFrets[i];
if (fret == -1) {
fret = 0;
Expand All @@ -136,7 +110,7 @@ protected override void UpdateBotMode() {

// Strum correct strings
StrumFlag flag = StrumFlag.NONE;
for (int i = 0; i < 6; i++) {
for (int i = 0; i < ProGuitar.StringCount; i++) {
if (note.stringFrets[i] != -1) {
flag |= StrumFlagFromInt(i);
}
Expand Down
76 changes: 76 additions & 0 deletions Assets/Script/Input/StageKitHapticsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Collections.Generic;
using PlasticBand.Haptics;
using UnityEngine.InputSystem;

namespace YARG.Input {
public static class StageKitHapticsManager {
private static List<IStageKitHaptics> stageKits = new();

public static void Initialize() {
InputSystem.onDeviceChange += OnDeviceChange;
foreach (var device in InputSystem.devices) {
if (device is IStageKitHaptics stageKit) {
stageKits.Add(stageKit);
}
}
}

private static void OnDeviceChange(InputDevice device, InputDeviceChange change) {
if (device is not IStageKitHaptics stageKit) {
return;
}

switch (change) {
case InputDeviceChange.Added:
case InputDeviceChange.Enabled:
case InputDeviceChange.Reconnected:
if (!stageKits.Contains(stageKit)) {
stageKits.Add(stageKit);
}
break;

case InputDeviceChange.Disabled:
case InputDeviceChange.Disconnected:
case InputDeviceChange.Removed:
stageKits.Remove(stageKit);
break;
}
}

public static void SetFogMachine(bool enabled) {
foreach (var stageKit in stageKits) {
stageKit.SetFogMachine(enabled);
}
}

public static void SetStrobeSpeed(StageKitStrobeSpeed speed) {
foreach (var stageKit in stageKits) {
stageKit.SetStrobeSpeed(speed);
}
}

public static void SetLeds(StageKitLedColor color, StageKitLed leds) {
foreach (var stageKit in stageKits) {
stageKit.SetLeds(color, leds);
}
}

public static void SetRedLeds(StageKitLed leds)
=> SetLeds(StageKitLedColor.Red, leds);

public static void SetYellowLeds(StageKitLed leds)
=> SetLeds(StageKitLedColor.Yellow, leds);

public static void SetBlueLeds(StageKitLed leds)
=> SetLeds(StageKitLedColor.Blue, leds);

public static void SetGreenLeds(StageKitLed leds)
=> SetLeds(StageKitLedColor.Green, leds);

public static void Reset() {
foreach (var stageKit in stageKits) {
stageKit.ResetHaptics();
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/Input/StageKitHapticsManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.thenathannator.hidrogen": "https://github.com/TheNathannator/HIDrogen.git?path=/Packages/com.thenathannator.hidrogen#v0.2.0",
"com.thenathannator.plasticband": "https://github.com/TheNathannator/PlasticBand-Unity.git?path=/Packages/com.thenathannator.plasticband#v0.2.3",
"com.thenathannator.plasticband": "https://github.com/TheNathannator/PlasticBand-Unity.git?path=/Packages/com.thenathannator.plasticband#v0.3.0",
"com.unity.2d.sprite": "1.0.0",
"com.unity.addressables": "1.21.9",
"com.unity.ai.navigation": "1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"hash": "73285a031b0a978420ad08c64f0205e07d8dcec5"
},
"com.thenathannator.plasticband": {
"version": "https://github.com/TheNathannator/PlasticBand-Unity.git?path=/Packages/com.thenathannator.plasticband#v0.2.3",
"version": "https://github.com/TheNathannator/PlasticBand-Unity.git?path=/Packages/com.thenathannator.plasticband#v0.3.0",
"depth": 0,
"source": "git",
"dependencies": {
"com.unity.inputsystem": "1.4.4"
},
"hash": "5cea9d1938c6545096248ee922da3bd72544c106"
"hash": "57a632d823c3ede765292ad26978f0cef3b486c5"
},
"com.unity.2d.sprite": {
"version": "1.0.0",
Expand Down