mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Prevent from setting tile indices out of bounds of the canvas
This commit is contained in:
parent
6b95908ef3
commit
64809c64d9
|
@ -77,7 +77,7 @@ func update_texture() -> void:
|
|||
cel.texture_changed.emit()
|
||||
|
||||
|
||||
func on_undo_redo(undo: bool) -> void:
|
||||
func on_undo_redo(_undo: bool) -> void:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ func update_tileset(undo: bool) -> void:
|
|||
if undo:
|
||||
var tile_removed := tileset.remove_unused_tiles()
|
||||
if tile_removed:
|
||||
re_index_tiles()
|
||||
re_index_all_tiles()
|
||||
|
||||
|
||||
## Cases:[br]
|
||||
|
@ -207,21 +207,26 @@ func update_cel_portions() -> void:
|
|||
|
||||
func get_tile_coords(portion_position: int) -> Vector2i:
|
||||
var x_coord := float(tileset.tile_size.x) * (portion_position % indices_x)
|
||||
@warning_ignore("integer_division")
|
||||
var y_coord := float(tileset.tile_size.y) * (portion_position / indices_x)
|
||||
return Vector2i(x_coord, y_coord)
|
||||
|
||||
|
||||
func get_tile_position(coords: Vector2i) -> int:
|
||||
var x := floori(coords.x / tileset.tile_size.x)
|
||||
var y := floori(coords.y / tileset.tile_size.y) * indices_x
|
||||
@warning_ignore("integer_division")
|
||||
var x := coords.x / tileset.tile_size.x
|
||||
x = clampi(x, 0, indices_x - 1)
|
||||
@warning_ignore("integer_division")
|
||||
var y := coords.y / tileset.tile_size.y
|
||||
y = clampi(y, 0, indices_y - 1)
|
||||
y *= indices_x
|
||||
return x + y
|
||||
|
||||
|
||||
func re_index_tiles() -> void:
|
||||
func re_index_all_tiles() -> void:
|
||||
for i in indices.size():
|
||||
var x_coord := float(tileset.tile_size.x) * (i % indices_x)
|
||||
var y_coord := float(tileset.tile_size.y) * (i / indices_x)
|
||||
var rect := Rect2i(Vector2i(x_coord, y_coord), tileset.tile_size)
|
||||
var coords := get_tile_coords(i)
|
||||
var rect := Rect2i(coords, tileset.tile_size)
|
||||
var image_portion := image.get_region(rect)
|
||||
if image_portion.is_invisible():
|
||||
indices[i] = 0
|
||||
|
|
|
@ -306,6 +306,7 @@ func draw_end(pos: Vector2i) -> void:
|
|||
func draw_tile(pos: Vector2i, tile_index: int) -> void:
|
||||
if Global.current_project.get_current_cel() is not CelTileMap:
|
||||
return
|
||||
pos = Global.current_project.tiles.get_canon_position(pos)
|
||||
var tile_position := get_tile_position(pos)
|
||||
var cel := Global.current_project.get_current_cel() as CelTileMap
|
||||
cel.set_index(tile_position, tile_index)
|
||||
|
|
Loading…
Reference in a new issue