diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2022-02-16 13:04:31 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2022-02-16 13:04:31 +0800 |
commit | 19a2ec3d04b0eaad0e9a8378ee6eb35e8c999dea (patch) | |
tree | b73f6e5aa2062ce0ac714234710c045ac4f1b565 | |
parent | 98b97d34df7f3ab2cafc3847358c231c3d357b40 (diff) |
Add GridMap.get_used_cells_by_item
-rw-r--r-- | modules/gridmap/doc_classes/GridMap.xml | 7 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 13 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index 2ea9a78970..049d372671 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -79,6 +79,13 @@ Returns an array of [Vector3] with the non-empty cell coordinates in the grid map. </description> </method> + <method name="get_used_cells_by_item" qualifiers="const"> + <return type="Array" /> + <argument index="0" name="item" type="int" /> + <description> + Returns an array of all cells with the given item index specified in [code]item[/code]. + </description> + </method> <method name="make_baked_meshes"> <return type="void" /> <argument index="0" name="gen_lightmap_uv" type="bool" default="false" /> diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 6df7835855..4b72c71a5a 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -878,6 +878,7 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear); ClassDB::bind_method(D_METHOD("get_used_cells"), &GridMap::get_used_cells); + ClassDB::bind_method(D_METHOD("get_used_cells_by_item", "item"), &GridMap::get_used_cells_by_item); ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes); ClassDB::bind_method(D_METHOD("get_bake_meshes"), &GridMap::get_bake_meshes); @@ -950,6 +951,18 @@ Array GridMap::get_used_cells() const { return a; } +Array GridMap::get_used_cells_by_item(int p_item) const { + Array a; + for (const KeyValue<IndexKey, Cell> &E : cell_map) { + if (E.value.item == p_item) { + Vector3 p(E.key.x, E.key.y, E.key.z); + a.push_back(p); + } + } + + return a; +} + Array GridMap::get_meshes() const { if (mesh_library.is_null()) { return Array(); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 6cdc3b178d..83d5af1324 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -266,6 +266,7 @@ public: float get_cell_scale() const; Array get_used_cells() const; + Array get_used_cells_by_item(int p_item) const; Array get_meshes() const; |