|
@@ -37,7 +37,10 @@
|
|
|
#include "core/templates/rb_set.h"
|
|
|
#include "scene/gui/control.h"
|
|
|
#include "scene/resources/image_texture.h"
|
|
|
+
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
#include "servers/navigation_server_2d.h"
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
/////////////////////////////// TileMapPattern //////////////////////////////////////
|
|
|
|
|
@@ -965,6 +968,7 @@ bool TileSet::is_valid_terrain_peering_bit(int p_terrain_set, TileSet::CellNeigh
|
|
|
return is_valid_terrain_peering_bit_for_mode(terrain_mode, p_peering_bit);
|
|
|
}
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation
|
|
|
int TileSet::get_navigation_layers_count() const {
|
|
|
return navigation_layers.size();
|
|
@@ -1039,6 +1043,7 @@ bool TileSet::get_navigation_layer_layer_value(int p_layer_index, int p_layer_nu
|
|
|
|
|
|
return get_navigation_layer_layers(p_layer_index) & (1 << (p_layer_number - 1));
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Custom data.
|
|
|
int TileSet::get_custom_data_layers_count() const {
|
|
@@ -3413,6 +3418,7 @@ void TileSet::_compatibility_conversion() {
|
|
|
tile_data->add_occluder_polygon(0);
|
|
|
tile_data->set_occluder_polygon(0, 0, occluder);
|
|
|
}
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
if (ctd->navigation.is_valid()) {
|
|
|
if (get_navigation_layers_count() < 1) {
|
|
|
add_navigation_layer();
|
|
@@ -3425,6 +3431,7 @@ void TileSet::_compatibility_conversion() {
|
|
|
navigation->set_vertices(vertices);
|
|
|
tile_data->set_navigation_polygon(0, navigation);
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
tile_data->set_z_index(ctd->z_index);
|
|
|
|
|
@@ -3522,6 +3529,7 @@ void TileSet::_compatibility_conversion() {
|
|
|
tile_data->add_occluder_polygon(0);
|
|
|
tile_data->set_occluder_polygon(0, 0, occluder);
|
|
|
}
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
if (ctd->autotile_navpoly_map.has(coords)) {
|
|
|
if (get_navigation_layers_count() < 1) {
|
|
|
add_navigation_layer();
|
|
@@ -3534,6 +3542,7 @@ void TileSet::_compatibility_conversion() {
|
|
|
navigation->set_vertices(vertices);
|
|
|
tile_data->set_navigation_polygon(0, navigation);
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
if (ctd->autotile_priority_map.has(coords)) {
|
|
|
tile_data->set_probability(ctd->autotile_priority_map[coords]);
|
|
|
}
|
|
@@ -3732,7 +3741,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
if (p[0].get_type() == Variant::VECTOR2) {
|
|
|
last_coord = p[0];
|
|
|
} else if (p[0].get_type() == Variant::OBJECT) {
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
ctd->autotile_navpoly_map.insert(last_coord, p[0]);
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
}
|
|
|
p.pop_front();
|
|
|
}
|
|
@@ -3794,7 +3805,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
} else if (what == "occluder") {
|
|
|
ctd->occluder = p_value;
|
|
|
} else if (what == "navigation") {
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
ctd->navigation = p_value;
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
/*
|
|
|
// IGNORED FOR NOW, they seem duplicated data compared to the shapes array
|
|
@@ -3913,6 +3926,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
}
|
|
|
}
|
|
|
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation layers.
|
|
|
int index = components[0].trim_prefix("navigation_layer_").to_int();
|
|
|
ERR_FAIL_COND_V(index < 0, false);
|
|
@@ -3924,6 +3938,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
set_navigation_layer_layers(index, p_value);
|
|
|
return true;
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
|
|
|
// Custom data layers.
|
|
|
int index = components[0].trim_prefix("custom_data_layer_").to_int();
|
|
@@ -4057,10 +4072,12 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
if (index < 0 || index >= navigation_layers.size()) {
|
|
|
return false;
|
|
|
}
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
if (components[1] == "layers") {
|
|
|
r_ret = get_navigation_layer_layers(index);
|
|
|
return true;
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
|
|
|
// Custom data layers.
|
|
|
int index = components[0].trim_prefix("custom_data_layer_").to_int();
|
|
@@ -4294,6 +4311,7 @@ void TileSet::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_terrain_color", "terrain_set", "terrain_index", "color"), &TileSet::set_terrain_color);
|
|
|
ClassDB::bind_method(D_METHOD("get_terrain_color", "terrain_set", "terrain_index"), &TileSet::get_terrain_color);
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation
|
|
|
ClassDB::bind_method(D_METHOD("get_navigation_layers_count"), &TileSet::get_navigation_layers_count);
|
|
|
ClassDB::bind_method(D_METHOD("add_navigation_layer", "to_position"), &TileSet::add_navigation_layer, DEFVAL(-1));
|
|
@@ -4303,6 +4321,7 @@ void TileSet::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_navigation_layer_layers", "layer_index"), &TileSet::get_navigation_layer_layers);
|
|
|
ClassDB::bind_method(D_METHOD("set_navigation_layer_layer_value", "layer_index", "layer_number", "value"), &TileSet::set_navigation_layer_layer_value);
|
|
|
ClassDB::bind_method(D_METHOD("get_navigation_layer_layer_value", "layer_index", "layer_number"), &TileSet::get_navigation_layer_layer_value);
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Custom data
|
|
|
ClassDB::bind_method(D_METHOD("get_custom_data_layers_count"), &TileSet::get_custom_data_layers_count);
|
|
@@ -4350,7 +4369,9 @@ void TileSet::_bind_methods() {
|
|
|
ADD_GROUP("", "");
|
|
|
ADD_ARRAY("physics_layers", "physics_layer_");
|
|
|
ADD_ARRAY("terrain_sets", "terrain_set_");
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
ADD_ARRAY("navigation_layers", "navigation_layer_");
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
ADD_ARRAY("custom_data_layers", "custom_data_layer_");
|
|
|
|
|
|
// -- Enum binding --
|
|
@@ -4558,6 +4579,7 @@ void TileSetAtlasSource::remove_terrain(int p_terrain_set, int p_index) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
void TileSetAtlasSource::add_navigation_layer(int p_to_pos) {
|
|
|
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
|
|
|
for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) {
|
|
@@ -4581,6 +4603,7 @@ void TileSetAtlasSource::remove_navigation_layer(int p_index) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
void TileSetAtlasSource::add_custom_data_layer(int p_to_pos) {
|
|
|
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
|
|
@@ -5932,7 +5955,9 @@ void TileData::notify_tile_data_properties_should_change() {
|
|
|
terrain_peering_bits[bit_index] = -1;
|
|
|
}
|
|
|
}
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
navigation.resize(tile_set->get_navigation_layers_count());
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Convert custom data to the new type.
|
|
|
custom_data.resize(tile_set->get_custom_data_layers_count());
|
|
@@ -6071,6 +6096,7 @@ void TileData::remove_terrain(int p_terrain_set, int p_index) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
void TileData::add_navigation_layer(int p_to_pos) {
|
|
|
if (p_to_pos < 0) {
|
|
|
p_to_pos = navigation.size();
|
|
@@ -6090,6 +6116,7 @@ void TileData::remove_navigation_layer(int p_index) {
|
|
|
ERR_FAIL_INDEX(p_index, navigation.size());
|
|
|
navigation.remove_at(p_index);
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
void TileData::add_custom_data_layer(int p_to_pos) {
|
|
|
if (p_to_pos < 0) {
|
|
@@ -6142,8 +6169,10 @@ TileData *TileData::duplicate() {
|
|
|
// Terrain
|
|
|
output->terrain_set = -1;
|
|
|
memcpy(output->terrain_peering_bits, terrain_peering_bits, 16 * sizeof(int));
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation
|
|
|
output->navigation = navigation;
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
// Misc
|
|
|
output->probability = probability;
|
|
|
// Custom data
|
|
@@ -6531,6 +6560,7 @@ TileSet::TerrainsPattern TileData::get_terrains_pattern() const {
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation
|
|
|
void TileData::set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon) {
|
|
|
ERR_FAIL_INDEX(p_layer_id, navigation.size());
|
|
@@ -6578,6 +6608,7 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id, bool p_f
|
|
|
return I->value;
|
|
|
}
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Misc
|
|
|
void TileData::set_probability(float p_probability) {
|
|
@@ -6706,9 +6737,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- } else
|
|
|
+ }
|
|
|
#ifndef PHYSICS_2D_DISABLED
|
|
|
- if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
|
|
|
+ else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
|
|
|
// Physics layers.
|
|
|
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
|
|
|
ERR_FAIL_COND_V(layer_index < 0, false);
|
|
@@ -6763,51 +6794,54 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- } else
|
|
|
+ }
|
|
|
#endif // PHYSICS_2D_DISABLED
|
|
|
- if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
|
|
|
- // Navigation layers.
|
|
|
- int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
|
|
|
- ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
- if (components[1] == "polygon") {
|
|
|
- Ref<NavigationPolygon> polygon = p_value;
|
|
|
-
|
|
|
- if (layer_index >= navigation.size()) {
|
|
|
- if (tile_set) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- navigation.resize(layer_index + 1);
|
|
|
- }
|
|
|
- }
|
|
|
- set_navigation_polygon(layer_index, polygon);
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
|
|
|
- // Terrains.
|
|
|
- for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
|
|
|
- TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
|
|
|
- if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
|
|
|
- set_terrain_peering_bit(bit, p_value);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
|
|
|
- // Custom data layers.
|
|
|
- int layer_index = components[0].trim_prefix("custom_data_").to_int();
|
|
|
- ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
+ else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
|
|
|
+ // Navigation layers.
|
|
|
+ int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
|
|
|
+ ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
+ if (components[1] == "polygon") {
|
|
|
+ Ref<NavigationPolygon> polygon = p_value;
|
|
|
|
|
|
- if (layer_index >= custom_data.size()) {
|
|
|
+ if (layer_index >= navigation.size()) {
|
|
|
if (tile_set) {
|
|
|
return false;
|
|
|
} else {
|
|
|
- custom_data.resize(layer_index + 1);
|
|
|
+ navigation.resize(layer_index + 1);
|
|
|
}
|
|
|
}
|
|
|
- set_custom_data_by_layer_id(layer_index, p_value);
|
|
|
-
|
|
|
+ set_navigation_polygon(layer_index, polygon);
|
|
|
return true;
|
|
|
}
|
|
|
+ }
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
+ else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
|
|
|
+ // Terrains.
|
|
|
+ for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
|
|
|
+ TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
|
|
|
+ if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
|
|
|
+ set_terrain_peering_bit(bit, p_value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
|
|
|
+ // Custom data layers.
|
|
|
+ int layer_index = components[0].trim_prefix("custom_data_").to_int();
|
|
|
+ ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
+
|
|
|
+ if (layer_index >= custom_data.size()) {
|
|
|
+ if (tile_set) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ custom_data.resize(layer_index + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ set_custom_data_by_layer_id(layer_index, p_value);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
return false;
|
|
|
}
|
|
@@ -6854,9 +6888,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- } else
|
|
|
+ }
|
|
|
#ifndef PHYSICS_2D_DISABLED
|
|
|
- if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
|
|
|
+ else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
|
|
|
// Physics layers.
|
|
|
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
|
|
|
ERR_FAIL_COND_V(layer_index < 0, false);
|
|
@@ -6892,38 +6926,32 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- } else
|
|
|
+ }
|
|
|
#endif // PHYSICS_2D_DISABLED
|
|
|
- if (components.size() == 2 && components[0] == "terrains_peering_bit") {
|
|
|
- // Terrains.
|
|
|
- for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
|
|
|
- if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
|
|
|
- r_ret = terrain_peering_bits[i];
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
|
|
|
- // Occlusion layers.
|
|
|
- int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
|
|
|
- ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
- if (layer_index >= navigation.size()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (components[1] == "polygon") {
|
|
|
- r_ret = get_navigation_polygon(layer_index);
|
|
|
+ else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
|
|
|
+ // Terrains.
|
|
|
+ for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
|
|
|
+ if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
|
|
|
+ r_ret = terrain_peering_bits[i];
|
|
|
return true;
|
|
|
}
|
|
|
- } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
|
|
|
- // Custom data layers.
|
|
|
- int layer_index = components[0].trim_prefix("custom_data_").to_int();
|
|
|
- ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
- if (layer_index >= custom_data.size()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- r_ret = get_custom_data_by_layer_id(layer_index);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
+ else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
|
|
|
+ // Occlusion layers.
|
|
|
+ int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
|
|
|
+ ERR_FAIL_COND_V(layer_index < 0, false);
|
|
|
+ if (layer_index >= navigation.size()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (components[1] == "polygon") {
|
|
|
+ r_ret = get_navigation_polygon(layer_index);
|
|
|
return true;
|
|
|
}
|
|
|
+ }
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
}
|
|
|
|
|
|
return false;
|
|
@@ -7007,6 +7035,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation layers.
|
|
|
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Navigation", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
|
|
|
for (int i = 0; i < navigation.size(); i++) {
|
|
@@ -7016,6 +7045,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
}
|
|
|
p_list->push_back(property_info);
|
|
|
}
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Custom data layers.
|
|
|
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Custom Data", "custom_data_"), PROPERTY_HINT_NONE, "custom_data_", PROPERTY_USAGE_GROUP));
|
|
@@ -7090,9 +7120,11 @@ void TileData::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_terrain_peering_bit", "peering_bit"), &TileData::get_terrain_peering_bit);
|
|
|
ClassDB::bind_method(D_METHOD("is_valid_terrain_peering_bit", "peering_bit"), &TileData::is_valid_terrain_peering_bit);
|
|
|
|
|
|
+#ifndef NAVIGATION_2D_DISABLED
|
|
|
// Navigation
|
|
|
ClassDB::bind_method(D_METHOD("set_navigation_polygon", "layer_id", "navigation_polygon"), &TileData::set_navigation_polygon);
|
|
|
ClassDB::bind_method(D_METHOD("get_navigation_polygon", "layer_id", "flip_h", "flip_v", "transpose"), &TileData::get_navigation_polygon, DEFVAL(false), DEFVAL(false), DEFVAL(false));
|
|
|
+#endif // NAVIGATION_2D_DISABLED
|
|
|
|
|
|
// Misc.
|
|
|
ClassDB::bind_method(D_METHOD("set_probability", "probability"), &TileData::set_probability);
|