1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

Load images as tilesets

This commit is contained in:
Emmanouil Papadeas 2024-11-26 01:17:41 +02:00
parent 5e5789752d
commit 62882cb8b1
4 changed files with 38 additions and 5 deletions

View file

@ -835,6 +835,25 @@ func import_reference_image_from_image(image: Image) -> void:
reference_image_imported.emit()
func open_image_as_tileset(
path: String, image: Image, horiz: int, vert: int, project := Global.current_project
) -> void:
horiz = mini(horiz, image.get_size().x)
vert = mini(vert, image.get_size().y)
var frame_width := image.get_size().x / horiz
var frame_height := image.get_size().y / vert
var tile_size := Vector2i(frame_width, frame_height)
var tileset := TileSetCustom.new(tile_size, project, path.get_file())
for yy in range(vert):
for xx in range(horiz):
var cropped_image := image.get_region(
Rect2i(frame_width * xx, frame_height * yy, frame_width, frame_height)
)
cropped_image.convert(project.get_image_format())
tileset.add_tile(cropped_image, null, 2)
project.tilesets.append(tileset)
func set_new_imported_tab(project: Project, path: String) -> void:
var prev_project_empty := Global.current_project.is_empty()
var prev_project_pos := Global.current_project_index

View file

@ -11,7 +11,8 @@ enum ImageImportOptions {
NEW_REFERENCE_IMAGE,
PALETTE,
BRUSH,
PATTERN
PATTERN,
TILESET
}
enum BrushTypes { FILE, PROJECT, RANDOM }
@ -75,6 +76,7 @@ func _on_ImportPreviewDialog_about_to_show() -> void:
import_option_button.add_item("New palette")
import_option_button.add_item("New brush")
import_option_button.add_item("New pattern")
import_option_button.add_item("Tileset")
# adding custom importers
for id in custom_importers.keys():
@ -207,6 +209,10 @@ func _on_ImportPreviewDialog_confirmed() -> void:
var location := "Patterns".path_join(file_name_ext)
var dir := DirAccess.open(path.get_base_dir())
dir.copy(path, Global.home_data_directory.path_join(location))
elif current_import_option == ImageImportOptions.TILESET:
OpenSave.open_image_as_tileset(
path, image, spritesheet_horizontal, spritesheet_vertical
)
else:
if current_import_option in custom_importers.keys():
@ -250,7 +256,11 @@ func synchronize() -> void:
dialog.at_layer_option.get_node("AtLayerOption") as OptionButton
)
# Sync properties (if any)
if id == ImageImportOptions.SPRITESHEET_TAB or id == ImageImportOptions.SPRITESHEET_LAYER:
if (
id == ImageImportOptions.SPRITESHEET_TAB
or id == ImageImportOptions.SPRITESHEET_LAYER
or id == ImageImportOptions.TILESET
):
var h_frames := spritesheet_options.find_child("HorizontalFrames") as SpinBox
var v_frames := spritesheet_options.find_child("VerticalFrames") as SpinBox
var d_h_frames := dialog.spritesheet_options.find_child("HorizontalFrames") as SpinBox
@ -298,7 +308,7 @@ func _on_ImportOption_item_selected(id: ImageImportOptions) -> void:
_hide_all_options()
import_options.get_parent().visible = true
if id == ImageImportOptions.SPRITESHEET_TAB:
if id == ImageImportOptions.SPRITESHEET_TAB or id == ImageImportOptions.TILESET:
frame_size_label.visible = true
spritesheet_options.visible = true
texture_rect.get_child(0).visible = true
@ -505,6 +515,7 @@ func _call_queue_redraw() -> void:
if (
current_import_option == ImageImportOptions.SPRITESHEET_TAB
or current_import_option == ImageImportOptions.SPRITESHEET_LAYER
or current_import_option == ImageImportOptions.TILESET
):
if smart_slice:
if is_instance_valid(sliced_rects) and not sliced_rects.rects.is_empty():

View file

@ -223,10 +223,9 @@ text = "Brush type:"
[node name="BrushTypeOption" type="OptionButton" parent="VBoxContainer/ImportOptionsContainer/ImportOptions/NewBrushOptions/Type"]
layout_mode = 2
mouse_default_cursor_shape = 2
item_count = 3
selected = 0
item_count = 3
popup/item_0/text = "File brush"
popup/item_0/id = 0
popup/item_1/text = "Project brush"
popup/item_1/id = 1
popup/item_2/text = "Random brush"

View file

@ -41,5 +41,9 @@ func _on_about_to_popup() -> void:
func _on_tileset_option_button_item_selected(index: int) -> void:
if index > 0:
var tileset := Global.current_project.tilesets[index - 1]
tileset_name_line_edit.text = tileset.name
tile_size_slider.value = tileset.tile_size
tileset_name_line_edit.editable = index == 0
tile_size_slider.editable = tileset_name_line_edit.editable