Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
code refactor, improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lxymahatma committed Feb 13, 2023
1 parent 3747f0b commit 08ff09c
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 293 deletions.
1 change: 1 addition & 0 deletions FC AP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<RootNamespace>FC_AP</RootNamespace>
<AssemblyName>FC AP</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<LangVersion>10.0</LangVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
Expand Down
207 changes: 107 additions & 100 deletions Indicator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Assets.Scripts.GameCore.HostComponent;
using Assets.Scripts.PeroTools.Commons;
using System;
using System;
using UnityEngine;
using UnityEngine.UI;
using static MuseDashMirror.BattleComponent;
Expand All @@ -9,121 +7,130 @@
using static MuseDashMirror.UICreate.Fonts;
using static MuseDashMirror.UICreate.TextGameObjectCreate;

namespace FC_AP
namespace FC_AP;

internal class Indicator : MonoBehaviour
{
internal class Indicator : MonoBehaviour
public Indicator(IntPtr intPtr) : base(intPtr)
{
internal static int GreatNum { get; set; }
internal static int MissNum { get; set; }
internal static int CurrentMissNum { get; set; }
internal static int GhostMiss { get; set; }
internal static int CollectableNoteMiss { get; set; }
private static GameObject AP { get; set; }
private static GameObject FC { get; set; }
private static GameObject Miss { get; set; }

public Indicator(IntPtr intPtr) : base(intPtr)
{
}
}

private static GameObject AP { get; set; }
private static GameObject FC { get; set; }
private static GameObject Miss { get; set; }

private void Start()
{
LoadFonts();
}

private void OnDestroy()
{
AP = null;
FC = null;
Miss = null;
UnloadFonts();
}

internal static void SetAPToggle()
{
CreateCanvas("Indicator Canvas", "Camera_2D");
AP = SetGameObject("AP", Color.yellow, "AP");
}

internal static void UpdateFCGameObject()
{
// if no great, return
if (GreatNum == 0) return;

private void Start()
// if has miss, don't need update FC
if (TotalMissNum != 0) return;

if (FC is null)
{
LoadFonts();
Destroy(AP);
FC = SetGameObject("FC", Blue, "FC " + GreatNum + "G");
}

private void Update()
else
{
// if indicator is enabled and not set, also is in game
if (Save.Settings.FC_APEnabled && AP == null && FC == null && Miss == null && IsInGame)
{
CreateCanvas("Indicator Canvas", "Camera_2D");
AP = SetGameObject("AP", Color.yellow, "AP");
}

//if AP is set, FC is not set and get a great
if (AP != null && FC == null && Miss == null && Great != 0)
{
Destroy(AP);
//if not AP then it must be 1 Great
GreatNum = 1;
FC = SetGameObject("FC", Blue, "FC " + GreatNum + "G");
}
FC.GetComponent<Text>().text = "FC " + GreatNum + "G";
}
}

//if AP is set, FC is not set and ghost not count as miss
if (AP != null && FC == null && GhostMiss != 0)
{
Destroy(AP);
FC = SetGameObject("FC", Blue, "FC");
}
internal static void UpdateMissGameObject()
{
// if no miss, return
if (TotalMissNum == 0) return;

//if AP is set, FC is not set and collectable note not count as miss
if (AP != null && FC == null && CollectableNoteMiss != 0)
{
Destroy(AP);
FC = SetGameObject("FC", Blue, "FC");
}
Destroy(AP);
Destroy(FC);

//if AP or FC is set, Miss doesn't set and get normal miss or ghost miss when enabled or collectable note miss when enabled
if (Miss == null && (AP != null || FC != null) && CurrentMissNum != 0)
{
Destroy(AP);
Destroy(FC);
MissNum = 1;
if (GreatNum == 0)
{
Miss = SetGameObject("Miss", Silver, MissNum + "M");
}
else
{
Miss = SetGameObject("Miss", Silver, MissNum + "M " + GreatNum + "G");
}
}
int currentMiss;
// if collectable note not count as miss and FC is null
if (!Save.Settings.CollectableMissEnabled && CollectableNoteMissNum != 0)
{
currentMiss = NormalMissNum + GhostMissNum;
if (Miss is null)
FC = SetFC();
}

//if FC or Miss is set and great number are not correct then +1
if (GreatNum < Singleton<TaskStageTarget>.instance.m_GreatResult)
{
GreatNum++;
if (FC != null)
{
FC.GetComponent<Text>().text = "FC " + GreatNum + "G";
}
if (Miss != null)
{
Miss.GetComponent<Text>().text = MissNum + "M " + GreatNum + "G";
}
}
// if collectable note not count as miss and FC is null
else if (!Save.Settings.GhostMissEnabled && GhostMissNum != 0)
{
currentMiss = NormalMissNum + CollectableNoteMissNum;
if (Miss is null)
FC = SetFC();
}

// if Miss is set and miss number are not correct then +1
if (MissNum < CurrentMissNum)
{
MissNum++;
if (Miss != null)
{
if (GreatNum == 0)
{
Miss.GetComponent<Text>().text = MissNum + "M";
}
else
{
Miss.GetComponent<Text>().text = MissNum + "M " + GreatNum + "G";
}
}
}
// if collectable note and ghost not count as miss and FC is null
else if (!Save.Settings.CollectableMissEnabled && CollectableNoteMissNum != 0 && !Save.Settings.GhostMissEnabled && GhostMissNum != 0)
{
currentMiss = NormalMissNum;
if (Miss is null)
FC = SetFC();
}
else
{
currentMiss = TotalMissNum;
Miss ??= SetMiss(currentMiss);
}

//Destroy gameobject in result screen
if (GameObject.Find("PnlVictory_2D") != null)
if (Miss is null)
{
if (currentMiss > NormalMissNum || NormalMissNum > 0)
{
Destroy(AP);
Destroy(FC);
Destroy(Miss);
Miss = SetMiss(currentMiss);
}
}

private static GameObject SetGameObject(string name, Color color, string text)
else
{
var gameobject = CreateTextGameObject("Indicator Canvas", name, text, TextAnchor.UpperLeft, true, new Vector3(-102.398f, 367.2864f, 0f), new Vector2(960, 216), 100, SnapsTasteFont, color);
return gameobject;
Miss.GetComponent<Text>().text = GreatNum == 0 ? currentMiss + "M" : currentMiss + "M " + GreatNum + "G";
}
}

private static GameObject SetFC()
{
var fc = GreatNum == 0 ? SetGameObject("FC", Blue, "FC") : SetGameObject("FC", Blue, "FC " + GreatNum + "G");
return fc;
}

private static GameObject SetMiss(int missNum)
{
var miss = GreatNum == 0 ? SetGameObject("Miss", Silver, missNum + "M") : SetGameObject("Miss", Silver, missNum + "M " + GreatNum + "G");
return miss;
}

internal static void DestroyGameObject()
{
Destroy(AP);
Destroy(FC);
Destroy(Miss);
}

private static GameObject SetGameObject(string name, Color color, string text)
{
var gameobject = CreateTextGameObject("Indicator Canvas", name, text, TextAnchor.UpperLeft, true, new Vector3(-102.398f, 367.2864f, 0f), new Vector2(960, 216), 100, SnapsTasteFont, color);
return gameobject;
}
}
83 changes: 37 additions & 46 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
using Assets.Scripts.UI.Panels;
using Il2CppSystem.IO;
using Il2CppSystem.IO;
using MelonLoader;
using MuseDashMirror;
using MuseDashMirror.CommonPatches;
using MuseDashMirror.UICreate;
using System;
using Tomlet;
using UnhollowerRuntimeLib;
using UnityEngine;
using static MuseDashMirror.CommonPatches.PatchEvents;
using static MuseDashMirror.BattleComponent;
using static MuseDashMirror.SceneInfo;
using static FC_AP.Indicator;

namespace FC_AP
namespace FC_AP;

public class Main : MelonMod
{
public class Main : MelonMod
public override void OnInitializeMelon()
{
public override void OnInitializeMelon()
{
Save.Load();
PatchEvents.PnlMenuEvent += new Action<PnlMenu>(Patch.PnlMenuPostfix);
PatchEvents.SwitchLanguagesEvent += new Action(Patch.SwitchLanguagesPostfix);
PatchEvents.MenuSelectEvent += new Action<int, int, bool>(DisableToggle);
SceneInfo.EnterGameScene += new Action(RegisterGameObject);
SceneInfo.ExitGameScene += new Action(Reset);
LoggerInstance.Msg("FC/AP indicator is loaded!");
}
Save.Load();
PnlMenuEvent += Patch.PnlMenuPostfix;
SwitchLanguagesEvent += Patch.SwitchLanguagesPostfix;
MenuSelectEvent += DisableToggle;
EnterGameScene += RegisterGameObject;
GameStartEvent += SetAPToggle;
OnVictoryEvent += DestroyGameObject;
AddScoreEvent += UpdateFCGameObject;
MissCubeEvent += UpdateMissGameObject;
LoggerInstance.Msg("FC/AP indicator is loaded!");
}

public override void OnDeinitializeMelon()
{
File.WriteAllText(Path.Combine("UserData", "FC AP.cfg"), TomletMain.TomlStringFrom(Save.Settings));
}
public override void OnDeinitializeMelon()
{
File.WriteAllText(Path.Combine("UserData", "FC AP.cfg"), TomletMain.TomlStringFrom(Save.Settings));
}

private void RegisterGameObject()
{
ClassInjector.RegisterTypeInIl2Cpp<Indicator>();
GameObject gameObject = new GameObject("Indicator");
UnityEngine.Object.DontDestroyOnLoad(gameObject);
gameObject.AddComponent<Indicator>();
}
private void RegisterGameObject()
{
if (!Save.Settings.FC_APEnabled) return;
ClassInjector.RegisterTypeInIl2Cpp<Indicator>();
var gameObject = new GameObject("Indicator");
gameObject.AddComponent<Indicator>();
}

private void Reset()
private void DisableToggle(int listIndex, int index, bool isOn)
{
if (listIndex == 0 && index == 0 && isOn)
{
Indicator.GreatNum = 0;
Indicator.CurrentMissNum = 0;
Indicator.MissNum = 0;
Indicator.GhostMiss = 0;
Indicator.CollectableNoteMiss = 0;
Fonts.UnloadFonts();
Patch.FC_APToggle.SetActive(true);
}

private void DisableToggle(int listIndex, int index, bool isOn)
else
{
if (listIndex == 0 && index == 0 && isOn)
{
Patch.FC_APToggle.SetActive(true);
}
else
{
Patch.FC_APToggle.SetActive(false);
}
Patch.FC_APToggle.SetActive(false);
}
}
}
19 changes: 9 additions & 10 deletions MelonBuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
namespace FC_AP
namespace FC_AP;

internal static class MelonBuildInfo
{
internal static class MelonBuildInfo
{
public const string Name = "FC AP indicator";
public const string Name = "FC AP indicator";

public const string Description = "Indicators for whether you are on FC/AP pace";
public const string Description = "Indicators for whether you are on FC/AP pace";

public const string Author = "lxy";
public const string Author = "lxy";

public const string Company = null;
public const string Company = null;

public const string Version = "1.5.4";
public const string Version = "1.6.0";

public const string DownloadLink = "https://github.com/MDModsDev/FC-AP-Indicator/releases/latest";
}
public const string DownloadLink = "https://github.com/MDModsDev/FC-AP-Indicator/releases/latest";
}
Loading

0 comments on commit 08ff09c

Please sign in to comment.