Skip to content

Commit 1253881

Browse files
committed
Add infinite repeat as a QOL option to update animations
Fix for #2651
1 parent 0dd7da2 commit 1253881

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

addons/dialogic/Modules/Character/class_dialogic_animation.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var base_scale: Vector2
2222

2323
## Used to repeate the animation for a number of times.
2424
var repeats: int
25+
var repeat_forever : bool = false
2526

2627
## If `true`, the animation will be reversed.
2728
## This must be implemented by each animation or it will have no effect.
@@ -43,7 +44,7 @@ func animate() -> void:
4344
func finished_one_loop() -> void:
4445
repeats -= 1
4546

46-
if repeats > 0:
47+
if repeats > 0 or repeat_forever:
4748
animate()
4849

4950
else:

addons/dialogic/Modules/Character/event_character.gd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var animation_name := ""
2626
var animation_length: float = 0.5
2727
## How often the animation is repeated. Only for Update events.
2828
var animation_repeats: int = 1
29+
var repeat_forever: bool = false
2930
## If true, the events waits for the animation to finish before the next event starts.
3031
var animation_wait := false
3132

@@ -175,15 +176,17 @@ func _execute() -> void:
175176
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
176177
var time_for_repetitions: float = time_per_event / animation_repeats
177178
final_animation_length = time_for_repetitions
178-
179+
179180
var animation := dialogic.Portraits.animate_character(
180181
character,
181182
animation_name,
182183
final_animation_length,
183184
final_animation_repetitions,
185+
false,
186+
repeat_forever
184187
)
185188

186-
if animation_wait:
189+
if animation_wait and !repeat_forever:
187190
dialogic.current_state = DialogicGameHandler.States.ANIMATING
188191
await animation.finished
189192
dialogic.current_state = DialogicGameHandler.States.IDLE
@@ -315,6 +318,7 @@ func get_shortcode_parameters() -> Dictionary:
315318
"length" : {"property": "animation_length", "default": 0.5},
316319
"wait" : {"property": "animation_wait", "default": false},
317320
"repeat" : {"property": "animation_repeats", "default": 1},
321+
"repeat_forever" : {"property": "repeat_forever", "default": false},
318322

319323
"z_index" : {"property": "z_index", "default": 0},
320324
"mirrored" : {"property": "mirrored", "default": false},
@@ -415,6 +419,8 @@ func build_event_editor() -> void:
415419
'should_show_animation_options() and !animation_name.is_empty()')
416420
add_body_edit('animation_repeats', ValueType.NUMBER, {'left_text':'Repeat:', 'mode':1, "min":1},
417421
'should_show_animation_options() and !animation_name.is_empty() and action == %s)' %Actions.UPDATE)
422+
add_body_edit('repeat_forever', ValueType.BOOL, {'left_text':'Repeat Forever:'},
423+
'should_show_animation_options() and !animation_name.is_empty() and action == %s)' %Actions.UPDATE)
418424
add_body_line_break()
419425
add_body_edit('transform_time', ValueType.NUMBER, {'left_text':'Movement duration:', "min":0, "tooltip": "When changing the characters position, this is how fast it will happen."},
420426
"should_show_transform_options()")

addons/dialogic/Modules/Character/subsystem_portraits.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func _update_portrait_transform(portrait_node: Node, time:float = 0.0) -> void:
248248

249249
## Animates the node with the given animation.
250250
## Is used both on the character node (most animations) and the portrait nodes (cross-fade animations)
251-
func _animate_node(node: Node, animation_path: String, length: float, repeats := 1, is_reversed := false) -> DialogicAnimation:
251+
func _animate_node(node: Node, animation_path: String, length: float, repeats := 1, is_reversed := false, repeat_forever := false) -> DialogicAnimation:
252252
if node.has_meta('animation_node') and is_instance_valid(node.get_meta('animation_node')):
253253
node.get_meta('animation_node').queue_free()
254254

@@ -261,6 +261,7 @@ func _animate_node(node: Node, animation_path: String, length: float, repeats :=
261261
anim_node.base_scale = node.scale
262262
anim_node.time = length
263263
anim_node.repeats = repeats
264+
anim_node.repeat_forever = repeat_forever
264265
anim_node.is_reversed = is_reversed
265266

266267
add_child(anim_node)
@@ -516,15 +517,14 @@ func change_character_extradata(character:DialogicCharacter, extra_data:="") ->
516517

517518

518519
## Starts the given animation on the given character. Only works with joined characters
519-
func animate_character(character: DialogicCharacter, animation_path: String, length: float, repeats := 1, is_reversed := false) -> DialogicAnimation:
520+
func animate_character(character: DialogicCharacter, animation_path: String, length: float, repeats := 1, is_reversed := false, repeat_forever := false) -> DialogicAnimation:
520521
if not is_character_joined(character):
521522
return null
522-
523+
523524
animation_path = DialogicPortraitAnimationUtil.guess_animation(animation_path)
524525

525526
var character_node: Node = dialogic.current_state_info.portraits[character.get_identifier()].node
526-
527-
return _animate_node(character_node, animation_path, length, repeats, is_reversed)
527+
return _animate_node(character_node, animation_path, length, repeats, is_reversed, repeat_forever)
528528

529529

530530
## Moves the given character to the given position. Only works with joined characters

0 commit comments

Comments
 (0)