@@ -19,8 +19,8 @@ var default_portrait_scene: PackedScene = load(get_script().resource_path.get_ba
19
19
## ##################################################################################################
20
20
21
21
func clear_game_state (_clear_flag := DialogicGameHandler .ClearFlags .FULL_CLEAR ) -> void :
22
- for character in dialogic .current_state_info .get ('portraits' , {}).keys ():
23
- remove_character (load ( character ))
22
+ for character_identifier in dialogic .current_state_info .get ('portraits' , {}).keys ():
23
+ remove_character (DialogicResourceUtil . get_character_resource ( character_identifier ))
24
24
dialogic .current_state_info ['portraits' ] = {}
25
25
26
26
@@ -315,7 +315,7 @@ func _change_portrait_z_index(character_node: Node, z_index:int, update_zindex:=
315
315
## fully visible yet.
316
316
func get_character_portrait (character : DialogicCharacter ) -> DialogicPortrait :
317
317
if is_character_joined (character ):
318
- var portrait_node : DialogicPortrait = dialogic .current_state_info ['portraits' ][character .resource_path ].node .get_child (- 1 )
318
+ var portrait_node : DialogicPortrait = dialogic .current_state_info ['portraits' ][character .get_identifier () ].node .get_child (- 1 )
319
319
return portrait_node
320
320
321
321
return null
@@ -411,14 +411,14 @@ func join_character(character:DialogicCharacter, portrait:String, position_id:S
411
411
if character_node == null :
412
412
return null
413
413
414
- dialogic .current_state_info ['portraits' ][character .resource_path ] = {'portrait' :portrait , 'node' :character_node , 'position_id' :position_id , 'custom_mirror' :mirrored }
414
+ dialogic .current_state_info ['portraits' ][character .get_identifier () ] = {'portrait' :portrait , 'node' :character_node , 'position_id' :position_id , 'custom_mirror' :mirrored }
415
415
416
416
_change_portrait_mirror (character_node , mirrored )
417
417
_change_portrait_extradata (character_node , extra_data )
418
418
_change_portrait_z_index (character_node , z_index )
419
419
420
420
var info := {'character' :character }
421
- info .merge (dialogic .current_state_info ['portraits' ][character .resource_path ])
421
+ info .merge (dialogic .current_state_info ['portraits' ][character .get_identifier () ])
422
422
character_joined .emit (info )
423
423
424
424
if animation_name .is_empty ():
@@ -452,30 +452,19 @@ func add_character(character: DialogicCharacter, container: DialogicNode_Portrai
452
452
printerr ('[DialogicError] Cannot call add_portrait() with null character.' )
453
453
return null
454
454
455
- ResourceLoader . load_threaded_request (character . resource_path )
455
+ var character_node := _create_character_node (character , container )
456
456
457
- var load_status = ResourceLoader .load_threaded_get_status (character .resource_path )
458
- while load_status == ResourceLoader .THREAD_LOAD_IN_PROGRESS :
459
- await get_tree ().process_frame
460
- load_status = ResourceLoader .load_threaded_get_status (character .resource_path )
461
-
462
- if load_status == ResourceLoader .THREAD_LOAD_LOADED :
463
- character = ResourceLoader .load_threaded_get (character .resource_path )
464
- var character_node := _create_character_node (character , container )
457
+ if character_node == null :
458
+ printerr ('[Dialogic] Failed to join character to position ' , position_id , ". Could not find position container." )
459
+ return null
465
460
466
- if character_node == null :
467
- printerr ('[Dialogic] Failed to join character to position ' , position_id , ". Could not find position container." )
468
- return null
461
+ dialogic .current_state_info ['portraits' ][character .get_identifier ()] = {'portrait' : portrait , 'node' : character_node , 'position_id' : position_id }
469
462
470
- dialogic .current_state_info ['portraits' ][character .resource_path ] = {'portrait' : portrait , 'node' : character_node , 'position_id' : position_id }
463
+ _move_character (character_node , position_id )
464
+ await _change_portrait (character_node , portrait )
471
465
472
- _move_character (character_node , position_id )
473
- await _change_portrait (character_node , portrait )
466
+ return character_node
474
467
475
- return character_node
476
- else :
477
- push_error ('[Dialogic] Failed to load character "' + str (character .resource_path ) + '".' )
478
- return null
479
468
480
469
## Changes the portrait of a character. Only works with joined characters.
481
470
func change_character_portrait (character : DialogicCharacter , portrait : String , fade_animation := "" , fade_length := - 1.0 ) -> void :
@@ -484,7 +473,7 @@ func change_character_portrait(character: DialogicCharacter, portrait: String, f
484
473
485
474
portrait = get_valid_portrait (character , portrait )
486
475
487
- if dialogic .current_state_info .portraits [character .resource_path ].portrait == portrait :
476
+ if dialogic .current_state_info .portraits [character .get_identifier () ].portrait == portrait :
488
477
return
489
478
490
479
if fade_animation == "" :
@@ -493,11 +482,11 @@ func change_character_portrait(character: DialogicCharacter, portrait: String, f
493
482
494
483
fade_animation = DialogicPortraitAnimationUtil .guess_animation (fade_animation , DialogicPortraitAnimationUtil .AnimationType .CROSSFADE )
495
484
496
- var info := await _change_portrait (dialogic .current_state_info .portraits [character .resource_path ].node , portrait , fade_animation , fade_length )
497
- dialogic .current_state_info .portraits [character .resource_path ].portrait = info .portrait
485
+ var info := await _change_portrait (dialogic .current_state_info .portraits [character .get_identifier () ].node , portrait , fade_animation , fade_length )
486
+ dialogic .current_state_info .portraits [character .get_identifier () ].portrait = info .portrait
498
487
_change_portrait_mirror (
499
- dialogic .current_state_info .portraits [character .resource_path ].node ,
500
- dialogic .current_state_info .portraits [character .resource_path ].get ('custom_mirror' , false )
488
+ dialogic .current_state_info .portraits [character .get_identifier () ].node ,
489
+ dialogic .current_state_info .portraits [character .get_identifier () ].get ('custom_mirror' , false )
501
490
)
502
491
character_portrait_changed .emit (info )
503
492
@@ -507,26 +496,26 @@ func change_character_mirror(character:DialogicCharacter, mirrored:= false, forc
507
496
if ! is_character_joined (character ):
508
497
return
509
498
510
- _change_portrait_mirror (dialogic .current_state_info .portraits [character .resource_path ].node , mirrored , force )
511
- dialogic .current_state_info .portraits [character .resource_path ]['custom_mirror' ] = mirrored
499
+ _change_portrait_mirror (dialogic .current_state_info .portraits [character .get_identifier () ].node , mirrored , force )
500
+ dialogic .current_state_info .portraits [character .get_identifier () ]['custom_mirror' ] = mirrored
512
501
513
502
514
503
## Changes the z_index of a character. Only works with joined characters
515
504
func change_character_z_index (character :DialogicCharacter , z_index :int , update_zindex := true ) -> void :
516
505
if ! is_character_joined (character ):
517
506
return
518
507
519
- _change_portrait_z_index (dialogic .current_state_info .portraits [character .resource_path ].node , z_index , update_zindex )
508
+ _change_portrait_z_index (dialogic .current_state_info .portraits [character .get_identifier () ].node , z_index , update_zindex )
520
509
if update_zindex :
521
- dialogic .current_state_info .portraits [character .resource_path ]['z_index' ] = z_index
510
+ dialogic .current_state_info .portraits [character .get_identifier () ]['z_index' ] = z_index
522
511
523
512
524
513
## Changes the extra data on the given character. Only works with joined characters
525
514
func change_character_extradata (character :DialogicCharacter , extra_data := "" ) -> void :
526
515
if ! is_character_joined (character ):
527
516
return
528
- _change_portrait_extradata (dialogic .current_state_info .portraits [character .resource_path ].node , extra_data )
529
- dialogic .current_state_info .portraits [character .resource_path ]['extra_data' ] = extra_data
517
+ _change_portrait_extradata (dialogic .current_state_info .portraits [character .get_identifier () ].node , extra_data )
518
+ dialogic .current_state_info .portraits [character .get_identifier () ]['extra_data' ] = extra_data
530
519
531
520
532
521
## Starts the given animation on the given character. Only works with joined characters
@@ -536,7 +525,7 @@ func animate_character(character: DialogicCharacter, animation_path: String, len
536
525
537
526
animation_path = DialogicPortraitAnimationUtil .guess_animation (animation_path )
538
527
539
- var character_node : Node = dialogic .current_state_info .portraits [character .resource_path ].node
528
+ var character_node : Node = dialogic .current_state_info .portraits [character .get_identifier () ].node
540
529
541
530
return _animate_node (character_node , animation_path , length , repeats , is_reversed )
542
531
@@ -546,11 +535,11 @@ func move_character(character:DialogicCharacter, position_id:String, time:= 0.0,
546
535
if ! is_character_joined (character ):
547
536
return
548
537
549
- if dialogic .current_state_info .portraits [character .resource_path ].position_id == position_id :
538
+ if dialogic .current_state_info .portraits [character .get_identifier () ].position_id == position_id :
550
539
return
551
540
552
- _move_character (dialogic .current_state_info .portraits [character .resource_path ].node , position_id , time , easing , trans )
553
- dialogic .current_state_info .portraits [character .resource_path ].position_id = position_id
541
+ _move_character (dialogic .current_state_info .portraits [character .get_identifier () ].node , position_id , time , easing , trans )
542
+ dialogic .current_state_info .portraits [character .get_identifier () ].position_id = position_id
554
543
character_moved .emit ({'character' :character , 'position_id' :position_id , 'time' :time })
555
544
556
545
@@ -592,8 +581,8 @@ func leave_all_characters(animation_name:="", animation_length:=0.0, animation_w
592
581
## Return `null` if the [param character] is not part of the scene.
593
582
func get_character_node (character : DialogicCharacter ) -> Node :
594
583
if is_character_joined (character ):
595
- if is_instance_valid (dialogic .current_state_info ['portraits' ][character .resource_path ].node ):
596
- return dialogic .current_state_info ['portraits' ][character .resource_path ].node
584
+ if is_instance_valid (dialogic .current_state_info ['portraits' ][character .get_identifier () ].node ):
585
+ return dialogic .current_state_info ['portraits' ][character .get_identifier () ].node
597
586
return null
598
587
599
588
@@ -609,12 +598,12 @@ func remove_character(character: DialogicCharacter) -> void:
609
598
character_node .queue_free ()
610
599
character_left .emit ({'character' : character })
611
600
612
- dialogic .current_state_info ['portraits' ].erase (character .resource_path )
601
+ dialogic .current_state_info ['portraits' ].erase (character .get_identifier () )
613
602
614
603
615
604
## Returns true if the given character is currently joined.
616
605
func is_character_joined (character : DialogicCharacter ) -> bool :
617
- if character == null or not character .resource_path in dialogic .current_state_info ['portraits' ]:
606
+ if character == null or not character .get_identifier () in dialogic .current_state_info ['portraits' ]:
618
607
return false
619
608
620
609
return true
@@ -624,8 +613,8 @@ func is_character_joined(character: DialogicCharacter) -> bool:
624
613
func get_joined_characters () -> Array [DialogicCharacter ]:
625
614
var chars : Array [DialogicCharacter ] = []
626
615
627
- for char_path : String in dialogic .current_state_info .get ('portraits' , {}).keys ():
628
- chars .append (load ( char_path ))
616
+ for char_identifier : String in dialogic .current_state_info .get ('portraits' , {}).keys ():
617
+ chars .append (DialogicResourceUtil . get_character_resource ( char_identifier ))
629
618
630
619
return chars
631
620
@@ -635,7 +624,7 @@ func get_joined_characters() -> Array[DialogicCharacter]:
635
624
## Only joined is included (and false) for not joined characters
636
625
func get_character_info (character :DialogicCharacter ) -> Dictionary :
637
626
if is_character_joined (character ):
638
- var info : Dictionary = dialogic .current_state_info ['portraits' ][character .resource_path ]
627
+ var info : Dictionary = dialogic .current_state_info ['portraits' ][character .get_identifier () ]
639
628
info ['joined' ] = true
640
629
return info
641
630
else :
@@ -672,18 +661,18 @@ func change_speaker(speaker: DialogicCharacter = null, portrait := "") -> void:
672
661
continue
673
662
674
663
if just_joined :
675
- ResourceLoader .load_threaded_request (speaker .resource_path )
664
+ ResourceLoader .load_threaded_request (speaker .get_identifier () )
676
665
677
- var load_status = ResourceLoader .load_threaded_get_status (speaker .resource_path )
666
+ var load_status = ResourceLoader .load_threaded_get_status (speaker .get_identifier () )
678
667
while load_status == ResourceLoader .THREAD_LOAD_IN_PROGRESS :
679
668
await get_tree ().process_frame
680
- load_status = ResourceLoader .load_threaded_get_status (speaker .resource_path )
669
+ load_status = ResourceLoader .load_threaded_get_status (speaker .get_identifier () )
681
670
682
671
if load_status == ResourceLoader .THREAD_LOAD_LOADED :
683
- speaker = ResourceLoader .load_threaded_get (speaker .resource_path )
672
+ speaker = ResourceLoader .load_threaded_get (speaker .get_identifier () )
684
673
_create_character_node (speaker , container )
685
674
else :
686
- push_error ('[Dialogic] Failed to load speaker "' + str (speaker .resource_path ) + '".' )
675
+ push_error ('[Dialogic] Failed to load speaker "' + str (speaker .get_identifier () ) + '".' )
687
676
continue
688
677
689
678
elif portrait .is_empty ():
@@ -728,10 +717,10 @@ func change_speaker(speaker: DialogicCharacter = null, portrait := "") -> void:
728
717
var prev_speaker : DialogicCharacter = dialogic .Text .get_current_speaker ()
729
718
if speaker != prev_speaker :
730
719
if is_character_joined (prev_speaker ):
731
- dialogic .current_state_info ["portraits" ][prev_speaker .resource_path ].node .get_child (- 1 )._unhighlight ()
720
+ dialogic .current_state_info ["portraits" ][prev_speaker .get_identifier () ].node .get_child (- 1 )._unhighlight ()
732
721
733
722
if is_character_joined (speaker ):
734
- dialogic .current_state_info ["portraits" ][speaker .resource_path ].node .get_child (- 1 )._highlight ()
723
+ dialogic .current_state_info ["portraits" ][speaker .get_identifier () ].node .get_child (- 1 )._highlight ()
735
724
736
725
#endregion
737
726
0 commit comments