From f434c75dbfd2f580e43b28be3641d2f98169002e Mon Sep 17 00:00:00 2001 From: chocola-mint <56677134+chocola-mint@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:59:47 +0900 Subject: [PATCH] Add has_custom_data() to TileData --- doc/classes/TileData.xml | 9 ++++++++- doc/classes/TileSet.xml | 7 +++++++ scene/resources/2d/tile_set.cpp | 11 +++++++++++ scene/resources/2d/tile_set.h | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/classes/TileData.xml b/doc/classes/TileData.xml index f9505124ef4..e8a74f0be0f 100644 --- a/doc/classes/TileData.xml +++ b/doc/classes/TileData.xml @@ -64,7 +64,7 @@ - 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]. @@ -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]. + + + + + Returns whether there exists a custom data layer named [param layer_name]. + + diff --git a/doc/classes/TileSet.xml b/doc/classes/TileSet.xml index 19b6e8d92cb..a24f920daf5 100644 --- a/doc/classes/TileSet.xml +++ b/doc/classes/TileSet.xml @@ -319,6 +319,13 @@ Returns if there is a coodinates-level proxy for the given identifiers. + + + + + Returns if there is a custom data layer named [param layer_name]. + + diff --git a/scene/resources/2d/tile_set.cpp b/scene/resources/2d/tile_set.cpp index 4daaa0d3798..9e6292bae49 100644 --- a/scene/resources/2d/tile_set.cpp +++ b/scene/resources/2d/tile_set.cpp @@ -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); diff --git a/scene/resources/2d/tile_set.h b/scene/resources/2d/tile_set.h index 6d3ccd1d2d5..31ec28c91d6 100644 --- a/scene/resources/2d/tile_set.h +++ b/scene/resources/2d/tile_set.h @@ -491,6 +491,7 @@ public: 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 @@ public: // 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;