Skip to content

Commit

Permalink
fix editor crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Feb 10, 2022
1 parent a97077d commit b61ee6f
Show file tree
Hide file tree
Showing 31 changed files with 448 additions and 407 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tool
extends AnimaAnimatable
class_name AnimaAccordion

const COLLAPSED_VALUE := "./Wrapper/Title:size:y"
const EXPANDED_VALUE := "./Wrapper/Title:size:y + ./Wrapper/ContentWrapper/MarginContainer:size:y"
Expand Down Expand Up @@ -161,6 +162,8 @@ func _enter_tree():
func _init():
._init()

_init_layout()

var extra_keys = ["Normal", "Hovered", "Focused", "Pressed"]

for key in RECTANGLE_PROPERTIES:
Expand Down Expand Up @@ -188,6 +191,26 @@ func _init():
_add_properties(CUSTOM_PROPERTIES)
_add_properties(_all_properties)

func _init_layout() -> void:
var wrapper := VBoxContainer.new()
var title := AnimaButton.new()
var icon := Sprite.new()

icon.texture = load("res://addons/anima/icons/collapse.svg")
icon.position = Vector2(16, 16)

title.anchor_right = 1
title.anchor_bottom = 1
title.set(title.BUTTON_BASE_PROPERTIES.BUTTON_ALIGN.name, 1)
title.set(title.BUTTON_BASE_PROPERTIES.BUTTON_VALIGN.name, 1)

title.add_child(icon)

wrapper.anchor_right = 1
wrapper.add_child(title)

add_child(wrapper)

func _ready():
set_expanded(expanded)
set_label(label)
Expand Down Expand Up @@ -239,11 +262,9 @@ func _animate_height_change() -> void:

anima.with(
Anima.Node($Wrapper/ContentWrapper/MarginContainer/Content) \
.anima_animation(get_property(CUSTOM_PROPERTIES.ANIMATION_NAME.name), true) \
.anima_easing(easing) \
.anima_pivot(Anima.PIVOT.CENTER) \
.anima_animation(get_property(CUSTOM_PROPERTIES.ANIMATION_NAME.name), true)
)
anima.also(
anima.with(
Anima.Node($Wrapper/Title/Icon) \
.anima_property("rotate", 0) \
.anima_from(-90) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

[ext_resource path="res://addons/anima/components/AnimaButton.gd" type="Script" id=1]
[ext_resource path="res://addons/anima/icons/collapse.svg" type="Texture" id=2]
[ext_resource path="res://addons/anima/ui/shared/AnimaAccordion.gd" type="Script" id=3]
[ext_resource path="res://addons/anima/components/AnimaAccordion.gd" type="Script" id=3]

[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.105882, 0.129412, 0.180392, 1 )

[node name="AnimaAccordion" type="Control"]
margin_right = 153.0
margin_bottom = 56.0
rect_min_size = Vector2( 153, 56 )
rect_pivot_offset = Vector2( 76.5, 16.4149 )
margin_bottom = 32.0
rect_min_size = Vector2( 153, 32 )
rect_pivot_offset = Vector2( 76.5, 16 )
rect_clip_content = true
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
expanded = false
Animation/AnimatePropertyChange = true
Animation/Speed = 0.3
Animation/Easing = 0
Expand Down Expand Up @@ -190,12 +191,13 @@ Pressed/Shadow/Offset = Vector2( -1, -1 )

[node name="Icon" type="Sprite" parent="Wrapper/Title"]
position = Vector2( 16, 15 )
rotation = -1.5708
texture = ExtResource( 2 )

[node name="ContentWrapper" type="Panel" parent="Wrapper"]
margin_top = 32.0
margin_right = 153.0
margin_bottom = 56.0
margin_bottom = 32.0
rect_pivot_offset = Vector2( 300, 0 )
size_flags_horizontal = 3
size_flags_vertical = 3
Expand All @@ -219,10 +221,12 @@ __meta__ = {
}

[node name="Content" type="VBoxContainer" parent="Wrapper/ContentWrapper/MarginContainer"]
modulate = Color( 1, 1, 1, 0 )
margin_left = 12.0
margin_top = 12.0
margin_right = 129.0
margin_bottom = 12.0
rect_pivot_offset = Vector2( 58.5, 0 )
size_flags_horizontal = 3
size_flags_vertical = 3
alignment = 1
Expand Down
4 changes: 1 addition & 3 deletions addons/anima/components/Animatable.gd
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func animate_params(params: Array) -> void:
var duration: float = get_property(BASE_PROPERTIES.ANIMATION_SPEED.name)

for param in params:
var animation := Anima.Node(self)

animation.anima_property(param.property, param.to, duration)
var animation := Anima.Node(self).anima_property(param.property, param.to, duration)

if param.has("from"):
animation.anima_from(param.from)
Expand Down
4 changes: 2 additions & 2 deletions addons/anima/components/Carousel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ func set_index(new_index: int) -> void:
.anima_duration(duration)
)

anima.also(
anima.with(
Anima.Node(_container) \
.anima_property("position:x") \
.anima_to(-x) \
.anima_easing(scroll_easing)
)
anima.also(
anima.with(
Anima.Node($Wrapper) \
.anima_property("size:y") \
.anima_to(wrapper_height) \
Expand Down
130 changes: 12 additions & 118 deletions addons/anima/core/anima.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
tool
extends Node

const BASE_PATH := 'res://addons/anima/animations/'
const ANIMA_NODE = preload('res://addons/anima/core/node.gd')

enum PIVOT {
TOP_LEFT,
TOP_CENTER,
Expand Down Expand Up @@ -86,7 +83,7 @@ const MINIMUM_DURATION := 0.000001
var _animations_list := []
var _custom_animations := {}

func begin(node: Node, name: String = 'anima', single_shot := false):
static func begin(node: Node, name: String = 'anima', single_shot := false):
var node_name = 'AnimaNode_' + name

for child in node.get_children():
Expand All @@ -95,7 +92,7 @@ func begin(node: Node, name: String = 'anima', single_shot := false):

break

var anima_node = ANIMA_NODE.new()
var anima_node = load('res://addons/anima/core/anima_node.gd').new()

anima_node.name = node_name
anima_node.init_node(node)
Expand All @@ -104,128 +101,25 @@ func begin(node: Node, name: String = 'anima', single_shot := false):

return anima_node

func begin_single_shot(node: Node, name: String = "anima"):
static func begin_single_shot(node: Node, name: String = "anima"):
return begin(node, name, true)

func player(node: Node):
var player = load('./player.gd').new()

node.add_child(player)

return player

func get_animation_path() -> String:
return BASE_PATH

func register_animation(animation_name: String, keyframes: Dictionary) -> void:
_deregister_animation(animation_name)

_custom_animations[animation_name] = keyframes

func _deregister_animation(animation_name: String) -> void:
_custom_animations.erase(animation_name)

func get_available_animations() -> Array:
if _animations_list.size() == 0:
var list = _get_animations_list()
var filtered := []

for file in list:
if file.find('.gd.') < 0 and file.find(".gd") > 0:
filtered.push_back(file.replace('.gdc', '.gd'))

_animations_list = filtered

return _animations_list + _custom_animations.keys()

func get_available_animation_by_category() -> Dictionary:
var animations = get_available_animations()
var base = get_animation_path()
var old_category := ''
var result := {}

for item in animations:
var category_and_file = item.replace(base, '').split('/')
var category = category_and_file[0]
var file_and_extension = category_and_file[1].split('.')
var file = file_and_extension[0]

if not result.has(category):
result[category] = []

result[category].push_back(file)

return result

func get_animation_keyframes(animation_name: String) -> Dictionary:
if _custom_animations.has(animation_name):
return _custom_animations[animation_name]

var resource_file = _get_animation_script_with_path(animation_name)
if resource_file:
var script: Reference = load(resource_file).new()
var keyframes: Dictionary = script.KEYFRAMES

_custom_animations[animation_name] = keyframes

script.unreference()

return keyframes

printerr('No animation found with name: ', animation_name)

return {}

func _get_animation_script_with_path(animation_name: String) -> String:
if not animation_name.ends_with('.gd'):
animation_name += '.gd'

animation_name = AnimaStrings.from_camel_to_snack_case(animation_name)

for file_name in get_available_animations():
if file_name is String and file_name.ends_with(animation_name):
return file_name

return ''

func is_built_in_animation(animation_name: String) -> bool:
return _animations_list.find(animation_name) >= 0

func _get_animations_list() -> Array:
var files = _get_scripts_in_dir(BASE_PATH)
var filtered := []

files.sort()
return files

func _get_scripts_in_dir(path: String, files: Array = []) -> Array:
var dir = Directory.new()
if dir.open(path) != OK:
return files

dir.list_dir_begin()
var file_name = dir.get_next()

while file_name != "":
if file_name != "." and file_name != "..":
if dir.current_is_dir():
_get_scripts_in_dir(path + file_name + '/', files)
else:
files.push_back(path + file_name)

file_name = dir.get_next()

return files
#
#static func player(node: Node):
# var player = load('./player.gd').new()
#
# node.add_child(player)
#
# return player

static func Node(node: Node) -> AnimaDeclarationNode:
return AnimaDeclarationNode.new(node)

static func Group(group: Node, items_delay: float, animation_type: int = Anima.GROUP.FROM_TOP, point := 0) -> AnimaDeclarationGroup:
static func Group(group: Node, items_delay: float, animation_type: int = GROUP.FROM_TOP, point := 0) -> AnimaDeclarationGroup:
var c := AnimaDeclarationGroup.new()

return c._init_me(group, items_delay, animation_type, point)

static func Grid(grid: Node, grid_size: Vector2, items_delay: float, animation_type: int = Anima.GROUP.FROM_TOP, point := 0) -> AnimaDeclarationGrid:
static func Grid(grid: Node, grid_size: Vector2, items_delay: float, animation_type: int = GROUP.FROM_TOP, point := 0) -> AnimaDeclarationGrid:
var c := AnimaDeclarationGrid.new()

return c._init_me(grid, grid_size, items_delay, animation_type, point)
Expand Down
42 changes: 1 addition & 41 deletions addons/anima/core/node.gd → addons/anima/core/anima_node.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
tool

class_name AnimaNode
extends Node

Expand Down Expand Up @@ -93,45 +92,6 @@ func with(data) -> float:
_last_tween_data = data

return _setup_animation(data)
#
#func also(data, extra_keys_to_ignore := []) -> float:
# if not data is Dictionary:
# data = data.get_data()
#
# if _last_tween_data == null:
# printerr('.also can be only used in after a .then or .with!')
#
# return _last_animation_duration
#
# var animation_data: Array = _anima_tween.get_animation_data()
# var previous_data = _last_tween_data
#
# var keys_to_ignore = [
# '_is_first_frame',
# '_is_last_frame',
# '_wait_time',
# 'delay',
# 'relative',
# '_grid_node',
# "animation",
# 'property',
# 'from',
# 'to',
# ]
#
# if previous_data.has('_grid_node'):
# previous_data.grid = previous_data._grid_node
#
# for key in previous_data:
# if keys_to_ignore.find(key) >= 0 or extra_keys_to_ignore.find(key) >= 0:
# continue
#
# if not data.has(key):
# data[key] = previous_data[key]
#
# data.__do_not_update_last_tween_data = true
#
# return with(data)

func _group(group_data: Array, animation_data: Dictionary) -> float:
var delay_index := 0
Expand Down Expand Up @@ -394,7 +354,7 @@ func _setup_node_animation(data: Dictionary) -> float:
var keyframes = data.animation

if keyframes is String:
keyframes = Anima.get_animation_keyframes(data.animation)
keyframes = AnimaAnimationsUtils.get_animation_keyframes(data.animation)

if keyframes.size() == 0:
printerr('animation not found: %s' % data.animation)
Expand Down
1 change: 0 additions & 1 deletion addons/anima/core/declaration/anima_declaration_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ func anima_on_completed(on_completed: FuncRef):
func debug():
_data.__debug = true

return self
Loading

0 comments on commit b61ee6f

Please sign in to comment.