mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Be less dumb.
This commit is contained in:
parent
10ce5da8c9
commit
26371d42f7
4 changed files with 26 additions and 24 deletions
|
|
@ -170,14 +170,10 @@ public class ImcModGroup(Mod mod) : IModGroup
|
|||
var identifier = ImcIdentifier.FromJson(json[nameof(Identifier)] as JObject);
|
||||
var ret = new ImcModGroup(mod)
|
||||
{
|
||||
Name = json[nameof(Name)]?.ToObject<string>() ?? string.Empty,
|
||||
Description = json[nameof(Description)]?.ToObject<string>() ?? string.Empty,
|
||||
Image = json[nameof(Image)]?.ToObject<string>() ?? string.Empty,
|
||||
Priority = json[nameof(Priority)]?.ToObject<ModPriority>() ?? ModPriority.Default,
|
||||
DefaultEntry = json[nameof(DefaultEntry)]?.ToObject<ImcEntry>() ?? new ImcEntry(),
|
||||
AllVariants = json[nameof(AllVariants)]?.ToObject<bool>() ?? false,
|
||||
};
|
||||
if (ret.Name.Length == 0)
|
||||
if (!ModSaveGroup.ReadJsonBase(json, ret))
|
||||
return null;
|
||||
|
||||
if (!identifier.HasValue || ret.DefaultEntry.MaterialId == 0)
|
||||
|
|
@ -216,7 +212,6 @@ public class ImcModGroup(Mod mod) : IModGroup
|
|||
}
|
||||
|
||||
ret.Identifier = identifier.Value;
|
||||
ret.DefaultSettings = json[nameof(DefaultSettings)]?.ToObject<Setting>() ?? Setting.Zero;
|
||||
ret.DefaultSettings = ret.FixSetting(ret.DefaultSettings);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.GameData.Files.ShaderStructs;
|
||||
using Penumbra.Mods.Settings;
|
||||
using Penumbra.Mods.SubMods;
|
||||
using Penumbra.Services;
|
||||
|
||||
|
|
@ -90,6 +93,8 @@ public readonly struct ModSaveGroup : ISavable
|
|||
jWriter.WriteValue(group.Description);
|
||||
jWriter.WritePropertyName(nameof(group.Image));
|
||||
jWriter.WriteValue(group.Image);
|
||||
jWriter.WritePropertyName(nameof(group.Page));
|
||||
jWriter.WriteValue(group.Page);
|
||||
jWriter.WritePropertyName(nameof(group.Priority));
|
||||
jWriter.WriteValue(group.Priority.Value);
|
||||
jWriter.WritePropertyName(nameof(group.Type));
|
||||
|
|
@ -97,4 +102,16 @@ public readonly struct ModSaveGroup : ISavable
|
|||
jWriter.WritePropertyName(nameof(group.DefaultSettings));
|
||||
jWriter.WriteValue(group.DefaultSettings.Value);
|
||||
}
|
||||
|
||||
public static bool ReadJsonBase(JObject json, IModGroup group)
|
||||
{
|
||||
group.Name = json[nameof(IModGroup.Name)]?.ToObject<string>() ?? string.Empty;
|
||||
group.Description = json[nameof(IModGroup.Description)]?.ToObject<string>() ?? string.Empty;
|
||||
group.Image = json[nameof(IModGroup.Image)]?.ToObject<string>() ?? string.Empty;
|
||||
group.Page = json[nameof(IModGroup.Page)]?.ToObject<int>() ?? 0;
|
||||
group.Priority = json[nameof(IModGroup.Priority)]?.ToObject<ModPriority>() ?? ModPriority.Default;
|
||||
group.DefaultSettings = json[nameof(IModGroup.DefaultSettings)]?.ToObject<Setting>() ?? Setting.Zero;
|
||||
|
||||
return group.Name.Length > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,15 +67,8 @@ public sealed class MultiModGroup(Mod mod) : IModGroup, ITexToolsGroup
|
|||
|
||||
public static MultiModGroup? Load(Mod mod, JObject json)
|
||||
{
|
||||
var ret = new MultiModGroup(mod)
|
||||
{
|
||||
Name = json[nameof(Name)]?.ToObject<string>() ?? string.Empty,
|
||||
Description = json[nameof(Description)]?.ToObject<string>() ?? string.Empty,
|
||||
Image = json[nameof(Image)]?.ToObject<string>() ?? string.Empty,
|
||||
Priority = json[nameof(Priority)]?.ToObject<ModPriority>() ?? ModPriority.Default,
|
||||
DefaultSettings = json[nameof(DefaultSettings)]?.ToObject<Setting>() ?? Setting.Zero,
|
||||
};
|
||||
if (ret.Name.Length == 0)
|
||||
var ret = new MultiModGroup(mod);
|
||||
if (!ModSaveGroup.ReadJsonBase(json, ret))
|
||||
return null;
|
||||
|
||||
var options = json["Options"];
|
||||
|
|
@ -106,6 +99,8 @@ public sealed class MultiModGroup(Mod mod) : IModGroup, ITexToolsGroup
|
|||
Name = Name,
|
||||
Description = Description,
|
||||
Priority = Priority,
|
||||
Image = Image,
|
||||
Page = Page,
|
||||
DefaultSettings = DefaultSettings.TurnMulti(OptionData.Count),
|
||||
};
|
||||
single.OptionData.AddRange(OptionData.Select(o => o.ConvertToSingle(single)));
|
||||
|
|
|
|||
|
|
@ -63,15 +63,8 @@ public sealed class SingleModGroup(Mod mod) : IModGroup, ITexToolsGroup
|
|||
public static SingleModGroup? Load(Mod mod, JObject json)
|
||||
{
|
||||
var options = json["Options"];
|
||||
var ret = new SingleModGroup(mod)
|
||||
{
|
||||
Name = json[nameof(Name)]?.ToObject<string>() ?? string.Empty,
|
||||
Description = json[nameof(Description)]?.ToObject<string>() ?? string.Empty,
|
||||
Image = json[nameof(Image)]?.ToObject<string>() ?? string.Empty,
|
||||
Priority = json[nameof(Priority)]?.ToObject<ModPriority>() ?? ModPriority.Default,
|
||||
DefaultSettings = json[nameof(DefaultSettings)]?.ToObject<Setting>() ?? Setting.Zero,
|
||||
};
|
||||
if (ret.Name.Length == 0)
|
||||
var ret = new SingleModGroup(mod);
|
||||
if (!ModSaveGroup.ReadJsonBase(json, ret))
|
||||
return null;
|
||||
|
||||
if (options != null)
|
||||
|
|
@ -92,6 +85,8 @@ public sealed class SingleModGroup(Mod mod) : IModGroup, ITexToolsGroup
|
|||
Name = Name,
|
||||
Description = Description,
|
||||
Priority = Priority,
|
||||
Image = Image,
|
||||
Page = Page,
|
||||
DefaultSettings = Setting.Multi((int)DefaultSettings.Value),
|
||||
};
|
||||
multi.OptionData.AddRange(OptionData.Select((o, i) => o.ConvertToMulti(multi, new ModPriority(i))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue