mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 13:44:42 -04:00
Added AnimationTag class
Replaces nested Global.animation_tags arrays. Also replaced array.duplicate(true) with looping through the array and creating a new class for each array element, because duplicate(true) does not create new classes, unfortunately, which was causing issues with undo/redo.
This commit is contained in:
parent
e229ad1519
commit
34bc528e97
14 changed files with 134 additions and 83 deletions
15
src/Classes/AnimationTag.gd
Normal file
15
src/Classes/AnimationTag.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
class_name AnimationTag extends Reference
|
||||
# A class for frame tag properties
|
||||
|
||||
|
||||
var name : String
|
||||
var color : Color
|
||||
var from : int
|
||||
var to : int
|
||||
|
||||
|
||||
func _init(_name, _color, _from, _to) -> void:
|
||||
name = _name
|
||||
color = _color
|
||||
from = _from
|
||||
to = _to
|
18
src/Classes/Cel.gd
Normal file
18
src/Classes/Cel.gd
Normal file
|
@ -0,0 +1,18 @@
|
|||
class_name Cel extends Reference
|
||||
# A class for cel properties
|
||||
|
||||
|
||||
var image : Image setget image_changed
|
||||
var image_texture : ImageTexture
|
||||
var opacity : float
|
||||
|
||||
|
||||
func _init(_image := Image.new(), _opacity := 1.0) -> void:
|
||||
self.image = _image
|
||||
opacity = _opacity
|
||||
|
||||
|
||||
func image_changed(value : Image) -> void:
|
||||
image = value
|
||||
image_texture = ImageTexture.new()
|
||||
image_texture.create_from_image(image, 0)
|
40
src/Classes/Drawers.gd
Normal file
40
src/Classes/Drawers.gd
Normal file
|
@ -0,0 +1,40 @@
|
|||
class Drawer:
|
||||
func reset() -> void:
|
||||
pass
|
||||
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
pass
|
||||
|
||||
|
||||
class SimpleDrawer extends Drawer:
|
||||
func reset() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||
_sprite.set_pixel(_pos.x, _pos.y, _new_color)
|
||||
|
||||
|
||||
class PixelPerfectDrawer extends Drawer:
|
||||
const neighbours = [Vector2(0, 1), Vector2(1, 0), Vector2(-1, 0), Vector2(0, -1)]
|
||||
const corners = [Vector2(1, 1), Vector2(-1, -1), Vector2(-1, 1), Vector2(1, -1)]
|
||||
var last_pixels = [null, null]
|
||||
|
||||
|
||||
func reset() -> void:
|
||||
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)
|
||||
|
||||
var corner = last_pixels.pop_front()
|
||||
var neighbour = last_pixels[0]
|
||||
|
||||
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])
|
||||
last_pixels[0] = corner
|
19
src/Classes/Layer.gd
Normal file
19
src/Classes/Layer.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
class_name Layer extends Reference
|
||||
# A class for layer properties
|
||||
|
||||
|
||||
var name := ""
|
||||
var visible := true
|
||||
var locked := false
|
||||
var frame_container : HBoxContainer
|
||||
var new_cels_linked := false
|
||||
var linked_cels := [] # Array of Canvases
|
||||
|
||||
|
||||
func _init(_name := tr("Layer") + " 0", _visible := true, _locked := false, _frame_container := HBoxContainer.new(), _new_cels_linked := false, _linked_cels := []) -> void:
|
||||
name = _name
|
||||
visible = _visible
|
||||
locked = _locked
|
||||
frame_container = _frame_container
|
||||
new_cels_linked = _new_cels_linked
|
||||
linked_cels = _linked_cels
|
Loading…
Add table
Add a link
Reference in a new issue