Skip to content

Commit

Permalink
Merge pull request #5 from EzioTheDeadPoet/settings-UI-beta
Browse files Browse the repository at this point in the history
Settings UI
  • Loading branch information
EzioTheDeadPoet authored Mar 30, 2021
2 parents 0227d0e + 8b0050d commit d0121be
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 73 deletions.
31 changes: 1 addition & 30 deletions HalgarisRPGLoot/ArmorAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace HalgarisRPGLoot
{
public class ArmorAnalyzer
{
private Settings Settings = new Settings();
private ArmorSettings Settings = Program.Settings.ArmorSettings;

public IPatcherState<ISkyrimMod, ISkyrimModGetter> State { get; set; }
public ILeveledItemGetter[] AllLeveledLists { get; set; }
Expand All @@ -39,35 +39,6 @@ public ArmorAnalyzer(IPatcherState<ISkyrimMod, ISkyrimModGetter> 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()
Expand Down
2 changes: 1 addition & 1 deletion HalgarisRPGLoot/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(this T[] itms)
{
Expand Down
9 changes: 8 additions & 1 deletion HalgarisRPGLoot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ namespace HalgarisRPGLoot
{
class Program
{
static Lazy<Settings> _LazySettings = null!;
public static Settings Settings => _LazySettings.Value;

static async Task<int> Main(string[] args)
{
return await SynthesisPipeline.Instance
.SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp")
.AddPatch<ISkyrimMod, ISkyrimModGetter>(RunPatch)
.SetAutogeneratedSettings(
nickname: "Settings",
path: "Settings.json",
out _LazySettings)
.SetTypicalOpen(GameRelease.SkyrimSE, "HalgariRpgLoot.esp")
.Run(args);
}

Expand Down
18 changes: 18 additions & 0 deletions HalgarisRPGLoot/Rarity.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
*/
56 changes: 45 additions & 11 deletions HalgarisRPGLoot/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
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 Settings
{
public int VarietyCountPerItem;
public List<Rarity> Rarities = new List<Rarity>();
public bool UseRNGRarities;
public int RandomSeed = 42;

public void InitializeDefault()
{
UseRNGRarities = true;
VarietyCountPerItem = 8;
Rarities = new List<Rarity>() {
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<Rarity> Rarities = new List<Rarity>() {
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<Rarity> Rarities = new List<Rarity>() {
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;
}
}
31 changes: 1 addition & 30 deletions HalgarisRPGLoot/WeaponAnalyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace HalgarisRPGLoot
{
public class WeaponAnalyzer
{
private Settings Settings = new Settings();
private WeaponSettings Settings = Program.Settings.WeaponSettings;

public IPatcherState<ISkyrimMod, ISkyrimModGetter> State { get; set; }
public ILeveledItemGetter[] AllLeveledLists { get; set; }
Expand All @@ -38,35 +38,6 @@ public WeaponAnalyzer(IPatcherState<ISkyrimMod, ISkyrimModGetter> 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()
Expand Down

0 comments on commit d0121be

Please sign in to comment.