Skip to content

Commit

Permalink
Fix indicator not showing and errors after restarting a play
Browse files Browse the repository at this point in the history
  • Loading branch information
Azn9 committed Feb 19, 2023
1 parent 1c1a3e2 commit 16c3359
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions AccuracyIndicator/Patch/SceneChangePatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AccuracyIndicator.Indicator;
using HarmonyLib;
using MelonLoader;
using UnityEngine;

namespace AccuracyIndicator.Patch;
Expand All @@ -8,46 +9,49 @@ public static class SceneChangePatch
{
public static void OnSceneWasUnloaded(string sceneName)
{
switch (sceneName)
{
case "GameMain":
if (Main.IndicatorObj != null)
{
Object.Destroy(Main.IndicatorObj);
Main.IndicatorObj = null;
}

break;
}
if (sceneName == "GameMain")
Destroy();
}

[HarmonyPatch(typeof(PnlVictory), "OnVictory")]
internal static class VictoryPatch
{

private static void Postfix()
{
var meanDelay = Main.InGameIndicator.GetMeanDelay();
var report = Main.InGameIndicator.GetReport();

Object.Destroy(Main.InGameIndicator);
Main.InGameIndicator = null;

var victoryIndicator = Main.IndicatorObj.AddComponent<VictoryIndicator>();

victoryIndicator.SetMeanDelay(meanDelay);
victoryIndicator.SetReport(report);
}
}

[HarmonyPatch(typeof(PnlFail), "Fail")]
internal static class FailPatch
{

private static void Postfix()
{
Destroy();
}
}

private static void Destroy()
{
if (Main.InGameIndicator is not null)
{
Object.Destroy(Main.InGameIndicator);
Main.InGameIndicator = null;
}

if (Main.IndicatorObj is not null)
{
Object.Destroy(Main.IndicatorObj);
Main.IndicatorObj = null;
}
}

}

0 comments on commit 16c3359

Please sign in to comment.