mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Make the manual mode work, kind of
This commit is contained in:
parent
d95c3f7555
commit
cd6212d892
|
@ -17,24 +17,28 @@ func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> v
|
||||||
|
|
||||||
func update_tileset() -> void:
|
func update_tileset() -> void:
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
var x_coord := float(tileset.tile_size.x) * (i % indices_x)
|
var coords := get_tile_coords(i)
|
||||||
var y_coord := float(tileset.tile_size.y) * (i / indices_x)
|
var rect := Rect2i(coords, 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)
|
||||||
var index := indices[i]
|
var index := indices[i]
|
||||||
var current_tile := tileset.tiles[index]
|
var current_tile := tileset.tiles[index]
|
||||||
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
||||||
|
if image_portion.is_invisible():
|
||||||
|
continue
|
||||||
if index == 0 or tileset.tiles.size() <= index:
|
if index == 0 or tileset.tiles.size() <= index:
|
||||||
|
# If the tileset is empty, only then add a new tile.
|
||||||
if tileset.tiles.size() <= 1:
|
if tileset.tiles.size() <= 1:
|
||||||
tileset.add_tile(image_portion, TileSetPanel.tile_editing_mode)
|
tileset.add_tile(image_portion, TileSetPanel.tile_editing_mode)
|
||||||
indices[i] = tileset.tiles.size() - 1
|
indices[i] = tileset.tiles.size() - 1
|
||||||
continue
|
continue
|
||||||
if image_portion.get_data() != tileset.tiles[index].image.get_data():
|
if image_portion.get_data() != current_tile.image.get_data():
|
||||||
tileset.replace_tile_at(image_portion, index)
|
tileset.replace_tile_at(image_portion, index)
|
||||||
# TODO: Update the rest of the tilemap
|
update_cel_portions()
|
||||||
elif TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.AUTO:
|
elif TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.AUTO:
|
||||||
handle_auto_editing_mode(i, image_portion)
|
handle_auto_editing_mode(i, image_portion)
|
||||||
else: # Stack
|
else: # Stack
|
||||||
|
if image_portion.is_invisible():
|
||||||
|
continue
|
||||||
var found_tile := false
|
var found_tile := false
|
||||||
for j in range(1, tileset.tiles.size()):
|
for j in range(1, tileset.tiles.size()):
|
||||||
var tile := tileset.tiles[j]
|
var tile := tileset.tiles[j]
|
||||||
|
@ -113,7 +117,6 @@ func handle_auto_editing_mode(i: int, image_portion: Image) -> void:
|
||||||
# Case 3: The portion is mapped and it did not change.
|
# Case 3: The portion is mapped and it did not change.
|
||||||
# Do nothing and move on to the next portion.
|
# Do nothing and move on to the next portion.
|
||||||
return
|
return
|
||||||
var previous_tile_index_in_tileset := tileset.find_tile(current_tile.image)
|
|
||||||
if index_in_tileset > -1: # If the portion exists in the tileset as a tile.
|
if index_in_tileset > -1: # If the portion exists in the tileset as a tile.
|
||||||
if current_tile.times_used > 1:
|
if current_tile.times_used > 1:
|
||||||
# Case 4: The portion is mapped and it exists in the tileset as a tile,
|
# Case 4: The portion is mapped and it exists in the tileset as a tile,
|
||||||
|
@ -153,6 +156,24 @@ func re_index_tiles_after_index(index: int) -> void:
|
||||||
indices[i] -= 1
|
indices[i] -= 1
|
||||||
|
|
||||||
|
|
||||||
|
func update_cel_portions() -> void:
|
||||||
|
for i in indices.size():
|
||||||
|
var coords := get_tile_coords(i)
|
||||||
|
var rect := Rect2i(coords, tileset.tile_size)
|
||||||
|
var image_portion := image.get_region(rect)
|
||||||
|
var index := indices[i]
|
||||||
|
var current_tile := tileset.tiles[index]
|
||||||
|
if image_portion.get_data() != current_tile.image.get_data():
|
||||||
|
var tile_size := current_tile.image.get_size()
|
||||||
|
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||||
|
|
||||||
|
|
||||||
|
func get_tile_coords(portion_index: int) -> Vector2i:
|
||||||
|
var x_coord := float(tileset.tile_size.x) * (portion_index % indices_x)
|
||||||
|
var y_coord := float(tileset.tile_size.y) * (portion_index / indices_x)
|
||||||
|
return Vector2i(x_coord, y_coord)
|
||||||
|
|
||||||
|
|
||||||
## Unused, should delete.
|
## Unused, should delete.
|
||||||
func re_index_tiles() -> void:
|
func re_index_tiles() -> void:
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
|
|
Loading…
Reference in a new issue