1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-22 05:23:14 +00:00

Fix tilesets being re-ordered when being moved, resized or deleted by selections

This commit is contained in:
Emmanouil Papadeas 2025-02-19 00:10:22 +02:00
parent 65ef6ff4a2
commit 892b993b9e
2 changed files with 13 additions and 5 deletions

View file

@ -574,12 +574,15 @@ func update_cel_portions() -> void:
## Loops through all [member cells] of the tilemap and updates their indices,
## so they can remain mapped to the [member tileset]'s tiles.
func _re_index_all_cells() -> void:
func re_index_all_cells(set_invisible_to_zero := false) -> void:
for i in cells.size():
var coords := get_cell_coords_in_image(i)
var rect := Rect2i(coords, tileset.tile_size)
var image_portion := image.get_region(rect)
if image_portion.is_invisible():
if set_invisible_to_zero:
cells[i].index = 0
continue
var index := cells[i].index
if index > 0 and index < tileset.tiles.size():
var current_tile := tileset.tiles[index]
@ -616,7 +619,7 @@ func _is_redo() -> bool:
## If [param replace_index] is larger than -1, it means that manual mode
## has been used to replace a tile in the tileset in another cel,
## so call [method update_cel_portions] to update it in this cel as well.
## Otherwise, call [method _re_index_all_cells] to ensure that the cells have correct indices.
## Otherwise, call [method re_index_all_cells] to ensure that the cells have correct indices.
func _on_tileset_updated(cel: CelTileMap, replace_index: int) -> void:
if cel == self:
return
@ -625,7 +628,7 @@ func _on_tileset_updated(cel: CelTileMap, replace_index: int) -> void:
if replace_index > -1: # Manual mode
update_cel_portions()
else:
_re_index_all_cells()
re_index_all_cells()
Global.canvas.update_all_layers = true
Global.canvas.queue_redraw()
@ -642,7 +645,7 @@ func _deserialize_cell_data(cell_indices: Array, resize: bool) -> void:
func set_content(content, texture: ImageTexture = null) -> void:
super.set_content(content, texture)
_resize_cells(image.get_size())
_re_index_all_cells()
re_index_all_cells()
func update_texture(undo := false) -> void:

View file

@ -665,7 +665,12 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
print("No undo data found!")
return
var project := Global.current_project
project.update_tilemaps(undo_data_tmp, TileSetPanel.TileEditingMode.AUTO)
if Tools.is_placing_tiles():
for cel in undo_data_tmp:
if cel is CelTileMap:
(cel as CelTileMap).re_index_all_cells(true)
else:
project.update_tilemaps(undo_data_tmp, TileSetPanel.TileEditingMode.AUTO)
var redo_data := get_undo_data(undo_data_tmp["undo_image"])
project.undos += 1
project.undo_redo.create_action(action)