mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 15:39:49 +00:00
Improve tileset editing logic
This commit is contained in:
parent
a8755bd92f
commit
f42454ef03
|
@ -4,7 +4,7 @@ extends PixelCel
|
||||||
enum TileEditingMode { MANUAL, AUTO, STACK }
|
enum TileEditingMode { MANUAL, AUTO, STACK }
|
||||||
|
|
||||||
var tileset: TileSetCustom
|
var tileset: TileSetCustom
|
||||||
var tile_editing_mode := TileEditingMode.STACK
|
var tile_editing_mode := TileEditingMode.AUTO
|
||||||
var indices := PackedInt32Array()
|
var indices := PackedInt32Array()
|
||||||
var indices_x: int
|
var indices_x: int
|
||||||
var indices_y: int
|
var indices_y: int
|
||||||
|
@ -18,11 +18,10 @@ func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> v
|
||||||
indices.resize(indices_x * indices_y)
|
indices.resize(indices_x * indices_y)
|
||||||
|
|
||||||
|
|
||||||
func update_texture() -> void:
|
func update_tileset() -> void:
|
||||||
super.update_texture()
|
var removed_tile_indices: Array[int] = []
|
||||||
if tile_editing_mode == TileEditingMode.AUTO:
|
if tile_editing_mode == TileEditingMode.AUTO:
|
||||||
var tiles_to_delete := PackedInt32Array()
|
for j in range(tileset.tiles.size() - 1, 0, -1):
|
||||||
for j in range(1, tileset.tiles.size()):
|
|
||||||
var tile := tileset.tiles[j]
|
var tile := tileset.tiles[j]
|
||||||
var tile_used := false
|
var tile_used := false
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
|
@ -36,9 +35,8 @@ func update_texture() -> void:
|
||||||
tile_used = true
|
tile_used = true
|
||||||
break
|
break
|
||||||
if not tile_used:
|
if not tile_used:
|
||||||
tiles_to_delete.append(j)
|
removed_tile_indices.append(j)
|
||||||
for j in tiles_to_delete:
|
tileset.remove_tile_at_index(j)
|
||||||
tileset.remove_tile_at_index(j)
|
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
var x_coord := float(tileset.tile_size.x) * (i % indices_x)
|
var x_coord := float(tileset.tile_size.x) * (i % indices_x)
|
||||||
var y_coord := float(tileset.tile_size.y) * (i / indices_x)
|
var y_coord := float(tileset.tile_size.y) * (i / indices_x)
|
||||||
|
@ -62,8 +60,13 @@ func update_texture() -> void:
|
||||||
found_tile = true
|
found_tile = true
|
||||||
break
|
break
|
||||||
if not found_tile:
|
if not found_tile:
|
||||||
tileset.add_tile(image_portion)
|
if removed_tile_indices.is_empty():
|
||||||
indices[i] = tileset.tiles.size()
|
tileset.add_tile(image_portion)
|
||||||
|
indices[i] = tileset.tiles.size()
|
||||||
|
else:
|
||||||
|
var index_position := removed_tile_indices.pop_back() as int
|
||||||
|
tileset.insert_tile(image_portion, index_position)
|
||||||
|
indices[i] = index_position
|
||||||
|
|
||||||
|
|
||||||
func get_class_name() -> String:
|
func get_class_name() -> String:
|
||||||
|
|
|
@ -23,6 +23,11 @@ func add_tile(tile: Image) -> void:
|
||||||
updated.emit()
|
updated.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func insert_tile(tile: Image, position: int) -> void:
|
||||||
|
tiles.insert(position, tile)
|
||||||
|
updated.emit()
|
||||||
|
|
||||||
|
|
||||||
func remove_tile_at_index(index: int) -> void:
|
func remove_tile_at_index(index: int) -> void:
|
||||||
tiles.remove_at(index)
|
tiles.remove_at(index)
|
||||||
updated.emit()
|
updated.emit()
|
||||||
|
|
|
@ -75,7 +75,12 @@ func draw_move(pos: Vector2i) -> void:
|
||||||
func draw_end(_pos: Vector2i) -> void:
|
func draw_end(_pos: Vector2i) -> void:
|
||||||
is_moving = false
|
is_moving = false
|
||||||
_draw_cache = []
|
_draw_cache = []
|
||||||
Global.current_project.can_undo = true
|
var project := Global.current_project
|
||||||
|
for cel_index in project.selected_cels:
|
||||||
|
var cel := project.frames[cel_index[0]].cels[cel_index[1]]
|
||||||
|
if cel is CelTileMap:
|
||||||
|
cel.update_tileset()
|
||||||
|
project.can_undo = true
|
||||||
|
|
||||||
|
|
||||||
func cursor_move(pos: Vector2i) -> void:
|
func cursor_move(pos: Vector2i) -> void:
|
||||||
|
|
Loading…
Reference in a new issue