1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

Make drawing on multiple selected tilemap cels that share the same tileset and applied a layer effect to all cels of the layer work

This now creates an issue when manual mode is used and we undo. Other cels don't get updated, even though they were changed by manual mode.
This commit is contained in:
Emmanouil Papadeas 2024-11-29 16:36:05 +02:00
parent 59a2ec4db1
commit a1f785f67e
3 changed files with 19 additions and 11 deletions

View file

@ -314,6 +314,11 @@ func _update_cell(cell_position: int) -> void:
var image_portion := image.get_region(rect)
var cell_data := cells[cell_position]
var index := cell_data.index
if index >= tileset.tiles.size():
printerr(
"Cell at position ", cell_position + 1, ", mapped to ", index, " is out of bounds!"
)
return
var current_tile := tileset.tiles[index].image
var transformed_tile := transform_tile(
current_tile, cell_data.flip_h, cell_data.flip_v, cell_data.transpose
@ -357,12 +362,15 @@ func _is_redo() -> bool:
## If the tileset has been modified by another tile, make sure to also update it here.
func _on_tileset_updated(cel: CelTileMap) -> void:
func _on_tileset_updated(cel: CelTileMap, replace_index: int) -> void:
if cel == self or not is_instance_valid(cel):
return
if link_set != null and cel in link_set["cels"]:
return
if replace_index > -1: # Manual mode
_update_cel_portions()
else:
_re_index_all_cells()
Global.canvas.update_all_layers = true
Global.canvas.queue_redraw()

View file

@ -8,7 +8,7 @@ extends RefCounted
## Emitted every time the tileset changes, such as when a tile is added, removed or replaced.
## The [CelTileMap] that the changes are coming from is referenced in the [param cel] parameter.
signal updated(cel: CelTileMap)
signal updated(cel: CelTileMap, replace_index: int)
## The tileset's name.
var name := ""
@ -52,7 +52,7 @@ func _init(_tile_size: Vector2i, _name := "") -> void:
func add_tile(image: Image, cel: CelTileMap) -> void:
var tile := Tile.new(image)
tiles.append(tile)
updated.emit(cel)
updated.emit(cel, -1)
## Adds a new [param image] as a tile in a given [param position] in the tileset.
@ -61,7 +61,7 @@ func add_tile(image: Image, cel: CelTileMap) -> void:
func insert_tile(image: Image, position: int, cel: CelTileMap) -> void:
var tile := Tile.new(image)
tiles.insert(position, tile)
updated.emit(cel)
updated.emit(cel, -1)
## Reduces a tile's [member TileSetCustom.Tile.times_used] by one,
@ -82,14 +82,14 @@ func unuse_tile_at_index(index: int, cel: CelTileMap) -> bool:
## The [param cel] parameter references the [CelTileMap] that this change is coming from.
func remove_tile_at_index(index: int, cel: CelTileMap) -> void:
tiles.remove_at(index)
updated.emit(cel)
updated.emit(cel, -1)
## Replaces a tile in a given [param index] in the tileset with a [param new_tile].
## The [param cel] parameter references the [CelTileMap] that this change is coming from.
func replace_tile_at(new_tile: Image, index: int, cel: CelTileMap) -> void:
tiles[index].image.copy_from(new_tile)
updated.emit(cel)
updated.emit(cel, index)
## Finds and returns the position of a tile [param image] inside the tileset.
@ -122,7 +122,7 @@ func clear_tileset(cel: CelTileMap) -> void:
tiles.clear()
var empty_image := Image.create_empty(tile_size.x, tile_size.y, false, Image.FORMAT_RGBA8)
tiles.append(Tile.new(empty_image))
updated.emit(cel)
updated.emit(cel, -1)
_tileset_has_been_cleared = true
set_deferred("_tileset_has_been_cleared", false)
@ -159,4 +159,4 @@ func deserialize_undo_data(dict: Dictionary, cel: CelTileMap) -> void:
tiles[i] = Tile.new(image)
tiles[i].times_used = tile_data[2]
i += 1
updated.emit(cel)
updated.emit(cel, -1)

View file

@ -77,10 +77,10 @@ func _on_cel_switched() -> void:
return
var cel := Global.current_project.get_current_cel() as CelTileMap
set_tileset(cel.tileset)
_update_tileset(cel)
_update_tileset(cel, -1)
func _update_tileset(cel: BaseCel) -> void:
func _update_tileset(cel: BaseCel, _replace_index: int) -> void:
_clear_tile_buttons()
if cel is not CelTileMap:
return