Skip to content

Commit

Permalink
pausing during saber return doesn't break the mod anymore & version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniMacaroni committed Aug 18, 2020
1 parent eab1517 commit 229f829
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
4 changes: 2 additions & 2 deletions TrickSaber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("9246546f-bdae-4371-8252-513e78a8791f")]
[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: AssemblyVersion("0.3.3.0")]
[assembly: AssemblyFileVersion("0.3.3.0")]
31 changes: 23 additions & 8 deletions TrickSaber/SaberTrickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,24 @@ private IEnumerator Start()

//We need to wait for CustomSabers to potentially change the saber models
yield return WaitForSaberModel(1);

GameObject saberModel = GetSaberModel();
if(saberModel) Plugin.Log.Debug($"Got saber model ({saberModel.name})");
else
{
Plugin.Log.Debug("Couldn't get saber model");
Destroy(gameObject);
yield break;
}

SaberTrickModel = new SaberTrickModel(GetSaberModel());

AddTrick<ThrowTrick>();
AddTrick<SpinTrick>();

BS_Utils.Utilities.BSEvents.songUnpaused += delegate
{
foreach (var trick in Tricks.Values)
{
trick.EndTrick();
}
};
Plugin.Log.Debug($"{Tricks.Count} tricks initialized");

BS_Utils.Utilities.BSEvents.songUnpaused += EndAllTricks;

Plugin.Log.Debug("Trick Manager initialized");
}
Expand Down Expand Up @@ -104,7 +110,8 @@ public GameObject GetSaberModel()
var model = Saber.transform.Find("SFSaber"); // Saber Factory
if (model == null) model = Saber.transform.Find(Saber.name); // Custom Sabers
if (model == null) model = Saber.transform.Find(SaberTrickModel.BasicSaberModelName); // Default Saber
return model.gameObject;
if (model != null) return model.gameObject;
return null;
}

private IEnumerator WaitForSaberModel(int timeout)
Expand Down Expand Up @@ -142,6 +149,14 @@ public bool IsDoingTrick()
return false;
}

public void EndAllTricks()
{
foreach (var trick in Tricks.Values)
{
trick.OnTrickEndImmediately();
}
}

private bool CanDoTrick()
{
return PluginConfig.Instance.TrickSaberEnabled &&
Expand Down
6 changes: 6 additions & 0 deletions TrickSaber/Tricks/SpinTrick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@ public override void OnTrickEndRequested()
{
StartCoroutine(PluginConfig.Instance.CompleteRotationMode ? CompleteRotation() : LerpToOriginalRotation());
}

public override void OnTrickEndImmediately()
{
_saberModelTransform.localRotation = Quaternion.identity;
Reset();
}
}
}
7 changes: 7 additions & 0 deletions TrickSaber/Tricks/ThrowTrick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public override void OnTrickEndRequested()
StartCoroutine(ReturnSaber(PluginConfig.Instance.ReturnSpeed));
}

public override void OnTrickEndImmediately()
{
StopAllCoroutines();
ThrowEnd();
}

public override void OnInit()
{
_controllerSnapThreshold = PluginConfig.Instance.ControllerSnapThreshold;
Expand All @@ -53,6 +59,7 @@ public IEnumerator ReturnSaber(float speed)
SaberTrickModel.Rigidbody.velocity = direction.normalized * force;
position = SaberTrickModel.TrickModel.transform.position;
controllerPos = MovementController.ControllerPosition;
Plugin.Log.Debug(controllerPos.ToString());
yield return new WaitForEndOfFrame();
}

Expand Down
3 changes: 3 additions & 0 deletions TrickSaber/Tricks/Trick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void Init(SaberTrickManager saberTrickManager)
MovementController = SaberTrickManager.MovementController;
SaberTrickModel = SaberTrickManager.SaberTrickModel;
OnInit();
Plugin.Log.Debug($"Trick: {Name} initialized");
}

public bool StartTrick()
Expand Down Expand Up @@ -62,6 +63,8 @@ protected void Reset()

public abstract void OnTrickEndRequested();

public abstract void OnTrickEndImmediately();

public abstract void OnInit();
}
}
8 changes: 4 additions & 4 deletions TrickSaber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"$schema": "https://raw.githubusercontent.com/beat-saber-modding-group/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "Toni Macaroni",
"description": "A BeatSaber mod for performing tricks",
"gameVersion": "1.9.1",
"gameVersion": "1.11.0",
"id": "TrickSaber",
"name": "TrickSaber",
"version": "0.3.2",
"version": "0.3.3",
"dependsOn": {
"BS Utils": "^1.4.10",
"BeatSaberMarkupLanguage": "^1.3.3"
"BS Utils": "^1.4.11",
"BeatSaberMarkupLanguage": "^1.3.4"
},
"links": {
"project-source": "https://github.com/ToniMacaroni/TrickSaber"
Expand Down

0 comments on commit 229f829

Please sign in to comment.