Skip to content

Commit d0121be

Browse files
Merge pull request #5 from EzioTheDeadPoet/settings-UI-beta
Settings UI
2 parents 0227d0e + 8b0050d commit d0121be

File tree

6 files changed

+74
-73
lines changed

6 files changed

+74
-73
lines changed

HalgarisRPGLoot/ArmorAnalyzer.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace HalgarisRPGLoot
1515
{
1616
public class ArmorAnalyzer
1717
{
18-
private Settings Settings = new Settings();
18+
private ArmorSettings Settings = Program.Settings.ArmorSettings;
1919

2020
public IPatcherState<ISkyrimMod, ISkyrimModGetter> State { get; set; }
2121
public ILeveledItemGetter[] AllLeveledLists { get; set; }
@@ -39,35 +39,6 @@ public ArmorAnalyzer(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
3939

4040
{
4141
State = state;
42-
LoadSettings();
43-
}
44-
45-
private void LoadSettings()
46-
{
47-
const string path = "Data/ArmorSettings.json";
48-
if (!File.Exists(path))
49-
{
50-
// Ensure the default settings are saved
51-
Settings.InitializeDefault();
52-
SaveSettings();
53-
return;
54-
}
55-
using (var file = File.OpenText(path))
56-
{
57-
var serializer = new JsonSerializer();
58-
Settings = (Settings)serializer.Deserialize(file, typeof(Settings));
59-
}
60-
}
61-
62-
private void SaveSettings()
63-
{
64-
const string path = "Data/ArmorSettings.json";
65-
Directory.CreateDirectory(Path.GetDirectoryName(path));
66-
using (var file = File.CreateText(path))
67-
{
68-
var serializer = new JsonSerializer();
69-
serializer.Serialize(file, Settings);
70-
}
7142
}
7243

7344
public void Analyze()

HalgarisRPGLoot/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HalgarisRPGLoot
88
{
99
public static class Extensions
1010
{
11-
public static Random Random { get; set; } = new Random(42);
11+
public static Random Random { get; set; } = new Random(Program.Settings.RandomSeed);
1212

1313
public static T RandomItem<T>(this T[] itms)
1414
{

HalgarisRPGLoot/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ namespace HalgarisRPGLoot
1010
{
1111
class Program
1212
{
13+
static Lazy<Settings> _LazySettings = null!;
14+
public static Settings Settings => _LazySettings.Value;
15+
1316
static async Task<int> Main(string[] args)
1417
{
1518
return await SynthesisPipeline.Instance
16-
.SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp")
1719
.AddPatch<ISkyrimMod, ISkyrimModGetter>(RunPatch)
20+
.SetAutogeneratedSettings(
21+
nickname: "Settings",
22+
path: "Settings.json",
23+
out _LazySettings)
24+
.SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp")
1825
.Run(args);
1926
}
2027

HalgarisRPGLoot/Rarity.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Mutagen.Bethesda.Synthesis.Settings;
7+
/*
8+
namespace HalgarisRPGLoot
9+
{
10+
[System.Serializable]
11+
public class Rarity
12+
{
13+
public string Label;
14+
public int NumEnchantments;
15+
public int LLEntries;
16+
}
17+
}
18+
*/

HalgarisRPGLoot/Settings.cs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,68 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text;
5+
using System.Threading.Tasks;
6+
using Mutagen.Bethesda.Synthesis.Settings;
47

58
namespace HalgarisRPGLoot
69
{
7-
[System.Serializable]
810
public class Settings
911
{
10-
public int VarietyCountPerItem;
11-
public List<Rarity> Rarities = new List<Rarity>();
12-
public bool UseRNGRarities;
12+
public int RandomSeed = 42;
1313

14-
public void InitializeDefault()
15-
{
16-
UseRNGRarities = true;
17-
VarietyCountPerItem = 8;
18-
Rarities = new List<Rarity>() {
14+
public ArmorSettings ArmorSettings = new ArmorSettings();
15+
public WeaponSettings WeaponSettings = new WeaponSettings();
16+
17+
}
18+
public class ArmorSettings
19+
{
20+
[SynthesisSettingName("Number of variations per Item")]
21+
[SynthesisTooltip("This determines how many different versions\n" +
22+
"of the same Armor you can find.")]
23+
public int VarietyCountPerItem = 50;
24+
[SynthesisSettingName("Rarity Levels")]
25+
[SynthesisTooltip("Custom defineable rarity levels")]
26+
public List<Rarity> Rarities = new List<Rarity>() {
27+
new Rarity() { Label= "Magical", NumEnchantments=1, LLEntries=80 },
28+
new Rarity() { Label= "Rare", NumEnchantments=2, LLEntries=13 },
29+
new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 },
30+
new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 },
31+
};
32+
[SynthesisSettingName("Use RNGRarity")]
33+
[SynthesisTooltip("With this set to true the number of variations\n" +
34+
"per item will be randomised.")]
35+
public bool UseRNGRarities = true;
36+
}
37+
38+
public class WeaponSettings
39+
{
40+
[SynthesisSettingName("Number of variations per Item")]
41+
[SynthesisTooltip("This determines how many different versions\n" +
42+
"of the same Weapon you can find.")]
43+
public int VarietyCountPerItem = 50;
44+
[SynthesisSettingName("Rarity Levels")]
45+
[SynthesisTooltip("Custom defineable rarity levels")]
46+
public List<Rarity> Rarities = new List<Rarity>() {
1947
new Rarity() { Label= "Magical", NumEnchantments=1, LLEntries=80 },
2048
new Rarity() { Label= "Rare", NumEnchantments=2, LLEntries=13 },
2149
new Rarity() { Label= "Epic", NumEnchantments=3, LLEntries=5 },
2250
new Rarity() { Label= "Legendary", NumEnchantments=4, LLEntries=2 },
2351
};
24-
}
52+
[SynthesisSettingName("Use RNGRarity")]
53+
[SynthesisTooltip("With this set to true the number of variations\n" +
54+
"per item will be randomised.")]
55+
public bool UseRNGRarities = true;
2556
}
2657

27-
[System.Serializable]
2858
public class Rarity
2959
{
60+
[SynthesisSettingName("Rarity Label")]
3061
public string Label;
62+
[SynthesisSettingName("Number of Enchantments")]
3163
public int NumEnchantments;
64+
[SynthesisSettingName("Number of LevedList Entries")]
65+
[SynthesisTooltip("The higher the number the more common it is.")]
3266
public int LLEntries;
3367
}
3468
}

HalgarisRPGLoot/WeaponAnalyer.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace HalgarisRPGLoot
1414
{
1515
public class WeaponAnalyzer
1616
{
17-
private Settings Settings = new Settings();
17+
private WeaponSettings Settings = Program.Settings.WeaponSettings;
1818

1919
public IPatcherState<ISkyrimMod, ISkyrimModGetter> State { get; set; }
2020
public ILeveledItemGetter[] AllLeveledLists { get; set; }
@@ -38,35 +38,6 @@ public WeaponAnalyzer(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
3838

3939
{
4040
State = state;
41-
LoadSettings();
42-
}
43-
44-
private void LoadSettings()
45-
{
46-
const string path = "Data/WeaponSettings.json";
47-
if(!File.Exists(path))
48-
{
49-
// Ensure the default settings are saved
50-
Settings.InitializeDefault();
51-
SaveSettings();
52-
return;
53-
}
54-
using (var file = File.OpenText(path))
55-
{
56-
var serializer = new JsonSerializer();
57-
Settings = (Settings)serializer.Deserialize(file, typeof(Settings));
58-
}
59-
}
60-
61-
private void SaveSettings()
62-
{
63-
const string path = "Data/WeaponSettings.json";
64-
Directory.CreateDirectory(Path.GetDirectoryName(path));
65-
using (var file = File.CreateText(path))
66-
{
67-
var serializer = new JsonSerializer();
68-
serializer.Serialize(file, Settings);
69-
}
7041
}
7142

7243
public void Analyze()

0 commit comments

Comments
 (0)