Skip to content

Commit f434c75

Browse files
committed
Add has_custom_data() to TileData
1 parent d79ff84 commit f434c75

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

doc/classes/TileData.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<return type="Variant" />
6565
<param index="0" name="layer_name" type="String" />
6666
<description>
67-
Returns the custom data value for custom data layer named [param layer_name].
67+
Returns the custom data value for custom data layer named [param layer_name]. To check if a custom data layer exists, use [method has_custom_data].
6868
</description>
6969
</method>
7070
<method name="get_custom_data_by_layer_id" qualifiers="const">
@@ -122,6 +122,13 @@
122122
Returns the tile's terrain bit for the given [param peering_bit] direction. To check that a direction is valid, use [method is_valid_terrain_peering_bit].
123123
</description>
124124
</method>
125+
<method name="has_custom_data" qualifiers="const">
126+
<return type="bool" />
127+
<param index="0" name="layer_name" type="String" />
128+
<description>
129+
Returns whether there exists a custom data layer named [param layer_name].
130+
</description>
131+
</method>
125132
<method name="is_collision_polygon_one_way" qualifiers="const">
126133
<return type="bool" />
127134
<param index="0" name="layer_id" type="int" />

doc/classes/TileSet.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@
319319
Returns if there is a coodinates-level proxy for the given identifiers.
320320
</description>
321321
</method>
322+
<method name="has_custom_data_layer_by_name" qualifiers="const">
323+
<return type="bool" />
324+
<param index="0" name="layer_name" type="String" />
325+
<description>
326+
Returns if there is a custom data layer named [param layer_name].
327+
</description>
328+
</method>
322329
<method name="has_source" qualifiers="const">
323330
<return type="bool" />
324331
<param index="0" name="source_id" type="int" />

scene/resources/2d/tile_set.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,10 @@ void TileSet::set_custom_data_layer_name(int p_layer_id, String p_value) {
11221122
emit_changed();
11231123
}
11241124

1125+
bool TileSet::has_custom_data_layer_by_name(const String &p_value) const {
1126+
return custom_data_layers_by_name.has(p_value);
1127+
}
1128+
11251129
String TileSet::get_custom_data_layer_name(int p_layer_id) const {
11261130
ERR_FAIL_INDEX_V(p_layer_id, custom_data_layers.size(), "");
11271131
return custom_data_layers[p_layer_id].name;
@@ -4354,6 +4358,7 @@ void TileSet::_bind_methods() {
43544358
ClassDB::bind_method(D_METHOD("remove_custom_data_layer", "layer_index"), &TileSet::remove_custom_data_layer);
43554359
ClassDB::bind_method(D_METHOD("get_custom_data_layer_by_name", "layer_name"), &TileSet::get_custom_data_layer_by_name);
43564360
ClassDB::bind_method(D_METHOD("set_custom_data_layer_name", "layer_index", "layer_name"), &TileSet::set_custom_data_layer_name);
4361+
ClassDB::bind_method(D_METHOD("has_custom_data_layer_by_name", "layer_name"), &TileSet::has_custom_data_layer_by_name);
43574362
ClassDB::bind_method(D_METHOD("get_custom_data_layer_name", "layer_index"), &TileSet::get_custom_data_layer_name);
43584363
ClassDB::bind_method(D_METHOD("set_custom_data_layer_type", "layer_index", "layer_type"), &TileSet::set_custom_data_layer_type);
43594364
ClassDB::bind_method(D_METHOD("get_custom_data_layer_type", "layer_index"), &TileSet::get_custom_data_layer_type);
@@ -6636,6 +6641,11 @@ Variant TileData::get_custom_data(String p_layer_name) const {
66366641
return get_custom_data_by_layer_id(p_layer_id);
66376642
}
66386643

6644+
bool TileData::has_custom_data(const String &p_layer_name) const {
6645+
ERR_FAIL_NULL_V(tile_set, false);
6646+
return tile_set->has_custom_data_layer_by_name(p_layer_name);
6647+
}
6648+
66396649
void TileData::set_custom_data_by_layer_id(int p_layer_id, Variant p_value) {
66406650
ERR_FAIL_INDEX(p_layer_id, custom_data.size());
66416651
custom_data.write[p_layer_id] = p_value;
@@ -7116,6 +7126,7 @@ void TileData::_bind_methods() {
71167126
// Custom data.
71177127
ClassDB::bind_method(D_METHOD("set_custom_data", "layer_name", "value"), &TileData::set_custom_data);
71187128
ClassDB::bind_method(D_METHOD("get_custom_data", "layer_name"), &TileData::get_custom_data);
7129+
ClassDB::bind_method(D_METHOD("has_custom_data", "layer_name"), &TileData::has_custom_data);
71197130
ClassDB::bind_method(D_METHOD("set_custom_data_by_layer_id", "layer_id", "value"), &TileData::set_custom_data_by_layer_id);
71207131
ClassDB::bind_method(D_METHOD("get_custom_data_by_layer_id", "layer_id"), &TileData::get_custom_data_by_layer_id);
71217132

scene/resources/2d/tile_set.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ class TileSet : public Resource {
491491
void remove_custom_data_layer(int p_index);
492492
int get_custom_data_layer_by_name(String p_value) const;
493493
void set_custom_data_layer_name(int p_layer_id, String p_value);
494+
bool has_custom_data_layer_by_name(const String &p_value) const;
494495
String get_custom_data_layer_name(int p_layer_id) const;
495496
void set_custom_data_layer_type(int p_layer_id, Variant::Type p_value);
496497
Variant::Type get_custom_data_layer_type(int p_layer_id) const;
@@ -999,6 +1000,7 @@ class TileData : public Object {
9991000
// Custom data.
10001001
void set_custom_data(String p_layer_name, Variant p_value);
10011002
Variant get_custom_data(String p_layer_name) const;
1003+
bool has_custom_data(const String &p_layer_name) const;
10021004
void set_custom_data_by_layer_id(int p_layer_id, Variant p_value);
10031005
Variant get_custom_data_by_layer_id(int p_layer_id) const;
10041006

0 commit comments

Comments
 (0)