Skip to content

Commit

Permalink
changes I forgot to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nhruo123 committed Sep 5, 2023
1 parent 47237fa commit dc31ed3
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions Celeste.Mod.mm/Mod/UI/OuiModToggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class OuiModToggler : OuiGenericMenu, OuiModOptions.ISubmenu {
// list of blacklisted mods when the menu was open
private HashSet<string> blacklistedModsOriginal;

// list of currently favorite mods
private HashSet<string> favoritedMods;
// list of favorite mods
private HashSet<string> favoriteMods;
// list of favorite mods when the menu was open
private HashSet<string> favoritedModsOriginal;
// dictionary mapping between the dependencies and the dependents
private Dictionary<string, HashSet<string>> favoriteDependencies;
private HashSet<string> favoriteModsOriginal;
// maps each dependency to all its dependents
private Dictionary<string, HashSet<string>> favoriteModDependencies;

private bool toggleDependencies = true;

Expand Down Expand Up @@ -231,8 +231,8 @@ protected override void addOptionsToMenu(TextMenu menu) {
menu.Add(new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_DISABLEALL")).Pressed(() => {
blacklistedMods.Clear();
foreach (KeyValuePair<string, TextMenu.OnOff> toggle in modToggles) {
bool isFavoriteOrDependent = favoritedMods.Contains(toggle.Key) || favoriteDependencies.ContainsKey(toggle.Key);
if (protectFavorites && isFavoriteOrDependent) {
bool isFavoriteDependency = favoriteMods.Contains(toggle.Key) || favoriteModDependencies.ContainsKey(toggle.Key);
if (protectFavorites && isFavoriteDependency) {
continue;
}

Expand Down Expand Up @@ -276,16 +276,15 @@ protected override void addOptionsToMenu(TextMenu menu) {
// "cancel" button to leave the screen without saving
menu.Add(new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_CANCEL")).Pressed(() => {
blacklistedMods = blacklistedModsOriginal;
favoritedMods = favoritedModsOriginal;
favoriteDependencies = null;
favoriteMods = favoriteModsOriginal;
onBackPressed(Overworld);
}));

// reset the mods list
allMods = new List<string>();
blacklistedMods = new HashSet<string>();
favoritedMods = new HashSet<string>();
favoriteDependencies = new Dictionary<string, HashSet<string>>();
favoriteMods = new HashSet<string>();
favoriteModDependencies = new Dictionary<string, HashSet<string>>();

string[] files;
bool headerInserted;
Expand Down Expand Up @@ -340,7 +339,7 @@ protected override void addOptionsToMenu(TextMenu menu) {

// clone the list to be able to check if the list changed when leaving the menu.
blacklistedModsOriginal = new HashSet<string>(blacklistedMods);
favoritedModsOriginal = new HashSet<string>(favoritedMods);
favoriteModsOriginal = new HashSet<string>(favoriteMods);

// set colors to mods listings
updateHighlightedMods();
Expand All @@ -360,7 +359,7 @@ private void addFileToMenu(TextMenu menu, string file) {
bool enabled = !Everest.Loader.Blacklist.Contains(file);
bool favorite = Everest.Loader.Favorites.Contains(file);

TextMenu.OnOff option = new TextMenu.OnOff(file.Length > 40 ? file.Substring(0, 40) + "..." : file, enabled);
TextMenu.OnOff option = new(file.Length > 40 ? file.Substring(0, 40) + "..." : file, enabled);

option.Change(b => {
if (b) {
Expand All @@ -371,7 +370,7 @@ private void addFileToMenu(TextMenu menu, string file) {

updateHighlightedMods();
}).AltPressed(() => {
if (!favoritedMods.Contains(file)) {
if (!favoriteMods.Contains(file)) {
Audio.Play(SFX.ui_main_button_toggle_on);
addToFavorites(file);
} else {
Expand Down Expand Up @@ -422,9 +421,9 @@ private void updateHighlightedMods() {
// adjust the mods' color if they are required dependencies for other mods
foreach (KeyValuePair<string, TextMenu.OnOff> toggle in modToggles) {
Color unselectedColor = Color.White;
if (favoritedMods.Contains(toggle.Key)) {
if (favoriteMods.Contains(toggle.Key)) {
unselectedColor = Color.DeepPink;
} else if (favoriteDependencies.ContainsKey(toggle.Key)) {
} else if (favoriteModDependencies.ContainsKey(toggle.Key)) {
unselectedColor = Color.LightPink;
} else if (modHasDependencies(toggle.Key)) {
unselectedColor = Color.Goldenrod;
Expand Down Expand Up @@ -491,7 +490,7 @@ private void removeFromBlacklist(string file) {
}

private void addToFavorites(string modFileName) {
favoritedMods.Add(modFileName);
favoriteMods.Add(modFileName);
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} was added to favorites");

if (TryGetModDependenciesFileNames(modFileName, out List<string> dependenciesFileNames)) {
Expand All @@ -502,15 +501,15 @@ private void addToFavorites(string modFileName) {
}

private void addToFavoritesDependencies(string modFileName, string dependentModFileName) {
bool existsInFavoriteDependencies = favoriteDependencies.TryGetValue(modFileName, out HashSet<string> dependents);
bool existsInFavoriteDependencies = favoriteModDependencies.TryGetValue(modFileName, out HashSet<string> dependents);

// If we have a cyclical dependencies we want to stop after the first occurrence of a mod, or if somehow a mod reached itself.
if ((existsInFavoriteDependencies && dependents.Contains(dependentModFileName)) || modFileName == dependentModFileName) {
return;
}

if (!existsInFavoriteDependencies) {
dependents = favoriteDependencies[modFileName] = new HashSet<string>();
dependents = favoriteModDependencies[modFileName] = new HashSet<string>();
}

// Add dependent mod
Expand All @@ -527,7 +526,7 @@ private void addToFavoritesDependencies(string modFileName, string dependentModF
}

private void removeFromFavorites(string modFileName) {
favoritedMods.Remove(modFileName);
favoriteMods.Remove(modFileName);
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} was removed from favorites");

if (TryGetModDependenciesFileNames(modFileName, out List<string> dependenciesFileNames)) {
Expand All @@ -538,13 +537,13 @@ private void removeFromFavorites(string modFileName) {
}

private void removeFromFavoritesDependencies(string modFileName, string dependentModFileName) {
if (favoriteDependencies.TryGetValue(modFileName, out HashSet<string> dependents) && dependents.Contains(dependentModFileName)) {
if (favoriteModDependencies.TryGetValue(modFileName, out HashSet<string> dependents) && dependents.Contains(dependentModFileName)) {

dependents.Remove(dependentModFileName);
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} was removed from being a favorite dependency of {dependentModFileName}");

if (dependents.Count == 0) {
favoriteDependencies.Remove(modFileName);
favoriteModDependencies.Remove(modFileName);
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} is no longer a favorite dependency");
}

Expand All @@ -559,14 +558,14 @@ private void removeFromFavoritesDependencies(string modFileName, string dependen
private void onBackPressed(Overworld overworld) {
// "back" only works if the loading is done.
if (modLoadingTask == null || modLoadingTask.IsCompleted || modLoadingTask.IsCanceled || modLoadingTask.IsFaulted) {
if (!favoritedModsOriginal.SetEquals(favoritedMods)) {
Everest.Loader.Favorites = favoritedMods;
if (!favoriteModsOriginal.SetEquals(favoriteMods)) {
Everest.Loader.Favorites = favoriteMods;
using (StreamWriter writer = File.CreateText(Everest.Loader.PathFavorites)) {
// header
writer.WriteLine("# This is the favorite list. Lines starting with # are ignored.");
writer.WriteLine("");

foreach (string mod in favoritedMods) {
foreach (string mod in favoriteMods) {
writer.WriteLine(mod);
}
}
Expand Down Expand Up @@ -649,9 +648,9 @@ public override IEnumerator Leave(Oui next) {
modLoadingTask = null;
toggleDependencies = true;
protectFavorites = false;
favoritedMods = null;
favoritedModsOriginal = null;
favoriteDependencies = null;
favoriteMods = null;
favoriteModsOriginal = null;
favoriteModDependencies = null;
}
}
}

0 comments on commit dc31ed3

Please sign in to comment.