mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 15:39:49 +00:00
Add smart tileset importing
This commit is contained in:
parent
9f3564fe71
commit
610d2deb27
|
@ -838,22 +838,46 @@ func import_reference_image_from_image(image: Image) -> void:
|
||||||
func open_image_as_tileset(
|
func open_image_as_tileset(
|
||||||
path: String, image: Image, horiz: int, vert: int, project := Global.current_project
|
path: String, image: Image, horiz: int, vert: int, project := Global.current_project
|
||||||
) -> void:
|
) -> void:
|
||||||
|
image.convert(project.get_image_format())
|
||||||
horiz = mini(horiz, image.get_size().x)
|
horiz = mini(horiz, image.get_size().x)
|
||||||
vert = mini(vert, image.get_size().y)
|
vert = mini(vert, image.get_size().y)
|
||||||
var frame_width := image.get_size().x / horiz
|
var frame_width := image.get_size().x / horiz
|
||||||
var frame_height := image.get_size().y / vert
|
var frame_height := image.get_size().y / vert
|
||||||
var tile_size := Vector2i(frame_width, frame_height)
|
var tile_size := Vector2i(frame_width, frame_height)
|
||||||
var tileset := TileSetCustom.new(tile_size, project, path.get_file())
|
var tileset := TileSetCustom.new(tile_size, project, path.get_basename().get_file())
|
||||||
for yy in range(vert):
|
for yy in range(vert):
|
||||||
for xx in range(horiz):
|
for xx in range(horiz):
|
||||||
var cropped_image := image.get_region(
|
var cropped_image := image.get_region(
|
||||||
Rect2i(frame_width * xx, frame_height * yy, frame_width, frame_height)
|
Rect2i(frame_width * xx, frame_height * yy, frame_width, frame_height)
|
||||||
)
|
)
|
||||||
cropped_image.convert(project.get_image_format())
|
@warning_ignore("int_as_enum_without_cast")
|
||||||
tileset.add_tile(cropped_image, null, 2)
|
tileset.add_tile(cropped_image, null, 2)
|
||||||
project.tilesets.append(tileset)
|
project.tilesets.append(tileset)
|
||||||
|
|
||||||
|
|
||||||
|
func open_image_as_tileset_smart(
|
||||||
|
path: String,
|
||||||
|
image: Image,
|
||||||
|
sliced_rects: Array[Rect2i],
|
||||||
|
tile_size: Vector2i,
|
||||||
|
project := Global.current_project
|
||||||
|
) -> void:
|
||||||
|
image.convert(project.get_image_format())
|
||||||
|
if sliced_rects.size() == 0: # Image is empty sprite (manually set data to be consistent)
|
||||||
|
tile_size = image.get_size()
|
||||||
|
sliced_rects.append(Rect2i(Vector2i.ZERO, tile_size))
|
||||||
|
var tileset := TileSetCustom.new(tile_size, project, path.get_basename().get_file())
|
||||||
|
for rect in sliced_rects:
|
||||||
|
var offset: Vector2 = (0.5 * (tile_size - rect.size)).floor()
|
||||||
|
var cropped_image := Image.create(
|
||||||
|
tile_size.x, tile_size.y, false, project.get_image_format()
|
||||||
|
)
|
||||||
|
cropped_image.blit_rect(image, rect, offset)
|
||||||
|
@warning_ignore("int_as_enum_without_cast")
|
||||||
|
tileset.add_tile(cropped_image, null, 2)
|
||||||
|
project.tilesets.append(tileset)
|
||||||
|
|
||||||
|
|
||||||
func set_new_imported_tab(project: Project, path: String) -> void:
|
func set_new_imported_tab(project: Project, path: String) -> void:
|
||||||
var prev_project_empty := Global.current_project.is_empty()
|
var prev_project_empty := Global.current_project.is_empty()
|
||||||
var prev_project_pos := Global.current_project_index
|
var prev_project_pos := Global.current_project_index
|
||||||
|
|
|
@ -210,9 +210,16 @@ func _on_ImportPreviewDialog_confirmed() -> void:
|
||||||
var dir := DirAccess.open(path.get_base_dir())
|
var dir := DirAccess.open(path.get_base_dir())
|
||||||
dir.copy(path, Global.home_data_directory.path_join(location))
|
dir.copy(path, Global.home_data_directory.path_join(location))
|
||||||
elif current_import_option == ImageImportOptions.TILESET:
|
elif current_import_option == ImageImportOptions.TILESET:
|
||||||
OpenSave.open_image_as_tileset(
|
if smart_slice:
|
||||||
path, image, spritesheet_horizontal, spritesheet_vertical
|
if !recycle_last_slice_result:
|
||||||
)
|
obtain_sliced_data()
|
||||||
|
OpenSave.open_image_as_tileset_smart(
|
||||||
|
path, image, sliced_rects.rects, sliced_rects.frame_size
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
OpenSave.open_image_as_tileset(
|
||||||
|
path, image, spritesheet_horizontal, spritesheet_vertical
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if current_import_option in custom_importers.keys():
|
if current_import_option in custom_importers.keys():
|
||||||
|
|
Loading…
Reference in a new issue