//Check color of a single mod. public void ColorItemOnOverrdingData(ModItem item) { ColorItemsOnOverridingData(new List <ModItem>() { item }); }
//See if items A and B are interacting in terms of manifest and return the intersect public void GetModOverridingData(ModItem itemA, ModItem itemB, int itemCount, OverridingData A, OverridingData B) { string modA = itemA.SubItems[2].Text; string modB = itemB.SubItems[2].Text; if (modA == modB) { return; } int priorityA = itemCount - itemA.Index; int priorityB = itemCount - itemB.Index; //Now we have a mod that is not the mod we are looking at is enbabled. //Lets compare the manifest! List <string> manifestA = this.ModDetails[this.DirectoryToPathDict[modA]].manifest; List <string> manifestB = this.ModDetails[this.DirectoryToPathDict[modB]].manifest; List <string> intersect = manifestA.Intersect(manifestB).ToList(); //If the intersects elements are greater then zero we have shared parts of the manifest if (intersect.Count() == 0) { return; } ////Console.WriteLine("---Intersection: " + modB + " : " + priorityB.ToString()); //If we are loaded after the mod we are looking at we are overriding it. if (priorityA > priorityB) { if (!(A.mod == modB)) { A.isOverriding = true; A.overrides[modB] = intersect; } if (!(B.mod == modA)) { B.isOverriden = true; B.overriddenBy[modA] = intersect; } } else { if (!(A.mod == modB)) { A.isOverriden = true; A.overriddenBy[modB] = intersect; } if (!(B.mod == modA)) { B.isOverriding = true; B.overrides[modA] = intersect; } } this.OverrridingData[modA] = A; this.OverrridingData[modB] = B; }
//used to update the overriding data when a mod is moved ONE up or ONE down. public void UpdateModOverridingdata(List <ModItem> items, ModItem movedMod, bool movedUp) { string modA = movedMod.SubItems[2].Text; //Console.WriteLine("UpdateModOverridingdata"); //Console.WriteLine("--" + modA); int indexToCheck = 0; if (movedUp) { indexToCheck = movedMod.Index + 1; } else { indexToCheck = movedMod.Index - 1; } ModItem itemB = items[indexToCheck]; string modB = itemB.SubItems[2].Text; //Console.WriteLine("++" + modB); if (!this.OverrridingData.ContainsKey(modA)) { this.OverrridingData[modA] = new OverridingData { mod = modA, overrides = new Dictionary <string, List <string> >(), overriddenBy = new Dictionary <string, List <string> >() }; } if (!this.OverrridingData.ContainsKey(modB)) { this.OverrridingData[modB] = new OverridingData { mod = modB, overrides = new Dictionary <string, List <string> >(), overriddenBy = new Dictionary <string, List <string> >() }; } ResetOverrdingBetweenMods(movedMod, itemB); GetModOverridingData(movedMod, items[indexToCheck], items.Count, OverrridingData[modA], OverrridingData[modA]); OverridingData A = OverrridingData[modA]; OverridingData B = OverrridingData[modB]; ColorItemsOnOverridingData(items); }
//Reset the orriding data between two mods and check if after mods are still overriding/beeing overrriden public void ResetOverrdingBetweenMods(ModItem itemA, ModItem itemB) { string modA = itemA.SubItems[2].Text; string modB = itemB.SubItems[2].Text; if (this.OverrridingData.ContainsKey(modA)) { if (this.OverrridingData[modA].overriddenBy.ContainsKey(modB)) { this.OverrridingData[modA].overriddenBy.Remove(modB); } if (this.OverrridingData[modA].overrides.ContainsKey(modB)) { this.OverrridingData[modA].overrides.Remove(modB); } if (this.OverrridingData[modA].overrides.Count == 0) { this.OverrridingData[modA].isOverriding = false; } if (this.OverrridingData[modA].overriddenBy.Count == 0) { this.OverrridingData[modA].isOverriden = false; } } if (this.OverrridingData.ContainsKey(modA)) { if (this.OverrridingData[modB].overriddenBy.ContainsKey(modA)) { this.OverrridingData[modB].overriddenBy.Remove(modA); } if (this.OverrridingData[modB].overrides.ContainsKey(modA)) { this.OverrridingData[modB].overrides.Remove(modA); } if (this.OverrridingData[modB].overrides.Count == 0) { this.OverrridingData[modB].isOverriding = false; } if (this.OverrridingData[modB].overriddenBy.Count == 0) { this.OverrridingData[modB].isOverriden = false; } } //Console.WriteLine("ResetOverrdingBetweenMods modA: " + modA + " " + this.OverrridingData[modA].isOverriding + " " + this.OverrridingData[modA].isOverriden); //Console.WriteLine("ResetOverrdingBetweenMods modB: " + modB + " " + this.OverrridingData[modB].isOverriding + " " + this.OverrridingData[modB].isOverriden); }
//Used to update the override data when a new item is added or removed to/from the mod list instead of checking all items agains each other again. public void UpdateNewModOverrideData(List <ModItem> items, ModItem newItem) { string modA = newItem.SubItems[2].Text; ////Console.WriteLine("UpdateNewModOverrideData"); ////Console.WriteLine("Mod checked or unchecked: " + modA); if (!newItem.Checked) { ////Console.WriteLine("--Unchecked"); if (this.OverrridingData.ContainsKey(modA)) { this.OverrridingData.Remove(modA); } foreach (string key in this.OverrridingData.Keys) { if (OverrridingData[key].overriddenBy.ContainsKey(modA)) { OverrridingData[key].overriddenBy.Remove(modA); } if (OverrridingData[key].overrides.ContainsKey(modA)) { OverrridingData[key].overrides.Remove(modA); } if (OverrridingData[key].overrides.Count == 0) { OverrridingData[key].isOverriding = false; } if (OverrridingData[key].overriddenBy.Count == 0) { OverrridingData[key].isOverriden = false; } } } else { ////Console.WriteLine("--Unchecked"); if (!this.OverrridingData.ContainsKey(modA)) { this.OverrridingData[modA] = new OverridingData { mod = modA, overrides = new Dictionary <string, List <string> >(), overriddenBy = new Dictionary <string, List <string> >() }; } //check each mod for changes foreach (ModItem item in items) { string modB = item.SubItems[2].Text; //Again dont compare mods to themselves. if (modA == modB) { continue; } if (!this.OverrridingData.ContainsKey(modB)) { this.OverrridingData[modB] = new OverridingData { mod = modB, overrides = new Dictionary <string, List <string> >(), overriddenBy = new Dictionary <string, List <string> >() }; } GetModOverridingData(newItem, item, items.Count, this.OverrridingData[modA], this.OverrridingData[modB]); } } ColorItemsOnOverridingData(items); }