Skip to content

Commit

Permalink
Version testing & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniMacaroni committed Apr 14, 2020
1 parent bbc2ac8 commit 7073486
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 90 deletions.
2 changes: 1 addition & 1 deletion TrickSaber/GameplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void OnGameSceneLoaded()
DisableScoreSubmissionIfNeeded();

var globalTrickManager = new GameObject("GlobalTrickManager").AddComponent<GlobalTrickManager>();
globalTrickManager.AudioTimeSyncController = UnityEngine.Object.FindObjectOfType<AudioTimeSyncController>();
globalTrickManager.AudioTimeSyncController = Object.FindObjectOfType<AudioTimeSyncController>();

GameObject leftSaber = GameObject.Find("GameCore/Origin/VRGameCore/LeftSaber");
GameObject rightSaber = GameObject.Find("GameCore/Origin/VRGameCore/RightSaber");
Expand Down
53 changes: 26 additions & 27 deletions TrickSaber/GlobalTrickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class GlobalTrickManager : MonoBehaviour
{
public static GlobalTrickManager Instance;

public SaberTrickManager LeftSaberSaberTrickManager;
public SaberTrickManager RightSaberSaberTrickManager;

public AudioTimeSyncController AudioTimeSyncController;

private Coroutine _applySlowmoCoroutine;
private Coroutine _EndSlowmoCoroutine;

private bool _slowmoApplied;
private float _slowmoStepAmount;

void Awake()
public AudioTimeSyncController AudioTimeSyncController;

public SaberTrickManager LeftSaberSaberTrickManager;
public SaberTrickManager RightSaberSaberTrickManager;

private void Awake()
{
Instance = this;
_slowmoStepAmount = PluginConfig.Instance.SlowmoStepAmount;
Expand All @@ -29,7 +29,7 @@ public void OnTrickStarted(TrickAction trickAction)
{
if (trickAction == TrickAction.Throw && PluginConfig.Instance.SlowmoDuringThrow && !_slowmoApplied)
{
if(_EndSlowmoCoroutine!=null)StopCoroutine(_EndSlowmoCoroutine);
if (_EndSlowmoCoroutine != null) StopCoroutine(_EndSlowmoCoroutine);
_applySlowmoCoroutine = StartCoroutine(ApplySlowmoSmooth(PluginConfig.Instance.SlowmoMultiplier));
_slowmoApplied = true;
}
Expand All @@ -49,20 +49,19 @@ public void OnTrickEndRequsted(TrickAction trickAction)

public void OnTrickEnded(TrickAction trickAction)
{

}

private IEnumerator ApplySlowmoSmooth(float multiplier)
{
float timeScale = 1;
var audioSource = AudioTimeSyncController.GetField<AudioSource, AudioTimeSyncController>("_audioSource");
while (timeScale > multiplier)
{
timeScale -= _slowmoStepAmount;
AudioTimeSyncController.SetField("_timeScale",timeScale);
audioSource.pitch = timeScale;
yield return new WaitForFixedUpdate();
}
float timeScale = 1;
var audioSource = AudioTimeSyncController.GetField<AudioSource, AudioTimeSyncController>("_audioSource");
while (timeScale > multiplier)
{
timeScale -= _slowmoStepAmount;
AudioTimeSyncController.SetField("_timeScale", timeScale);
audioSource.pitch = timeScale;
yield return new WaitForFixedUpdate();
}
}

private void ApplySlowmo(float multiplier)
Expand All @@ -76,15 +75,15 @@ private void ApplySlowmo(float multiplier)

private IEnumerator EndSlowmoSmooth()
{
float timeScale = AudioTimeSyncController.timeScale;
var audioSource = AudioTimeSyncController.GetField<AudioSource, AudioTimeSyncController>("_audioSource");
while (timeScale<1f)
{
timeScale += _slowmoStepAmount;
AudioTimeSyncController.SetField("_timeScale", timeScale);
audioSource.pitch = timeScale;
yield return new WaitForFixedUpdate();
}
float timeScale = AudioTimeSyncController.timeScale;
var audioSource = AudioTimeSyncController.GetField<AudioSource, AudioTimeSyncController>("_audioSource");
while (timeScale < 1f)
{
timeScale += _slowmoStepAmount;
AudioTimeSyncController.SetField("_timeScale", timeScale);
audioSource.pitch = timeScale;
yield return new WaitForFixedUpdate();
}
}

private void EndSlowmo()
Expand All @@ -100,4 +99,4 @@ public bool IsTrickInState(TrickAction trickAction, TrickState state)
RightSaberSaberTrickManager.IsTrickInState(trickAction, state);
}
}
}
}
6 changes: 4 additions & 2 deletions TrickSaber/InputHandling/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public void Init(SaberType type, VRControllersInputManager vrControllersInputMan
var dir = (ThumstickDir) Enum.Parse(typeof(ThumstickDir), PluginConfig.Instance.ThumstickDirection, true);

var triggerHandler = new TriggerHandler(node, PluginConfig.Instance.TriggerThreshold);
var gripHandler = new GripHandler(vrSystem, oculusController, controllerInputDevice, PluginConfig.Instance.GripThreshold);
var gripHandler = new GripHandler(vrSystem, oculusController, controllerInputDevice,
PluginConfig.Instance.GripThreshold);
var thumbstickAction = new ThumbstickHandler(node, PluginConfig.Instance.ThumbstickThreshold, dir);

_trickInputHandler.Add(PluginConfig.Instance.TriggerAction.GetEnumValue<TrickAction>(), triggerHandler);
_trickInputHandler.Add(PluginConfig.Instance.GripAction.GetEnumValue<TrickAction>(), gripHandler);
_trickInputHandler.Add(PluginConfig.Instance.ThumbstickAction.GetEnumValue<TrickAction>(), thumbstickAction);
_trickInputHandler.Add(PluginConfig.Instance.ThumbstickAction.GetEnumValue<TrickAction>(),
thumbstickAction);

Plugin.Log.Debug("Started Input Manager using " + vrSystem);
}
Expand Down
4 changes: 2 additions & 2 deletions TrickSaber/MovementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class MovementController : MonoBehaviour

public Vector3 ControllerPosition = Vector3.zero;
public Quaternion ControllerRotation = Quaternion.identity;
public Vector3 LocalControllerPosition => Controller.gameObject.transform.localPosition;
public Quaternion LocalControllerRotation => Controller.gameObject.transform.localRotation;
public SaberTrickManager SaberTrickManager;

public Vector3 Velocity = Vector3.zero;
public VRPlatformHelper VrPlatformHelper;
public Vector3 LocalControllerPosition => Controller.gameObject.transform.localPosition;
public Quaternion LocalControllerRotation => Controller.gameObject.transform.localRotation;

public float SaberSpeed => Velocity.magnitude;

Expand Down
34 changes: 20 additions & 14 deletions TrickSaber/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using System;
using System.Collections;
using System.Net;
using System.Reflection;
using BS_Utils.Utilities;
using HarmonyLib;
using IPA;
using IPA.Config.Stores;
using OVRSimpleJSON;
using SemVer;
using TMPro;
using TrickSaber.UI;
using UnityEngine.Networking;
using UnityEngine.XR;
using Config = IPA.Config.Config;
using Logger = IPA.Logging.Logger;
using Version = SemVer.Version;

namespace TrickSaber
{
Expand All @@ -15,33 +23,31 @@ internal class Plugin
{
public static string ControllerModel;

public static Version Version;
public static string VersionString;

public static Logger Log { get; set; }
public static Harmony Harmony { get; set; }
public static bool IsControllerSupported => !ControllerModel.Contains("Knuckles");

[Init]
public Plugin(Logger logger, Config config)
{
Log = logger;
PluginConfig.Instance = config.Generated<PluginConfig>();
var ver = Assembly.GetExecutingAssembly().GetName().Version;
Version = new Version(ver.Major, ver.Minor, ver.Build);
VersionString = Version.Major + "." + Version.Minor + "." + Version.Patch;
}

public static string Version
{
get
{
Version ver = Assembly.GetExecutingAssembly().GetName().Version;
return ver.Major + "." + ver.Minor + "." + ver.Build;
}
}

public static Logger Log { get; set; }
public static Harmony Harmony { get; set; }
public static bool IsControllerSupported => !ControllerModel.Contains("Knuckles");

[OnStart]
public void OnStart()
{
TrickSaberPlugin.Create();
SettingsUI.CreateMenu();
BSEvents.gameSceneLoaded += GameplayManager.OnGameSceneLoaded;
BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh;
Log.Debug($"TrickSaber version {Version} started");
Log.Debug($"TrickSaber version {VersionString} started");
}

public static string GetControllerName()
Expand Down
10 changes: 6 additions & 4 deletions TrickSaber/SaberTrickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private IEnumerator Start()
_movementController.SaberTrickManager = this;

_inputManager = gameObject.AddComponent<InputManager>();
_inputManager.Init(Saber.saberType, Controller.GetField<VRControllersInputManager, VRController>("_vrControllersInputManager"));
_inputManager.Init(Saber.saberType,
Controller.GetField<VRControllersInputManager, VRController>("_vrControllersInputManager"));
_inputManager.TrickActivated += OnTrickActivated;
_inputManager.TrickDeactivated += OnTrickDeactivated;

Expand All @@ -54,16 +55,17 @@ private IEnumerator Start()
private void OnTrickDeactivated(TrickAction trickAction)
{
var trick = Tricks[trickAction];
if (trick.State!=TrickState.Started) return;
if (trick.State != TrickState.Started) return;
trick.EndTrick();
}

private void OnTrickActivated(TrickAction trickAction, float val)
{
var trick = Tricks[trickAction];
trick.Value = val;
if (trick.State!=TrickState.Inactive) return;
if (GlobalTrickManager.Instance.AudioTimeSyncController.state == AudioTimeSyncController.State.Paused) return;
if (trick.State != TrickState.Inactive) return;
if (GlobalTrickManager.Instance.AudioTimeSyncController.state ==
AudioTimeSyncController.State.Paused) return;
trick.StartTrick();
}

Expand Down
8 changes: 8 additions & 0 deletions TrickSaber/TrickSaber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\OculusPlatform.dll</HintPath>
</Reference>
<Reference Include="SemVer">
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Libs\SemVer.dll</HintPath>
</Reference>
<Reference Include="SteamVR, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\SteamVR.dll</HintPath>
Expand Down Expand Up @@ -115,6 +118,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -144,6 +151,7 @@
<Compile Include="UI\SettingsUI.cs" />
<Compile Include="InputHandling\ThumbstickHandler.cs" />
<Compile Include="SaberTrickManager.cs" />
<Compile Include="UI\TrickSaberPlugin.cs" />
<Compile Include="VectorExtensions.cs" />
<Compile Include="ViewControllers\BindingsViewController.cs" />
<Compile Include="InputHandling\TriggerHandler.cs" />
Expand Down
11 changes: 6 additions & 5 deletions TrickSaber/Tricks/SpinTrick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace TrickSaber
{
public class SpinTrick : Trick
{
private bool _isVelocityDependent;
private Transform _saberModelTransform;
private Vector3 _spinVelocity;
private bool _isVelocityDependent;

public override TrickAction TrickAction => TrickAction.Spin;

Expand All @@ -23,7 +23,7 @@ public override void OnTrickStart()
if (_isVelocityDependent)
{
var angularVelocity = MovementController.GetAverageAngularVelocity();
_spinVelocity = new Vector3(Math.Abs(angularVelocity.x)+Math.Abs(angularVelocity.y), 0, 0);
_spinVelocity = new Vector3(Math.Abs(angularVelocity.x) + Math.Abs(angularVelocity.y), 0, 0);
angularVelocity = Quaternion.Inverse(MovementController.ControllerRotation) * angularVelocity;
if (angularVelocity.x < 0) _spinVelocity *= -1;
}
Expand All @@ -40,19 +40,20 @@ public override void OnTrickStart()
public override void OnTrickUpdate()
{
var vel = _spinVelocity;
if (!_isVelocityDependent) vel *= (float)Math.Pow(Value, 3);
if (!_isVelocityDependent) vel *= (float) Math.Pow(Value, 3);
_saberModelTransform.Rotate(vel);
}

IEnumerator LerpToOriginalRotation()
private IEnumerator LerpToOriginalRotation()
{
var rot = _saberModelTransform.localRotation;
while (Quaternion.Angle(rot, Quaternion.identity)>5f)
while (Quaternion.Angle(rot, Quaternion.identity) > 5f)
{
rot = Quaternion.Lerp(rot, Quaternion.identity, Time.deltaTime * 20);
_saberModelTransform.localRotation = rot;
yield return new WaitForEndOfFrame();
}

_saberModelTransform.localRotation = Quaternion.identity;
Reset();
}
Expand Down
1 change: 0 additions & 1 deletion TrickSaber/Tricks/ThrowTrick.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using IPA.Utilities;
using UnityEngine;

namespace TrickSaber
Expand Down
11 changes: 5 additions & 6 deletions TrickSaber/Tricks/Trick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ namespace TrickSaber
{
public abstract class Trick : MonoBehaviour
{
protected bool _endRequested;
protected MovementController MovementController;
protected SaberTrickManager SaberTrickManager;
protected SaberTrickModel SaberTrickModel;

protected bool _endRequested;
public float Value;
public TrickState State = TrickState.Inactive;
public float Value;

public abstract TrickAction TrickAction { get; }
public string Name => TrickAction.ToString();
Expand All @@ -31,7 +30,7 @@ public void Init(SaberTrickManager saberTrickManager, MovementController movemen

public bool StartTrick()
{
if (State==TrickState.Inactive)
if (State == TrickState.Inactive)
{
State = TrickState.Started;
OnTrickStart();
Expand All @@ -44,7 +43,7 @@ public bool StartTrick()

public void EndTrick()
{
if (State==TrickState.Started) _endRequested = true;
if (State == TrickState.Started) _endRequested = true;
}

protected void Reset()
Expand All @@ -56,7 +55,7 @@ protected void Reset()

private void Update()
{
if (State==TrickState.Started)
if (State == TrickState.Started)
if (!_endRequested)
{
OnTrickUpdate();
Expand Down
Loading

0 comments on commit 7073486

Please sign in to comment.