More cleanup.

This commit is contained in:
Ottermandias 2024-04-25 18:14:21 +02:00
parent 72db023804
commit 0fd14ffefc
6 changed files with 89 additions and 129 deletions

View file

@ -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<Utf8GamePath, FullPath> redirections, HashSet<MetaManipulation> manipulations)
=> SubModHelpers.AddContainerTo(this, redirections, manipulations);
public string GetName()
=> FullName;
public string GetFullName()
=> FullName;
public (int GroupIndex, int DataIndex) GetDataIndices()
=> (-1, 0);
}

View file

@ -15,24 +15,7 @@ public interface IModDataContainer
public Dictionary<Utf8GamePath, FullPath> FileSwaps { get; set; }
public HashSet<MetaManipulation> 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;

View file

@ -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<MultiModGroup>(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<Utf8GamePath, FullPath> Files { get; set; } = [];
public Dictionary<Utf8GamePath, FullPath> FileSwaps { get; set; } = [];
public HashSet<MetaManipulation> 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<Utf8GamePath, FullPath> redirections, HashSet<MetaManipulation> 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;
}
}
}

View file

@ -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<T>(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<Utf8GamePath, FullPath> Files { get; set; } = [];
public Dictionary<Utf8GamePath, FullPath> FileSwaps { get; set; } = [];
public HashSet<MetaManipulation> Manipulations { get; set; } = [];
public void AddDataTo(Dictionary<Utf8GamePath, FullPath> redirections, HashSet<MetaManipulation> 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;
}
}

View file

@ -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<SingleModGroup>(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<Utf8GamePath, FullPath> Files { get; set; } = [];
public Dictionary<Utf8GamePath, FullPath> FileSwaps { get; set; } = [];
public HashSet<MetaManipulation> 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<Utf8GamePath, FullPath> redirections, HashSet<MetaManipulation> 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;
}
}
}

View file

@ -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();
}
}
/// <summary> Write the data for a selectable mod option on a JsonWriter. </summary>
/// <summary> Write the data for a selectable mod option on a JsonWriter. </summary>
public static void WriteModOption(JsonWriter j, IModOption option)
{
j.WritePropertyName(nameof(option.Name));