From acea7b2e728787a0d83bbf83c8c1f042d2c32e7e Mon Sep 17 00:00:00 2001
From: chai <215380520@qq.com>
Date: Mon, 3 Jun 2024 10:15:45 +0800
Subject: + plugins project
---
.../MonoGame.Extended.Collisions/Layers/Layer.cs | 39 ++++++++++++++++++++++
.../Layers/UndefinedLayerException.cs | 18 ++++++++++
2 files changed, 57 insertions(+)
create mode 100644 Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/Layer.cs
create mode 100644 Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/UndefinedLayerException.cs
(limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers')
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/Layer.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/Layer.cs
new file mode 100644
index 0000000..6e97ac8
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/Layer.cs
@@ -0,0 +1,39 @@
+using System;
+
+namespace MonoGame.Extended.Collisions.Layers;
+
+///
+/// Layer is a group of collision's actors.
+///
+public class Layer
+{
+ ///
+ /// If this property equals true, layer always will reset collision space.
+ ///
+ public bool IsDynamic { get; set; } = true;
+
+
+ ///
+ /// The space, which contain actors.
+ ///
+ public readonly ISpaceAlgorithm Space;
+
+ ///
+ /// Constructor for layer
+ ///
+ /// A space algorithm for actors
+ /// is null
+ public Layer(ISpaceAlgorithm spaceAlgorithm)
+ {
+ Space = spaceAlgorithm ?? throw new ArgumentNullException(nameof(spaceAlgorithm));
+ }
+
+ ///
+ /// Restructure a inner collection, if layer is dynamic, because actors can change own position
+ ///
+ public virtual void Reset()
+ {
+ if (IsDynamic)
+ Space.Reset();
+ }
+}
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/UndefinedLayerException.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/UndefinedLayerException.cs
new file mode 100644
index 0000000..a27b5b6
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/Layers/UndefinedLayerException.cs
@@ -0,0 +1,18 @@
+namespace MonoGame.Extended.Collisions.Layers;
+
+using System;
+
+///
+/// Thrown when the collision system has no layer defined with the specified name
+///
+public class UndefinedLayerException : Exception
+{
+ ///
+ /// Thrown when the collision system has no layer defined with the specified name
+ ///
+ /// The undefined layer name
+ public UndefinedLayerException(string layerName)
+ : base($"Layer with name '{layerName}' is undefined")
+ {
+ }
+}
--
cgit v1.1-26-g67d0