From 011f1c55cabd687eb759a6de31623c2cb17b6f62 Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 30 Mar 2021 14:43:01 +0200 Subject: [PATCH 1/2] updated to UI settings --- HalgarisRPGLoot/ArmorAnalyzer.cs | 31 +------------------------------ HalgarisRPGLoot/Program.cs | 8 +++++++- HalgarisRPGLoot/Settings.cs | 20 +++++++------------- HalgarisRPGLoot/WeaponAnalyer.cs | 31 +------------------------------ 4 files changed, 16 insertions(+), 74 deletions(-) diff --git a/HalgarisRPGLoot/ArmorAnalyzer.cs b/HalgarisRPGLoot/ArmorAnalyzer.cs index f496ef2..2ee26a3 100644 --- a/HalgarisRPGLoot/ArmorAnalyzer.cs +++ b/HalgarisRPGLoot/ArmorAnalyzer.cs @@ -15,7 +15,7 @@ namespace HalgarisRPGLoot { public class ArmorAnalyzer { - private Settings Settings = new Settings(); + private Settings Settings = Program.Settings; public IPatcherState State { get; set; } public ILeveledItemGetter[] AllLeveledLists { get; set; } @@ -39,35 +39,6 @@ public ArmorAnalyzer(IPatcherState state) { State = state; - LoadSettings(); - } - - private void LoadSettings() - { - const string path = "Data/ArmorSettings.json"; - if (!File.Exists(path)) - { - // Ensure the default settings are saved - Settings.InitializeDefault(); - SaveSettings(); - return; - } - using (var file = File.OpenText(path)) - { - var serializer = new JsonSerializer(); - Settings = (Settings)serializer.Deserialize(file, typeof(Settings)); - } - } - - private void SaveSettings() - { - const string path = "Data/ArmorSettings.json"; - Directory.CreateDirectory(Path.GetDirectoryName(path)); - using (var file = File.CreateText(path)) - { - var serializer = new JsonSerializer(); - serializer.Serialize(file, Settings); - } } public void Analyze() diff --git a/HalgarisRPGLoot/Program.cs b/HalgarisRPGLoot/Program.cs index e67b0db..f07c698 100644 --- a/HalgarisRPGLoot/Program.cs +++ b/HalgarisRPGLoot/Program.cs @@ -10,11 +10,17 @@ namespace HalgarisRPGLoot { class Program { + static Lazy _LazySettings = null!; + public static Settings Settings => _LazySettings.Value; static async Task Main(string[] args) { return await SynthesisPipeline.Instance - .SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp") .AddPatch(RunPatch) + .SetAutogeneratedSettings( + nickname: "Settings", + path: "settings.json", + out _LazySettings) + .SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp") .Run(args); } diff --git a/HalgarisRPGLoot/Settings.cs b/HalgarisRPGLoot/Settings.cs index 38a00bc..440dfa5 100644 --- a/HalgarisRPGLoot/Settings.cs +++ b/HalgarisRPGLoot/Settings.cs @@ -1,27 +1,21 @@ -using System; +using Mutagen.Bethesda; +using System; using System.Collections.Generic; using System.Text; namespace HalgarisRPGLoot { - [System.Serializable] - public class Settings + public record Settings { - public int VarietyCountPerItem; - public List Rarities = new List(); - public bool UseRNGRarities; - - public void InitializeDefault() - { - UseRNGRarities = true; - VarietyCountPerItem = 8; - Rarities = new List() { + public int VarietyCountPerItem = 8; + public List Rarities = new List() { new Rarity() { Label= "Magical", NumEnchantments=1, LLEntries=80 }, new Rarity() { Label= "Rare", NumEnchantments=2, LLEntries=13 }, new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 }, new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 }, }; - } + public bool UseRNGRarities = true; + } [System.Serializable] diff --git a/HalgarisRPGLoot/WeaponAnalyer.cs b/HalgarisRPGLoot/WeaponAnalyer.cs index d74b6bd..97afa1d 100644 --- a/HalgarisRPGLoot/WeaponAnalyer.cs +++ b/HalgarisRPGLoot/WeaponAnalyer.cs @@ -14,7 +14,7 @@ namespace HalgarisRPGLoot { public class WeaponAnalyzer { - private Settings Settings = new Settings(); + private Settings Settings = Program.Settings; public IPatcherState State { get; set; } public ILeveledItemGetter[] AllLeveledLists { get; set; } @@ -38,35 +38,6 @@ public WeaponAnalyzer(IPatcherState state) { State = state; - LoadSettings(); - } - - private void LoadSettings() - { - const string path = "Data/WeaponSettings.json"; - if(!File.Exists(path)) - { - // Ensure the default settings are saved - Settings.InitializeDefault(); - SaveSettings(); - return; - } - using (var file = File.OpenText(path)) - { - var serializer = new JsonSerializer(); - Settings = (Settings)serializer.Deserialize(file, typeof(Settings)); - } - } - - private void SaveSettings() - { - const string path = "Data/WeaponSettings.json"; - Directory.CreateDirectory(Path.GetDirectoryName(path)); - using (var file = File.CreateText(path)) - { - var serializer = new JsonSerializer(); - serializer.Serialize(file, Settings); - } } public void Analyze() From 8b0050db958fdf49541282115106e6cc5873594e Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 30 Mar 2021 16:01:24 +0200 Subject: [PATCH 2/2] fixed errors --- HalgarisRPGLoot/ArmorAnalyzer.cs | 2 +- HalgarisRPGLoot/Extensions.cs | 2 +- HalgarisRPGLoot/Program.cs | 3 +- HalgarisRPGLoot/Rarity.cs | 18 ++++++++++++ HalgarisRPGLoot/Settings.cs | 50 ++++++++++++++++++++++++++++---- HalgarisRPGLoot/WeaponAnalyer.cs | 2 +- 6 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 HalgarisRPGLoot/Rarity.cs diff --git a/HalgarisRPGLoot/ArmorAnalyzer.cs b/HalgarisRPGLoot/ArmorAnalyzer.cs index 2ee26a3..a337cbb 100644 --- a/HalgarisRPGLoot/ArmorAnalyzer.cs +++ b/HalgarisRPGLoot/ArmorAnalyzer.cs @@ -15,7 +15,7 @@ namespace HalgarisRPGLoot { public class ArmorAnalyzer { - private Settings Settings = Program.Settings; + private ArmorSettings Settings = Program.Settings.ArmorSettings; public IPatcherState State { get; set; } public ILeveledItemGetter[] AllLeveledLists { get; set; } diff --git a/HalgarisRPGLoot/Extensions.cs b/HalgarisRPGLoot/Extensions.cs index 1d414fd..ec8c122 100644 --- a/HalgarisRPGLoot/Extensions.cs +++ b/HalgarisRPGLoot/Extensions.cs @@ -8,7 +8,7 @@ namespace HalgarisRPGLoot { public static class Extensions { - public static Random Random { get; set; } = new Random(42); + public static Random Random { get; set; } = new Random(Program.Settings.RandomSeed); public static T RandomItem(this T[] itms) { diff --git a/HalgarisRPGLoot/Program.cs b/HalgarisRPGLoot/Program.cs index f07c698..953fb1d 100644 --- a/HalgarisRPGLoot/Program.cs +++ b/HalgarisRPGLoot/Program.cs @@ -12,13 +12,14 @@ class Program { static Lazy _LazySettings = null!; public static Settings Settings => _LazySettings.Value; + static async Task Main(string[] args) { return await SynthesisPipeline.Instance .AddPatch(RunPatch) .SetAutogeneratedSettings( nickname: "Settings", - path: "settings.json", + path: "Settings.json", out _LazySettings) .SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp") .Run(args); diff --git a/HalgarisRPGLoot/Rarity.cs b/HalgarisRPGLoot/Rarity.cs new file mode 100644 index 0000000..a4c4b22 --- /dev/null +++ b/HalgarisRPGLoot/Rarity.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Mutagen.Bethesda.Synthesis.Settings; +/* +namespace HalgarisRPGLoot +{ + [System.Serializable] + public class Rarity + { + public string Label; + public int NumEnchantments; + public int LLEntries; + } +} +*/ \ No newline at end of file diff --git a/HalgarisRPGLoot/Settings.cs b/HalgarisRPGLoot/Settings.cs index 440dfa5..cd9277f 100644 --- a/HalgarisRPGLoot/Settings.cs +++ b/HalgarisRPGLoot/Settings.cs @@ -1,28 +1,68 @@ -using Mutagen.Bethesda; -using System; +using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; +using Mutagen.Bethesda.Synthesis.Settings; namespace HalgarisRPGLoot { - public record Settings + public class Settings { - public int VarietyCountPerItem = 8; + public int RandomSeed = 42; + + public ArmorSettings ArmorSettings = new ArmorSettings(); + public WeaponSettings WeaponSettings = new WeaponSettings(); + + } + public class ArmorSettings + { + [SynthesisSettingName("Number of variations per Item")] + [SynthesisTooltip("This determines how many different versions\n" + + "of the same Armor you can find.")] + public int VarietyCountPerItem = 50; + [SynthesisSettingName("Rarity Levels")] + [SynthesisTooltip("Custom defineable rarity levels")] public List Rarities = new List() { new Rarity() { Label= "Magical", NumEnchantments=1, LLEntries=80 }, new Rarity() { Label= "Rare", NumEnchantments=2, LLEntries=13 }, new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 }, new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 }, }; + [SynthesisSettingName("Use RNGRarity")] + [SynthesisTooltip("With this set to true the number of variations\n" + + "per item will be randomised.")] public bool UseRNGRarities = true; + } + public class WeaponSettings + { + [SynthesisSettingName("Number of variations per Item")] + [SynthesisTooltip("This determines how many different versions\n" + + "of the same Weapon you can find.")] + public int VarietyCountPerItem = 50; + [SynthesisSettingName("Rarity Levels")] + [SynthesisTooltip("Custom defineable rarity levels")] + public List Rarities = new List() { + new Rarity() { Label= "Magical", NumEnchantments=1, LLEntries=80 }, + new Rarity() { Label= "Rare", NumEnchantments=2, LLEntries=13 }, + new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 }, + new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 }, + }; + [SynthesisSettingName("Use RNGRarity")] + [SynthesisTooltip("With this set to true the number of variations\n" + + "per item will be randomised.")] + public bool UseRNGRarities = true; } - [System.Serializable] public class Rarity { + [SynthesisSettingName("Rarity Label")] public string Label; + [SynthesisSettingName("Number of Enchantments")] public int NumEnchantments; + [SynthesisSettingName("Number of LevedList Entries")] + [SynthesisTooltip("The higher the number the more common it is.")] public int LLEntries; } } diff --git a/HalgarisRPGLoot/WeaponAnalyer.cs b/HalgarisRPGLoot/WeaponAnalyer.cs index 97afa1d..a393b16 100644 --- a/HalgarisRPGLoot/WeaponAnalyer.cs +++ b/HalgarisRPGLoot/WeaponAnalyer.cs @@ -14,7 +14,7 @@ namespace HalgarisRPGLoot { public class WeaponAnalyzer { - private Settings Settings = Program.Settings; + private WeaponSettings Settings = Program.Settings.WeaponSettings; public IPatcherState State { get; set; } public ILeveledItemGetter[] AllLeveledLists { get; set; }