Merge pull request #257 from Orama-Interactive/refactoring

Last refactoring merge
This commit is contained in:
Manolis Papadeas 2020-06-05 02:23:59 +03:00 committed by GitHub
commit 2e69e1a8c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 727 additions and 692 deletions

View file

@ -74,22 +74,22 @@ func _on_CreateNewImage_confirmed() -> void:
var height : int = height_value.value
var fill_color : Color = fill_color_node.color
Global.clear_frames()
Global.layers.clear()
Global.layers.append(Layer.new())
Global.canvas.size = Vector2(width, height).floor()
Global.current_project.layers.clear()
Global.current_project.layers.append(Layer.new())
Global.current_project.size = Vector2(width, height).floor()
Global.canvas.fill_color = fill_color
var frame : Frame = Global.canvas.new_empty_frame()
Global.canvas.camera_zoom()
Global.frames.append(frame)
Global.current_project.frames.append(frame)
Global.current_layer = 0
Global.frames = Global.frames # To trigger Global.frames_changed()
Global.current_frame = 0
Global.layers = Global.layers # To trigger Global.layers_changed()
Global.project_has_changed = false
Global.current_project.current_layer = 0
Global.current_project.frames = Global.current_project.frames # To trigger Global.frames_changed()
Global.current_project.current_frame = 0
Global.current_project.layers = Global.current_project.layers # To trigger Global.layers_changed()
Global.current_project.has_changed = false
if fill_color.a > 0:
Global.frames[0].cels[0].image.fill(fill_color)
Global.frames[0].cels[0].image.lock()
Global.current_project.frames[0].cels[0].image.fill(fill_color)
Global.current_project.frames[0].cels[0].image.lock()
Global.canvas.update_texture(0)

View file

@ -89,8 +89,8 @@ func show_tab() -> void:
$VBoxContainer/File/FileFormat.selected = FileFormat.PNG
$FrameTimer.stop()
if not was_exported:
frame_number = Global.current_frame + 1
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.max_value = Global.frames.size() + 1
frame_number = Global.current_project.current_frame + 1
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.max_value = Global.current_project.frames.size() + 1
var prev_frame_number = $VBoxContainer/FrameOptions/FrameNumber/FrameNumber.value
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.value = frame_number
if prev_frame_number == frame_number:
@ -135,9 +135,9 @@ func external_export() -> void:
func process_frame() -> void:
var frame = Global.frames[frame_number - 1]
var frame = Global.current_project.frames[frame_number - 1]
var image := Image.new()
image.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
blend_layers(image, frame)
processed_images.clear()
processed_images.append(image)
@ -147,11 +147,11 @@ func process_spritesheet() -> void:
# Range of frames determined by tags
var frames := []
if frame_current_tag > 0:
var frame_start = Global.animation_tags[frame_current_tag - 1].from
var frame_end = Global.animation_tags[frame_current_tag - 1].to
frames = Global.frames.slice(frame_start-1, frame_end-1, 1, true)
var frame_start = Global.current_project.animation_tags[frame_current_tag - 1].from
var frame_end = Global.current_project.animation_tags[frame_current_tag - 1].to
frames = Global.current_project.frames.slice(frame_start-1, frame_end-1, 1, true)
else:
frames = Global.frames
frames = Global.current_project.frames
# Then store the size of frames for other functions
number_of_frames = frames.size()
@ -160,8 +160,8 @@ func process_spritesheet() -> void:
var spritesheet_columns = lines_count if orientation == Orientation.ROWS else frames_divided_by_spritesheet_lines()
var spritesheet_rows = lines_count if orientation == Orientation.COLUMNS else frames_divided_by_spritesheet_lines()
var width = Global.canvas.size.x * spritesheet_columns
var height = Global.canvas.size.y * spritesheet_rows
var width = Global.current_project.size.x * spritesheet_columns
var height = Global.current_project.size.y * spritesheet_rows
var whole_image := Image.new()
whole_image.create(width, height, false, Image.FORMAT_RGBA8)
@ -173,22 +173,22 @@ func process_spritesheet() -> void:
for frame in frames:
if orientation == Orientation.ROWS:
if vv < spritesheet_columns:
origin.x = Global.canvas.size.x * vv
origin.x = Global.current_project.size.x * vv
vv += 1
else:
hh += 1
origin.x = 0
vv = 1
origin.y = Global.canvas.size.y * hh
origin.y = Global.current_project.size.y * hh
else:
if hh < spritesheet_rows:
origin.y = Global.canvas.size.y * hh
origin.y = Global.current_project.size.y * hh
hh += 1
else:
vv += 1
origin.y = 0
hh = 1
origin.x = Global.canvas.size.x * vv
origin.x = Global.current_project.size.x * vv
blend_layers(whole_image, frame, origin)
processed_images.clear()
@ -197,9 +197,9 @@ func process_spritesheet() -> void:
func process_animation() -> void:
processed_images.clear()
for frame in Global.frames:
for frame in Global.current_project.frames:
var image := Image.new()
image.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
blend_layers(image, frame)
processed_images.append(image)
@ -280,7 +280,7 @@ func remove_previews() -> void:
func get_proccessed_image_animation_tag_and_start_id(processed_image_id : int) -> Array:
var result_animation_tag_and_start_id = null
for animation_tag in Global.animation_tags:
for animation_tag in Global.current_project.animation_tags:
# Check if processed image is in frame tag and assign frame tag and start id if yes
# Then stop
if (processed_image_id + 1) >= animation_tag.from and (processed_image_id + 1) <= animation_tag.to:
@ -365,7 +365,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
image.lock()
var layer_i := 0
for cel in frame.cels:
if Global.layers[layer_i].visible:
if Global.current_project.layers[layer_i].visible:
var cel_image := Image.new()
cel_image.copy_from(cel.image)
cel_image.lock()
@ -375,7 +375,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
var pixel_color := cel_image.get_pixel(xx, yy)
var alpha : float = pixel_color.a * cel.opacity
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
DrawingAlgos.blend_rect(image, cel_image, Rect2(Global.canvas.location, Global.canvas.size), origin)
DrawingAlgos.blend_rect(image, cel_image, Rect2(Global.canvas.location, Global.current_project.size), origin)
layer_i += 1
image.unlock()
@ -453,7 +453,7 @@ func create_frame_tag_list() -> void:
frame_container.add_item("All Frames", 0) # Re-add removed 'All Frames' item
# Repopulate list with current tag list
for item in Global.animation_tags:
for item in Global.current_project.animation_tags:
frame_container.add_item(item.name)
@ -476,8 +476,8 @@ func store_export_settings() -> void:
# Fill the dialog with previous export settings
func restore_previous_export_settings() -> void:
current_tab = exported_tab
frame_number = exported_frame_number if exported_frame_number <= Global.frames.size() else Global.frames.size()
frame_current_tag = exported_frame_current_tag if exported_frame_current_tag <= Global.animation_tags.size() else 0
frame_number = exported_frame_number if exported_frame_number <= Global.current_project.frames.size() else Global.current_project.frames.size()
frame_current_tag = exported_frame_current_tag if exported_frame_current_tag <= Global.current_project.animation_tags.size() else 0
orientation = exported_orientation
lines_count = exported_lines_count
animation_type = exported_animation_type

View file

@ -23,7 +23,7 @@ func _ready() -> void:
func _on_HSVDialog_about_to_show() -> void:
current_cel = Global.frames[Global.current_frame].cels[Global.current_layer].image
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
preview_image.copy_from(current_cel)
update_preview()
@ -38,7 +38,7 @@ func _on_Apply_pressed() -> void:
DrawingAlgos.adjust_hsv(current_cel,0,hue_slider.value)
DrawingAlgos.adjust_hsv(current_cel,1,sat_slider.value)
DrawingAlgos.adjust_hsv(current_cel,2,val_slider.value)
Global.canvas.update_texture(Global.current_layer)
Global.canvas.update_texture(Global.current_project.current_layer)
Global.canvas.handle_redo("Draw")
reset()
visible = false

View file

@ -38,12 +38,12 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
Global.control.opensprite_file_selected = true
if !new_frame: # If we're not adding a new frame, delete the previous
Global.clear_frames()
Global.layers.clear()
Global.layers.append(Layer.new())
Global.current_layer = 0
Global.current_project.layers.clear()
Global.current_project.layers.append(Layer.new())
Global.current_project.current_layer = 0
var first_path : String = paths[0]
var i : int = Global.frames.size()
var i : int = Global.current_project.frames.size()
if !import_spritesheet:
for path in paths:
var image := Image.new()
@ -55,20 +55,20 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
Global.dialog_open(true)
continue
Global.canvas.size = image.get_size()
Global.current_project.size = image.get_size()
var frame := Frame.new()
image.convert(Image.FORMAT_RGBA8)
image.lock()
frame.cels.append(Cel.new(image, 1))
for _i in range(1, Global.layers.size()):
for _i in range(1, Global.current_project.layers.size()):
var empty_sprite := Image.new()
empty_sprite.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.fill(Color(0, 0, 0, 0))
empty_sprite.lock()
frame.cels.append(Cel.new(empty_sprite, 1))
Global.frames.append(frame)
Global.current_project.frames.append(frame)
i += 1
@ -91,31 +91,31 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
var frame := Frame.new()
var cropped_image := Image.new()
cropped_image = image.get_rect(Rect2(frame_width * xx, frame_height * yy, frame_width, frame_height))
Global.canvas.size = cropped_image.get_size()
Global.current_project.size = cropped_image.get_size()
cropped_image.convert(Image.FORMAT_RGBA8)
cropped_image.lock()
frame.cels.append(Cel.new(cropped_image, 1))
for _i in range(1, Global.layers.size()):
for _i in range(1, Global.current_project.layers.size()):
var empty_sprite := Image.new()
empty_sprite.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.fill(Color(0, 0, 0, 0))
empty_sprite.lock()
frame.cels.append(Cel.new(empty_sprite, 1))
Global.frames.append(frame)
Global.current_project.frames.append(frame)
i += 1
Global.canvas.camera_zoom()
Global.frames = Global.frames # Just to call Global.frames_changed
Global.current_frame = i - 1
Global.current_project.frames = Global.current_project.frames # Just to call Global.frames_changed
Global.current_project.current_frame = i - 1
if !new_frame:
Global.layers = Global.layers # Just to call Global.layers_changed
Global.current_project.layers = Global.current_project.layers # Just to call Global.layers_changed
Global.window_title = first_path.get_file() + " (" + tr("imported") + ") - Pixelorama " + Global.current_version
if Global.project_has_changed:
if Global.current_project.has_changed:
Global.window_title = Global.window_title + "(*)"
var file_name := first_path.get_basename().get_file()
var directory_path := first_path.get_basename().replace(file_name, "")

View file

@ -10,7 +10,7 @@ func _on_OutlineDialog_confirmed() -> void:
var diagonal : bool = $OptionsContainer/DiagonalCheckBox.pressed
var inside_image : bool = $OptionsContainer/InsideImageCheckBox.pressed
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
if image.is_invisible():
return
var new_image := Image.new()
@ -30,13 +30,13 @@ func _on_OutlineDialog_confirmed() -> void:
var outline_pos : Vector2 = pos + Vector2.LEFT # Left
if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.RIGHT * (i - 1)
if new_pos.x < Global.canvas.size.x:
if new_pos.x < Global.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.RIGHT # Right
if outline_pos.x >= Global.canvas.size.x || image.get_pixelv(outline_pos).a == 0:
if outline_pos.x >= Global.current_project.size.x || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.LEFT * (i - 1)
if new_pos.x >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -46,13 +46,13 @@ func _on_OutlineDialog_confirmed() -> void:
outline_pos = pos + Vector2.UP # Up
if outline_pos.y < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.DOWN * (i - 1)
if new_pos.y < Global.canvas.size.y:
if new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.DOWN # Down
if outline_pos.y >= Global.canvas.size.y || image.get_pixelv(outline_pos).a == 0:
if outline_pos.y >= Global.current_project.size.y || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.UP * (i - 1)
if new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -63,29 +63,29 @@ func _on_OutlineDialog_confirmed() -> void:
outline_pos = pos + (Vector2.LEFT + Vector2.UP) # Top left
if (outline_pos.x < 0 && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.DOWN) * (i - 1)
if new_pos.x < Global.canvas.size.x && new_pos.y < Global.canvas.size.y:
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.LEFT + Vector2.DOWN) # Bottom left
if (outline_pos.x < 0 && outline_pos.y >= Global.canvas.size.y) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x < 0 && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.UP) * (i - 1)
if new_pos.x < Global.canvas.size.x && new_pos.y >= 0:
if new_pos.x < Global.current_project.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.UP) # Top right
if (outline_pos.x >= Global.canvas.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.DOWN) * (i - 1)
if new_pos.x >= 0 && new_pos.y < Global.canvas.size.y:
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.DOWN) # Bottom right
if (outline_pos.x >= Global.canvas.size.x && outline_pos.y >= Global.canvas.size.y) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.UP) * (i - 1)
if new_pos.x >= 0 && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -100,7 +100,7 @@ func _on_OutlineDialog_confirmed() -> void:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.RIGHT * i # Right
if new_pos.x < Global.canvas.size.x:
if new_pos.x < Global.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
@ -112,7 +112,7 @@ func _on_OutlineDialog_confirmed() -> void:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.DOWN * i # Down
if new_pos.y < Global.canvas.size.y:
if new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
@ -125,19 +125,19 @@ func _on_OutlineDialog_confirmed() -> void:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left
if new_pos.x >= 0 && new_pos.y < Global.canvas.size.y:
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right
if new_pos.x < Global.canvas.size.x && new_pos.y >= 0:
if new_pos.x < Global.current_project.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.DOWN) * i # Bottom right
if new_pos.x < Global.canvas.size.x && new_pos.y < Global.canvas.size.y:
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)

View file

@ -5,19 +5,19 @@ func _on_ScaleImage_confirmed() -> void:
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
var interpolation : int = $VBoxContainer/OptionsContainer/InterpolationType.selected
Global.undos += 1
Global.undo_redo.create_action("Scale")
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
for f in Global.frames:
for f in Global.current_project.frames:
for i in range(f.cels.size() - 1, -1, -1):
var sprite := Image.new()
sprite.copy_from(f.cels[i].image)
sprite.resize(width, height, interpolation)
Global.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
Global.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
Global.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
Global.undo_redo.add_undo_method(Global, "undo")
Global.undo_redo.add_do_method(Global, "redo")
Global.undo_redo.commit_action()
Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()