mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 15:24:44 -04:00
Refactoring tools (#281)
* Refactoring tools * Remove unused code * Fixed some inferring errors and added translations * Attempt to fix some Script Errors found in the CI workflow * Fix bucket crash. * Fix static type convert. Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
This commit is contained in:
parent
e1724148fc
commit
4a668f71f5
42 changed files with 2489 additions and 2389 deletions
|
@ -1,8 +1,20 @@
|
|||
class_name Drawer
|
||||
|
||||
|
||||
class ColorOp:
|
||||
var strength := 1.0
|
||||
|
||||
|
||||
func process(src: Color, _dst: Color) -> Color:
|
||||
return src
|
||||
|
||||
|
||||
class SimpleDrawer:
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
_sprite.set_pixel(_pos.x, _pos.y, _new_color)
|
||||
func set_pixel(image: Image, position: Vector2, color: Color, op : ColorOp) -> void:
|
||||
var color_old := image.get_pixelv(position)
|
||||
var color_new := op.process(color, color_old)
|
||||
if not color_new.is_equal_approx(color_old):
|
||||
image.set_pixelv(position, color_new)
|
||||
|
||||
|
||||
class PixelPerfectDrawer:
|
||||
|
@ -15,9 +27,10 @@ class PixelPerfectDrawer:
|
|||
last_pixels = [null, null]
|
||||
|
||||
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
last_pixels.push_back([_pos, _sprite.get_pixel(_pos.x, _pos.y)])
|
||||
_sprite.set_pixel(_pos.x, _pos.y, _new_color)
|
||||
func set_pixel(image: Image, position: Vector2, color: Color, op : ColorOp) -> void:
|
||||
var color_old = image.get_pixelv(position)
|
||||
last_pixels.push_back([position, color_old])
|
||||
image.set_pixelv(position, op.process(color, color_old))
|
||||
|
||||
var corner = last_pixels.pop_front()
|
||||
var neighbour = last_pixels[0]
|
||||
|
@ -25,14 +38,15 @@ class PixelPerfectDrawer:
|
|||
if corner == null or neighbour == null:
|
||||
return
|
||||
|
||||
if _pos - corner[0] in corners and _pos - neighbour[0] in neighbours:
|
||||
_sprite.set_pixel(neighbour[0].x, neighbour[0].y, neighbour[1])
|
||||
if position - corner[0] in corners and position - neighbour[0] in neighbours:
|
||||
image.set_pixel(neighbour[0].x, neighbour[0].y, neighbour[1])
|
||||
last_pixels[0] = corner
|
||||
|
||||
|
||||
var pixel_perfect := false setget set_pixel_perfect
|
||||
var h_mirror := false
|
||||
var v_mirror := false
|
||||
var horizontal_mirror := false
|
||||
var vertical_mirror := false
|
||||
var color_op := ColorOp.new()
|
||||
|
||||
var simple_drawer := SimpleDrawer.new()
|
||||
var pixel_perfect_drawers = [PixelPerfectDrawer.new(), PixelPerfectDrawer.new(), PixelPerfectDrawer.new(), PixelPerfectDrawer.new()]
|
||||
|
@ -52,14 +66,14 @@ func set_pixel_perfect(value: bool) -> void:
|
|||
drawers = [simple_drawer, simple_drawer, simple_drawer, simple_drawer]
|
||||
|
||||
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
var mirror_x = Global.current_project.x_max + Global.current_project.x_min - _pos.x - 1
|
||||
var mirror_y = Global.current_project.y_max + Global.current_project.y_min - _pos.y - 1
|
||||
func set_pixel(image: Image, position: Vector2, color: Color) -> void:
|
||||
var mirror_x = Global.current_project.x_max + Global.current_project.x_min - position.x - 1
|
||||
var mirror_y = Global.current_project.y_max + Global.current_project.y_min - position.y - 1
|
||||
|
||||
drawers[0].set_pixel(_sprite, _pos, _new_color)
|
||||
if h_mirror:
|
||||
drawers[1].set_pixel(_sprite, Vector2(mirror_x, _pos.y), _new_color)
|
||||
if v_mirror:
|
||||
drawers[2].set_pixel(_sprite, Vector2(mirror_x, mirror_y), _new_color)
|
||||
if v_mirror:
|
||||
drawers[3].set_pixel(_sprite, Vector2(_pos.x, mirror_y), _new_color)
|
||||
drawers[0].set_pixel(image, position, color, color_op)
|
||||
if horizontal_mirror:
|
||||
drawers[1].set_pixel(image, Vector2(mirror_x, position.y), color, color_op)
|
||||
if vertical_mirror:
|
||||
drawers[2].set_pixel(image, Vector2(mirror_x, mirror_y), color, color_op)
|
||||
if vertical_mirror:
|
||||
drawers[3].set_pixel(image, Vector2(position.x, mirror_y), color, color_op)
|
||||
|
|
|
@ -16,12 +16,13 @@ var guides := [] # Array of Guides
|
|||
|
||||
var brushes := [] # Array of Images
|
||||
|
||||
var selected_pixels := []
|
||||
var x_min := 0
|
||||
var x_max := 64
|
||||
var y_min := 0
|
||||
var y_max := 64
|
||||
|
||||
var selected_rect := Rect2(0, 0, 0, 0) setget _set_selected_rect
|
||||
|
||||
# For every camera (currently there are 3)
|
||||
var cameras_zoom := [Vector2(0.15, 0.15), Vector2(0.15, 0.15), Vector2(0.15, 0.15)] # Array of Vector2
|
||||
var cameras_offset := [Vector2.ZERO, Vector2.ZERO, Vector2.ZERO] # Array of Vector2
|
||||
|
@ -39,6 +40,11 @@ func _init(_frames := [], _name := tr("untitled")) -> void:
|
|||
OpenSave.backup_save_paths.append("")
|
||||
|
||||
|
||||
func _set_selected_rect(value : Rect2) -> void:
|
||||
selected_rect = value
|
||||
Global.selection_rectangle.set_rect(value)
|
||||
|
||||
|
||||
func change_project() -> void:
|
||||
# Remove old nodes
|
||||
for container in Global.layers_container.get_children():
|
||||
|
@ -94,16 +100,7 @@ func change_project() -> void:
|
|||
self.animation_tags = animation_tags
|
||||
|
||||
# Change the selection rectangle
|
||||
if selected_pixels.size() != 0:
|
||||
Global.selection_rectangle.polygon[0] = Vector2(x_min, y_min)
|
||||
Global.selection_rectangle.polygon[1] = Vector2(x_max, y_min)
|
||||
Global.selection_rectangle.polygon[2] = Vector2(x_max, y_max)
|
||||
Global.selection_rectangle.polygon[3] = Vector2(x_min, y_max)
|
||||
else:
|
||||
Global.selection_rectangle.polygon[0] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[1] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[2] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[3] = Vector2.ZERO
|
||||
Global.selection_rectangle.set_rect(selected_rect)
|
||||
|
||||
# Change the guides
|
||||
for guide in Global.canvas.get_children():
|
||||
|
@ -114,11 +111,9 @@ func change_project() -> void:
|
|||
guide.visible = false
|
||||
|
||||
# Change the project brushes
|
||||
for child in Global.project_brush_container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
Brushes.clear_project_brush()
|
||||
for brush in brushes:
|
||||
Global.create_brush_button(brush)
|
||||
Brushes.add_project_brush(brush)
|
||||
|
||||
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
|
||||
var i := 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue