mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Implement all draw modes (untested)
This commit is contained in:
parent
174f7d4b9f
commit
062889b4bb
|
@ -20,22 +20,48 @@ func _init(_tileset: TileSetCustom, _image := Image.new(), _opacity := 1.0) -> v
|
||||||
|
|
||||||
func update_texture() -> void:
|
func update_texture() -> void:
|
||||||
super.update_texture()
|
super.update_texture()
|
||||||
|
if tile_editing_mode == TileEditingMode.AUTO:
|
||||||
|
var tiles_to_delete := PackedInt32Array()
|
||||||
|
for j in range(1, tileset.tiles.size()):
|
||||||
|
var tile := tileset.tiles[j]
|
||||||
|
var tile_used := false
|
||||||
|
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 image_portion := image.get_region(rect)
|
||||||
|
if image_portion.is_invisible():
|
||||||
|
continue
|
||||||
|
if image_portion.get_data() == tile.get_data():
|
||||||
|
tile_used = true
|
||||||
|
break
|
||||||
|
if not tile_used:
|
||||||
|
tiles_to_delete.append(j)
|
||||||
|
for j in tiles_to_delete:
|
||||||
|
tileset.tiles.remove_at(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)
|
||||||
var rect := Rect2i(Vector2i(x_coord, y_coord), tileset.tile_size)
|
var rect := Rect2i(Vector2i(x_coord, y_coord), tileset.tile_size)
|
||||||
var image_portion := image.get_region(rect)
|
var image_portion := image.get_region(rect)
|
||||||
|
if image_portion.is_invisible():
|
||||||
|
continue
|
||||||
var index := indices[i]
|
var index := indices[i]
|
||||||
if tile_editing_mode == TileEditingMode.MANUAL:
|
if tile_editing_mode == TileEditingMode.MANUAL:
|
||||||
if index == 0:
|
if index == 0 or tileset.tiles.size() <= index:
|
||||||
continue
|
continue
|
||||||
if image_portion.get_data() != tileset.tiles[index].get_data():
|
if image_portion.get_data() != tileset.tiles[index].get_data():
|
||||||
tileset.tiles[index].copy_from(image_portion)
|
tileset.tiles[index].copy_from(image_portion)
|
||||||
elif tile_editing_mode == TileEditingMode.AUTO:
|
# TODO: Update the rest of the tilemap
|
||||||
if index == 0:
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
if not image_portion.is_invisible():
|
var found_tile := false
|
||||||
|
for j in range(1, tileset.tiles.size()):
|
||||||
|
var tile := tileset.tiles[j]
|
||||||
|
if image_portion.get_data() == tile.get_data():
|
||||||
|
indices[i] = j
|
||||||
|
found_tile = true
|
||||||
|
break
|
||||||
|
if not found_tile:
|
||||||
tileset.tiles.append(image_portion)
|
tileset.tiles.append(image_portion)
|
||||||
indices[i] = tileset.tiles.size()
|
indices[i] = tileset.tiles.size()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue