Work on fixing compile when layered tile maps are enabled.

This commit is contained in:
Relintai 2024-03-02 09:13:07 +01:00
parent 82fe33fdcb
commit 13d0ac8d5d
16 changed files with 288 additions and 289 deletions

View File

@ -25,7 +25,7 @@
</description>
</method>
<method name="get_collision_polygon_points" qualifiers="const">
<return type="PackedVector2Array" />
<return type="PoolVector2Array" />
<param index="0" name="layer_id" type="int" />
<param index="1" name="polygon_index" type="int" />
<description>
@ -134,7 +134,7 @@
<return type="void" />
<param index="0" name="layer_id" type="int" />
<param index="1" name="polygon_index" type="int" />
<param index="2" name="polygon" type="PackedVector2Array" />
<param index="2" name="polygon" type="PoolVector2Array" />
<description>
Sets the points of the polygon at index [param polygon_index] for LayeredTileSet physics layer with index [param layer_id].
</description>

View File

@ -50,7 +50,7 @@
Returns whether the pattern has a tile at the given coordinates.
</description>
</method>
<method name="is_empty" qualifiers="const">
<method name="empty" qualifiers="const">
<return type="bool" />
<description>
Returns whether the pattern is empty or not.

View File

@ -145,7 +145,7 @@
</description>
</method>
<method name="get_tiles_to_be_removed_on_change">
<return type="PackedVector2Array" />
<return type="PoolVector2Array" />
<param index="0" name="texture" type="Texture2D" />
<param index="1" name="margins" type="Vector2i" />
<param index="2" name="separation" type="Vector2i" />

View File

@ -183,7 +183,7 @@ void GenericTilePolygonEditor::_base_control_draw() {
// Draw the polygons.
for (const Vector<Vector2> &polygon : polygons) {
Color color = polygon_color;
if (!in_creation_polygon.is_empty()) {
if (!in_creation_polygon.empty()) {
color = color.darkened(0.3);
}
color.a = 0.5;
@ -198,7 +198,7 @@ void GenericTilePolygonEditor::_base_control_draw() {
}
// Draw the polygon in creation.
if (!in_creation_polygon.is_empty()) {
if (!in_creation_polygon.empty()) {
for (int i = 0; i < in_creation_polygon.size() - 1; i++) {
base_control->draw_line(in_creation_polygon[i], in_creation_polygon[i + 1], Color(1.0, 1.0, 1.0));
}
@ -209,7 +209,7 @@ void GenericTilePolygonEditor::_base_control_draw() {
_snap_to_tile_shape(in_creation_point, in_creation_distance, grab_threshold / editor_zoom_widget->get_zoom());
_snap_point(in_creation_point);
if (drag_type == DRAG_TYPE_CREATE_POINT && !in_creation_polygon.is_empty()) {
if (drag_type == DRAG_TYPE_CREATE_POINT && !in_creation_polygon.empty()) {
base_control->draw_line(in_creation_polygon[in_creation_polygon.size() - 1], in_creation_point, Color(1.0, 1.0, 1.0));
}
@ -225,7 +225,7 @@ void GenericTilePolygonEditor::_base_control_draw() {
}
base_control->draw_set_transform_matrix(Transform2D());
if (!in_creation_polygon.is_empty()) {
if (!in_creation_polygon.empty()) {
for (int i = 0; i < in_creation_polygon.size(); i++) {
base_control->draw_texture(handle, xform.xform(in_creation_polygon[i]) - handle->get_size() / 2);
}
@ -294,7 +294,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "queue_redraw");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
for (const PackedVector2Array &poly : polygons) {
for (const PoolVector2Array &poly : polygons) {
undo_redo->add_undo_method(this, "add_polygon", poly);
}
undo_redo->add_undo_method(base_control, "queue_redraw");
@ -307,7 +307,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "queue_redraw");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
for (const PackedVector2Array &polygon : polygons) {
for (const PoolVector2Array &polygon : polygons) {
undo_redo->add_undo_method(this, "add_polygon", polygon);
}
undo_redo->add_undo_method(base_control, "queue_redraw");
@ -582,8 +582,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
int closest_point;
_grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point);
if (closest_polygon >= 0) {
PackedVector2Array old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove_at(closest_point);
PoolVector2Array old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove(closest_point);
undo_redo->create_action(TTR("Edit Polygons"));
if (polygons[closest_polygon].size() < 3) {
remove_polygon(closest_polygon);
@ -627,8 +627,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
int closest_point;
_grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point);
if (closest_polygon >= 0) {
PackedVector2Array old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove_at(closest_point);
PoolVector2Array old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove(closest_point);
undo_redo->create_action(TTR("Edit Polygons"));
if (polygons[closest_polygon].size() < 3) {
remove_polygon(closest_polygon);
@ -771,7 +771,7 @@ int GenericTilePolygonEditor::add_polygon(const Vector<Point2> &p_polygon, int p
void GenericTilePolygonEditor::remove_polygon(int p_index) {
ERR_FAIL_INDEX(p_index, (int)polygons.size());
polygons.remove_at(p_index);
polygons.remove(p_index);
if (polygons.size() == 0) {
button_create->set_pressed(true);
@ -1253,7 +1253,7 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2
}
void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const String &p_property, const String &p_label, const Variant &p_default_value) {
ERR_FAIL_COND_MSG(!property.is_empty(), "Cannot setup TileDataDefaultEditor twice");
ERR_FAIL_COND_MSG(!property.empty(), "Cannot setup TileDataDefaultEditor twice");
property = p_property;
property_type = p_type;
@ -1278,7 +1278,7 @@ void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const St
// Create and setup the property editor.
property_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, p_type, p_property, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
property_editor->set_object_and_property(dummy_object, p_property);
if (p_label.is_empty()) {
if (p_label.empty()) {
property_editor->set_label(EditorPropertyNameProcessor::get_singleton()->process_name(p_property, EditorPropertyNameProcessor::get_default_inspector_style()));
} else {
property_editor->set_label(p_label);
@ -1752,7 +1752,7 @@ void TileDataCollisionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transfor
p_canvas_item->draw_polygon(polygon, color);
if (tile_data->is_collision_polygon_one_way(physics_layer, i)) {
PackedVector2Array uvs;
PoolVector2Array uvs;
uvs.resize(polygon.size());
Vector2 size_1 = Vector2(1, 1) / tile_set->get_tile_size();
@ -1791,7 +1791,7 @@ void TileDataTerrainsEditor::_update_terrain_selector() {
options.push_back(String(TTR("No terrain")) + String(":-1"));
for (int i = 0; i < tile_set->get_terrains_count(terrain_set); i++) {
String name = tile_set->get_terrain_name(terrain_set, i);
if (name.is_empty()) {
if (name.empty()) {
options.push_back(vformat("Terrain %d", i));
} else {
options.push_back(name);
@ -2003,7 +2003,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(LayeredTileAtlasView *p_til
for (int j = 0; j < polygon.size(); j++) {
polygon.write[j] += position;
}
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) {
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).empty()) {
// Draw terrain.
p_canvas_item->draw_polygon(polygon, color);
}
@ -2015,7 +2015,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(LayeredTileAtlasView *p_til
for (int j = 0; j < polygon.size(); j++) {
polygon.write[j] += position;
}
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) {
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).empty()) {
// Draw bit.
p_canvas_item->draw_polygon(polygon, color);
}
@ -2483,7 +2483,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVi
for (int j = 0; j < polygon.size(); j++) {
polygon.write[j] += position;
}
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) {
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).empty()) {
// Draw terrain.
undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E.alternative_tile), terrain);
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E.alternative_tile), tile_data->get_terrain());
@ -2496,7 +2496,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVi
for (int j = 0; j < polygon.size(); j++) {
polygon.write[j] += position;
}
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) {
if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).empty()) {
// Draw bit.
undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(LayeredTileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.alternative_tile), terrain);
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(LayeredTileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.alternative_tile), tile_data->get_terrain_peering_bit(bit));

View File

@ -115,7 +115,7 @@ private:
int drag_polygon_index = 0;
int drag_point_index = 0;
Vector2 drag_last_pos;
PackedVector2Array drag_old_polygon;
PoolVector2Array drag_old_polygon;
HBoxContainer *toolbar = nullptr;
Ref<ButtonGroup> tools_button_group;
@ -286,7 +286,7 @@ private:
// UI
GenericTilePolygonEditor *polygon_editor = nullptr;
void _polygon_changed(const PackedVector2Array &p_polygon);
void _polygon_changed(const PoolVector2Array &p_polygon);
virtual Variant _get_painted_value();
virtual void _set_painted_value(LayeredTileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile);
@ -395,12 +395,12 @@ class TileDataNavigationEditor : public TileDataDefaultEditor {
private:
int navigation_layer = -1;
PackedVector2Array navigation_polygon;
PoolVector2Array navigation_polygon;
// UI
GenericTilePolygonEditor *polygon_editor = nullptr;
void _polygon_changed(const PackedVector2Array &p_polygon);
void _polygon_changed(const PoolVector2Array &p_polygon);
virtual Variant _get_painted_value();
virtual void _set_painted_value(LayeredTileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile);

View File

@ -189,7 +189,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
String item_text;
// Common to all type of sources.
if (!source->get_name().is_empty()) {
if (!source->get_name().empty()) {
item_text = source->get_name();
}
@ -197,7 +197,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source) {
texture = atlas_source->get_texture();
if (item_text.is_empty()) {
if (item_text.empty()) {
if (texture.is_valid()) {
item_text = texture->get_path().get_file();
} else {
@ -210,7 +210,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source);
if (scene_collection_source) {
texture = tiles_bottom_panel->get_editor_theme_icon(SNAME("PackedScene"));
if (item_text.is_empty()) {
if (item_text.empty()) {
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
} else {
@ -220,7 +220,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
}
// Use default if not valid.
if (item_text.is_empty()) {
if (item_text.empty()) {
item_text = vformat(TTR("Unknown Type Source (ID: %d)"), source_id);
}
if (!texture.is_valid()) {
@ -547,7 +547,7 @@ bool LayeredTileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<In
// Shortcuts
if (ED_IS_SHORTCUT("tiles_editor/cut", p_event) || ED_IS_SHORTCUT("tiles_editor/copy", p_event)) {
// Fill in the clipboard.
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
tile_map_clipboard.instantiate();
PoolVector2iArray coords_array;
for (const Vector2i &E : tile_map_selection) {
@ -558,7 +558,7 @@ bool LayeredTileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<In
if (ED_IS_SHORTCUT("tiles_editor/cut", p_event)) {
// Delete selected tiles.
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Delete tiles"));
for (const Vector2i &coords : tile_map_selection) {
@ -590,7 +590,7 @@ bool LayeredTileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<In
}
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event)) {
// Delete selected tiles.
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Delete tiles"));
for (const Vector2i &coords : tile_map_selection) {
@ -848,7 +848,7 @@ void LayeredTileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Con
if (!(patterns_item_list->is_visible_in_tree() && patterns_item_list->has_point(patterns_item_list->get_local_mouse_position()))) {
// Preview when moving.
Vector2i top_left;
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
top_left = tile_map_selection.front()->get();
}
for (const Vector2i &E : tile_map_selection) {
@ -897,7 +897,7 @@ void LayeredTileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Con
}
// Expand the grid if needed
if (expand_grid && !preview.is_empty()) {
if (expand_grid && !preview.empty()) {
drawn_grid_rect = Rect2i(preview.begin()->key, Vector2i(0, 0));
for (const KeyValue<Vector2i, LayeredTileMapCell> &E : preview) {
drawn_grid_rect.expand_to(E.key);
@ -906,7 +906,7 @@ void LayeredTileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Con
}
}
if (!preview.is_empty()) {
if (!preview.empty()) {
const int fading = 5;
// Draw the lines of the grid behind the preview.
@ -1086,7 +1086,7 @@ HashMap<Vector2i, LayeredTileMapCell> LayeredTileMapLayerEditorTilesPlugin::_dra
Ref<LayeredTileMapPattern> pattern = p_erase ? erase_pattern : selection_pattern;
HashMap<Vector2i, LayeredTileMapCell> output;
if (!pattern->is_empty()) {
if (!pattern->empty()) {
// Paint the tiles on the tile map.
if (!p_erase && random_tile_toggle->is_pressed()) {
// Paint a random tile.
@ -1139,7 +1139,7 @@ HashMap<Vector2i, LayeredTileMapCell> LayeredTileMapLayerEditorTilesPlugin::_dra
Ref<LayeredTileMapPattern> pattern = p_erase ? erase_pattern : selection_pattern;
HashMap<Vector2i, LayeredTileMapCell> err_output;
ERR_FAIL_COND_V(pattern->is_empty(), err_output);
ERR_FAIL_COND_V(pattern->empty(), err_output);
// Compute the offset to align things to the bottom or right.
bool aligned_right = p_end_cell.x < p_start_cell.x;
@ -1147,7 +1147,7 @@ HashMap<Vector2i, LayeredTileMapCell> LayeredTileMapLayerEditorTilesPlugin::_dra
Vector2i offset = Vector2i(aligned_right ? -(pattern->get_size().x - (rect.get_size().x % pattern->get_size().x)) : 0, valigned_bottom ? -(pattern->get_size().y - (rect.get_size().y % pattern->get_size().y)) : 0);
HashMap<Vector2i, LayeredTileMapCell> output;
if (!pattern->is_empty()) {
if (!pattern->empty()) {
if (!p_erase && random_tile_toggle->is_pressed()) {
// Paint a random tile.
for (int x = 0; x < rect.size.x; x++) {
@ -1195,7 +1195,7 @@ HashMap<Vector2i, LayeredTileMapCell> LayeredTileMapLayerEditorTilesPlugin::_dra
erase_pattern->set_cell(Vector2i(0, 0), LayeredTileSet::INVALID_SOURCE, LayeredTileSetSource::INVALID_ATLAS_COORDS, LayeredTileSetSource::INVALID_TILE_ALTERNATIVE);
Ref<LayeredTileMapPattern> pattern = p_erase ? erase_pattern : selection_pattern;
if (!pattern->is_empty()) {
if (!pattern->empty()) {
LayeredTileMapCell source_cell = edited_layer->get_cell(p_coords);
// If we are filling empty tiles, compute the tilemap boundaries.
@ -1209,7 +1209,7 @@ HashMap<Vector2i, LayeredTileMapCell> LayeredTileMapLayerEditorTilesPlugin::_dra
RBSet<Vector2i> already_checked;
List<Vector2i> to_check;
to_check.push_back(p_coords);
while (!to_check.is_empty()) {
while (!to_check.empty()) {
Vector2i coords = to_check.back()->get();
to_check.pop_back();
if (!already_checked.has(coords)) {
@ -1351,7 +1351,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_stop_dragging() {
} else {
// Get the top-left cell.
Vector2i top_left;
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
top_left = tile_map_selection.front()->get();
}
for (const Vector2i &E : tile_map_selection) {
@ -1439,7 +1439,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_stop_dragging() {
}
Ref<LayeredTileMapPattern> new_selection_pattern = edited_layer->get_pattern(coords_array);
if (!new_selection_pattern->is_empty()) {
if (!new_selection_pattern->empty()) {
selection_pattern = new_selection_pattern;
_update_tileset_selection_from_selection_pattern();
}
@ -1503,7 +1503,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_stop_dragging() {
}
void LayeredTileMapLayerEditorTilesPlugin::_apply_transform(int p_type) {
if (selection_pattern.is_null() || selection_pattern->is_empty()) {
if (selection_pattern.is_null() || selection_pattern->empty()) {
return;
}
@ -1650,7 +1650,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() {
E = N;
}
if (!tile_map_selection.is_empty()) {
if (!tile_map_selection.empty()) {
_update_selection_pattern_from_tilemap_selection();
} else if (tiles_bottom_panel->is_visible_in_tree()) {
_update_selection_pattern_from_tileset_tiles_selection();
@ -2722,7 +2722,7 @@ RBSet<Vector2i> LayeredTileMapLayerEditorTerrainsPlugin::_get_cells_for_bucket_f
RBSet<Vector2i> already_checked;
List<Vector2i> to_check;
to_check.push_back(p_coords);
while (!to_check.is_empty()) {
while (!to_check.empty()) {
Vector2i coords = to_check.back()->get();
to_check.pop_back();
if (!already_checked.has(coords)) {
@ -3216,7 +3216,7 @@ void LayeredTileMapLayerEditorTerrainsPlugin::forward_canvas_draw_over_viewport(
}
// Expand the grid if needed
if (expand_grid && !preview.is_empty()) {
if (expand_grid && !preview.empty()) {
drawn_grid_rect = Rect2i(preview.front()->get(), Vector2i(1, 1));
for (const Vector2i &E : preview) {
drawn_grid_rect.expand_to(E);
@ -3224,7 +3224,7 @@ void LayeredTileMapLayerEditorTerrainsPlugin::forward_canvas_draw_over_viewport(
}
}
if (!preview.is_empty()) {
if (!preview.empty()) {
const int fading = 5;
// Draw the lines of the grid behind the preview.

View File

@ -136,7 +136,7 @@ void LayeredTileSetAtlasSourceEditor::LayeredTileSetAtlasSourceProxyObject::edit
// Disconnect to changes.
if (tile_set_atlas_source.is_valid()) {
tile_set_atlas_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
tile_set_atlas_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
tile_set = p_tile_set;
@ -145,12 +145,12 @@ void LayeredTileSetAtlasSourceEditor::LayeredTileSetAtlasSourceProxyObject::edit
// Connect to changes.
if (tile_set_atlas_source.is_valid()) {
if (!tile_set_atlas_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_set_atlas_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
if (!tile_set_atlas_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify))) {
tile_set_atlas_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
}
notify_property_list_changed();
property_list_changed_notify();
}
// -- Proxy object used by the tile inspector --
@ -272,7 +272,7 @@ bool LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::_set(const St
tile_set_atlas_source->set_tile_animation_frames_count(tile.tile, frame_count);
}
}
notify_property_list_changed();
property_list_changed_notify();
emit_signal(SNAME("changed"), "animation_separation");
return true;
} else if (components.size() == 2 && components[0].begins_with("animation_frame_") && components[0].trim_prefix("animation_frame_").is_valid_int()) {
@ -510,7 +510,7 @@ void LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::_get_property
void LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::edit(Ref<LayeredTileSetAtlasSource> p_tile_set_atlas_source, const RBSet<TileSelection> &p_tiles) {
ERR_FAIL_COND(!p_tile_set_atlas_source.is_valid());
ERR_FAIL_COND(p_tiles.is_empty());
ERR_FAIL_COND(p_tiles.empty());
for (const TileSelection &E : p_tiles) {
ERR_FAIL_COND(E.tile == LayeredTileSetSource::INVALID_ATLAS_COORDS);
ERR_FAIL_COND(E.alternative < 0);
@ -523,8 +523,8 @@ void LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::edit(Ref<Laye
if (tile_set_atlas_source.is_valid() && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative);
if (tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_data->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
if (tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify))) {
tile_data->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
}
}
@ -539,13 +539,13 @@ void LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::edit(Ref<Laye
if (tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative);
if (!tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_data->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
if (!tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify))) {
tile_data->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
}
}
notify_property_list_changed();
property_list_changed_notify();
}
void LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject::_bind_methods() {
@ -606,11 +606,11 @@ void LayeredTileSetAtlasSourceEditor::_update_atlas_source_inspector() {
void LayeredTileSetAtlasSourceEditor::_update_tile_inspector() {
// Update visibility.
if (tools_button_group->get_pressed_button() == tool_select_button) {
if (!selection.is_empty()) {
if (!selection.empty()) {
tile_proxy_object->edit(tile_set_atlas_source, selection);
}
tile_inspector->set_visible(!selection.is_empty());
tile_inspector_no_tile_selected_label->set_visible(selection.is_empty());
tile_inspector->set_visible(!selection.empty());
tile_inspector_no_tile_selected_label->set_visible(selection.empty());
} else {
tile_inspector->hide();
tile_inspector_no_tile_selected_label->hide();
@ -801,7 +801,7 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {
String prop_name = tile_set->get_custom_data_layer_name(i);
Variant::Type prop_type = tile_set->get_custom_data_layer_type(i);
if (prop_name.is_empty()) {
if (prop_name.empty()) {
ADD_TILE_DATA_EDITOR(group, vformat(TTR("Custom Data %d"), i), editor_name);
} else {
ADD_TILE_DATA_EDITOR(group, prop_name, editor_name);
@ -873,7 +873,7 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {
void LayeredTileSetAtlasSourceEditor::_update_current_tile_data_editor() {
// Find the property to use.
String property;
if (tools_button_group->get_pressed_button() == tool_select_button && tile_inspector->is_visible() && !tile_inspector->get_selected_path().is_empty()) {
if (tools_button_group->get_pressed_button() == tool_select_button && tile_inspector->is_visible() && !tile_inspector->get_selected_path().empty()) {
Vector<String> components = tile_inspector->get_selected_path().split("/");
if (components.size() >= 1) {
property = components[0];
@ -1695,7 +1695,7 @@ void LayeredTileSetAtlasSourceEditor::_menu_option(int p_option) {
void LayeredTileSetAtlasSourceEditor::shortcut_input(const Ref<InputEvent> &p_event) {
// Check for shortcuts.
if (ED_IS_SHORTCUT("tiles_editor/delete_tile", p_event)) {
if (tools_button_group->get_pressed_button() == tool_select_button && !selection.is_empty()) {
if (tools_button_group->get_pressed_button() == tool_select_button && !selection.empty()) {
_menu_option(TILE_DELETE);
accept_event();
}
@ -2769,7 +2769,7 @@ void EditorPropertyTilePolygon::_add_focusable_children(Node *p_node) {
}
void EditorPropertyTilePolygon::_polygons_changed() {
if (String(count_property).is_empty()) {
if (String(count_property).empty()) {
if (base_type == "OccluderPolygon2D") {
// Single OccluderPolygon2D.
Ref<OccluderPolygon2D> occluder;
@ -2800,7 +2800,7 @@ void EditorPropertyTilePolygon::_polygons_changed() {
emit_changed(get_edited_property(), navigation_polygon);
}
} else {
if (base_type.is_empty()) {
if (base_type.empty()) {
// Multiple array of vertices.
Vector<String> changed_properties;
Array values;
@ -2819,7 +2819,7 @@ void EditorPropertyTilePolygon::_polygons_changed() {
void EditorPropertyTilePolygon::update_property() {
LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject *atlas_tile_proxy_object = Object::cast_to<LayeredTileSetAtlasSourceEditor::LayeredAtlasTileProxyObject>(get_edited_object());
ERR_FAIL_NULL(atlas_tile_proxy_object);
ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().is_empty());
ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().empty());
Ref<LayeredTileSetAtlasSource> tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source();
generic_tile_polygon_editor->set_tile_set(Ref<LayeredTileSet>(tile_set_atlas_source->get_tile_set()));
@ -2833,7 +2833,7 @@ void EditorPropertyTilePolygon::update_property() {
// Reset the polygons.
generic_tile_polygon_editor->clear_polygons();
if (String(count_property).is_empty()) {
if (String(count_property).empty()) {
if (base_type == "OccluderPolygon2D") {
// Single OccluderPolygon2D.
Ref<OccluderPolygon2D> occluder = get_edited_property_value();
@ -2853,7 +2853,7 @@ void EditorPropertyTilePolygon::update_property() {
}
} else {
int count = get_edited_object()->get(count_property);
if (base_type.is_empty()) {
if (base_type.empty()) {
// Multiple array of vertices.
generic_tile_polygon_editor->clear_polygons();
for (int i = 0; i < count; i++) {

View File

@ -129,7 +129,7 @@ void LayeredTileSetEditor::_load_texture_files(const Vector<String> &p_paths) {
atlases.append(atlas_source);
}
if (!atlases.is_empty()) {
if (!atlases.empty()) {
tile_set_atlas_source_editor->init_new_atlases(atlases);
}
@ -170,7 +170,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
String item_text;
// Common to all type of sources.
if (!source->get_name().is_empty()) {
if (!source->get_name().empty()) {
item_text = source->get_name();
}
@ -178,7 +178,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source) {
texture = atlas_source->get_texture();
if (item_text.is_empty()) {
if (item_text.empty()) {
if (texture.is_valid()) {
item_text = texture->get_path().get_file();
} else {
@ -191,7 +191,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source);
if (scene_collection_source) {
texture = get_editor_theme_icon(SNAME("PackedScene"));
if (item_text.is_empty()) {
if (item_text.empty()) {
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
} else {
@ -201,7 +201,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
}
// Use default if not valid.
if (item_text.is_empty()) {
if (item_text.empty()) {
item_text = vformat(TTR("Unknown Type Source (ID: %d)"), source_id);
}
if (!texture.is_valid()) {

View File

@ -118,7 +118,7 @@ void LayeredTileSetScenesCollectionSourceEditor::LayeredTileSetScenesCollectionP
// Disconnect to changes.
if (tile_set_scenes_collection_source) {
tile_set_scenes_collection_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
tile_set_scenes_collection_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
tile_set = p_tile_set;
@ -127,12 +127,12 @@ void LayeredTileSetScenesCollectionSourceEditor::LayeredTileSetScenesCollectionP
// Connect to changes.
if (tile_set_scenes_collection_source) {
if (!tile_set_scenes_collection_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_set_scenes_collection_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
if (!tile_set_scenes_collection_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify))) {
tile_set_scenes_collection_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::property_list_changed_notify));
}
}
notify_property_list_changed();
property_list_changed_notify();
}
// -- Proxy object used by the tile inspector --
@ -208,7 +208,7 @@ void LayeredTileSetScenesCollectionSourceEditor::LayeredSceneTileProxyObject::ed
tile_set_scenes_collection_source = p_tile_set_scenes_collection_source;
scene_id = p_scene_id;
notify_property_list_changed();
property_list_changed_notify();
}
void LayeredTileSetScenesCollectionSourceEditor::LayeredSceneTileProxyObject::_bind_methods() {
@ -270,7 +270,7 @@ void LayeredTileSetScenesCollectionSourceEditor::_scene_file_selected(const Stri
void LayeredTileSetScenesCollectionSourceEditor::_source_delete_pressed() {
Vector<int> selected_indices = scene_tiles_list->get_selected_items();
ERR_FAIL_COND(selected_indices.is_empty());
ERR_FAIL_COND(selected_indices.empty());
int scene_id = scene_tiles_list->get_item_metadata(selected_indices[0]);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

View File

@ -86,7 +86,7 @@ void LayeredTilesEditorUtils::_thread() {
thumbnail_size *= EDSCALE;
Vector2 thumbnail_size2 = Vector2(thumbnail_size, thumbnail_size);
if (item.pattern.is_valid() && !item.pattern->is_empty()) {
if (item.pattern.is_valid() && !item.pattern->empty()) {
// Generate the pattern preview
SubViewport *viewport = memnew(SubViewport);
viewport->set_size(thumbnail_size2);
@ -242,19 +242,19 @@ bool LayeredTilesEditorUtils::SourceNameComparator::operator()(const int &p_a, c
{
LayeredTileSetSource *source = *tile_set->get_source(p_a);
if (!source->get_name().is_empty()) {
if (!source->get_name().empty()) {
name_a = source->get_name();
}
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source) {
Ref<Texture> texture = atlas_source->get_texture();
if (name_a.is_empty() && texture.is_valid()) {
if (name_a.empty() && texture.is_valid()) {
name_a = texture->get_path().get_file();
}
}
if (name_a.is_empty()) {
if (name_a.empty()) {
name_a = itos(p_a);
}
}
@ -262,19 +262,19 @@ bool LayeredTilesEditorUtils::SourceNameComparator::operator()(const int &p_a, c
{
LayeredTileSetSource *source = *tile_set->get_source(p_b);
if (!source->get_name().is_empty()) {
if (!source->get_name().empty()) {
name_b = source->get_name();
}
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source) {
Ref<Texture> texture = atlas_source->get_texture();
if (name_b.is_empty() && texture.is_valid()) {
if (name_b.empty() && texture.is_valid()) {
name_b = texture->get_path().get_file();
}
}
if (name_b.is_empty()) {
if (name_b.empty()) {
name_b = itos(p_b);
}
}

View File

@ -29,17 +29,19 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "tilemap_navigation_geometry_parser_2d.h"
#include "layered_tilemap_navigation_geometry_parser_2d.h"
//#include "scene/2d/tile_map.h"
#include "modules/tile_map/tile_map.h"
#include "modules/tile_map/tile_set.h"
#include "../layered_tile_map.h"
#include "../layered_tile_set.h"
#include "scene/resources/navigation_2d/navigation_mesh_source_geometry_data_2d.h"
#include "scene/resources/navigation_2d/navigation_polygon.h"
#include "modules/modules_enabled.gen.h"
/*
bool LayeredTileMap2DNavigationGeometryParser2D::parses_node(Node *p_node) {
return (Object::cast_to<LayeredTileMap>(p_node) != nullptr);
}
@ -83,25 +85,12 @@ void LayeredTileMap2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Re
p_source_geometry->_add_traversable_outline(traversable_outline_new);
}
}
/*
TODO
if (parsed_geometry_type != NavigationPolygon::PARSED_GEOMETRY_MESH_INSTANCES && (tilemap->get_collision_layer() & navigation_polygon_collision_mask)) {
for (int collision_polygon_index = 0; collision_polygon_index < tile_set->tile_get_shape_count(cell_id); collision_polygon_index++) {
Vector<Vector2> obstruction_outline = tile_set->get_collision_polygon_points(collision_polygon_index);
for (int obstruction_outline_index = 0; obstruction_outline_index < obstruction_outline.size(); obstruction_outline_index++) {
obstruction_outline.write[obstruction_outline_index] = tile_transform_offset.xform(obstruction_outline[obstruction_outline_index]);
}
p_source_geometry->_add_obstruction_outline(obstruction_outline);
}
}
*/
}
}
}
*/
bool LayeredTileMap2DNavigationGeometryParser2D::parses_node(Node *p_node) {
return (Object::cast_to<LayeredTileMap>(p_node) != nullptr);
}

View File

@ -222,7 +222,7 @@ void LayeredTileMap::add_layer(int p_to_pos) {
}
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LayeredTileMap::_emit_changed));
notify_property_list_changed();
property_list_changed_notify();
_emit_changed();
@ -236,12 +236,12 @@ void LayeredTileMap::move_layer(int p_layer, int p_to_pos) {
// Clear before shuffling layers.
LayeredTileMapLayer *layer = layers[p_layer];
layers.insert(p_to_pos, layer);
layers.remove_at(p_to_pos < p_layer ? p_layer + 1 : p_layer);
layers.remove(p_to_pos < p_layer ? p_layer + 1 : p_layer);
for (uint32_t i = 0; i < layers.size(); i++) {
move_child(layers[i], i);
layers[i]->set_as_tile_map_internal_node(i);
}
notify_property_list_changed();
property_list_changed_notify();
_emit_changed();
@ -253,11 +253,11 @@ void LayeredTileMap::remove_layer(int p_layer) {
// Clear before removing the layer.
layers[p_layer]->queue_free();
layers.remove_at(p_layer);
layers.remove(p_layer);
for (uint32_t i = 0; i < layers.size(); i++) {
layers[i]->set_as_tile_map_internal_node(i);
}
notify_property_list_changed();
property_list_changed_notify();
_emit_changed();
@ -508,7 +508,7 @@ void LayeredTileMap::notify_runtime_tile_data_update(int p_layer) {
#ifdef TOOLS_ENABLED
Rect2 LayeredTileMap::_edit_get_rect() const {
// Return the visible rect of the tilemap.
if (layers.is_empty()) {
if (layers.empty()) {
return Rect2();
}
@ -570,7 +570,7 @@ bool LayeredTileMap::_set(const StringName &p_name, const Variant &p_value) {
layers.push_back(new_layer);
}
notify_property_list_changed();
property_list_changed_notify();
_emit_changed();
update_configuration_warnings();
}

View File

@ -1118,7 +1118,7 @@ void LayeredTileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item,
}
// Check if the navigation is used.
if (r_cell_data.navigation_regions.is_empty()) {
if (r_cell_data.navigation_regions.empty()) {
return;
}
@ -1458,7 +1458,7 @@ LayeredTileSet::TerrainsPattern LayeredTileMapLayer::_get_best_terrain_pattern_f
// Returns all tiles compatible with the given constraints.
RBMap<LayeredTileSet::TerrainsPattern, int> terrain_pattern_score;
RBSet<LayeredTileSet::TerrainsPattern> pattern_set = tile_set->get_terrains_pattern_set(p_terrain_set);
ERR_FAIL_COND_V(pattern_set.is_empty(), LayeredTileSet::TerrainsPattern());
ERR_FAIL_COND_V(pattern_set.empty(), LayeredTileSet::TerrainsPattern());
for (LayeredTileSet::TerrainsPattern &terrain_pattern : pattern_set) {
int score = 0;
@ -2347,7 +2347,7 @@ Ref<LayeredTileMapPattern> LayeredTileMapLayer::get_pattern(PoolVector2iArray p_
Ref<LayeredTileMapPattern> output;
output.instantiate();
if (p_coords_array.is_empty()) {
if (p_coords_array.empty()) {
return output;
}

View File

@ -42,7 +42,7 @@ void LayeredTileMapLayerGroup::_cleanup_selected_layers() {
const String name = selected_layers[i];
LayeredTileMapLayer *layer = Object::cast_to<LayeredTileMapLayer>(get_node_or_null(name));
if (!layer) {
selected_layers.remove_at(i);
selected_layers.remove(i);
i--;
}
}

View File

@ -34,6 +34,7 @@
#include "core/containers/local_vector.h"
#include "core/containers/rb_set.h"
#include "core/core_string_names.h"
#include "core/io/marshalls.h"
#include "core/math/geometry.h"
#include "scene/main/control.h"
@ -75,7 +76,7 @@ void LayeredTileMapPattern::_set_tile_data(const Vector<int> &p_data) {
uint16_t alternative_tile = decode_uint16(&local[10]);
set_cell(Vector2i(x, y), source_id, Vector2i(atlas_coords_x, atlas_coords_y), alternative_tile);
}
emit_signal(SNAME("changed"));
emit_signal("changed");
}
Vector<int> LayeredTileMapPattern::_get_tile_data() const {
@ -87,14 +88,15 @@ Vector<int> LayeredTileMapPattern::_get_tile_data() const {
// Save in highest format
int idx = 0;
for (const KeyValue<Vector2i, LayeredTileMapCell> &E : pattern) {
for (const HashMap<Vector2i, LayeredTileMapCell>::Element *E = pattern.front(); E; E = E->next) {
uint8_t *ptr = (uint8_t *)&w[idx];
encode_uint16((int16_t)(E.key.x), &ptr[0]);
encode_uint16((int16_t)(E.key.y), &ptr[2]);
encode_uint16(E.value.source_id, &ptr[4]);
encode_uint16(E.value.coord_x, &ptr[6]);
encode_uint16(E.value.coord_y, &ptr[8]);
encode_uint16(E.value.alternative_tile, &ptr[10]);
encode_uint16((int16_t)(E->key().x), &ptr[0]);
encode_uint16((int16_t)(E->key().y), &ptr[2]);
encode_uint16(E->value().source_id, &ptr[4]);
encode_uint16(E->value().coord_x, &ptr[6]);
encode_uint16(E->value().coord_y, &ptr[8]);
encode_uint16(E->value().alternative_tile, &ptr[10]);
idx += 3;
}
@ -119,8 +121,8 @@ void LayeredTileMapPattern::remove_cell(const Vector2i &p_coords, bool p_update_
pattern.erase(p_coords);
if (p_update_size) {
size = Size2i();
for (const KeyValue<Vector2i, LayeredTileMapCell> &E : pattern) {
size = size.max(E.key + Vector2i(1, 1));
for (const HashMap<Vector2i, LayeredTileMapCell>::Element *E = pattern.front(); E; E = E->next) {
size = size.max(E->key() + Vector2i(1, 1));
}
}
emit_changed();
@ -149,8 +151,8 @@ PoolVector2iArray LayeredTileMapPattern::get_used_cells() const {
PoolVector2iArray a;
a.resize(pattern.size());
int i = 0;
for (const KeyValue<Vector2i, LayeredTileMapCell> &E : pattern) {
Vector2i p(E.key.x, E.key.y);
for (const HashMap<Vector2i, LayeredTileMapCell>::Element *E = pattern.front(); E; E = E->next) {
Vector2i p(E->key().x, E->key().y);
a[i++] = p;
}
@ -162,8 +164,8 @@ Size2i LayeredTileMapPattern::get_size() const {
}
void LayeredTileMapPattern::set_size(const Size2i &p_size) {
for (const KeyValue<Vector2i, LayeredTileMapCell> &E : pattern) {
Vector2i coords = E.key;
for (const HashMap<Vector2i, LayeredTileMapCell>::Element *E = pattern.front(); E; E = E->next) {
Vector2i coords = E->key();
if (p_size.x <= coords.x || p_size.y <= coords.y) {
ERR_FAIL_MSG(vformat("Cannot set pattern size to %s, it contains a tile at %s. Size can only be increased.", p_size, coords));
};
@ -173,8 +175,8 @@ void LayeredTileMapPattern::set_size(const Size2i &p_size) {
emit_changed();
}
bool LayeredTileMapPattern::is_empty() const {
return pattern.is_empty();
bool LayeredTileMapPattern::empty() const {
return pattern.empty();
};
void LayeredTileMapPattern::clear() {
@ -203,7 +205,7 @@ bool LayeredTileMapPattern::_get(const StringName &p_name, Variant &r_ret) const
}
void LayeredTileMapPattern::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
}
void LayeredTileMapPattern::_bind_methods() {
@ -217,7 +219,7 @@ void LayeredTileMapPattern::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_used_cells"), &LayeredTileMapPattern::get_used_cells);
ClassDB::bind_method(D_METHOD("get_size"), &LayeredTileMapPattern::get_size);
ClassDB::bind_method(D_METHOD("set_size", "size"), &LayeredTileMapPattern::set_size);
ClassDB::bind_method(D_METHOD("is_empty"), &LayeredTileMapPattern::is_empty);
ClassDB::bind_method(D_METHOD("empty"), &LayeredTileMapPattern::empty);
}
/////////////////////////////// LayeredTileSet //////////////////////////////////////
@ -328,35 +330,35 @@ LayeredTileSet::TerrainsPattern::TerrainsPattern(const LayeredTileSet *p_tile_se
const int LayeredTileSet::INVALID_SOURCE = -1;
const char *LayeredTileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[] = {
PNAME("right_side"),
PNAME("right_corner"),
PNAME("bottom_right_side"),
PNAME("bottom_right_corner"),
PNAME("bottom_side"),
PNAME("bottom_corner"),
PNAME("bottom_left_side"),
PNAME("bottom_left_corner"),
PNAME("left_side"),
PNAME("left_corner"),
PNAME("top_left_side"),
PNAME("top_left_corner"),
PNAME("top_side"),
PNAME("top_corner"),
PNAME("top_right_side"),
PNAME("top_right_corner"),
"right_side",
"right_corner",
"bottom_right_side",
"bottom_right_corner",
"bottom_side",
"bottom_corner",
"bottom_left_side",
"bottom_left_corner",
"left_side",
"left_corner",
"top_left_side",
"top_left_corner",
"top_side",
"top_corner",
"top_right_side",
"top_right_corner",
};
// -- Shape and layout --
void LayeredTileSet::set_tile_shape(LayeredTileSet::TileShape p_shape) {
tile_shape = p_shape;
for (KeyValue<int, Ref<LayeredTileSetSource>> &E_source : sources) {
E_source.value->notify_tile_data_properties_should_change();
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *E_source = sources.front(); E_source; E_source = E_source->next) {
E_source->value()->notify_tile_data_properties_should_change();
}
terrain_bits_meshes_dirty = true;
tile_meshes_dirty = true;
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
LayeredTileSet::TileShape LayeredTileSet::get_tile_shape() const {
@ -374,8 +376,8 @@ LayeredTileSet::TileLayout LayeredTileSet::get_tile_layout() const {
void LayeredTileSet::set_tile_offset_axis(LayeredTileSet::TileOffsetAxis p_alignment) {
tile_offset_axis = p_alignment;
for (KeyValue<int, Ref<LayeredTileSetSource>> &E_source : sources) {
E_source.value->notify_tile_data_properties_should_change();
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *E_source = sources.front(); E_source; E_source = E_source->next) {
E_source->value()->notify_tile_data_properties_should_change();
}
terrain_bits_meshes_dirty = true;
@ -405,12 +407,13 @@ void LayeredTileSet::_update_terrains_cache() {
if (terrains_cache_dirty) {
// Organizes tiles into structures.
per_terrain_pattern_tiles.resize(terrain_sets.size());
for (RBMap<LayeredTileSet::TerrainsPattern, RBSet<LayeredTileMapCell>> &tiles : per_terrain_pattern_tiles) {
tiles.clear();
for (int i = 0; i < per_terrain_pattern_tiles.size(); ++i) {
per_terrain_pattern_tiles[i].clear();
}
for (const KeyValue<int, Ref<LayeredTileSetSource>> &kv : sources) {
Ref<LayeredTileSetSource> source = kv.value;
for (const HashMap<int, Ref<LayeredTileSetSource>>::Element *kv = sources.front(); kv; kv = kv->next) {
Ref<LayeredTileSetSource> source = kv->value();
Ref<LayeredTileSetAtlasSource> atlas_source = source;
if (atlas_source.is_valid()) {
for (int tile_index = 0; tile_index < source->get_tiles_count(); tile_index++) {
@ -423,7 +426,7 @@ void LayeredTileSet::_update_terrains_cache() {
int terrain_set = tile_data->get_terrain_set();
if (terrain_set >= 0) {
LayeredTileMapCell cell;
cell.source_id = kv.key;
cell.source_id = kv->key();
cell.set_atlas_coords(tile_id);
cell.alternative_tile = alternative_id;
@ -488,7 +491,7 @@ int LayeredTileSet::add_source(Ref<LayeredTileSetSource> p_tile_set_source, int
p_tile_set_source->set_tile_set(this);
_compute_next_source_id();
sources[new_source_id]->connect_changed(callable_mp(this, &LayeredTileSet::_source_changed));
sources[new_source_id]->connect(CoreStringNames::get_singleton()->changed, this, "_source_changed");
terrains_cache_dirty = true;
emit_changed();
@ -499,7 +502,7 @@ int LayeredTileSet::add_source(Ref<LayeredTileSetSource> p_tile_set_source, int
void LayeredTileSet::remove_source(int p_source_id) {
ERR_FAIL_COND_MSG(!sources.has(p_source_id), vformat("Cannot remove LayeredTileSet atlas source. No tileset atlas source with id %d.", p_source_id));
sources[p_source_id]->disconnect_changed(callable_mp(this, &LayeredTileSet::_source_changed));
sources[p_source_id]->connect(CoreStringNames::get_singleton()->changed, this, "_source_changed");
sources[p_source_id]->set_tile_set(nullptr);
sources.erase(p_source_id);
@ -511,9 +514,9 @@ void LayeredTileSet::remove_source(int p_source_id) {
}
void LayeredTileSet::remove_source_ptr(LayeredTileSetSource *p_tile_set_source) {
for (const KeyValue<int, Ref<LayeredTileSetSource>> &kv : sources) {
if (kv.value.ptr() == p_tile_set_source) {
remove_source(kv.key);
for (const HashMap<int, Ref<LayeredTileSetSource>>::Element *kv = sources.front(); kv; kv = kv->next) {
if (kv->value().ptr() == p_tile_set_source) {
remove_source(kv->key());
return;
}
}
@ -585,11 +588,11 @@ void LayeredTileSet::add_occlusion_layer(int p_index) {
ERR_FAIL_INDEX(p_index, occlusion_layers.size() + 1);
occlusion_layers.insert(p_index, OcclusionLayer());
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_occlusion_layer(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_occlusion_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -597,21 +600,24 @@ void LayeredTileSet::move_occlusion_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, occlusion_layers.size());
ERR_FAIL_INDEX(p_to_pos, occlusion_layers.size() + 1);
occlusion_layers.insert(p_to_pos, occlusion_layers[p_from_index]);
occlusion_layers.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_occlusion_layer(p_from_index, p_to_pos);
occlusion_layers.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_occlusion_layer(p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
void LayeredTileSet::remove_occlusion_layer(int p_index) {
ERR_FAIL_INDEX(p_index, occlusion_layers.size());
occlusion_layers.remove_at(p_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_occlusion_layer(p_index);
occlusion_layers.remove(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_occlusion_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -648,11 +654,11 @@ void LayeredTileSet::add_physics_layer(int p_index) {
ERR_FAIL_INDEX(p_index, physics_layers.size() + 1);
physics_layers.insert(p_index, PhysicsLayer());
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_physics_layer(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_physics_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -660,21 +666,21 @@ void LayeredTileSet::move_physics_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, physics_layers.size());
ERR_FAIL_INDEX(p_to_pos, physics_layers.size() + 1);
physics_layers.insert(p_to_pos, physics_layers[p_from_index]);
physics_layers.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_physics_layer(p_from_index, p_to_pos);
physics_layers.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_physics_layer(p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
void LayeredTileSet::remove_physics_layer(int p_index) {
ERR_FAIL_INDEX(p_index, physics_layers.size());
physics_layers.remove_at(p_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_physics_layer(p_index);
physics_layers.remove(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_physics_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -722,11 +728,11 @@ void LayeredTileSet::add_terrain_set(int p_index) {
ERR_FAIL_INDEX(p_index, terrain_sets.size() + 1);
terrain_sets.insert(p_index, TerrainSet());
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_terrain_set(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_terrain_set(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -735,22 +741,22 @@ void LayeredTileSet::move_terrain_set(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, terrain_sets.size());
ERR_FAIL_INDEX(p_to_pos, terrain_sets.size() + 1);
terrain_sets.insert(p_to_pos, terrain_sets[p_from_index]);
terrain_sets.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_terrain_set(p_from_index, p_to_pos);
terrain_sets.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_terrain_set(p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
void LayeredTileSet::remove_terrain_set(int p_index) {
ERR_FAIL_INDEX(p_index, terrain_sets.size());
terrain_sets.remove_at(p_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_terrain_set(p_index);
terrain_sets.remove(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_terrain_set(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -758,11 +764,11 @@ void LayeredTileSet::remove_terrain_set(int p_index) {
void LayeredTileSet::set_terrain_set_mode(int p_terrain_set, TerrainMode p_terrain_mode) {
ERR_FAIL_INDEX(p_terrain_set, terrain_sets.size());
terrain_sets.write[p_terrain_set].mode = p_terrain_mode;
for (KeyValue<int, Ref<LayeredTileSetSource>> &E_source : sources) {
E_source.value->notify_tile_data_properties_should_change();
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *E_source = sources.front(); E_source; E_source = E_source->next) {
E_source->value()->notify_tile_data_properties_should_change();
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -793,11 +799,11 @@ void LayeredTileSet::add_terrain(int p_terrain_set, int p_index) {
terrains.write[p_index].color = c;
terrains.write[p_index].name = String(vformat("Terrain %d", p_index));
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_terrain(p_terrain_set, p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_terrain(p_terrain_set, p_index);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -809,11 +815,11 @@ void LayeredTileSet::move_terrain(int p_terrain_set, int p_from_index, int p_to_
ERR_FAIL_INDEX(p_from_index, terrains.size());
ERR_FAIL_INDEX(p_to_pos, terrains.size() + 1);
terrains.insert(p_to_pos, terrains[p_from_index]);
terrains.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_terrain(p_terrain_set, p_from_index, p_to_pos);
terrains.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_terrain(p_terrain_set, p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -823,11 +829,11 @@ void LayeredTileSet::remove_terrain(int p_terrain_set, int p_index) {
Vector<Terrain> &terrains = terrain_sets.write[p_terrain_set].terrains;
ERR_FAIL_INDEX(p_index, terrains.size());
terrains.remove_at(p_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_terrain(p_terrain_set, p_index);
terrains.remove(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_terrain(p_terrain_set, p_index);
}
notify_property_list_changed();
property_list_changed_notify();
terrains_cache_dirty = true;
emit_changed();
}
@ -966,11 +972,11 @@ void LayeredTileSet::add_navigation_layer(int p_index) {
ERR_FAIL_INDEX(p_index, navigation_layers.size() + 1);
navigation_layers.insert(p_index, NavigationLayer());
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_navigation_layer(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_navigation_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -978,21 +984,21 @@ void LayeredTileSet::move_navigation_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, navigation_layers.size());
ERR_FAIL_INDEX(p_to_pos, navigation_layers.size() + 1);
navigation_layers.insert(p_to_pos, navigation_layers[p_from_index]);
navigation_layers.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_navigation_layer(p_from_index, p_to_pos);
navigation_layers.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_navigation_layer(p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
void LayeredTileSet::remove_navigation_layer(int p_index) {
ERR_FAIL_INDEX(p_index, navigation_layers.size());
navigation_layers.remove_at(p_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_navigation_layer(p_index);
navigation_layers.remove(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_navigation_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -1041,11 +1047,11 @@ void LayeredTileSet::add_custom_data_layer(int p_index) {
ERR_FAIL_INDEX(p_index, custom_data_layers.size() + 1);
custom_data_layers.insert(p_index, CustomDataLayer());
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->add_custom_data_layer(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->add_custom_data_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -1053,32 +1059,34 @@ void LayeredTileSet::move_custom_data_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, custom_data_layers.size());
ERR_FAIL_INDEX(p_to_pos, custom_data_layers.size() + 1);
custom_data_layers.insert(p_to_pos, custom_data_layers[p_from_index]);
custom_data_layers.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->move_custom_data_layer(p_from_index, p_to_pos);
custom_data_layers.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->move_custom_data_layer(p_from_index, p_to_pos);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
void LayeredTileSet::remove_custom_data_layer(int p_index) {
ERR_FAIL_INDEX(p_index, custom_data_layers.size());
custom_data_layers.remove_at(p_index);
custom_data_layers.remove(p_index);
String to_erase;
for (KeyValue<String, int> &E : custom_data_layers_by_name) {
if (E.value == p_index) {
to_erase = E.key;
} else if (E.value > p_index) {
E.value--;
for (HashMap<String, int>::Element *E = custom_data_layers_by_name.front(); E; E = E->next) {
if (E->value() == p_index) {
to_erase = E->key();
} else if (E->value() > p_index) {
E->value()--;
}
}
custom_data_layers_by_name.erase(to_erase);
for (KeyValue<int, Ref<LayeredTileSetSource>> source : sources) {
source.value->remove_custom_data_layer(p_index);
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *source = sources.front(); source; source = source->next) {
source->value()->remove_custom_data_layer(p_index);
}
notify_property_list_changed();
property_list_changed_notify();
emit_changed();
}
@ -1094,7 +1102,7 @@ void LayeredTileSet::set_custom_data_layer_name(int p_layer_id, String p_value)
ERR_FAIL_INDEX(p_layer_id, custom_data_layers.size());
// Exit if another property has the same name.
if (!p_value.is_empty()) {
if (!p_value.empty()) {
for (int other_layer_id = 0; other_layer_id < get_custom_data_layers_count(); other_layer_id++) {
if (other_layer_id != p_layer_id && get_custom_data_layer_name(other_layer_id) == p_value) {
ERR_FAIL_MSG(vformat("There is already a custom property named %s", p_value));
@ -1102,7 +1110,7 @@ void LayeredTileSet::set_custom_data_layer_name(int p_layer_id, String p_value)
}
}
if (p_value.is_empty() && custom_data_layers_by_name.has(p_value)) {
if (p_value.empty() && custom_data_layers_by_name.has(p_value)) {
custom_data_layers_by_name.erase(p_value);
} else {
custom_data_layers_by_name[p_value] = p_layer_id;
@ -1121,8 +1129,8 @@ void LayeredTileSet::set_custom_data_layer_type(int p_layer_id, Variant::Type p_
ERR_FAIL_INDEX(p_layer_id, custom_data_layers.size());
custom_data_layers.write[p_layer_id].type = p_value;
for (KeyValue<int, Ref<LayeredTileSetSource>> &E_source : sources) {
E_source.value->notify_tile_data_properties_should_change();
for (HashMap<int, Ref<LayeredTileSetSource>>::Element *E_source = sources.front(); E_source; E_source = E_source->next) {
E_source->value()->notify_tile_data_properties_should_change();
}
emit_changed();
@ -1383,7 +1391,7 @@ void LayeredTileSet::clear_tile_proxies() {
int LayeredTileSet::add_pattern(Ref<LayeredTileMapPattern> p_pattern, int p_index) {
ERR_FAIL_COND_V(!p_pattern.is_valid(), -1);
ERR_FAIL_COND_V_MSG(p_pattern->is_empty(), -1, "Cannot add an empty pattern to the LayeredTileSet.");
ERR_FAIL_COND_V_MSG(p_pattern->empty(), -1, "Cannot add an empty pattern to the LayeredTileSet.");
for (const Ref<LayeredTileMapPattern> &pattern : patterns) {
ERR_FAIL_COND_V_MSG(pattern == p_pattern, -1, "LayeredTileSet has already this pattern.");
}
@ -1403,7 +1411,7 @@ Ref<LayeredTileMapPattern> LayeredTileSet::get_pattern(int p_index) {
void LayeredTileSet::remove_pattern(int p_index) {
ERR_FAIL_INDEX(p_index, (int)patterns.size());
patterns.remove_at(p_index);
patterns.remove(p_index);
emit_changed();
}
@ -3251,7 +3259,7 @@ void LayeredTileSet::reset_state() {
}
compatibility_data.clear();
#endif // DISABLE_DEPRECATED
while (!source_ids.is_empty()) {
while (!source_ids.empty()) {
remove_source(source_ids[0]);
}
@ -4239,6 +4247,8 @@ void LayeredTileSet::_validate_property(PropertyInfo &p_property) const {
}
void LayeredTileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("_source_changed"), &LayeredTileSet::_source_changed);
// Sources management.
ClassDB::bind_method(D_METHOD("get_next_source_id"), &LayeredTileSet::get_next_source_id);
ClassDB::bind_method(D_METHOD("add_source", "source", "atlas_source_id_override"), &LayeredTileSet::add_source, DEFVAL(LayeredTileSet::INVALID_SOURCE));
@ -4414,7 +4424,7 @@ LayeredTileSet::~LayeredTileSet() {
memdelete(E.value);
}
#endif // DISABLE_DEPRECATED
while (!source_ids.is_empty()) {
while (!source_ids.empty()) {
remove_source(source_ids[0]);
}
}
@ -4971,7 +4981,7 @@ void LayeredTileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const
tad.alternatives[0]->set_tile_set(tile_set);
tad.alternatives[0]->set_allow_transform(false);
tad.alternatives[0]->connect("changed", callable_mp((Resource *)this, &LayeredTileSetAtlasSource::emit_changed));
tad.alternatives[0]->notify_property_list_changed();
tad.alternatives[0]->property_list_changed_notify();
tad.alternatives_ids.push_back(0);
// Create and resize the tile.
@ -5115,7 +5125,7 @@ void LayeredTileSetAtlasSource::set_tile_animation_frames_count(const Vector2i p
_create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture();
notify_property_list_changed();
property_list_changed_notify();
emit_signal(SNAME("changed"));
}
@ -5228,10 +5238,10 @@ void LayeredTileSetAtlasSource::clear_tiles_outside_texture() {
}
}
PackedVector2Array LayeredTileSetAtlasSource::get_tiles_to_be_removed_on_change(Ref<Texture> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size) {
ERR_FAIL_COND_V(p_margins.x < 0 || p_margins.y < 0, PackedVector2Array());
ERR_FAIL_COND_V(p_separation.x < 0 || p_separation.y < 0, PackedVector2Array());
ERR_FAIL_COND_V(p_texture_region_size.x <= 0 || p_texture_region_size.y <= 0, PackedVector2Array());
PoolVector2Array LayeredTileSetAtlasSource::get_tiles_to_be_removed_on_change(Ref<Texture> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size) {
ERR_FAIL_COND_V(p_margins.x < 0 || p_margins.y < 0, PoolVector2Array());
ERR_FAIL_COND_V(p_separation.x < 0 || p_separation.y < 0, PoolVector2Array());
ERR_FAIL_COND_V(p_texture_region_size.x <= 0 || p_texture_region_size.y <= 0, PoolVector2Array());
// Compute the new atlas grid size.
Size2 new_grid_size;
@ -5355,7 +5365,7 @@ int LayeredTileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_co
tiles[p_atlas_coords].alternatives[new_alternative_id]->set_tile_set(tile_set);
tiles[p_atlas_coords].alternatives[new_alternative_id]->set_allow_transform(true);
tiles[p_atlas_coords].alternatives[new_alternative_id]->connect("changed", callable_mp((Resource *)this, &LayeredTileSetAtlasSource::emit_changed));
tiles[p_atlas_coords].alternatives[new_alternative_id]->notify_property_list_changed();
tiles[p_atlas_coords].alternatives[new_alternative_id]->property_list_changed_notify();
tiles[p_atlas_coords].alternatives_ids.push_back(new_alternative_id);
tiles[p_atlas_coords].alternatives_ids.sort();
_compute_next_alternative_id(p_atlas_coords);
@ -5630,7 +5640,7 @@ void LayeredTileSetAtlasSource::_update_padded_texture() {
padded_texture->disconnect_changed(callable_mp(this, &LayeredTileSetAtlasSource::_queue_update_padded_texture));
}
padded_texture = Ref<CanvasTexture>();
padded_texture = Ref<Texture>();
if (texture.is_null()) {
return;
@ -5642,7 +5652,7 @@ void LayeredTileSetAtlasSource::_update_padded_texture() {
padded_texture.instantiate();
Ref<CanvasTexture> src_canvas_texture = texture;
Ref<Texture> src_canvas_texture = texture;
if (src_canvas_texture.is_valid()) {
// Use all textures.
// Diffuse
@ -5755,14 +5765,14 @@ void LayeredTileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<Pa
// Check if it extends CanvasItem.
Ref<SceneState> scene_state = p_packed_scene->get_state();
String type;
while (scene_state.is_valid() && type.is_empty()) {
while (scene_state.is_valid() && type.empty()) {
// Make sure we have a root node. Supposed to be at 0 index because find_node_by_path() does not seem to work.
ERR_FAIL_COND(scene_state->get_node_count() < 1);
type = scene_state->get_node_type(0);
scene_state = scene_state->get_base_scene_state();
}
ERR_FAIL_COND_EDMSG(type.is_empty(), vformat("Invalid PackedScene for LayeredTileSetScenesCollectionSource: %s. Could not get the type of the root node.", p_packed_scene->get_path()));
ERR_FAIL_COND_EDMSG(type.empty(), vformat("Invalid PackedScene for LayeredTileSetScenesCollectionSource: %s. Could not get the type of the root node.", p_packed_scene->get_path()));
bool extends_correct_class = ClassDB::is_parent_class(type, "CanvasItem");
ERR_FAIL_COND_EDMSG(!extends_correct_class, vformat("Invalid PackedScene for LayeredTileSetScenesCollectionSource: %s. Root node should extend CanvasItem. Found %s instead.", p_packed_scene->get_path(), type));
@ -5906,7 +5916,7 @@ void TileData::notify_tile_data_properties_should_change() {
}
}
notify_property_list_changed();
property_list_changed_notify();
emit_signal(SNAME("changed"));
}
@ -5922,12 +5932,12 @@ void TileData::move_occlusion_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, occluders.size());
ERR_FAIL_INDEX(p_to_pos, occluders.size() + 1);
occluders.insert(p_to_pos, occluders[p_from_index]);
occluders.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
occluders.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
}
void TileData::remove_occlusion_layer(int p_index) {
ERR_FAIL_INDEX(p_index, occluders.size());
occluders.remove_at(p_index);
occluders.remove(p_index);
}
void TileData::add_physics_layer(int p_to_pos) {
@ -5942,12 +5952,12 @@ void TileData::move_physics_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, physics.size());
ERR_FAIL_INDEX(p_to_pos, physics.size() + 1);
physics.insert(p_to_pos, physics[p_from_index]);
physics.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
physics.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
}
void TileData::remove_physics_layer(int p_index) {
ERR_FAIL_INDEX(p_index, physics.size());
physics.remove_at(p_index);
physics.remove(p_index);
}
void TileData::add_terrain_set(int p_to_pos) {
@ -6037,12 +6047,12 @@ void TileData::move_navigation_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, navigation.size());
ERR_FAIL_INDEX(p_to_pos, navigation.size() + 1);
navigation.insert(p_to_pos, navigation[p_from_index]);
navigation.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
navigation.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
}
void TileData::remove_navigation_layer(int p_index) {
ERR_FAIL_INDEX(p_index, navigation.size());
navigation.remove_at(p_index);
navigation.remove(p_index);
}
void TileData::add_custom_data_layer(int p_to_pos) {
@ -6057,12 +6067,12 @@ void TileData::move_custom_data_layer(int p_from_index, int p_to_pos) {
ERR_FAIL_INDEX(p_from_index, custom_data.size());
ERR_FAIL_INDEX(p_to_pos, custom_data.size() + 1);
custom_data.insert(p_to_pos, custom_data[p_from_index]);
custom_data.remove_at(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
custom_data.remove(p_to_pos < p_from_index ? p_from_index + 1 : p_from_index);
}
void TileData::remove_custom_data_layer(int p_index) {
ERR_FAIL_INDEX(p_index, custom_data.size());
custom_data.remove_at(p_index);
custom_data.remove(p_index);
}
void TileData::set_allow_transform(bool p_allow_transform) {
@ -6237,7 +6247,7 @@ void TileData::set_collision_polygons_count(int p_layer_id, int p_polygons_count
return;
}
physics.write[p_layer_id].polygons.resize(p_polygons_count);
notify_property_list_changed();
property_list_changed_notify();
emit_signal(SNAME("changed"));
}
@ -6255,7 +6265,7 @@ void TileData::add_collision_polygon(int p_layer_id) {
void TileData::remove_collision_polygon(int p_layer_id, int p_polygon_index) {
ERR_FAIL_INDEX(p_layer_id, physics.size());
ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size());
physics.write[p_layer_id].polygons.remove_at(p_polygon_index);
physics.write[p_layer_id].polygons.remove(p_polygon_index);
emit_signal(SNAME("changed"));
}
@ -6266,12 +6276,12 @@ void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index,
TileData::PhysicsLayerTileData::PolygonShapeTileData &polygon_shape_tile_data = physics.write[p_layer_id].polygons.write[p_polygon_index];
if (p_polygon.is_empty()) {
if (p_polygon.empty()) {
polygon_shape_tile_data.shapes.clear();
} else {
// Decompose into convex shapes.
Vector<Vector<Vector2>> decomp = Geometry2D::decompose_polygon_in_convex(p_polygon);
ERR_FAIL_COND_MSG(decomp.is_empty(), "Could not decompose the polygon into convex shapes.");
ERR_FAIL_COND_MSG(decomp.empty(), "Could not decompose the polygon into convex shapes.");
polygon_shape_tile_data.shapes.resize(decomp.size());
for (int i = 0; i < decomp.size(); i++) {
@ -6370,7 +6380,7 @@ void TileData::set_terrain_set(int p_terrain_set) {
}
}
terrain_set = p_terrain_set;
notify_property_list_changed();
property_list_changed_notify();
emit_signal(SNAME("changed"));
}
@ -6455,11 +6465,11 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id, bool p_f
Ref<NavigationPolygon> transformed_polygon;
transformed_polygon.instantiate();
PackedVector2Array new_points = get_transformed_vertices(layer_tile_data.navigation_polygon->get_vertices(), p_flip_h, p_flip_v, p_transpose);
PoolVector2Array new_points = get_transformed_vertices(layer_tile_data.navigation_polygon->get_vertices(), p_flip_h, p_flip_v, p_transpose);
transformed_polygon->set_vertices(new_points);
for (int i = 0; i < layer_tile_data.navigation_polygon->get_outline_count(); i++) {
PackedVector2Array new_outline = get_transformed_vertices(layer_tile_data.navigation_polygon->get_outline(i), p_flip_h, p_flip_v, p_transpose);
PoolVector2Array new_outline = get_transformed_vertices(layer_tile_data.navigation_polygon->get_outline(i), p_flip_h, p_flip_v, p_transpose);
transformed_polygon->add_outline(new_outline);
}
@ -6513,11 +6523,11 @@ Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const {
return custom_data[p_layer_id];
}
PackedVector2Array TileData::get_transformed_vertices(const PackedVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose) {
PoolVector2Array TileData::get_transformed_vertices(const PoolVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose) {
const Vector2 *r = p_vertices.ptr();
int size = p_vertices.size();
PackedVector2Array new_points;
PoolVector2Array new_points;
new_points.resize(size);
Vector2 *w = new_points.ptrw();
@ -6786,7 +6796,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
for (int j = 0; j < physics[i].polygons.size(); j++) {
// physics_layer_%d/points
property_info = PropertyInfo(Variant::ARRAY, vformat("physics_layer_%d/polygon_%d/%s", i, j, PNAME("points")), PROPERTY_HINT_ARRAY_TYPE, "Vector2", PROPERTY_USAGE_DEFAULT);
if (physics[i].polygons[j].polygon.is_empty()) {
if (physics[i].polygons[j].polygon.empty()) {
property_info.usage ^= PROPERTY_USAGE_STORAGE;
}
p_list->push_back(property_info);

View File

@ -44,7 +44,7 @@
#include "scene/resources/navigation_2d/navigation_polygon.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/physics_material.h"
#include "scene/resources/shapes_2d/concave_polygon_shape_2d.h"
#include "scene/resources/shapes_2d/convex_polygon_shape_2d.h"
#include "scene/resources/texture.h"
#ifndef DISABLE_DEPRECATED
@ -54,7 +54,7 @@
class LayeredTileMap;
class LayeredTileSetSource;
class LayeredTileSetAtlasSource;
class TileData;
class LayeredTileData;
// Forward-declare the plugins.
class LayeredTileSetPlugin;
@ -144,7 +144,7 @@ public:
Size2i get_size() const;
void set_size(const Size2i &p_size);
bool is_empty() const;
bool empty() const;
void clear();
};
@ -543,7 +543,7 @@ public:
Vector<Point2> get_terrain_polygon(int p_terrain_set);
Vector<Point2> get_terrain_peering_bit_polygon(int p_terrain_set, LayeredTileSet::CellNeighbor p_bit);
void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data);
void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const LayeredTileData *p_tile_data);
Vector<Vector<Ref<Texture>>> generate_terrains_icons(Size2i p_size);
// Resource management
@ -632,7 +632,7 @@ private:
LocalVector<real_t> animation_frames_durations;
// Alternatives
HashMap<int, TileData *> alternatives;
HashMap<int, LayeredTileData *> alternatives;
Vector<int> alternatives_ids;
int next_alternative_id = 1;
};
@ -646,8 +646,8 @@ private:
Vector<Vector2i> tiles_ids;
HashMap<Vector2i, Vector2i> _coords_mapping_cache; // Maps any coordinate to the including tile
TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile);
const TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile) const;
LayeredTileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile);
const LayeredTileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile) const;
void _compute_next_alternative_id(const Vector2i p_atlas_coords);
@ -655,7 +655,7 @@ private:
void _create_coords_mapping_cache(Vector2i p_atlas_coords);
bool use_texture_padding = true;
Ref<CanvasTexture> padded_texture;
Ref<Texture> padded_texture;
bool padded_texture_needs_update = false;
void _queue_update_padded_texture();
Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture> &p_source);
@ -718,7 +718,7 @@ public:
virtual Vector2i get_tile_id(int p_index) const;
bool has_room_for_tile(Vector2i p_atlas_coords, Vector2i p_size, int p_animation_columns, Vector2i p_animation_separation, int p_frames_count, Vector2i p_ignored_tile = INVALID_ATLAS_COORDS) const;
PackedVector2Array get_tiles_to_be_removed_on_change(Ref<Texture> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size);
PoolVector2Array get_tiles_to_be_removed_on_change(Ref<Texture> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size);
Vector2i get_tile_at_coords(Vector2i p_atlas_coords) const;
bool has_tiles_outside_texture() const;
@ -977,7 +977,7 @@ public:
Variant get_custom_data_by_layer_id(int p_layer_id) const;
// Polygons.
static PackedVector2Array get_transformed_vertices(const PackedVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose);
static PoolVector2Array get_transformed_vertices(const PoolVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose);
};
VARIANT_ENUM_CAST(LayeredTileSet::CellNeighbor);