Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add has_custom_data() to TileData #101488

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion doc/classes/TileData.xml
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@
<return type="Variant" />
<param index="0" name="layer_name" type="String" />
<description>
Returns the custom data value for custom data layer named [param layer_name].
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].
</description>
</method>
<method name="get_custom_data_by_layer_id" qualifiers="const">
@@ -122,6 +122,13 @@
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].
</description>
</method>
<method name="has_custom_data" qualifiers="const">
<return type="bool" />
<param index="0" name="layer_name" type="String" />
<description>
Returns whether there exists a custom data layer named [param layer_name].
</description>
</method>
<method name="is_collision_polygon_one_way" qualifiers="const">
<return type="bool" />
<param index="0" name="layer_id" type="int" />
7 changes: 7 additions & 0 deletions doc/classes/TileSet.xml
Original file line number Diff line number Diff line change
@@ -319,6 +319,13 @@
Returns if there is a coodinates-level proxy for the given identifiers.
</description>
</method>
<method name="has_custom_data_layer_by_name" qualifiers="const">
<return type="bool" />
<param index="0" name="layer_name" type="String" />
<description>
Returns if there is a custom data layer named [param layer_name].
</description>
</method>
<method name="has_source" qualifiers="const">
<return type="bool" />
<param index="0" name="source_id" type="int" />
11 changes: 11 additions & 0 deletions scene/resources/2d/tile_set.cpp
Original file line number Diff line number Diff line change
@@ -1122,6 +1122,10 @@ void TileSet::set_custom_data_layer_name(int p_layer_id, String p_value) {
emit_changed();
}

bool TileSet::has_custom_data_layer_by_name(const String &p_value) const {
return custom_data_layers_by_name.has(p_value);
}

String TileSet::get_custom_data_layer_name(int p_layer_id) const {
ERR_FAIL_INDEX_V(p_layer_id, custom_data_layers.size(), "");
return custom_data_layers[p_layer_id].name;
@@ -4354,6 +4358,7 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_custom_data_layer", "layer_index"), &TileSet::remove_custom_data_layer);
ClassDB::bind_method(D_METHOD("get_custom_data_layer_by_name", "layer_name"), &TileSet::get_custom_data_layer_by_name);
ClassDB::bind_method(D_METHOD("set_custom_data_layer_name", "layer_index", "layer_name"), &TileSet::set_custom_data_layer_name);
ClassDB::bind_method(D_METHOD("has_custom_data_layer_by_name", "layer_name"), &TileSet::has_custom_data_layer_by_name);
ClassDB::bind_method(D_METHOD("get_custom_data_layer_name", "layer_index"), &TileSet::get_custom_data_layer_name);
ClassDB::bind_method(D_METHOD("set_custom_data_layer_type", "layer_index", "layer_type"), &TileSet::set_custom_data_layer_type);
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 {
return get_custom_data_by_layer_id(p_layer_id);
}

bool TileData::has_custom_data(const String &p_layer_name) const {
ERR_FAIL_NULL_V(tile_set, false);
return tile_set->has_custom_data_layer_by_name(p_layer_name);
}

void TileData::set_custom_data_by_layer_id(int p_layer_id, Variant p_value) {
ERR_FAIL_INDEX(p_layer_id, custom_data.size());
custom_data.write[p_layer_id] = p_value;
@@ -7116,6 +7126,7 @@ void TileData::_bind_methods() {
// Custom data.
ClassDB::bind_method(D_METHOD("set_custom_data", "layer_name", "value"), &TileData::set_custom_data);
ClassDB::bind_method(D_METHOD("get_custom_data", "layer_name"), &TileData::get_custom_data);
ClassDB::bind_method(D_METHOD("has_custom_data", "layer_name"), &TileData::has_custom_data);
ClassDB::bind_method(D_METHOD("set_custom_data_by_layer_id", "layer_id", "value"), &TileData::set_custom_data_by_layer_id);
ClassDB::bind_method(D_METHOD("get_custom_data_by_layer_id", "layer_id"), &TileData::get_custom_data_by_layer_id);

2 changes: 2 additions & 0 deletions scene/resources/2d/tile_set.h
Original file line number Diff line number Diff line change
@@ -491,6 +491,7 @@ class TileSet : public Resource {
void remove_custom_data_layer(int p_index);
int get_custom_data_layer_by_name(String p_value) const;
void set_custom_data_layer_name(int p_layer_id, String p_value);
bool has_custom_data_layer_by_name(const String &p_value) const;
String get_custom_data_layer_name(int p_layer_id) const;
void set_custom_data_layer_type(int p_layer_id, Variant::Type p_value);
Variant::Type get_custom_data_layer_type(int p_layer_id) const;
@@ -999,6 +1000,7 @@ class TileData : public Object {
// Custom data.
void set_custom_data(String p_layer_name, Variant p_value);
Variant get_custom_data(String p_layer_name) const;
bool has_custom_data(const String &p_layer_name) const;
void set_custom_data_by_layer_id(int p_layer_id, Variant p_value);
Variant get_custom_data_by_layer_id(int p_layer_id) const;