Skip to content

Commit

Permalink
Fixed a bug with energy after online play
Browse files Browse the repository at this point in the history
Oops. Also cleaned up the code a bit.
  • Loading branch information
MCJack123 committed Jan 23, 2021
1 parent ca0a0bc commit 96ac6a6
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 220 deletions.
22 changes: 9 additions & 13 deletions PerformanceMeterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
using TMPro;

namespace PerformanceMeter {
/// <summary>
/// Monobehaviours (scripts) are added to GameObjects.
/// For a full list of Messages a Monobehaviour can receive from the game, see https://docs.unity3d.com/ScriptReference/MonoBehaviour.html.
/// </summary>
public class PerformanceMeterController : MonoBehaviour {
public static PerformanceMeterController instance { get; private set; }
List<float> energyList = new List<float>();
Expand Down Expand Up @@ -76,18 +72,17 @@ public void ShowResults() {
graphObj.transform.SetParent(panel.transform);
graphObj.transform.name = "GraphContainer";
WindowGraph graph = panel.AddComponent<WindowGraph>();
graph.ShowGraph(energyList, false, true, true);
graph.ShowGraph(energyList);

StartCoroutine(WaitForMenu());
}

#region Monobehaviour Messages
IEnumerator WaitForMenu() {
bool loaded = false;
if (endActions is StandardLevelGameplayManager) {
ResultsViewController resultsController = null;
while (!loaded) {
if (resultsController == null) resultsController = Resources.FindObjectsOfTypeAll<ResultsViewController>().FirstOrDefault();
if (resultsController == null) resultsController = Resources.FindObjectsOfTypeAll<ResultsViewController>().LastOrDefault();
if (resultsController != null) loaded = true;
else yield return new WaitForSeconds(0.1f);
}
Expand All @@ -98,7 +93,7 @@ IEnumerator WaitForMenu() {
} else {
MissionResultsViewController resultsController = null;
while (!loaded) {
if (resultsController == null) resultsController = Resources.FindObjectsOfTypeAll<MissionResultsViewController>().FirstOrDefault();
if (resultsController == null) resultsController = Resources.FindObjectsOfTypeAll<MissionResultsViewController>().LastOrDefault();
if (resultsController != null) loaded = true;
else yield return new WaitForSeconds(0.1f);
}
Expand Down Expand Up @@ -134,10 +129,10 @@ public void GetControllers() {
if (PluginConfig.Instance.GetMode() == PluginConfig.MeasurementMode.Energy) energyList.Add(0.5f);

scoreController = Resources.FindObjectsOfTypeAll<ScoreController>().LastOrDefault();
energyCounter = Resources.FindObjectsOfTypeAll<GameEnergyCounter>().FirstOrDefault();
rankCounter = Resources.FindObjectsOfTypeAll<RelativeScoreAndImmediateRankCounter>().FirstOrDefault();
endActions = Resources.FindObjectsOfTypeAll<StandardLevelGameplayManager>().FirstOrDefault();
if (endActions == null) endActions = Resources.FindObjectsOfTypeAll<MissionLevelGameplayManager>().FirstOrDefault();
energyCounter = Resources.FindObjectsOfTypeAll<GameEnergyCounter>().LastOrDefault();
rankCounter = Resources.FindObjectsOfTypeAll<RelativeScoreAndImmediateRankCounter>().LastOrDefault();
endActions = Resources.FindObjectsOfTypeAll<StandardLevelGameplayManager>().LastOrDefault();
if (endActions == null) endActions = Resources.FindObjectsOfTypeAll<MissionLevelGameplayManager>().LastOrDefault();

if (scoreController != null && energyCounter != null && rankCounter != null && endActions != null) {
scoreController.noteWasCutEvent += NoteHit;
Expand All @@ -146,7 +141,7 @@ public void GetControllers() {
endActions.levelFailedEvent += LevelFinished;
Logger.log.Debug("PerformanceMeter reloaded successfully");
} else {
Logger.log.Error("Could not reload PerformanceMeter");
Logger.log.Error("Could not reload PerformanceMeter. This may occur when playing online - if so, disregard this message.");
scoreController = null;
energyCounter = null;
rankCounter = null;
Expand Down Expand Up @@ -187,6 +182,7 @@ private void LevelFinished() {
if (scoreController != null && energyCounter != null && rankCounter != null && endActions != null) levelOk = true;
}

#region Monobehaviour Messages
/// <summary>
/// Only ever called once, mainly used to initialize variables.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyFileVersion("1.1.1")]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Out of the box, PerformanceMeter displays a graph of the energy bar's status fro

You can change the type of data PerformanceMeter records in the Mod Settings. See below for more information on how to do this.

Note: PerformanceMeter only appears in Solo, Party, and Campaign game modes. It does not appear in online matches.

## Configuration
### UI
PerformanceMeter can be configured in the Mod Settings section of the options. Here you can enable/disable PerformanceMeter, as well as change the mode.
Expand Down
3 changes: 0 additions & 3 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

namespace PerformanceMeter {
internal class Settings : PersistentSingleton<Settings> {
// For this method of setting the ResourceName, this class must be the first class in the file.
//public override string ResourceName => string.Join(".", GetType().Namespace, GetType().Name);

[UIValue("mode-options")]
public List<object> modeOptions = new object[] { "Energy", "Percentage (Modified)", "Percentage (Raw)", "Note Cut Value", "Average Cut Value" }.ToList();

Expand Down
Loading

0 comments on commit 96ac6a6

Please sign in to comment.