diff --git a/DungeonShooting_Godot/src/framework/Grid.cs b/DungeonShooting_Godot/src/framework/Grid.cs
index ac48e11..4966fa1 100644
--- a/DungeonShooting_Godot/src/framework/Grid.cs
+++ b/DungeonShooting_Godot/src/framework/Grid.cs
@@ -4,12 +4,20 @@
using Godot;
///
-/// 网格数据结构
+/// 网格数据结构, 通过 x 和 y 存储数据
///
public class Grid
{
+ ///
+ /// 遍历网格数据回调
+ ///
+ public delegate void EachGridCallback(int x, int y, T data);
+
private readonly Dictionary> _map = new Dictionary>();
+ ///
+ /// 返回指定xy位置是否存在数据
+ ///
public bool Contains(int x, int y)
{
if (_map.TryGetValue(x, out var value))
@@ -20,6 +28,9 @@
return false;
}
+ ///
+ /// 设置指定xy位置的数据
+ ///
public void Set(int x, int y, T data)
{
if (_map.TryGetValue(x, out var value))
@@ -34,6 +45,9 @@
}
}
+ ///
+ /// 获取指定xy位置的数据
+ ///
public T Get(int x, int y)
{
if (_map.TryGetValue(x, out var value))
@@ -43,7 +57,13 @@
return default;
}
-
+
+ ///
+ /// 往一个区域中填充指定的数据
+ ///
+ /// 起点位置
+ /// 区域大小
+ /// 数据
public void AddRect(Vector2 pos, Vector2 size, T data)
{
var x = (int)pos.x;
@@ -66,6 +86,11 @@
}
}
+ ///
+ /// 移除指定区域数据
+ ///
+ /// 起点位置
+ /// 区域大小
public void RemoveRect(Vector2 pos, Vector2 size)
{
var x = (int)pos.x;
@@ -86,6 +111,11 @@
}
}
+ ///
+ /// 检测矩形区域内是否与其他数据有碰撞
+ ///
+ /// 起点位置
+ /// 区域大小
public bool RectCollision(Vector2 pos, Vector2 size)
{
var x = (int)pos.x;
@@ -113,7 +143,10 @@
return false;
}
- public void ForEach(Action cb)
+ ///
+ /// 遍历网格数据
+ ///
+ public void ForEach(EachGridCallback cb)
{
foreach (var pair1 in _map)
{