Skip to content

Commit

Permalink
Be less dumb.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Sep 9, 2024
1 parent 10ce5da commit 26371d4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
7 changes: 1 addition & 6 deletions Penumbra/Mods/Groups/ImcModGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,10 @@ public void WriteJson(JsonTextWriter jWriter, JsonSerializer serializer, Directo
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)
Expand Down Expand Up @@ -216,7 +212,6 @@ public void WriteJson(JsonTextWriter jWriter, JsonSerializer serializer, Directo
}

ret.Identifier = identifier.Value;
ret.DefaultSettings = json[nameof(DefaultSettings)]?.ToObject<Setting>() ?? Setting.Zero;
ret.DefaultSettings = ret.FixSetting(ret.DefaultSettings);
return ret;
}
Expand Down
17 changes: 17 additions & 0 deletions Penumbra/Mods/Groups/ModSaveGroup.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -90,11 +93,25 @@ public static void WriteJsonBase(JsonTextWriter jWriter, IModGroup group)
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));
jWriter.WriteValue(group.Type.ToString());
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;
}
}
13 changes: 4 additions & 9 deletions Penumbra/Mods/Groups/MultiModGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ public bool IsOption

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"];
Expand Down Expand Up @@ -106,6 +99,8 @@ public SingleModGroup ConvertToSingle()
Name = Name,
Description = Description,
Priority = Priority,
Image = Image,
Page = Page,
DefaultSettings = DefaultSettings.TurnMulti(OptionData.Count),
};
single.OptionData.AddRange(OptionData.Select(o => o.ConvertToSingle(single)));
Expand Down
13 changes: 4 additions & 9 deletions Penumbra/Mods/Groups/SingleModGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,8 @@ public bool IsOption
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)
Expand All @@ -92,6 +85,8 @@ public MultiModGroup ConvertToMulti()
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))));
Expand Down

0 comments on commit 26371d4

Please sign in to comment.