Skip to content

Commit

Permalink
Reduced Instances of loading
Browse files Browse the repository at this point in the history
custom name dictionary is now only built the first time the song list is loaded.
  • Loading branch information
Meeps committed Sep 13, 2020
1 parent c6f4c68 commit f127a52
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
77 changes: 40 additions & 37 deletions AudicaMod/src/CustomDifficultyName/CustomDifficultyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AudicaModding
public class CustomDifficultyNames : MelonMod
{
public static Dictionary<string, CustomNameData> CustomDifficulties = new Dictionary<string, CustomNameData>();

public static bool NamesAlreadyLoaded = false;
public class CustomNameData
{
public bool hasCustomExpertName = false;
Expand All @@ -28,57 +28,60 @@ public class CustomNameData

public static void LoadCustomNames()
{
CustomDifficulties = new Dictionary<string, CustomNameData>();

foreach (SongList.SongData data in SongList.I.songs.ToArray())
if (!NamesAlreadyLoaded)
{
ZipArchive SongFiles = ZipFile.OpenRead(data.foundPath);
CustomDifficulties = new Dictionary<string, CustomNameData>();

foreach (ZipArchiveEntry entry in SongFiles.Entries)
foreach (SongList.SongData data in SongList.I.songs.ToArray())
{
if (entry.Name == "song.desc")
ZipArchive SongFiles = ZipFile.OpenRead(data.foundPath);

foreach (ZipArchiveEntry entry in SongFiles.Entries)
{
Stream songData = entry.Open();
StreamReader reader = new StreamReader(songData);
string descDump = reader.ReadToEnd();
CustomNameData DifficultyNames = new CustomNameData();
DifficultyNames = JSON.Load(descDump).Make<CustomNameData>();
if (entry.Name == "song.desc")
{
Stream songData = entry.Open();
StreamReader reader = new StreamReader(songData);
string descDump = reader.ReadToEnd();
CustomNameData DifficultyNames = new CustomNameData();
DifficultyNames = JSON.Load(descDump).Make<CustomNameData>();

bool anyAreTrue = false;
bool anyAreTrue = false;


if (DifficultyNames.customExpert.Length > 0)
{
DifficultyNames.hasCustomExpertName = true;
anyAreTrue = true;
}
if (DifficultyNames.customExpert.Length > 0)
{
DifficultyNames.hasCustomExpertName = true;
anyAreTrue = true;
}

if (DifficultyNames.customAdvanced.Length > 0)
{
DifficultyNames.hasCustomAdvancedName = true;
anyAreTrue = true;
}
if (DifficultyNames.customAdvanced.Length > 0)
{
DifficultyNames.hasCustomAdvancedName = true;
anyAreTrue = true;
}

if (DifficultyNames.customModerate.Length > 0)
{
DifficultyNames.hasCustomModerateName = true;
anyAreTrue = true;
}
if (DifficultyNames.customModerate.Length > 0)
{
DifficultyNames.hasCustomModerateName = true;
anyAreTrue = true;
}

if (DifficultyNames.customBeginner.Length > 0)
{
DifficultyNames.hasCustomBeginnerName = true;
anyAreTrue = true;
}
if (DifficultyNames.customBeginner.Length > 0)
{
DifficultyNames.hasCustomBeginnerName = true;
anyAreTrue = true;
}

if (anyAreTrue)
CustomDifficulties[data.songID] = DifficultyNames;
if (anyAreTrue)
CustomDifficulties[data.songID] = DifficultyNames;


}
}
NamesAlreadyLoaded = true;
SongFiles.Dispose();
}

SongFiles.Dispose();
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions AudicaMod/src/CustomDifficultyName/DifficultyHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static IEnumerator ChangeNamesLP(LaunchPanel __instance)
{
yield return new WaitForSeconds(0.05f);

__instance.difficultySelect.gameObject.SetActive(false);
var song = SongDataHolder.I.songData;
CustomDifficultyNames.CustomNameData data;
if (CustomDifficultyNames.CustomDifficulties.ContainsKey(song.songID))
Expand Down Expand Up @@ -76,9 +75,6 @@ public static IEnumerator ChangeNamesDS(DifficultySelect __instance)
}
}

/// <summary>
/// Author: MeepsKitten
/// </summary>
[HarmonyPatch(typeof(LaunchPanel), "OnEnable", new Type[0])]
private static class DisplayCustomNameLP
{
Expand Down

0 comments on commit f127a52

Please sign in to comment.