summaryrefslogtreecommitdiff
path: root/Extensions.cs
diff options
context:
space:
mode:
authorSarah B <git@sarahduck.ca>2023-12-25 00:02:12 -0800
committerSarah B <git@sarahduck.ca>2023-12-25 00:02:12 -0800
commitff3cbc5b49f8618531c5778d69b49c0aa4a9442a (patch)
treebdee837392669a3eb4ac3f0296c3749c6485078c /Extensions.cs
parent760fb20f4d248d19524392d2b8c3a3fcdb762453 (diff)
Changed how server handles UserInfo, and started work on networking the cursor's sprite.
Diffstat (limited to 'Extensions.cs')
-rw-r--r--Extensions.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Extensions.cs b/Extensions.cs
new file mode 100644
index 0000000..e6368c3
--- /dev/null
+++ b/Extensions.cs
@@ -0,0 +1,40 @@
+using System.Numerics;
+
+namespace OnekoOnline;
+
+static class MathExtensions
+{
+ public static Vector2 LimitLength(this Vector2 toLimit, float lengthLimit)
+ {
+ float length = toLimit.Length();
+ if (toLimit == Vector2.Zero) return Vector2.Zero;
+ return Vector2.Normalize(toLimit) * MathF.Min(length, lengthLimit);
+ }
+
+ public static Vector2 Round(this Vector2 toRound)
+ {
+ return new(MathF.Round(toRound.X), MathF.Round(toRound.Y));
+ }
+}
+
+static class StringExtensions
+{
+ public static string LimitLength(this string value, int maxLength)
+ {
+ if (string.IsNullOrEmpty(value)) return value;
+ return value.Length <= maxLength ? value : value[..maxLength];
+ }
+}
+
+public static class Directions
+{
+ public static readonly Vector2 Up = new(0,-1);
+ public static readonly Vector2 Down = new(0,1);
+ public static readonly Vector2 Left = new(-1,0);
+ public static readonly Vector2 Right = new(1,0);
+
+ public static readonly Vector2 UpLeft = Vector2.Normalize(Up+Left);
+ public static readonly Vector2 UpRight = Vector2.Normalize(Up+Right);
+ public static readonly Vector2 DownLeft = Vector2.Normalize(Down+Left);
+ public static readonly Vector2 DownRight = Vector2.Normalize(Down+Right);
+} \ No newline at end of file