diff --git a/HighRollerClassic/DataStructures/Misc.cs b/HighRollerClassic/DataStructures/Misc.cs index 2821fcb..8f83fe8 100644 --- a/HighRollerClassic/DataStructures/Misc.cs +++ b/HighRollerClassic/DataStructures/Misc.cs @@ -1,6 +1,6 @@ namespace HighRollerClassic.DataStructures; -public class Misc +public static class Misc { /// /// Appends message if error par is true diff --git a/HighRollerClassic/DataStructures/SettingValueType.cs b/HighRollerClassic/DataStructures/SettingValueType.cs index 7be4b03..d796c97 100644 --- a/HighRollerClassic/DataStructures/SettingValueType.cs +++ b/HighRollerClassic/DataStructures/SettingValueType.cs @@ -2,5 +2,9 @@ namespace HighRollerClassic.DataStructures; public enum SettingValueType { - + Multiplier, + Roll, + Colour, + MaxBet, + Step, } diff --git a/HighRollerClassic/DataStructures/Settings.cs b/HighRollerClassic/DataStructures/Settings.cs index 9aa051d..eee9372 100644 --- a/HighRollerClassic/DataStructures/Settings.cs +++ b/HighRollerClassic/DataStructures/Settings.cs @@ -28,6 +28,7 @@ public class Settings /// Contains data about each multiplier, roll, etc. /// public List Rolls { get; private set; } = new(); + // todo we'll make this a new class because we have 3 roll methods already 'polluting' this class /// /// Adds roll @@ -46,6 +47,11 @@ public class Settings return null; } + public void RemoveRoll(SettingsRoll roll) + { + Rolls.Remove(roll); + } + /// /// Validates new roll /// diff --git a/HighRollerClassic/DataStructures/TrackedValue.cs b/HighRollerClassic/DataStructures/TrackedValue.cs index be743ae..89f7fc7 100644 --- a/HighRollerClassic/DataStructures/TrackedValue.cs +++ b/HighRollerClassic/DataStructures/TrackedValue.cs @@ -1,22 +1,95 @@ using System; +using System.Diagnostics; +using System.Numerics; +using FFXIVClientStructs.FFXIV.Component.GUI; namespace HighRollerClassic.DataStructures; -public class TrackedValue +/// +/// Tracks value and its validity and changes +/// +public class TrackedValue { - public TValue Value { get; set; } - public bool IsValid { get; set; } - public bool HasChanged { get; set; } + private SettingValueType type; + private Configuration configuration; + + private uint? Value { get; + set + { + SetValue(value); + field = value; + } + } + private Vector4? colourValue { get; set; } + + public bool IsValid { get; private set; } + public bool HasChanged { get; private set; } private const uint MinRoll = 1; private const uint MaxRoll = 999; private const uint MaxGil = 999_999_999; - private Func multiplierRollValid = v => v is >= MinRoll and <= MaxRoll; - private Func maxBetValid = v => v <= MaxGil; + private bool multiplierValid => Value is not null; + private bool rollValid => Value is >= MinRoll and <= MaxRoll; + private bool maxBetValid => Value is <= MaxGil; + private bool stepValid => CheckStepValid(); - private static bool StepValid(uint step, uint bet) + public TrackedValue(uint? value, SettingValueType type, Configuration configuration) { - return step <= bet; + Initialise(type, configuration); + Value = value; + } + + public TrackedValue(Vector4? value, SettingValueType type, Configuration configuration) + { + Initialise(type, configuration); + colourValue = value; + } + + private void Initialise(SettingValueType type, Configuration configuration) + { + this.type = type; + this.configuration = configuration; + } + + private bool CheckStepValid() + { + return Value <= configuration.Settings.MaxBet; + } + + private void SetValue(uint? value) + { + bool? valid = null; + bool? change = null; + + switch (type) + { + case SettingValueType.Multiplier: + valid = multiplierValid; + break; + case SettingValueType.Roll: + valid = rollValid; + break; + case SettingValueType.Colour: + valid = true; + break; + case SettingValueType.MaxBet: + valid = maxBetValid; + change = value == configuration.Settings.MaxBet; + break; + case SettingValueType.Step: + valid = stepValid; + change = value == configuration.Settings.Step; + break; + } + + if (valid.HasValue) IsValid = valid.Value; + if (change.HasValue) HasChanged = change.Value; + } + + private void SetColourValue(Vector4? value) + { + IsValid = true; // colour will always be valid because we set it from colour picker + HasChanged = true; // todo we have to check } }