Skip to content

Commit

Permalink
add @viewport_rect for dynamic sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Sep 19, 2023
1 parent 9a01cb8 commit 7a4b9b2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
8 changes: 7 additions & 1 deletion addons/anima/utils/node_properties.gd
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static func set_2D_pivot(node: Node, pivot: int) -> void:
node.global_position = position - node.offset
_:
pass
# printerr('Pivot point not handled yet')

static func get_property_value(node: Node, animation_data: Dictionary, property = null):
if property == null:
Expand Down Expand Up @@ -174,6 +173,13 @@ static func get_property_value(node: Node, animation_data: Dictionary, property
node_property_name = property_name
elif rect_property_name in node:
node_property_name = rect_property_name
elif property_name == "@viewport_rect":
var rect = node.get_viewport_rect()

if subkey == "x":
return rect.size.x
else:
return rect.size.y

if p[0] == 'shader_param':
var material: ShaderMaterial
Expand Down
18 changes: 9 additions & 9 deletions addons/anima/utils/tween_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ static func calculate_dynamic_value(value, animation_data: Dictionary):
else:
values_to_check = value

var regex := RegEx.new()
regex.compile("([\\.:\\/]*[a-zA-Z]*:[a-z]*:?[^\\s]+)")
var DYNAMIC_EXTRACTOR_REGEX := RegEx.new()
DYNAMIC_EXTRACTOR_REGEX.compile("(@?[\\.:\\/]*[a-zA-Z_]*:[a-z]*:?[^\\s\\)]+)")

var all_results := []
var root = animation_data.node
Expand All @@ -108,21 +108,25 @@ static func calculate_dynamic_value(value, animation_data: Dictionary):
if single_formula == "":
single_formula = "0.0"

var results := regex.search_all(single_formula)
var results := DYNAMIC_EXTRACTOR_REGEX.search_all(single_formula)
var variables := []
var values := []

results.reverse()

for index in results.size():
var rm: RegExMatch = results[index]
var info: Array = rm.get_string().split(":")
var regex_result = rm.get_string()
var info: Array = regex_result.split(":")
var source = info.pop_front()
var source_node: Node
var property: String = ":".join(PackedStringArray(info))


if source == '' or source == '.':
source_node = animation_data.node
elif source[0] == '@':
source_node = animation_data.node
property = regex_result
else:
source_node = root.get_node(source)

Expand All @@ -131,16 +135,12 @@ static func calculate_dynamic_value(value, animation_data: Dictionary):

return value

var property: String = ":".join(PackedStringArray(info))

var property_value = AnimaNodesProperties.get_property_value(source_node, animation_data, property)
var variable := char(65 + index)

variables.push_back(variable)
values.push_back(property_value)

# single_formula.erase(rm.get_start(), rm.get_end() - rm.get_start())
# single_formula = single_formula.insert(rm.get_start(), variable)
single_formula = "%s%s%s" % [single_formula.substr(0, rm.get_start()), variable, single_formula.substr(rm.get_end())]

var expression := Expression.new()
Expand Down
Binary file added docs/static/img/anima.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/examples/parallel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/examples/then.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/hide_strategy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/popup.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a4b9b2

Please sign in to comment.