Add GridMap.get_used_cells_by_item

This commit is contained in:
Haoyu Qiu 2022-02-16 13:03:50 +08:00
parent 685d4b4739
commit b2c012a8c8
3 changed files with 21 additions and 0 deletions

View file

@ -83,6 +83,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" />

View file

@ -886,6 +886,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);
@ -959,6 +960,18 @@ Array GridMap::get_used_cells() const {
return a;
}
Array GridMap::get_used_cells_by_item(int p_item) const {
Array a;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) {
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();

View file

@ -259,6 +259,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;