Merge pull request #54549 from KoBeWi/fastcells
Add a method to get TileData from a cell
This commit is contained in:
commit
d5052d9084
@ -107,6 +107,16 @@
|
||||
Returns the tile source ID of the cell on layer [param layer] at coordinates [param coords]. If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell_tile_data" qualifiers="const">
|
||||
<return type="TileData" />
|
||||
<param index="0" name="layer" type="int" />
|
||||
<param index="1" name="coords" type="Vector2i" />
|
||||
<param index="2" name="use_proxies" type="bool" default="false" />
|
||||
<description>
|
||||
Returns the [TileData] object associated with the given cell, or [code]null[/code] if the cell is not a [TileSetAtlasSource].
|
||||
If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_coords_for_body_rid">
|
||||
<return type="Vector2i" />
|
||||
<param index="0" name="body" type="RID" />
|
||||
|
@ -2063,6 +2063,18 @@ int TileMap::get_cell_alternative_tile(int p_layer, const Vector2i &p_coords, bo
|
||||
return E->value.alternative_tile;
|
||||
}
|
||||
|
||||
TileData *TileMap::get_cell_tile_data(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
|
||||
int source_id = get_cell_source_id(p_layer, p_coords, p_use_proxies);
|
||||
ERR_FAIL_COND_V_MSG(source_id == TileSet::INVALID_SOURCE, nullptr, vformat("Invalid TileSetSource at cell %s. Make sure a tile exists at this cell.", p_coords));
|
||||
|
||||
Ref<TileSetAtlasSource> source = tile_set->get_source(source_id);
|
||||
if (source.is_valid()) {
|
||||
return source->get_tile_data(get_cell_atlas_coords(p_layer, p_coords, p_use_proxies), get_cell_alternative_tile(p_layer, p_coords, p_use_proxies));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ref<TileMapPattern> TileMap::get_pattern(int p_layer, TypedArray<Vector2i> p_coords_array) {
|
||||
ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), nullptr);
|
||||
ERR_FAIL_COND_V(!tile_set.is_valid(), nullptr);
|
||||
@ -3849,6 +3861,7 @@ void TileMap::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_cell_source_id", "layer", "coords", "use_proxies"), &TileMap::get_cell_source_id);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_atlas_coords", "layer", "coords", "use_proxies"), &TileMap::get_cell_atlas_coords);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_alternative_tile", "layer", "coords", "use_proxies"), &TileMap::get_cell_alternative_tile);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_tile_data", "layer", "coords", "use_proxies"), &TileMap::get_cell_tile_data, DEFVAL(false));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_coords_for_body_rid", "body"), &TileMap::get_coords_for_body_rid);
|
||||
|
||||
|
@ -343,6 +343,8 @@ public:
|
||||
int get_cell_source_id(int p_layer, const Vector2i &p_coords, bool p_use_proxies = false) const;
|
||||
Vector2i get_cell_atlas_coords(int p_layer, const Vector2i &p_coords, bool p_use_proxies = false) const;
|
||||
int get_cell_alternative_tile(int p_layer, const Vector2i &p_coords, bool p_use_proxies = false) const;
|
||||
// Helper method to make accessing the data easier.
|
||||
TileData *get_cell_tile_data(int p_layer, const Vector2i &p_coords, bool p_use_proxies = false) const;
|
||||
|
||||
// Patterns.
|
||||
Ref<TileMapPattern> get_pattern(int p_layer, TypedArray<Vector2i> p_coords_array);
|
||||
|
Loading…
Reference in New Issue
Block a user