mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-26 13:34:42 -04:00
Created a Projects class
A Project class contains project-specific data like name, undo_redo, frames, layers, tags and brushes. These variables have been moved from Global. This is the first step towards multiple tab support, where each tab will be a different Project.
This commit is contained in:
parent
9d38cbd13e
commit
4e111a7ac0
21 changed files with 656 additions and 627 deletions
|
@ -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.current_project.layers.clear()
|
||||
Global.current_project.layers.append(Layer.new())
|
||||
Global.canvas.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)
|
||||
|
||||
|
||||
|
|
|
@ -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,7 +135,7 @@ 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)
|
||||
blend_layers(image, frame)
|
||||
|
@ -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()
|
||||
|
@ -197,7 +197,7 @@ 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)
|
||||
blend_layers(image, frame)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
@ -61,14 +61,14 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
|||
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.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
|
||||
|
||||
|
@ -96,26 +96,26 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
|||
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.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, "")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.canvas, "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.canvas, "size", Global.canvas.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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue