From aa69b75081a8e4b384f628ec8a9b04f50f265fd9 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sat, 2 Apr 2022 16:18:26 +0500 Subject: [PATCH] Refactor settings to reduce code warnings --- .../RJWSexperience/Configurations.cs | 125 +++++++++--------- RJWSexperience/RJWSexperience/DebugAction.cs | 2 +- .../RJWSexperience/Patches/RJW_Patch.cs | 2 +- .../RJWSexperience/Patches/Rimworld_Patch.cs | 2 +- .../RJWSexperience/RJWSexperience.csproj | 1 + .../SexHistory/RecordRandomizer.cs | 16 ++- .../RJWSexperience/SexperienceMod.cs | 24 ++++ RJWSexperience/RJWSexperience/StatParts.cs | 2 +- RJWSexperience/RJWSexperience/UI/SexStatus.cs | 9 +- 9 files changed, 103 insertions(+), 80 deletions(-) create mode 100644 RJWSexperience/RJWSexperience/SexperienceMod.cs diff --git a/RJWSexperience/RJWSexperience/Configurations.cs b/RJWSexperience/RJWSexperience/Configurations.cs index 1443a6e..5ef06d2 100644 --- a/RJWSexperience/RJWSexperience/Configurations.cs +++ b/RJWSexperience/RJWSexperience/Configurations.cs @@ -19,55 +19,68 @@ namespace RJWSexperience public const float MinSexablePercentDefault = 0.2f; public const float VirginRatioDefault = 0.01f; - private float maxSingleLustChange = MaxSingleLustChangeDefault; + private float maxLustDeviation = MaxInitialLustDefault; + private float avgLust = AvgLustDefault; + private float maxSexCountDeviation = MaxSexCountDeviationDefault; + private float lustEffectPower = LustEffectPowerDefault; + private float sexPerYear = SexPerYearDefault; + private bool slavesBeenRapedExp = SlavesBeenRapedExpDefault; + private bool enableRecordRandomizer = EnableStatRandomizerDefault; + private float lustLimit = LustLimitDefault; private bool minSexableFromLifestage = MinSexableFromLifestageDefault; + private float minSexablePercent = MinSexablePercentDefault; + private float virginRatio = VirginRatioDefault; + private float maxSingleLustChange = MaxSingleLustChangeDefault; - public static float MaxLustDeviation = MaxInitialLustDefault; - public static float AvgLust = AvgLustDefault; - public static float MaxSexCountDeviation = MaxSexCountDeviationDefault; - public static float LustEffectPower = LustEffectPowerDefault; - public static float SexPerYear = SexPerYearDefault; - public static bool SlavesBeenRapedExp = SlavesBeenRapedExpDefault; - public static bool EnableRecordRandomizer = EnableStatRandomizerDefault; - public static float LustLimit = LustLimitDefault; + public float MaxLustDeviation { get => maxLustDeviation; } + public float AvgLust { get => avgLust; } + public float MaxSexCountDeviation { get => maxSexCountDeviation; } + public float LustEffectPower { get => lustEffectPower; } + public float SexPerYear { get => sexPerYear; } + public bool SlavesBeenRapedExp { get => slavesBeenRapedExp; } + public bool EnableRecordRandomizer { get => enableRecordRandomizer; } + public float LustLimit { get => lustLimit; } public bool MinSexableFromLifestage { get => minSexableFromLifestage; } - public static float MinSexablePercent = MinSexablePercentDefault; - public static float VirginRatio = VirginRatioDefault; + public float MinSexablePercent { get => minSexablePercent; } + public float VirginRatio { get => virginRatio; } public float MaxSingleLustChange { get => maxSingleLustChange; } - public static bool SelectionLocked = false; + private bool selectionLocked = false; + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S2292:Trivial properties should be auto-implemented", Justification = "Can't scribe property")] + public bool SelectionLocked { get => selectionLocked; set => selectionLocked = value; } public void ResetToDefault() { - MaxLustDeviation = MaxInitialLustDefault; - AvgLust = AvgLustDefault; - MaxSexCountDeviation = MaxSexCountDeviationDefault; - LustEffectPower = LustEffectPowerDefault; - SexPerYear = SexPerYearDefault; - SlavesBeenRapedExp = SlavesBeenRapedExpDefault; - EnableRecordRandomizer = EnableStatRandomizerDefault; - LustLimit = LustLimitDefault; + maxLustDeviation = MaxInitialLustDefault; + avgLust = AvgLustDefault; + maxSexCountDeviation = MaxSexCountDeviationDefault; + lustEffectPower = LustEffectPowerDefault; + sexPerYear = SexPerYearDefault; + slavesBeenRapedExp = SlavesBeenRapedExpDefault; + enableRecordRandomizer = EnableStatRandomizerDefault; + lustLimit = LustLimitDefault; maxSingleLustChange = MaxSingleLustChangeDefault; minSexableFromLifestage = MinSexableFromLifestageDefault; - MinSexablePercent = MinSexablePercentDefault; - VirginRatio = VirginRatioDefault; + minSexablePercent = MinSexablePercentDefault; + virginRatio = VirginRatioDefault; } public override void ExposeData() { - Scribe_Values.Look(ref MaxLustDeviation, "MaxLustDeviation", MaxInitialLustDefault, true); - Scribe_Values.Look(ref AvgLust, "AvgLust", AvgLust, true); - Scribe_Values.Look(ref MaxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviation, true); - Scribe_Values.Look(ref LustEffectPower, "LustEffectPower", LustEffectPower, true); - Scribe_Values.Look(ref SexPerYear, "SexPerYear", SexPerYear, true); - Scribe_Values.Look(ref SlavesBeenRapedExp, "SlavesBeenRapedExp", SlavesBeenRapedExp, true); - Scribe_Values.Look(ref EnableRecordRandomizer, "EnableRecordRandomizer", EnableRecordRandomizer, true); - Scribe_Values.Look(ref LustLimit, "LustLimit", LustLimit, true); + Scribe_Values.Look(ref maxLustDeviation, "MaxLustDeviation", MaxInitialLustDefault, true); + Scribe_Values.Look(ref avgLust, "AvgLust", AvgLustDefault, true); + Scribe_Values.Look(ref maxSexCountDeviation, "MaxSexCountDeviation", MaxSexCountDeviationDefault, true); + Scribe_Values.Look(ref lustEffectPower, "LustEffectPower", LustEffectPowerDefault, true); + Scribe_Values.Look(ref sexPerYear, "SexPerYear", SexPerYearDefault, true); + Scribe_Values.Look(ref slavesBeenRapedExp, "SlavesBeenRapedExp", SlavesBeenRapedExpDefault, true); + Scribe_Values.Look(ref enableRecordRandomizer, "EnableRecordRandomizer", EnableStatRandomizerDefault, true); + Scribe_Values.Look(ref lustLimit, "LustLimit", LustLimitDefault, true); Scribe_Values.Look(ref maxSingleLustChange, "maxSingleLustChange", MaxSingleLustChangeDefault, true); - Scribe_Values.Look(ref minSexableFromLifestage, "MinSexableFromLifestage", MinSexableFromLifestage, true); - Scribe_Values.Look(ref MinSexablePercent, "MinSexablePercent", MinSexablePercent, true); - Scribe_Values.Look(ref VirginRatio, "VirginRatio", VirginRatio, true); - Scribe_Values.Look(ref SelectionLocked, "SelectionLocked", SelectionLocked, true); + Scribe_Values.Look(ref minSexableFromLifestage, "MinSexableFromLifestage", MinSexableFromLifestageDefault, true); + Scribe_Values.Look(ref minSexablePercent, "MinSexablePercent", MinSexablePercentDefault, true); + Scribe_Values.Look(ref virginRatio, "VirginRatio", VirginRatioDefault, true); + Scribe_Values.Look(ref selectionLocked, "SelectionLocked"); base.ExposeData(); } @@ -79,31 +92,31 @@ namespace RJWSexperience listmain.maxOneColumn = true; listmain.Begin(inRect); - SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_2_Label + " x" + LustEffectPower, Keyed.Option_2_Desc, ref LustEffectPower, 0f, 2f, 0.001f); - SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_8_Label + " " + LustLimit, Keyed.Option_8_Desc, ref LustLimit, 0f, 5000f, 1f); + SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_2_Label + " x" + lustEffectPower, Keyed.Option_2_Desc, ref lustEffectPower, 0f, 2f, 0.001f); + SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_8_Label + " " + lustLimit, Keyed.Option_8_Desc, ref lustLimit, 0f, 5000f, 1f); SliderOption(listmain.GetRect(lineHeight * 2f), Keyed.Option_MaxSingleLustChange_Label + " " + maxSingleLustChange, Keyed.Option_MaxSingleLustChange_Desc, ref maxSingleLustChange, 0f, 10f, 0.05f); - listmain.CheckboxLabeled(Keyed.Option_1_Label, ref EnableRecordRandomizer, Keyed.Option_1_Desc); - if (EnableRecordRandomizer) + listmain.CheckboxLabeled(Keyed.Option_1_Label, ref enableRecordRandomizer, Keyed.Option_1_Desc); + if (enableRecordRandomizer) { float sectionHeight = 12f; - if (!MinSexableFromLifestage) sectionHeight += 2f; + if (!minSexableFromLifestage) sectionHeight += 2f; Listing_Standard section = listmain.BeginSection(lineHeight * sectionHeight); - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_3_Label + " " + MaxLustDeviation, Keyed.Option_3_Desc, ref MaxLustDeviation, 0f, 2000f, 1f); - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_4_Label + " " + AvgLust, Keyed.Option_4_Desc, ref AvgLust, -1000f, 1000f, 1f); - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_5_Label + " " + MaxSexCountDeviation, Keyed.Option_5_Desc, ref MaxSexCountDeviation, 0f, 2000f, 1f); - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_6_Label + " " + SexPerYear, Keyed.Option_6_Desc, ref SexPerYear, 0f, 2000f, 1f); + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_3_Label + " " + maxLustDeviation, Keyed.Option_3_Desc, ref maxLustDeviation, 0f, 2000f, 1f); + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_4_Label + " " + avgLust, Keyed.Option_4_Desc, ref avgLust, -1000f, 1000f, 1f); + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_5_Label + " " + maxSexCountDeviation, Keyed.Option_5_Desc, ref maxSexCountDeviation, 0f, 2000f, 1f); + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_6_Label + " " + sexPerYear, Keyed.Option_6_Desc, ref sexPerYear, 0f, 2000f, 1f); section.CheckboxLabeled(Keyed.Option_MinSexableFromLifestage_Label, ref minSexableFromLifestage, Keyed.Option_MinSexableFromLifestage_Desc); - if (!MinSexableFromLifestage) - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_9_Label + " " + MinSexablePercent * 100 + "% " + ThingDefOf.Human.race.lifeExpectancy * MinSexablePercent + " human years", Keyed.Option_9_Desc, ref MinSexablePercent, 0, 1, 0.001f); + if (!minSexableFromLifestage) + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_9_Label + " " + minSexablePercent * 100 + "% " + ThingDefOf.Human.race.lifeExpectancy * minSexablePercent + " human years", Keyed.Option_9_Desc, ref minSexablePercent, 0, 1, 0.001f); - SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_10_Label + " " + VirginRatio * 100 + "%", Keyed.Option_10_Desc, ref VirginRatio, 0, 1, 0.001f); + SliderOption(section.GetRect(lineHeight * 2f), Keyed.Option_10_Label + " " + virginRatio * 100 + "%", Keyed.Option_10_Desc, ref virginRatio, 0, 1, 0.001f); - section.CheckboxLabeled(Keyed.Option_7_Label, ref SlavesBeenRapedExp, Keyed.Option_7_Desc); + section.CheckboxLabeled(Keyed.Option_7_Label, ref slavesBeenRapedExp, Keyed.Option_7_Desc); listmain.EndSection(section); } @@ -131,22 +144,4 @@ namespace RJWSexperience value = Widgets.HorizontalSlider(doublerect.BottomHalf(), value, min, max, roundTo: roundTo); } } - - public class SexperienceMod : Mod - { - private static Configurations settings; - public static Configurations Settings { get => settings; } - - public SexperienceMod(ModContentPack content) : base(content) - { - settings = GetSettings(); - } - - public override string SettingsCategory() - { - return Keyed.Mod_Title; - } - - public override void DoSettingsWindowContents(Rect inRect) => Settings.DoSettingsWindowContents(inRect); - } } diff --git a/RJWSexperience/RJWSexperience/DebugAction.cs b/RJWSexperience/RJWSexperience/DebugAction.cs index 61a253d..f34395e 100644 --- a/RJWSexperience/RJWSexperience/DebugAction.cs +++ b/RJWSexperience/RJWSexperience/DebugAction.cs @@ -60,7 +60,7 @@ namespace RJWSexperience { if (!allzero) { - if (Configurations.EnableRecordRandomizer && pawn != null && xxx.is_human(pawn)) + if (SexperienceMod.Settings.EnableRecordRandomizer && pawn != null && xxx.is_human(pawn)) { RecordRandomizer.Randomize(pawn); } diff --git a/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs b/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs index ee999cf..0f92abb 100644 --- a/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs +++ b/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs @@ -102,7 +102,7 @@ namespace RJWSexperience private static float LustIncrementFactor(float lust) { - return Mathf.Exp(-Mathf.Pow(lust / Configurations.LustLimit, 2)); + return Mathf.Exp(-Mathf.Pow(lust / SexperienceMod.Settings.LustLimit, 2)); } } diff --git a/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs b/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs index 2c105bc..5000545 100644 --- a/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs +++ b/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs @@ -14,7 +14,7 @@ namespace RJWSexperience { public static void Postfix(PawnGenerationRequest request, ref Pawn __result) { - if (Configurations.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result)) + if (SexperienceMod.Settings.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result)) { RecordRandomizer.Randomize(__result); } diff --git a/RJWSexperience/RJWSexperience/RJWSexperience.csproj b/RJWSexperience/RJWSexperience/RJWSexperience.csproj index 4879c20..6ccae5f 100644 --- a/RJWSexperience/RJWSexperience/RJWSexperience.csproj +++ b/RJWSexperience/RJWSexperience/RJWSexperience.csproj @@ -86,6 +86,7 @@ + diff --git a/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs b/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs index c7e3954..576b0f9 100644 --- a/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs +++ b/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs @@ -9,28 +9,30 @@ namespace RJWSexperience { public static class RecordRandomizer { + private static Configurations Settings => SexperienceMod.Settings; + public static void Randomize(Pawn pawn) { int avgsex = -500; - bool isvirgin = Rand.Chance(Configurations.VirginRatio); + bool isvirgin = Rand.Chance(Settings.VirginRatio); int totalsex = 0; int totalbirth = 0; - int deviation = (int)Configurations.MaxSexCountDeviation; + int deviation = (int)Settings.MaxSexCountDeviation; if (pawn.story != null) { _ = RandomizeLust(pawn); int sexableage = 0; int minsexage = 0; - if (SexperienceMod.Settings.MinSexableFromLifestage) + if (Settings.MinSexableFromLifestage) minsexage = (int)pawn.RaceProps.lifeStageAges.Find(x => x.def.reproductive).minAge; else - minsexage = (int)(pawn.RaceProps.lifeExpectancy * Configurations.MinSexablePercent); + minsexage = (int)(pawn.RaceProps.lifeExpectancy * Settings.MinSexablePercent); if (pawn.ageTracker.AgeBiologicalYears > minsexage) { sexableage = pawn.ageTracker.AgeBiologicalYears - minsexage; - avgsex = (int)(sexableage * Configurations.SexPerYear * StatPart_Lust.GetLustFactor(pawn)); + avgsex = (int)(sexableage * Settings.SexPerYear * StatPart_Lust.GetLustFactor(pawn)); } if (pawn.relations != null && pawn.gender == Gender.Female) @@ -70,7 +72,7 @@ namespace RJWSexperience avgsex /= 4; } - if (pawn.IsSlave) + if (Settings.SlavesBeenRapedExp && pawn.IsSlave) { totalsex += RandomizeRecord(pawn, xxx.CountOfBeenRapedByAnimals, Rand.Range(-50, 10), Rand.Range(0, 10) * sexableage); totalsex += RandomizeRecord(pawn, xxx.CountOfBeenRapedByHumanlikes, 0, Rand.Range(0, 100) * sexableage); @@ -87,7 +89,7 @@ namespace RJWSexperience public static float RandomizeLust(Pawn pawn) { - float value = Utility.RandGaussianLike(Configurations.AvgLust - Configurations.MaxLustDeviation, Configurations.AvgLust + Configurations.MaxLustDeviation); + float value = Utility.RandGaussianLike(Settings.AvgLust - Settings.MaxLustDeviation, Settings.AvgLust + Settings.MaxLustDeviation); float minValue; if (xxx.is_nympho(pawn)) diff --git a/RJWSexperience/RJWSexperience/SexperienceMod.cs b/RJWSexperience/RJWSexperience/SexperienceMod.cs new file mode 100644 index 0000000..7b03aad --- /dev/null +++ b/RJWSexperience/RJWSexperience/SexperienceMod.cs @@ -0,0 +1,24 @@ +using UnityEngine; +using Verse; + +namespace RJWSexperience +{ + + public class SexperienceMod : Mod + { + private static Configurations settings; + public static Configurations Settings { get => settings; } + + public SexperienceMod(ModContentPack content) : base(content) + { + settings = GetSettings(); + } + + public override string SettingsCategory() + { + return Keyed.Mod_Title; + } + + public override void DoSettingsWindowContents(Rect inRect) => Settings.DoSettingsWindowContents(inRect); + } +} diff --git a/RJWSexperience/RJWSexperience/StatParts.cs b/RJWSexperience/RJWSexperience/StatParts.cs index 8cb35a6..969861f 100644 --- a/RJWSexperience/RJWSexperience/StatParts.cs +++ b/RJWSexperience/RJWSexperience/StatParts.cs @@ -31,7 +31,7 @@ namespace RJWSexperience public static float GetLustFactor(Pawn pawn) { - float lust = pawn.records.GetValue(VariousDefOf.Lust) * Configurations.LustEffectPower; + float lust = pawn.records.GetValue(VariousDefOf.Lust) * SexperienceMod.Settings.LustEffectPower; if (lust < 0) { lust = Mathf.Exp((lust + 200f * Mathf.Log(10f)) / 100f) - 100f; diff --git a/RJWSexperience/RJWSexperience/UI/SexStatus.cs b/RJWSexperience/RJWSexperience/UI/SexStatus.cs index 383245b..f46ef4f 100644 --- a/RJWSexperience/RJWSexperience/UI/SexStatus.cs +++ b/RJWSexperience/RJWSexperience/UI/SexStatus.cs @@ -124,7 +124,7 @@ namespace RJWSexperience.UI public override void DoWindowContents(Rect inRect) { pos = windowRect.position; - if (!Configurations.SelectionLocked) + if (!SexperienceMod.Settings.SelectionLocked) { List selected = Find.Selector.SelectedPawns; if (selected.Count == 1) @@ -349,12 +349,13 @@ namespace RJWSexperience.UI if (Mouse.IsOver(portraitRect)) { - Texture lockicon = Configurations.SelectionLocked ? HistoryUtility.Locked : HistoryUtility.Unlocked; + Configurations settings = SexperienceMod.Settings; + Texture lockicon = settings.SelectionLocked ? HistoryUtility.Locked : HistoryUtility.Unlocked; Widgets.DrawTextureFitted(lockRect, lockicon, 1.0f); if (Widgets.ButtonInvisible(lockRect)) { SoundDefOf.Click.PlayOneShotOnCamera(); - Configurations.SelectionLocked = !Configurations.SelectionLocked; + settings.SelectionLocked = !settings.SelectionLocked; } } @@ -396,7 +397,7 @@ namespace RJWSexperience.UI tmp = listmain.GetRect(FONTHEIGHT); p = pawn.records.GetValue(VariousDefOf.Lust); - FillableBarLabeled(tmp, String.Format(Keyed.Lust +": {0:0.00}", p), Mathf.Clamp01(p.Normalization(-Configurations.LustLimit*3, Configurations.LustLimit*3)), HistoryUtility.Slaanesh, Texture2D.blackTexture, null, String.Format(xxx.sex_drive_stat.LabelCap.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat))); + FillableBarLabeled(tmp, String.Format(Keyed.Lust +": {0:0.00}", p), Mathf.Clamp01(p.Normalization(-SexperienceMod.Settings.LustLimit*3, SexperienceMod.Settings.LustLimit*3)), HistoryUtility.Slaanesh, Texture2D.blackTexture, null, String.Format(xxx.sex_drive_stat.LabelCap.CapitalizeFirst() + ": {0:P2}", pawn.Dead ? 0 : pawn.GetStatValue(xxx.sex_drive_stat))); listmain.Gap(1f); if (Mouse.IsOver(tmp)) {