diff --git a/Penumbra/Mods/SubMods/DefaultSubMod.cs b/Penumbra/Mods/SubMods/DefaultSubMod.cs index 8b00e2ae..1eddcef6 100644 --- a/Penumbra/Mods/SubMods/DefaultSubMod.cs +++ b/Penumbra/Mods/SubMods/DefaultSubMod.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json.Linq; using Penumbra.Meta.Manipulations; using Penumbra.Mods.Editor; using Penumbra.Mods.Groups; @@ -25,6 +24,12 @@ public class DefaultSubMod(IMod mod) : IModDataContainer public void AddTo(Dictionary redirections, HashSet manipulations) => SubModHelpers.AddContainerTo(this, redirections, manipulations); + public string GetName() + => FullName; + + public string GetFullName() + => FullName; + public (int GroupIndex, int DataIndex) GetDataIndices() => (-1, 0); } diff --git a/Penumbra/Mods/SubMods/IModDataContainer.cs b/Penumbra/Mods/SubMods/IModDataContainer.cs index 1e676816..a6ab491f 100644 --- a/Penumbra/Mods/SubMods/IModDataContainer.cs +++ b/Penumbra/Mods/SubMods/IModDataContainer.cs @@ -15,24 +15,7 @@ public interface IModDataContainer public Dictionary FileSwaps { get; set; } public HashSet Manipulations { get; set; } - public string GetName() - => this switch - { - IModOption o => o.FullName, - DefaultSubMod => DefaultSubMod.FullName, - _ => $"Container {GetDataIndices().DataIndex + 1}", - }; - - public string GetFullName() - => this switch - { - IModOption o => o.FullName, - DefaultSubMod => DefaultSubMod.FullName, - _ when Group != null => $"{Group.Name}: Container {GetDataIndices().DataIndex + 1}", - _ => $"Container {GetDataIndices().DataIndex + 1}", - }; - + public string GetName(); + public string GetFullName(); public (int GroupIndex, int DataIndex) GetDataIndices(); } - -public interface IModDataOption : IModOption, IModDataContainer; diff --git a/Penumbra/Mods/SubMods/MultiSubMod.cs b/Penumbra/Mods/SubMods/MultiSubMod.cs index ccb787a5..c43d4b9e 100644 --- a/Penumbra/Mods/SubMods/MultiSubMod.cs +++ b/Penumbra/Mods/SubMods/MultiSubMod.cs @@ -1,37 +1,13 @@ -using Newtonsoft.Json.Linq; -using OtterGui; -using Penumbra.Meta.Manipulations; -using Penumbra.Mods.Editor; +using Newtonsoft.Json.Linq; using Penumbra.Mods.Groups; using Penumbra.Mods.Settings; -using Penumbra.String.Classes; - -namespace Penumbra.Mods.SubMods; - -public class MultiSubMod(Mod mod, MultiModGroup group) : IModDataOption + +namespace Penumbra.Mods.SubMods; + +public class MultiSubMod(Mod mod, MultiModGroup group) : OptionSubMod(mod, group) { - internal readonly Mod Mod = mod; - internal readonly MultiModGroup Group = group; - - public string Name { get; set; } = "Option"; - - public string FullName - => $"{Group.Name}: {Name}"; - - public string Description { get; set; } = string.Empty; public ModPriority Priority { get; set; } = ModPriority.Default; - public Dictionary Files { get; set; } = []; - public Dictionary FileSwaps { get; set; } = []; - public HashSet Manipulations { get; set; } = []; - - IMod IModDataContainer.Mod - => Mod; - - IModGroup IModDataContainer.Group - => Group; - - public MultiSubMod(Mod mod, MultiModGroup group, JToken json) : this(mod, group) { @@ -44,9 +20,9 @@ public class MultiSubMod(Mod mod, MultiModGroup group) : IModDataOption { var ret = new MultiSubMod(mod, group) { - Name = Name, + Name = Name, Description = Description, - Priority = Priority, + Priority = Priority, }; SubModHelpers.Clone(this, ret); @@ -57,36 +33,18 @@ public class MultiSubMod(Mod mod, MultiModGroup group) : IModDataOption { var ret = new SingleSubMod(mod, group) { - Name = Name, + Name = Name, Description = Description, }; SubModHelpers.Clone(this, ret); return ret; } - public void AddDataTo(Dictionary redirections, HashSet manipulations) - => SubModHelpers.AddContainerTo(this, redirections, manipulations); - public static MultiSubMod CreateForSaving(string name, string description, ModPriority priority) => new(null!, null!) { - Name = name, + Name = name, Description = description, - Priority = priority, + Priority = priority, }; - - public (int GroupIndex, int DataIndex) GetDataIndices() - => (Group.GetIndex(), GetDataIndex()); - - public (int GroupIndex, int OptionIndex) GetOptionIndices() - => (Group.GetIndex(), GetDataIndex()); - - private int GetDataIndex() - { - var dataIndex = Group.DataContainers.IndexOf(this); - if (dataIndex < 0) - throw new Exception($"Group {Group.Name} from SubMod {Name} does not contain this SubMod."); - - return dataIndex; - } -} +} diff --git a/Penumbra/Mods/SubMods/OptionSubMod.cs b/Penumbra/Mods/SubMods/OptionSubMod.cs new file mode 100644 index 00000000..79c50e51 --- /dev/null +++ b/Penumbra/Mods/SubMods/OptionSubMod.cs @@ -0,0 +1,57 @@ +using OtterGui; +using Penumbra.Meta.Manipulations; +using Penumbra.Mods.Editor; +using Penumbra.Mods.Groups; +using Penumbra.String.Classes; + +namespace Penumbra.Mods.SubMods; + +public interface IModDataOption : IModDataContainer, IModOption; + +public abstract class OptionSubMod(Mod mod, T group) : IModDataOption + where T : IModGroup +{ + internal readonly Mod Mod = mod; + internal readonly IModGroup Group = group; + + public string Name { get; set; } = "Option"; + + public string FullName + => $"{Group!.Name}: {Name}"; + + public string Description { get; set; } = string.Empty; + + IMod IModDataContainer.Mod + => Mod; + + IModGroup IModDataContainer.Group + => Group; + + public Dictionary Files { get; set; } = []; + public Dictionary FileSwaps { get; set; } = []; + public HashSet Manipulations { get; set; } = []; + + public void AddDataTo(Dictionary redirections, HashSet manipulations) + => SubModHelpers.AddContainerTo(this, redirections, manipulations); + + public string GetName() + => Name; + + public string GetFullName() + => FullName; + + public (int GroupIndex, int DataIndex) GetDataIndices() + => (Group.GetIndex(), GetDataIndex()); + + public (int GroupIndex, int OptionIndex) GetOptionIndices() + => (Group.GetIndex(), GetDataIndex()); + + private int GetDataIndex() + { + var dataIndex = Group.DataContainers.IndexOf(this); + if (dataIndex < 0) + throw new Exception($"Group {Group.Name} from SubMod {Name} does not contain this SubMod."); + + return dataIndex; + } +} diff --git a/Penumbra/Mods/SubMods/SingleSubMod.cs b/Penumbra/Mods/SubMods/SingleSubMod.cs index e6740a47..5d68e401 100644 --- a/Penumbra/Mods/SubMods/SingleSubMod.cs +++ b/Penumbra/Mods/SubMods/SingleSubMod.cs @@ -1,37 +1,13 @@ -using Newtonsoft.Json.Linq; -using OtterGui; -using Penumbra.Meta.Manipulations; -using Penumbra.Mods.Editor; +using Newtonsoft.Json.Linq; using Penumbra.Mods.Groups; using Penumbra.Mods.Settings; -using Penumbra.String.Classes; - -namespace Penumbra.Mods.SubMods; - -public class SingleSubMod(Mod mod, SingleModGroup group) : IModDataOption + +namespace Penumbra.Mods.SubMods; + +public class SingleSubMod(Mod mod, SingleModGroup singleGroup) : OptionSubMod(mod, singleGroup) { - internal readonly Mod Mod = mod; - internal readonly SingleModGroup Group = group; - - public string Name { get; set; } = "Option"; - - public string FullName - => $"{Group.Name}: {Name}"; - - public string Description { get; set; } = string.Empty; - - IMod IModDataContainer.Mod - => Mod; - - IModGroup IModDataContainer.Group - => Group; - - public Dictionary Files { get; set; } = []; - public Dictionary FileSwaps { get; set; } = []; - public HashSet Manipulations { get; set; } = []; - - public SingleSubMod(Mod mod, SingleModGroup group, JToken json) - : this(mod, group) + public SingleSubMod(Mod mod, SingleModGroup singleGroup, JToken json) + : this(mod, singleGroup) { SubModHelpers.LoadOptionData(json, this); SubModHelpers.LoadDataContainer(json, this, mod.ModPath); @@ -41,7 +17,7 @@ public class SingleSubMod(Mod mod, SingleModGroup group) : IModDataOption { var ret = new SingleSubMod(mod, group) { - Name = Name, + Name = Name, Description = Description, }; SubModHelpers.Clone(this, ret); @@ -53,30 +29,12 @@ public class SingleSubMod(Mod mod, SingleModGroup group) : IModDataOption { var ret = new MultiSubMod(mod, group) { - Name = Name, + Name = Name, Description = Description, - Priority = priority, + Priority = priority, }; SubModHelpers.Clone(this, ret); return ret; } - - public void AddDataTo(Dictionary redirections, HashSet manipulations) - => SubModHelpers.AddContainerTo(this, redirections, manipulations); - - public (int GroupIndex, int DataIndex) GetDataIndices() - => (Group.GetIndex(), GetDataIndex()); - - public (int GroupIndex, int OptionIndex) GetOptionIndices() - => (Group.GetIndex(), GetDataIndex()); - - private int GetDataIndex() - { - var dataIndex = Group.DataContainers.IndexOf(this); - if (dataIndex < 0) - throw new Exception($"Group {Group.Name} from SubMod {Name} does not contain this SubMod."); - - return dataIndex; - } -} +} diff --git a/Penumbra/Mods/SubMods/SubModHelpers.cs b/Penumbra/Mods/SubMods/SubModHelpers.cs index 9992b6e8..2a09fbc3 100644 --- a/Penumbra/Mods/SubMods/SubModHelpers.cs +++ b/Penumbra/Mods/SubMods/SubModHelpers.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Penumbra.Meta.Manipulations; -using Penumbra.Mods.ItemSwap; using Penumbra.String.Classes; namespace Penumbra.Mods.SubMods; @@ -92,9 +91,9 @@ public static class SubModHelpers j.WritePropertyName(nameof(data.Manipulations)); serializer.Serialize(j, data.Manipulations); j.WriteEndObject(); - } + } - /// Write the data for a selectable mod option on a JsonWriter. + /// Write the data for a selectable mod option on a JsonWriter. public static void WriteModOption(JsonWriter j, IModOption option) { j.WritePropertyName(nameof(option.Name));