From ae6c3b857395dd0428cf8272be9a2420610e9bf4 Mon Sep 17 00:00:00 2001 From: Callum Jules White <62078259+juleswhi@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:08:58 +0000 Subject: [PATCH] Begin work on identifier and value combo --- src/FormSystem/FormHelper.cs | 28 ++++++++++++++++++++++++++++ src/Globals.cs | 6 +++++- src/StateSystem/State.cs | 11 +++++++++++ src/StateSystem/StateHelper.cs | 4 +--- src/StateSystem/StateType.cs | 5 ++++- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/StateSystem/State.cs diff --git a/src/FormSystem/FormHelper.cs b/src/FormSystem/FormHelper.cs index 6b9f3a0..a021799 100644 --- a/src/FormSystem/FormHelper.cs +++ b/src/FormSystem/FormHelper.cs @@ -1,6 +1,34 @@ namespace FormSystem; // Contains a bunch of extension methods +public enum ControlDirection +{ + X, + Y +} + public static class FormHelper { + public static void Center(this Control control, ControlDirection controlDirection) + { + switch(controlDirection) + { + case X: + control.Location = new Point((control.Parent!.Width / 2) - (int)0.5*(control.Width), control.Location.Y); + break; + + case Y: + control.Location = new Point(control.Location.X, (control.Parent!.Height / 2) - (int)0.5*(control.Width)); + break; + } + } + + public static void CenterX(this Control control) + { + control.Location = new Point((control.Parent!.Width / 2) - (int)0.5 * (control.Width), control.Location.Y); + } + public static void CenterY(this Control control) + { + control.Location = new Point(control.Location.X, (control.Parent!.Height / 2) - (int)0.5 * (control.Width)); + } } diff --git a/src/Globals.cs b/src/Globals.cs index e58348a..46734e8 100644 --- a/src/Globals.cs +++ b/src/Globals.cs @@ -1,14 +1,18 @@ // System namespaces global using System.Reflection; // FormManager +global using FormSystem; +global using static FormSystem.FormHelper; +global using static FormSystem.ControlDirection; // Scraper global using static Scraper.ScrapeType; // State +global using StateSystem; global using static StateSystem.StateHelper; global using static StateSystem.StateType; -global using State = System.Collections.Generic.Dictionary, object?>; +// global using State = System.Collections.Generic.Dictionary, object?>; global using Password = (string Hashed, byte[] Salt); // Misc diff --git a/src/StateSystem/State.cs b/src/StateSystem/State.cs new file mode 100644 index 0000000..95b1526 --- /dev/null +++ b/src/StateSystem/State.cs @@ -0,0 +1,11 @@ +namespace StateSystem; + +public class State : Dictionary, object?> +{ + public static State From() + { + return GetGlobalState(); + } + + // Way of storing objects stored with arbitrary strings +} diff --git a/src/StateSystem/StateHelper.cs b/src/StateSystem/StateHelper.cs index 23f419a..f6c4421 100644 --- a/src/StateSystem/StateHelper.cs +++ b/src/StateSystem/StateHelper.cs @@ -1,5 +1,4 @@ using ExceptionSystem.ToolingExceptions; -using FormSystem; namespace StateSystem; @@ -184,7 +183,7 @@ public static State GlobalStateAdd(State state) public static State GlobalStateRemove(State state) { - FormManager.GlobalState = FormManager.GlobalState.Where(x => !state.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); + FormManager.GlobalState = (State)FormManager.GlobalState.Where(x => !state.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); return FlagFailure; } @@ -356,7 +355,6 @@ public static IEnumerable UnwrapAll(this State state) } - /// /// Unwraps a value, but allows null /// diff --git a/src/StateSystem/StateType.cs b/src/StateSystem/StateType.cs index f913717..304df19 100644 --- a/src/StateSystem/StateType.cs +++ b/src/StateSystem/StateType.cs @@ -19,5 +19,8 @@ public enum StateType FLAG_FAILURE, FLAG_NONNULL, - FLAG_NULL + FLAG_NULL, + + FLAG_IDENTIFIER, + FLAG_VALUE } \ No newline at end of file