Fix painting LayeredTileMap peering bits.

This commit is contained in:
Relintai 2024-03-12 23:21:43 +01:00
parent 053b283c47
commit 7789b60b2b

View File

@ -2477,13 +2477,17 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVi
for (HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell>::Element *E = drag_modified.front(); E; E = E->next) { for (HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell>::Element *E = drag_modified.front(); E; E = E->next) {
Dictionary dict = E->value(); Dictionary dict = E->value();
Vector2i coords = E->key().get_atlas_coords(); Vector2i coords = E->key().get_atlas_coords();
LayeredTileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, E->key().alternative_tile);
undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), terrain); undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), terrain);
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), dict["terrain"]); undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), dict["terrain"]);
Array array = dict["terrain_peering_bits"]; Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
LayeredTileSet::CellNeighbor bit = LayeredTileSet::CellNeighbor(i); LayeredTileSet::CellNeighbor bit = LayeredTileSet::CellNeighbor(i);
if (tile_set->is_valid_terrain_peering_bit(terrain_set, bit)) { if (tile_set->is_valid_terrain_peering_bit(terrain_set, 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->key().alternative_tile), terrain); 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->key().alternative_tile), tile_data->get_terrain_peering_bit(bit));
} }
if (tile_set->is_valid_terrain_peering_bit(dict["terrain_set"], bit)) { if (tile_set->is_valid_terrain_peering_bit(dict["terrain_set"], bit)) {
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->key().alternative_tile), array[i]); 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->key().alternative_tile), array[i]);
@ -2528,6 +2532,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVi
mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, mb->get_position().y)); mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, mb->get_position().y));
undo_redo->create_action(TTR("Painting Terrain")); undo_redo->create_action(TTR("Painting Terrain"));
for (const RBSet<LayeredTileMapCell>::Element *E = edited.front(); E; E = E->next()) { for (const RBSet<LayeredTileMapCell>::Element *E = edited.front(); E; E = E->next()) {
Vector2i coords = E->get().get_atlas_coords(); Vector2i coords = E->get().get_atlas_coords();
LayeredTileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, 0); LayeredTileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, 0);
@ -2810,13 +2815,16 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(LayeredTile
for (HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell>::Element *E = drag_modified.front(); E; E = E->next) { for (HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell>::Element *E = drag_modified.front(); E; E = E->next) {
Dictionary dict = E->value(); Dictionary dict = E->value();
Vector2i coords = E->key().get_atlas_coords(); Vector2i coords = E->key().get_atlas_coords();
LayeredTileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, E->key().alternative_tile);
undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), terrain); undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), terrain);
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), dict["terrain"]); undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain", coords.x, coords.y, E->key().alternative_tile), dict["terrain"]);
Array array = dict["terrain_peering_bits"]; Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
LayeredTileSet::CellNeighbor bit = LayeredTileSet::CellNeighbor(i); LayeredTileSet::CellNeighbor bit = LayeredTileSet::CellNeighbor(i);
if (tile_set->is_valid_terrain_peering_bit(terrain_set, bit)) { if (tile_set->is_valid_terrain_peering_bit(terrain_set, 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->key().alternative_tile), terrain); 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->key().alternative_tile), tile_data->get_terrain_peering_bit(bit));
} }
if (tile_set->is_valid_terrain_peering_bit(dict["terrain_set"], bit)) { if (tile_set->is_valid_terrain_peering_bit(dict["terrain_set"], bit)) {
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->key().alternative_tile), array[i]); 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->key().alternative_tile), array[i]);