diff --git a/addons/anima/core/declaration/anima_declaration_base.gd b/addons/anima/core/declaration/anima_declaration_base.gd deleted file mode 100644 index 42dfa69..0000000 --- a/addons/anima/core/declaration/anima_declaration_base.gd +++ /dev/null @@ -1,231 +0,0 @@ -extends Object -class_name AnimaDeclarationBase - -var _data := {} -var _is_single_shot := true -var _anima_node: AnimaNode - -enum PlayAction { - PLAY, - PLAY_WITH_DELAY, - PLAY_WITH_SPEED, - PLAY_BACKWARDS, - PLAY_BACKWARDS_WITH_DELAY, - PLAY_BACKWARDS_WITH_SPEED, - LOOP, - LOOP_IN_CIRCLE, - LOOP_IN_CIRCLE_WITH_DELAY, - LOOP_IN_CIRCLE_WITH_SPEED, - LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED, - LOOP_BACKWARDS, - LOOP_BACKWARDS_WITH_SPEED, - LOOP_BACKWARDS_WITH_DELAY, - LOOP_BACKWARDS_WITH_DELAY_AND_SPEED, - LOOP_WITH_DELAY, - LOOP_WITH_SPEED, - LOOP_TIMES_WITH_DELAY, - LOOP_TIMES_WITH_DELAY_AND_SPEED -} - -func clear(): - _anima_node.clear() - -func get_data() -> Dictionary: - return _data - -func _init_me(data: Dictionary): - for key in data: - var value = data[key] - - if value != null: - _data[key] = data[key] - -func anima_from(from) -> Variant: - if from == null: - return self - - _data.from = from - - return self - -func anima_to(to) -> Variant: - if to == null: - return self - - _data.to = to - - return self - -func anima_delay(delay: float) -> Variant: - _data.delay = delay - - return self - -func anima_visibility_strategy(strategy: int) -> Variant: - _data.visibility_strategy = strategy - - return self - -func anima_initial_value(initial_value) -> Variant: - var values := {} - values[_data.property] = initial_value - - _data.initial_values = values - - return self - -func anima_on_started(target: Callable, on_started_value = null, on_backwards_completed_value = null) -> Variant: - if typeof(on_started_value) != TYPE_ARRAY: - if on_started_value == null: - on_started_value = [] - else: - on_started_value = [on_started_value] - - if typeof(on_backwards_completed_value) != TYPE_ARRAY: - if on_backwards_completed_value == null: - on_backwards_completed_value = [] - else: - on_backwards_completed_value = [on_backwards_completed_value] - - _data.on_started = { - target = target, - value = on_started_value, - backwards_value = on_backwards_completed_value - } - - return self - -func anima_on_completed(target: Callable, on_completed_value = null, on_backwards_completed_value = null) -> Variant: - _data.on_completed = { - target = target, - value = on_completed_value, - backwards_value = on_backwards_completed_value - } - - return self - -func as_reusable() -> Variant: - _is_single_shot = false - - return self - -func debug(what = "---") -> Variant: - _data.__debug = what - - return self - -func __get_source(): - if _data.has("node"): - return _data.node - elif _data.has("grid"): - return _data.grid - elif _data.has("group"): - return _data.group - - return null - -func _do_play(action: PlayAction, param = null) -> AnimaNode: - if _anima_node == null: - _anima_node = Anima.begin(__get_source()).then(_data) - - var single_shot = _is_single_shot if action < PlayAction.LOOP else false - _anima_node.set_single_shot(single_shot) - - match action: - PlayAction.PLAY: - _anima_node.play() - PlayAction.PLAY_WITH_DELAY: - _anima_node.play_with_delay(param) - PlayAction.PLAY_WITH_SPEED: - _anima_node.play_with_speed(param) - PlayAction.PLAY_BACKWARDS: - _anima_node.play_backwards() - PlayAction.PLAY_BACKWARDS_WITH_DELAY: - _anima_node.play_backwards_with_delay(param) - PlayAction.PLAY_BACKWARDS_WITH_SPEED: - _anima_node.play_backwards_with_speed(param) - PlayAction.LOOP: - _anima_node.loop(param) - PlayAction.LOOP_IN_CIRCLE: - _anima_node.loop_in_circle(param) - PlayAction.LOOP_IN_CIRCLE_WITH_DELAY: - _anima_node.loop_in_circle_with_delay(param) - PlayAction.LOOP_IN_CIRCLE_WITH_SPEED: - _anima_node.loop_in_circle_with_speed(param.speed, param.times) - PlayAction.LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED: - _anima_node.loop_in_circle_with_delay_and_speed(param.delay, param.speed, param.times) - PlayAction.LOOP_BACKWARDS: - _anima_node.loop_backwards(param) - PlayAction.LOOP_BACKWARDS_WITH_SPEED: - _anima_node.loop_backwards_with_speed(param.speed, param.times) - PlayAction.LOOP_BACKWARDS_WITH_DELAY: - _anima_node.loop_with_delay(param.delay, param.times) - PlayAction.LOOP_BACKWARDS_WITH_DELAY_AND_SPEED: - _anima_node.loop_times_with_delay_and_speed(param.times, param.delay, param.speed) - PlayAction.LOOP_WITH_DELAY: - _anima_node.loop_with_delay(param.delay, param.times) - PlayAction.LOOP_WITH_SPEED: - _anima_node.loop_with_speed(param.speed, param.times) - PlayAction.LOOP_TIMES_WITH_DELAY: - _anima_node.loop_times_with_delay(param.times, param.delay) - PlayAction.LOOP_TIMES_WITH_DELAY_AND_SPEED: - _anima_node.loop_times_with_delay_and_speed(param.times, param.delay, param.speed) - - return _anima_node - -func play() -> AnimaNode: - return _do_play(PlayAction.PLAY) - -func play_with_delay(delay: float) -> AnimaNode: - return _do_play(PlayAction.PLAY_WITH_DELAY, delay) - -func play_with_speed(speed: float) -> AnimaNode: - return _do_play(PlayAction.PLAY_BACKWARDS_WITH_SPEED, speed) - -func play_backwards() -> AnimaNode: - return _do_play(PlayAction.PLAY_BACKWARDS) - -func play_backwards_with_delay(delay: float) -> AnimaNode: - return _do_play(PlayAction.PLAY_BACKWARDS_WITH_DELAY, delay) - -func play_backwards_with_speed(speed: float) -> AnimaNode: - return _do_play(PlayAction.PLAY_BACKWARDS_WITH_SPEED, speed) - -func loop(times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP, times) - -func loop_in_circle(times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_IN_CIRCLE, times) - -func loop_in_circle_with_delay(delay: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_DELAY, times) - -func loop_in_circle_with_speed(speed: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_SPEED, { times = times, speed = speed }) - -func loop_in_circle_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) - -func loop_backwards(times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_BACKWARDS, times) - -func loop_backwards_with_speed(speed: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_BACKWARDS_WITH_SPEED, { times = times, speed = speed }) - -func loop_backwards_with_delay(delay: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_BACKWARDS_WITH_DELAY, { times = times, delay = delay }) - -func loop_backwards_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_BACKWARDS_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) - -func loop_with_delay(delay: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_WITH_DELAY, { times = times, delay = delay }) - -func loop_with_speed(speed: float, times: int = -1) -> AnimaNode: - return _do_play(PlayAction.LOOP_WITH_SPEED, { times = times, speed = speed }) - -func loop_times_with_delay(times: float, delay: float) -> AnimaNode: - return _do_play(PlayAction.LOOP_TIMES_WITH_DELAY, { times = times, delay = delay }) - -func loop_times_with_delay_and_speed(times: int, delay: float, speed: float) -> AnimaNode: - return _do_play(PlayAction.LOOP_TIMES_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) diff --git a/addons/anima/core/declaration/anima_declaration_for_animation.gd b/addons/anima/core/declaration/anima_declaration_for_animation.gd index 13ca344..b82a5c6 100644 --- a/addons/anima/core/declaration/anima_declaration_for_animation.gd +++ b/addons/anima/core/declaration/anima_declaration_for_animation.gd @@ -1,5 +1,5 @@ class_name AnimaDeclarationForAnimation -extends AnimaDeclarationBase +extends AnimaDeclarationForBase # We can't use _init otherwise Godot complains with this nonsense # Too few arguments for "_init()". Expected at least 1 diff --git a/addons/anima/core/declaration/anima_declaration_for_base.gd b/addons/anima/core/declaration/anima_declaration_for_base.gd new file mode 100644 index 0000000..2e9d0f0 --- /dev/null +++ b/addons/anima/core/declaration/anima_declaration_for_base.gd @@ -0,0 +1,144 @@ +extends Object +class_name AnimaDeclarationForBase + +var _parent_class + +func _add(key, value): + _parent_class._add(key, value) + +func get_data() -> Dictionary: + return _parent_class.get_data() + +func _init(parent_class): + _parent_class = parent_class + +func _init_me(data: Dictionary): + for key in data: + var value = data[key] + + if value != null: + _parent_class._add(key, data[key]) + +func anima_from(from) -> Variant: + if from == null: + return self + + _parent_class._add("from", from) + + return self + +func anima_to(to) -> Variant: + if to == null: + return self + + _parent_class._add("to", to) + + return self + +func anima_delay(delay: float) -> Variant: + _parent_class._add("delay", delay) + + return self + +func anima_visibility_strategy(strategy: int) -> Variant: + _parent_class._add("visibility_strategy", strategy) + + return self + +func anima_initial_value(initial_value) -> Variant: + var values := {} + values[_parent_class.get("property")] = initial_value + + _parent_class._add("initial_values", values) + + return self + +func anima_on_started(target: Callable, on_started_value = null, on_backwards_completed_value = null) -> Variant: + if typeof(on_started_value) != TYPE_ARRAY: + if on_started_value == null: + on_started_value = [] + else: + on_started_value = [on_started_value] + + if typeof(on_backwards_completed_value) != TYPE_ARRAY: + if on_backwards_completed_value == null: + on_backwards_completed_value = [] + else: + on_backwards_completed_value = [on_backwards_completed_value] + + _parent_class._add("on_started", { + target = target, + value = on_started_value, + backwards_value = on_backwards_completed_value + }) + + return self + +func anima_on_completed(target: Callable, on_completed_value = null, on_backwards_completed_value = null) -> Variant: + _parent_class._add("on_completed", { + target = target, + value = on_completed_value, + backwards_value = on_backwards_completed_value + }) + + return self + +func anima_with() -> AnimaDeclarationNode: + return _parent_class._with() + +func play() -> AnimaNode: + return _parent_class.play() + +func play_with_delay(delay: float) -> AnimaNode: + return _parent_class.play_with_delay(delay) + +func play_with_speed(speed: float) -> AnimaNode: + return _parent_class.play_with_speed(speed) + +func play_backwards() -> AnimaNode: + return _parent_class.play_backwards() + +func play_backwards_with_delay(delay: float) -> AnimaNode: + return _parent_class.play_backwards_with_delay(delay) + +func play_backwards_with_speed(speed: float) -> AnimaNode: + return _parent_class.play_backwards_with_speed(speed) + +func loop(times: int = -1) -> AnimaNode: + return _parent_class.loop(times) + +func loop_in_circle(times: int = -1) -> AnimaNode: + return _parent_class.loop_in_circle(times) + +func loop_in_circle_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_in_circle_with_delay(delay, times) + +func loop_in_circle_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_in_circle_with_speed(speed, times) + +func loop_in_circle_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_in_circle_with_delay_and_speed(delay, speed, times) + +func loop_backwards(times: int = -1) -> AnimaNode: + return _parent_class.loop_backwards(times) + +func loop_backwards_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_backwards_with_speed(speed, times) + +func loop_backwards_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_backwards_with_delay(delay, times) + +func loop_backwards_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_backwards_with_delay_and_speed(delay, speed, times) + +func loop_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_with_delay(delay, times) + +func loop_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _parent_class.loop_with_speed(speed, times) + +func loop_times_with_delay(times: float, delay: float) -> AnimaNode: + return _parent_class.loop_times_with_delay(times, delay) + +func loop_times_with_delay_and_speed(times: int, delay: float, speed: float) -> AnimaNode: + return _parent_class.loop_times_with_delay_and_speed(times, delay, speed) diff --git a/addons/anima/core/declaration/anima_declaration_for_property.gd b/addons/anima/core/declaration/anima_declaration_for_property.gd index d7ae8b0..bc9d31a 100644 --- a/addons/anima/core/declaration/anima_declaration_for_property.gd +++ b/addons/anima/core/declaration/anima_declaration_for_property.gd @@ -1,5 +1,5 @@ class_name AnimaDeclarationForProperty -extends AnimaDeclarationBase +extends AnimaDeclarationForBase # We can't use _init otherwise Godot complains with this nonsense # Too few arguments for "_init()". Expected at least 1 @@ -9,17 +9,17 @@ func _init_me(data: Dictionary) -> AnimaDeclarationForProperty: return self func anima_as_relative() -> AnimaDeclarationForProperty: - self._data.relative = true - + super._add("relative", true) + return self func anima_easing(easing) -> AnimaDeclarationForProperty: - self._data.easing = easing + super._add("easing", easing) return self func anima_pivot(pivot: int) -> AnimaDeclarationForProperty: - self._data.pivot = pivot + super._add("pivot", pivot) return self diff --git a/addons/anima/core/declaration/anima_declaration_for_relative_property.gd b/addons/anima/core/declaration/anima_declaration_for_relative_property.gd index c38cbc0..a57c456 100644 --- a/addons/anima/core/declaration/anima_declaration_for_relative_property.gd +++ b/addons/anima/core/declaration/anima_declaration_for_relative_property.gd @@ -1,5 +1,5 @@ class_name AnimaDeclarationForRelativeProperty -extends AnimaDeclarationBase +extends AnimaDeclarationForBase # We can't use _init otherwise Godot complains with this nonsense # Too few arguments for "_init()". Expected at least 1 diff --git a/addons/anima/core/declaration/anima_declaration_node.gd b/addons/anima/core/declaration/anima_declaration_node.gd index 307f33d..2d8cb7d 100644 --- a/addons/anima/core/declaration/anima_declaration_node.gd +++ b/addons/anima/core/declaration/anima_declaration_node.gd @@ -1,51 +1,74 @@ class_name AnimaDeclarationNode var _data := {} + +var _target_data = _data var _anima_declaration +var _anima_node: AnimaNode +var _is_single_shot := true + +enum PlayAction { + PLAY, + PLAY_WITH_DELAY, + PLAY_WITH_SPEED, + PLAY_BACKWARDS, + PLAY_BACKWARDS_WITH_DELAY, + PLAY_BACKWARDS_WITH_SPEED, + LOOP, + LOOP_IN_CIRCLE, + LOOP_IN_CIRCLE_WITH_DELAY, + LOOP_IN_CIRCLE_WITH_SPEED, + LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED, + LOOP_BACKWARDS, + LOOP_BACKWARDS_WITH_SPEED, + LOOP_BACKWARDS_WITH_DELAY, + LOOP_BACKWARDS_WITH_DELAY_AND_SPEED, + LOOP_WITH_DELAY, + LOOP_WITH_SPEED, + LOOP_TIMES_WITH_DELAY, + LOOP_TIMES_WITH_DELAY_AND_SPEED +} func _init(node: Node = null): _data.clear() + _target_data = _data + + _target_data.node = node - _data.node = node +func _set_data(data: Dictionary): + _target_data = data -func _set_data(data: Dictionary) -> void: - _data = data + return self func _clear_data(): - _init(_data.node) + _init(_target_data.node) func _create_declaration_for_animation(data: Dictionary) -> AnimaDeclarationForAnimation: - var c:= AnimaDeclarationForAnimation.new() - - _clear_data() + var c:= AnimaDeclarationForAnimation.new(self) for key in data: - _data[key] = data[key] + _target_data[key] = data[key] - return c._init_me(_data) + return c._init_me(_target_data) func _create_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForProperty: - if _anima_declaration: - _anima_declaration.clear() + var c:= AnimaDeclarationForProperty.new(self) - var c:= AnimaDeclarationForProperty.new() - - _clear_data() + if data.has("duration") and data.duration == null and _target_data.has("duration"): + data.duration = _target_data.duration for key in data: - _data[key] = data[key] + _target_data[key] = data[key] - return c._init_me(_data) + return c._init_me(_target_data) func _create_relative_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForRelativeProperty: - var c:= AnimaDeclarationForRelativeProperty.new() - - _clear_data() + var c:= AnimaDeclarationForRelativeProperty.new(self) for key in data: - _data[key] = data[key] + _target_data[key] = data[key] - return c._init_me(_data) + return c._init_me(_target_data) func anima_animation(animation: String, duration = null) -> AnimaDeclarationForAnimation: _anima_declaration = _create_declaration_for_animation({ animation = animation, duration = duration }) @@ -203,5 +226,169 @@ func anima_shader_param(param_name: String, to_value, duration = null) -> AnimaD return _anima_declaration func clear(): - if _anima_declaration: - _anima_declaration.clear() + if _anima_node and is_instance_valid(_anima_node): + _anima_node.clear() + + return self + +func _with(): + if not _target_data.has("_with"): + _target_data._with = {} + + if _target_data.has("node"): + _target_data._with.node = _target_data.node + elif _target_data.has("grid"): + _target_data._with.grid = _target_data.grid + elif _target_data.has("group"): + _target_data._with.group = _target_data.group + + var has_duration = _target_data.has("duration") + var duration = _target_data.duration if has_duration else null + + if has_duration: + _target_data._with.duration = duration + + _target_data = _target_data._with + + return self + +func as_reusable() -> Variant: + _is_single_shot = false + + return self + +func debug(what = "---") -> Variant: + _data.__debug = what + + return self + +func __get_source(): + if _data.has("node"): + return _data.node + elif _data.has("grid"): + return _data.grid + elif _data.has("group"): + return _data.group + + return null + +func _init_anima_node(data, mode): + if _anima_node == null: + _anima_node = Anima.begin(__get_source()) + + if mode == "with": + _anima_node.with(data) + + if data.has("_with"): + _init_anima_node(data._with, "with") + +func _do_play(action: PlayAction, param = null) -> AnimaNode: + _init_anima_node(_data, "with") + + var single_shot = _is_single_shot if action < PlayAction.LOOP else false + _anima_node.set_single_shot(single_shot) + + match action: + PlayAction.PLAY: + _anima_node.play() + PlayAction.PLAY_WITH_DELAY: + _anima_node.play_with_delay(param) + PlayAction.PLAY_WITH_SPEED: + _anima_node.play_with_speed(param) + PlayAction.PLAY_BACKWARDS: + _anima_node.play_backwards() + PlayAction.PLAY_BACKWARDS_WITH_DELAY: + _anima_node.play_backwards_with_delay(param) + PlayAction.PLAY_BACKWARDS_WITH_SPEED: + _anima_node.play_backwards_with_speed(param) + PlayAction.LOOP: + _anima_node.loop(param) + PlayAction.LOOP_IN_CIRCLE: + _anima_node.loop_in_circle(param) + PlayAction.LOOP_IN_CIRCLE_WITH_DELAY: + _anima_node.loop_in_circle_with_delay(param) + PlayAction.LOOP_IN_CIRCLE_WITH_SPEED: + _anima_node.loop_in_circle_with_speed(param.speed, param.times) + PlayAction.LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED: + _anima_node.loop_in_circle_with_delay_and_speed(param.delay, param.speed, param.times) + PlayAction.LOOP_BACKWARDS: + _anima_node.loop_backwards(param) + PlayAction.LOOP_BACKWARDS_WITH_SPEED: + _anima_node.loop_backwards_with_speed(param.speed, param.times) + PlayAction.LOOP_BACKWARDS_WITH_DELAY: + _anima_node.loop_with_delay(param.delay, param.times) + PlayAction.LOOP_BACKWARDS_WITH_DELAY_AND_SPEED: + _anima_node.loop_times_with_delay_and_speed(param.times, param.delay, param.speed) + PlayAction.LOOP_WITH_DELAY: + _anima_node.loop_with_delay(param.delay, param.times) + PlayAction.LOOP_WITH_SPEED: + _anima_node.loop_with_speed(param.speed, param.times) + PlayAction.LOOP_TIMES_WITH_DELAY: + _anima_node.loop_times_with_delay(param.times, param.delay) + PlayAction.LOOP_TIMES_WITH_DELAY_AND_SPEED: + _anima_node.loop_times_with_delay_and_speed(param.times, param.delay, param.speed) + + return _anima_node + +func play() -> AnimaNode: + return _do_play(PlayAction.PLAY) + +func play_with_delay(delay: float) -> AnimaNode: + return _do_play(PlayAction.PLAY_WITH_DELAY, delay) + +func play_with_speed(speed: float) -> AnimaNode: + return _do_play(PlayAction.PLAY_BACKWARDS_WITH_SPEED, speed) + +func play_backwards() -> AnimaNode: + return _do_play(PlayAction.PLAY_BACKWARDS) + +func play_backwards_with_delay(delay: float) -> AnimaNode: + return _do_play(PlayAction.PLAY_BACKWARDS_WITH_DELAY, delay) + +func play_backwards_with_speed(speed: float) -> AnimaNode: + return _do_play(PlayAction.PLAY_BACKWARDS_WITH_SPEED, speed) + +func loop(times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP, times) + +func loop_in_circle(times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_IN_CIRCLE, times) + +func loop_in_circle_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_DELAY, times) + +func loop_in_circle_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_SPEED, { times = times, speed = speed }) + +func loop_in_circle_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_IN_CIRCLE_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) + +func loop_backwards(times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_BACKWARDS, times) + +func loop_backwards_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_BACKWARDS_WITH_SPEED, { times = times, speed = speed }) + +func loop_backwards_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_BACKWARDS_WITH_DELAY, { times = times, delay = delay }) + +func loop_backwards_with_delay_and_speed(delay: float, speed: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_BACKWARDS_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) + +func loop_with_delay(delay: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_WITH_DELAY, { times = times, delay = delay }) + +func loop_with_speed(speed: float, times: int = -1) -> AnimaNode: + return _do_play(PlayAction.LOOP_WITH_SPEED, { times = times, speed = speed }) + +func loop_times_with_delay(times: float, delay: float) -> AnimaNode: + return _do_play(PlayAction.LOOP_TIMES_WITH_DELAY, { times = times, delay = delay }) + +func loop_times_with_delay_and_speed(times: int, delay: float, speed: float) -> AnimaNode: + return _do_play(PlayAction.LOOP_TIMES_WITH_DELAY_AND_SPEED, { times = times, delay = delay, speed = speed }) + +func _add(key, value) -> void: + _target_data[key] = value + +func _get(key) -> Variant: + return _target_data[key] diff --git a/addons/anima/core/declaration/anima_declaration_nodes.gd b/addons/anima/core/declaration/anima_declaration_nodes.gd index cda0c98..bec2449 100644 --- a/addons/anima/core/declaration/anima_declaration_nodes.gd +++ b/addons/anima/core/declaration/anima_declaration_nodes.gd @@ -1,6 +1,5 @@ class_name AnimaDeclarationNodes - -var _data: Dictionary +extends AnimaDeclarationNode func _init(nodes, items_delay: float): _data.items_delay = items_delay @@ -28,123 +27,3 @@ func _init(nodes, items_delay: float): func _can_add_node(child) -> bool: return "visible" in child and child.visible - -func _set_data(data: Dictionary) -> void: - _data = data - -func _create_declaration_for_animation(data: Dictionary) -> AnimaDeclarationForAnimation: - var c:= AnimaDeclarationForAnimation.new() - - for key in data: - _data[key] = data[key] - - return c._init_me(_data) - -func _create_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForProperty: - var c:= AnimaDeclarationForProperty.new() - - for key in data: - _data[key] = data[key] - - return c._init_me(_data) - -func _create_relative_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForRelativeProperty: - var c:= AnimaDeclarationForRelativeProperty.new() - - for key in data: - _data[key] = data[key] - - return c._init_me(_data) - -func anima_animation(animation: String, duration = null) -> AnimaDeclarationForAnimation: - return _create_declaration_for_animation({ animation = animation, duration = duration }) - -func anima_animation_frames(frames: Dictionary, duration = null) -> AnimaDeclarationForAnimation: - return _create_declaration_for_animation({ animation = frames, duration = duration }) - -func anima_property(property: String, final_value = null, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = property, to = final_value, duration = duration }) - -func anima_fade_in(duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "opacity", from = 0.0, to = 1.0, duration = duration }) - -func anima_fade_out(duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "opacity", from = 1.0, to = 0.0, duration = duration }) - -func anima_position(position: Vector2, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "position", to = position, duration = duration }) - -func anima_position3D(position: Vector3, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "position", to = position, duration = duration }) - -func anima_position_x(x: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "x", to = x, duration = duration }) - -func anima_position_y(y: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "y", to = y, duration = duration }) - -func anima_position_z(z: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "z", to = z, duration = duration }) - -func anima_relative_position(position: Vector2, duration = null) -> AnimaDeclarationForRelativeProperty: - return _create_relative_declaration_with_easing({ property = "position", to = position, duration = duration, relative = true }) - -func anima_relative_position3D(position: Vector3, duration = null) -> AnimaDeclarationForRelativeProperty: - return _create_relative_declaration_with_easing({ property = "position", to = position, duration = duration, relative = true }) - -func anima_relative_position_x(x: float, duration = null) -> AnimaDeclarationForRelativeProperty: - return _create_relative_declaration_with_easing({ property = "x", to = x, duration = duration, relative = true }) - -func anima_relative_position_y(y: float, duration = null) -> AnimaDeclarationForRelativeProperty: - return _create_relative_declaration_with_easing({ property = "y", to = y, duration = duration, relative = true }) - -func anima_relative_position_z(z: float, duration = null) -> AnimaDeclarationForRelativeProperty: - return _create_relative_declaration_with_easing({ property = "z", to = z, duration = duration, relative = true }) - -func anima_scale(scale: Vector2, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "scale", to = scale, duration = duration }) - -func anima_scale3D(scale: Vector3, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "scale", to = scale, duration = duration }) - -func anima_scale_x(x: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "scale:x", to = x, duration = duration }) - -func anima_scale_y(y: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "scale:y", to = y, duration = duration }) - -func anima_scale_z(z: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "scale:z", to = z, duration = duration }) - -func anima_size(size: Vector2, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "size", to = size, duration = duration }) - -func anima_size3D(size: Vector3, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "size", to = size, duration = duration }) - -func anima_size_x(size: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "size:x", to = size, duration = duration }) - -func anima_size_y(size: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "size:y", to = size, duration = duration }) - -func anima_size_z(size: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "size:z", to = size, duration = duration }) - -func anima_rotate(rotate: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "rotate", to = rotate, duration = duration }) - -func anima_rotate3D(rotate: Vector3, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "rotation", to = rotate, duration = duration }) - -func anima_rotate_x(x: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "rotation:x", to = x, duration = duration }) - -func anima_rotate_y(y: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "rotation:y", to = y, duration = duration }) - -func anima_rotate_z(z: float, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "rotation:z", to = z, duration = duration }) - -func anima_shader_param(param_name: String, to_value, duration = null) -> AnimaDeclarationForProperty: - return _create_declaration_with_easing({ property = "shader_param:" + param_name, to = to_value, duration = duration })