From 581ac433b406a055bc1deb1f697d6f446a78e702 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Tue, 23 Jan 2024 15:04:19 +0100 Subject: [PATCH 1/3] Some renames and lot's of small code-cleanup --- .../portraits/simple_highlight_portrait.gd | 2 +- .../dialogic/Modules/Audio/subsystem_audio.gd | 31 +++-- .../Background/subsystem_backgrounds.gd | 17 ++- .../Modules/Character/subsystem_portraits.gd | 98 +++++++------- .../Modules/Choice/settings_choices.gd | 4 +- .../Modules/Choice/subsystem_choices.gd | 31 +++-- addons/dialogic/Modules/Clear/event_clear.gd | 2 +- .../Modules/Core/subsystem_animation.gd | 13 +- .../Modules/Core/subsystem_expression.gd | 15 ++- .../dialogic/Modules/Core/subsystem_input.gd | 40 ++++-- .../Modules/History/subsystem_history.gd | 34 ++--- .../dialogic/Modules/Jump/subsystem_jump.gd | 24 ++-- .../dialogic/Modules/Save/subsystem_save.gd | 61 +++++---- .../Modules/Settings/subsystem_settings.gd | 13 +- .../Modules/Style/subsystem_styles.gd | 18 ++- addons/dialogic/Modules/Text/auto_advance.gd | 2 +- addons/dialogic/Modules/Text/event_text.gd | 12 +- .../dialogic/Modules/Text/subsystem_text.gd | 125 ++++++++++-------- .../Modules/TextInput/subsystem_text_input.gd | 12 +- .../Modules/Variable/subsystem_variables.gd | 79 ++++++----- .../dialogic/Modules/Voice/subsystem_voice.gd | 26 ++-- addons/dialogic/Modules/Wait/event_wait.gd | 2 +- .../Modules/WaitInput/event_wait_input.gd | 2 +- addons/dialogic/Other/Dialogic_Subsystem.gd | 6 +- 24 files changed, 379 insertions(+), 290 deletions(-) diff --git a/addons/dialogic/Example Assets/portraits/simple_highlight_portrait.gd b/addons/dialogic/Example Assets/portraits/simple_highlight_portrait.gd index b3bc64fb0..64aac03b4 100644 --- a/addons/dialogic/Example Assets/portraits/simple_highlight_portrait.gd +++ b/addons/dialogic/Example Assets/portraits/simple_highlight_portrait.gd @@ -2,7 +2,7 @@ extends DialogicPortrait @export_group('Main') -@export_file var image : String = "" +@export_file var image: String = "" var unhighlighted_color := Color.DARK_GRAY var prev_z_index := 0 diff --git a/addons/dialogic/Modules/Audio/subsystem_audio.gd b/addons/dialogic/Modules/Audio/subsystem_audio.gd index 9db6d656d..8bd1a67e3 100644 --- a/addons/dialogic/Modules/Audio/subsystem_audio.gd +++ b/addons/dialogic/Modules/Audio/subsystem_audio.gd @@ -8,33 +8,38 @@ signal sound_started(info:Dictionary) var base_music_player := AudioStreamPlayer.new() var base_sound_player := AudioStreamPlayer.new() -#################################################################################################### -## STATE + +#region STATE #################################################################################################### -func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): +func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: update_music() stop_all_sounds() -func load_game_state(load_flag:=LoadFlags.FULL_LOAD): + +func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: if load_flag == LoadFlags.ONLY_DNODES: return - var info = dialogic.current_state_info.get('music') - if info == null or info.path.is_empty(): + var info: Dictionary = dialogic.current_state_info.get("music", {}) + if info.is_empty() or info.path.is_empty(): update_music() else: update_music(info.path, info.volume, info.audio_bus, 0, info.loop) + func pause() -> void: for child in get_children(): child.stream_paused = true + func resume() -> void: for child in get_children(): child.stream_paused = false -#################################################################################################### -## MAIN METHODS +#endregion + + +#region MAIN METHODS #################################################################################################### func _ready() -> void: @@ -46,13 +51,13 @@ func _ready() -> void: ## Updates the background music. Will fade out previous music. -func update_music(path:String = '', volume:float = 0.0, audio_bus:String = "Master", fade_time:float = 0.0, loop:bool = true) -> void: +func update_music(path := "", volume := 0.0, audio_bus := "Master", fade_time := 0.0, loop := true) -> void: dialogic.current_state_info['music'] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop} music_started.emit(dialogic.current_state_info['music']) var fader: Tween = null if base_music_player.playing or !path.is_empty(): fader = create_tween() - var prev_node = null + var prev_node: Node = null if base_music_player.playing: prev_node = base_music_player.duplicate() add_child(prev_node) @@ -85,7 +90,7 @@ func has_music() -> bool: ## Plays a given sound file. -func play_sound(path:String, volume:float = 0.0, audio_bus:String = "Master", loop :bool= false) -> void: +func play_sound(path:String, volume := 0.0, audio_bus := "Master", loop := false) -> void: if base_sound_player != null and !path.is_empty(): sound_started.emit({'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop}) var new_sound_node := base_sound_player.duplicate() @@ -113,7 +118,7 @@ func stop_all_sounds() -> void: node.queue_free() -func interpolate_volume_linearly(value :float, node:Node) -> void: +func interpolate_volume_linearly(value:float, node:Node) -> void: node.volume_db = linear_to_db(value) @@ -124,3 +129,5 @@ func is_music_playing_resource(resource_path: String) -> bool: and base_music_player.stream.resource_path == resource_path) return is_playing_resource + +#endregion diff --git a/addons/dialogic/Modules/Background/subsystem_backgrounds.gd b/addons/dialogic/Modules/Background/subsystem_backgrounds.gd index ceb9401df..cd1409821 100644 --- a/addons/dialogic/Modules/Background/subsystem_backgrounds.gd +++ b/addons/dialogic/Modules/Background/subsystem_backgrounds.gd @@ -4,14 +4,12 @@ extends DialogicSubsystem signal background_changed(info:Dictionary) -var _tween: Tween -var _tween_callbacks: Array[Callable] var default_background_scene: PackedScene = load(get_script().resource_path.get_base_dir().path_join('DefaultBackgroundScene/default_background.tscn')) var default_transition: String = get_script().resource_path.get_base_dir().path_join("Transitions/Defaults/simple_fade.gd") -#################################################################################################### -## STATE + +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): @@ -21,9 +19,10 @@ func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): func load_game_state(load_flag:=LoadFlags.FULL_LOAD): update_background(dialogic.current_state_info.get('background_scene', ''), dialogic.current_state_info.get('background_argument', ''), 0.0, default_transition, true) +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### ## Method that adds a given scene as child of the DialogicNode_BackgroundHolder. @@ -35,7 +34,7 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD): ## and use the same scene. ## To do so implement [_should_do_background_update()] on the custom background scene. ## Then [_update_background()] will be called directly on that previous scene. -func update_background(scene:String = '', argument:String = '', fade_time:float = 0.0, transition_path:=default_transition, force:bool = false) -> void: +func update_background(scene := "", argument := "", fade_time := 0.0, transition_path:=default_transition, force := false) -> void: var background_holder: DialogicNode_BackgroundHolder if dialogic.has_subsystem('Styles'): background_holder = dialogic.Styles.get_first_node_in_layout('dialogic_background_holders') @@ -83,7 +82,7 @@ func update_background(scene:String = '', argument:String = '', fade_time:float else: new_viewport = null - var trans_script :Script = load(DialogicResourceUtil.guess_special_resource("BackgroundTransition", transition_path, default_transition)) + var trans_script: Script = load(DialogicResourceUtil.guess_special_resource("BackgroundTransition", transition_path, default_transition)) var trans_node := Node.new() trans_node.set_script(trans_script) trans_node = (trans_node as DialogicBackgroundTransition) @@ -161,4 +160,4 @@ func add_background_node(scene:PackedScene, parent:DialogicNode_BackgroundHolder func has_background() -> bool: return !dialogic.current_state_info.get('background_scene', '').is_empty() or !dialogic.current_state_info.get('background_argument','').is_empty() - +#endregion diff --git a/addons/dialogic/Modules/Character/subsystem_portraits.gd b/addons/dialogic/Modules/Character/subsystem_portraits.gd index b62be5e4c..6c836f2b5 100644 --- a/addons/dialogic/Modules/Character/subsystem_portraits.gd +++ b/addons/dialogic/Modules/Character/subsystem_portraits.gd @@ -10,26 +10,23 @@ signal position_changed(info:Dictionary) ## The default portrait scene. -var default_portrait_scene :PackedScene = load(get_script().resource_path.get_base_dir().path_join('default_portrait.tscn')) +var default_portrait_scene: PackedScene = load(get_script().resource_path.get_base_dir().path_join('default_portrait.tscn')) -## A reference to the current [DialogicNode_PortraitHolder]. -var _portrait_holder_reference: Node = null -#################################################################################################### -## STATE +#region STATE #################################################################################################### -func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): +func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: for character in dialogic.current_state_info.get('portraits', {}).keys(): remove_character(load(character)) dialogic.current_state_info['portraits'] = {} -func load_game_state(load_flag:=LoadFlags.FULL_LOAD): - var portraits_info :Dictionary = dialogic.current_state_info.portraits.duplicate() +func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: + var portraits_info: Dictionary = dialogic.current_state_info.portraits.duplicate() dialogic.current_state_info.portraits = {} for character_path in portraits_info: - var character_info :Dictionary = portraits_info[character_path] + var character_info: Dictionary = portraits_info[character_path] await join_character(load(character_path), character_info.portrait, character_info.position_index, character_info.get('custom_mirror', false), @@ -59,9 +56,10 @@ func _ready() -> void: if !ProjectSettings.get_setting('dialogic/portraits/default_portrait', '').is_empty(): default_portrait_scene = load(ProjectSettings.get_setting('dialogic/portraits/default_portrait', '')) +#endregion -################### Main Methods ################################################################## +#region MAIN METHODS #################################################################################################### ## The following methods allow manipulating portraits. ## A portrait is made up of a character node [Node2D] that instances the portrait scene as it's child. @@ -85,7 +83,7 @@ func _create_character_node(character:DialogicCharacter, container:DialogicNode_ # Changes the portrait of a specific [character node]. func _change_portrait(character_node:Node2D, portrait:String, update_transform:=true) -> Dictionary: - var character :DialogicCharacter = character_node.get_meta('character') + var character: DialogicCharacter = character_node.get_meta('character') if portrait.is_empty(): portrait = character.default_portrait @@ -96,9 +94,9 @@ func _change_portrait(character_node:Node2D, portrait:String, update_transform:= return info # path to the scene to use - var scene_path :String = character.portraits[portrait].get('scene', '') + var scene_path: String = character.portraits[portrait].get('scene', '') - var portrait_node : Node = null + var portrait_node: Node = null # check if the scene is the same as the currently loaded scene if (character_node.get_child_count() and @@ -115,9 +113,9 @@ func _change_portrait(character_node:Node2D, portrait:String, update_transform:= character_node.remove_child(character_node.get_child(0)) if ResourceLoader.exists(scene_path): - var p: PackedScene = load(scene_path) - if p: - portrait_node = p.instantiate() + var packed_scene: PackedScene = load(scene_path) + if packed_scene: + portrait_node = packed_scene.instantiate() else: push_error('[Dialogic] Portrait node "' + str(scene_path) + '" for character [' + character.display_name + '] could not be loaded. Your portrait might not show up on the screen. Confirm the path is correct.') @@ -148,7 +146,7 @@ func _change_portrait(character_node:Node2D, portrait:String, update_transform:= ## portrait mirror and portrait position mirror settings. func _change_portrait_mirror(character_node:Node2D, mirrored:=false, force:=false) -> void: if character_node.get_child(0).has_method('_set_mirror'): - var character :DialogicCharacter= character_node.get_meta('character') + var character: DialogicCharacter= character_node.get_meta('character') var current_portrait_info := character.get_portrait_info(character_node.get_meta('portrait')) character_node.get_child(0)._set_mirror(force or (mirrored != character.mirror != character_node.get_parent().mirrored != current_portrait_info.get('mirror', false))) @@ -159,18 +157,18 @@ func _change_portrait_extradata(character_node:Node2D, extra_data:="") -> void: func _update_portrait_transform(character_node:Node2D, time:float = 0.0) -> void: - var character :DialogicCharacter= character_node.get_meta('character') + var character: DialogicCharacter= character_node.get_meta('character') - var portrait_node :Node = character_node.get_child(0) - var portrait_info :Dictionary = character.portraits.get(character_node.get_meta('portrait'), {}) + var portrait_node: Node = character_node.get_child(0) + var portrait_info: Dictionary = character.portraits.get(character_node.get_meta('portrait'), {}) # ignore the character scale on custom portraits that have 'ignore_char_scale' set to true - var apply_character_scale :bool= !portrait_info.get('ignore_char_scale', false) - var transform :Rect2 = character_node.get_parent().get_local_portrait_transform( + var apply_character_scale: bool= !portrait_info.get('ignore_char_scale', false) + var transform: Rect2 = character_node.get_parent().get_local_portrait_transform( portrait_node._get_covered_rect(), (character.scale * portrait_info.get('scale', 1))*int(apply_character_scale)+portrait_info.get('scale', 1)*int(!apply_character_scale)) - var tween : Tween + var tween: Tween if character_node.has_meta('move_tween'): if character_node.get_meta('move_tween').is_running(): time = character_node.get_meta('move_time')-character_node.get_meta('move_tween').get_total_elapsed_time() @@ -190,11 +188,11 @@ func _update_portrait_transform(character_node:Node2D, time:float = 0.0) -> void ## Animates the portrait in the given container with the given animation. -func _animate_portrait(character_node:Node2D, animation_path:String, length:float, repeats = 1) -> DialogicAnimation: +func _animate_portrait(character_node:Node2D, animation_path:String, length:float, repeats := 1) -> DialogicAnimation: if character_node.has_meta('animation_node') and is_instance_valid(character_node.get_meta('animation_node')): character_node.get_meta('animation_node').queue_free() - var anim_script :Script = load(animation_path) + var anim_script: Script = load(animation_path) var anim_node := Node.new() anim_node.set_script(anim_script) anim_node = (anim_node as DialogicAnimation) @@ -211,7 +209,7 @@ func _animate_portrait(character_node:Node2D, animation_path:String, length:floa ## Moves the given portrait to the given container. -func _move_portrait(character_node:Node2D, portrait_container:DialogicNode_PortraitContainer, time:float = 0.0) -> void: +func _move_portrait(character_node:Node2D, portrait_container:DialogicNode_PortraitContainer, time:= 0.0) -> void: var global_pos := character_node.global_position if character_node.get_parent(): character_node.get_parent().remove_child(character_node) @@ -245,28 +243,32 @@ func _remove_portrait(character_node:Node2D) -> void: character_node.get_parent().remove_child(character_node) character_node.queue_free() + ## Gets the default animation length for joining characters ## If Auto-Skip is enabled, limits the time. func _get_join_default_length() -> float: - var default_time = ProjectSettings.get_setting('dialogic/animations/join_default_length', 0.5) + var default_time: float = ProjectSettings.get_setting('dialogic/animations/join_default_length', 0.5) if dialogic.Inputs.auto_skip.enabled: default_time = min(default_time, dialogic.Inputs.auto_skip.time_per_event) return default_time + ## Gets the default animation length for leaving characters ## If Auto-Skip is enabled, limits the time. func _get_leave_default_length() -> float: - var default_time = ProjectSettings.get_setting('dialogic/animations/leave_default_length', 0.5) + var default_time: float = ProjectSettings.get_setting('dialogic/animations/leave_default_length', 0.5) if dialogic.Inputs.auto_skip.enabled: default_time = min(default_time, dialogic.Inputs.auto_skip.time_per_event) return default_time +#endregion -################### Character Methods ############################################################# + +#region Character Methods #################################################################################################### ## The following methods are used to manage character portraits with the following rules: ## - a character can only be present once with these methods. @@ -275,7 +277,7 @@ func _get_leave_default_length() -> float: ## Adds a character at a position and sets it's portrait. ## If the character is already joined it will only update, portrait, position, etc. -func join_character(character:DialogicCharacter, portrait:String, position_idx:int, mirrored: bool = false, z_index: int = 0, extra_data:String = "", animation_name:String = "", animation_length:float = 0, animation_wait := false) -> Node: +func join_character(character:DialogicCharacter, portrait:String, position_idx:int, mirrored:= false, z_index:= 0, extra_data:= "", animation_name:= "", animation_length:= 0.0, animation_wait := false) -> Node: if is_character_joined(character): change_character_portrait(character, portrait) if animation_name.is_empty(): @@ -310,7 +312,7 @@ func join_character(character:DialogicCharacter, portrait:String, position_idx: animation_name = DialogicResourceUtil.guess_special_resource("PortraitAnimation", animation_name, "") if animation_name and animation_length > 0: - var anim:DialogicAnimation = _animate_portrait(character_node, animation_name, animation_length) + var anim: DialogicAnimation = _animate_portrait(character_node, animation_name, animation_length) if animation_wait: dialogic.current_state = DialogicGameHandler.States.ANIMATING @@ -339,7 +341,7 @@ func add_character(character:DialogicCharacter, portrait:String, position_idx:i printerr("[DialogicError] Character ",character.display_name, " has no default portrait to use.") return null - var character_node :Node = null + var character_node: Node = null for portrait_position in get_tree().get_nodes_in_group('dialogic_portrait_con_position'): if portrait_position.is_visible_in_tree() and portrait_position.position_index == position_idx: @@ -401,7 +403,7 @@ func change_character_extradata(character:DialogicCharacter, extra_data:="") -> ## Starts the given animation on the given character. Only works with joined characters -func animate_character(character:DialogicCharacter, animation_path:String, length:float, repeats = 1) -> DialogicAnimation: +func animate_character(character:DialogicCharacter, animation_path:String, length:float, repeats := 1) -> DialogicAnimation: if !is_character_joined(character): return null @@ -411,7 +413,7 @@ func animate_character(character:DialogicCharacter, animation_path:String, lengt ## Moves the given character to the given position. Only works with joined characters -func move_character(character:DialogicCharacter, position_idx:int, time:float = 0.0) -> void: +func move_character(character:DialogicCharacter, position_idx:int, time:= 0.0) -> void: if !is_character_joined(character): return @@ -429,7 +431,7 @@ func move_character(character:DialogicCharacter, position_idx:int, time:float = ## Removes a character with a given animation or the default animation. -func leave_character(character:DialogicCharacter, animation_name :String = "", animation_length:float = 0, animation_wait := false) -> void: +func leave_character(character:DialogicCharacter, animation_name:= "", animation_length:= 0.0, animation_wait := false) -> void: if !is_character_joined(character): return @@ -455,7 +457,7 @@ func leave_character(character:DialogicCharacter, animation_name :String = "", a ## Removes all joined characters with a given animation or the default animation. -func leave_all_characters(animation_name:String="", animation_length:float= 0, animation_wait:= false) -> void: +func leave_all_characters(animation_name:="", animation_length:=0.0, animation_wait:= false) -> void: for character in get_joined_characters(): leave_character(character, animation_name, animation_length, false) @@ -492,7 +494,7 @@ func is_character_joined(character:DialogicCharacter) -> bool: ## Returns a list of the joined charcters (as resources) func get_joined_characters() -> Array[DialogicCharacter]: - var chars :Array[DialogicCharacter]= [] + var chars: Array[DialogicCharacter]= [] for char_path in dialogic.current_state_info.get('portraits', {}).keys(): chars.append(load(char_path)) return chars @@ -503,15 +505,16 @@ func get_joined_characters() -> Array[DialogicCharacter]: ## Only joined is included (and false) for not joined characters func get_character_info(character:DialogicCharacter) -> Dictionary: if is_character_joined(character): - var info :Dictionary = dialogic.current_state_info['portraits'][character.resource_path] + var info: Dictionary = dialogic.current_state_info['portraits'][character.resource_path] info['joined'] = true return info else: return {'joined':false} +#endregion -################### Positions ##################################################################### +#region Positions #################################################################################################### func get_portrait_container(postion_index:int) -> DialogicNode_PortraitContainer: @@ -537,7 +540,7 @@ func add_portrait_position(position_index: int, position:Vector2) -> void: position_changed.emit({'change':'added', 'container_node':new_position, 'position_index':position_index}) -func move_portrait_position(position_index: int, vector:Vector2, relative:bool = false, time:float = 0.0) -> void: +func move_portrait_position(position_index: int, vector:Vector2, relative:= false, time:= 0.0) -> void: for portrait_container in get_tree().get_nodes_in_group('dialogic_portrait_con_position'): if portrait_container.is_visible_in_tree() and portrait_container.position_index == position_index: if !portrait_container.has_meta('default_position'): @@ -555,26 +558,27 @@ func move_portrait_position(position_index: int, vector:Vector2, relative:bool = add_portrait_position(position_index, vector) -func reset_all_portrait_positions(time:float = 0.0) -> void: +func reset_all_portrait_positions(time:= 0.0) -> void: for portrait_position in get_tree().get_nodes_in_group('dialogic_portrait_con_position'): if portrait_position.is_visible_in_tree(): if portrait_position.has_meta('default_position'): move_portrait_position(portrait_position.position_index, portrait_position.get_meta('default_position'), false, time) -func reset_portrait_position(position_index:int, time:float = 0.0) -> void: +func reset_portrait_position(position_index:int, time:= 0.0) -> void: for portrait_position in get_tree().get_nodes_in_group('dialogic_portrait_con_position'): if portrait_position.is_visible_in_tree() and portrait_position.position_index == position_index: if portrait_position.has_meta('default_position'): move_portrait_position(position_index, portrait_position.get_meta('default_position'), false, time) +#endregion -################## SPEAKER PORTRAIT CONTAINERS ##################################################### +#region SPEAKER PORTRAIT CONTAINERS #################################################################################################### ## Updates all portrait containers set to SPEAKER. -func change_speaker(speaker:DialogicCharacter= null, portrait:= ""): +func change_speaker(speaker:DialogicCharacter = null, portrait:= ""): for con in get_tree().get_nodes_in_group('dialogic_portrait_con_speaker'): for character_node in con.get_children(): if character_node.get_meta('character') != speaker: @@ -610,7 +614,10 @@ func change_speaker(speaker:DialogicCharacter= null, portrait:= ""): elif dialogic.current_state_info['speaker'] and is_character_joined(load(dialogic.current_state_info['speaker'])): dialogic.current_state_info['portraits'][dialogic.current_state_info['speaker']].node.get_child(0)._unhighlight() -################### TEXT EFFECTS ################################################################### +#endregion + + +#region TEXT EFFECTS #################################################################################################### ## Called from the [portrait=something] text effect. @@ -619,3 +626,4 @@ func text_effect_portrait(text_node:Control, skipped:bool, argument:String) -> v if dialogic.current_state_info.get('speaker', null): change_character_portrait(load(dialogic.current_state_info.speaker), argument) change_speaker(load(dialogic.current_state_info.speaker), argument) +#endregion diff --git a/addons/dialogic/Modules/Choice/settings_choices.gd b/addons/dialogic/Modules/Choice/settings_choices.gd index b40fae5b9..cfd736d8b 100644 --- a/addons/dialogic/Modules/Choice/settings_choices.gd +++ b/addons/dialogic/Modules/Choice/settings_choices.gd @@ -6,7 +6,7 @@ func _refresh() -> void: %Delay.value = ProjectSettings.get_setting('dialogic/choices/delay', 0.2) %FalseBehaviour.select(ProjectSettings.get_setting('dialogic/choices/def_false_behaviour', 0)) %HotkeyType.select(ProjectSettings.get_setting('dialogic/choices/hotkey_behaviour', 0)) - + var reveal_delay :float = ProjectSettings.get_setting('dialogic/choices/reveal_delay', 0) var reveal_by_input :bool = ProjectSettings.get_setting('dialogic/choices/reveal_by_input', false) if not reveal_by_input and reveal_delay == 0: @@ -17,7 +17,7 @@ func _refresh() -> void: _on_appear_mode_item_selected(2) if reveal_by_input and reveal_delay != 0: _on_appear_mode_item_selected(3) - + %RevealDelay.value = reveal_delay func _on_Autofocus_toggled(button_pressed: bool) -> void: diff --git a/addons/dialogic/Modules/Choice/subsystem_choices.gd b/addons/dialogic/Modules/Choice/subsystem_choices.gd index 98cb10b0d..d151ec511 100644 --- a/addons/dialogic/Modules/Choice/subsystem_choices.gd +++ b/addons/dialogic/Modules/Choice/subsystem_choices.gd @@ -11,22 +11,23 @@ var choice_blocker := Timer.new() var last_question_info := {} -func _ready(): - choice_blocker.one_shot = true - DialogicUtil.update_timer_process_callback(choice_blocker) - add_child(choice_blocker) - -#################################################################################################### -## STATE +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): hide_all_choices() -#################################################################################################### -## MAIN METHODS +func _ready(): + choice_blocker.one_shot = true + DialogicUtil.update_timer_process_callback(choice_blocker) + add_child(choice_blocker) + +#endregion + + +#region MAIN METHODS #################################################################################################### ## Hides all choice buttons. @@ -43,7 +44,7 @@ func show_current_choices(instant:=true) -> void: choice_blocker.stop() var reveal_delay := float(ProjectSettings.get_setting('dialogic/choices/reveal_delay', 0.0)) - var reveal_by_input :bool = ProjectSettings.get_setting('dialogic/choices/reveal_by_input', false) + var reveal_by_input: bool = ProjectSettings.get_setting('dialogic/choices/reveal_by_input', false) if !instant and (reveal_delay != 0 or reveal_by_input): if reveal_delay != 0: @@ -137,6 +138,7 @@ func show_choice(button_index:int, text:String, enabled:bool, event_index:int) - if not shown_at_all: printerr("[Dialogic] The layout you are using doesn't have enough Choice Buttons for the choices you are trying to display.") + func _on_ChoiceButton_choice_selected(event_index:int, choice_info:={}) -> void: if dialogic.paused or not choice_blocker.is_stopped(): return @@ -148,7 +150,7 @@ func _on_ChoiceButton_choice_selected(event_index:int, choice_info:={}) -> void: func get_current_choice_indexes() -> Array: var choices := [] - var evt_idx :int= dialogic.current_event_idx + var evt_idx := dialogic.current_event_idx var ignore := 0 while true: @@ -169,8 +171,10 @@ func get_current_choice_indexes() -> Array: ignore -= 1 return choices -#################################################################################################### -## HELPERS +#endregion + + +#region HELPERS #################################################################################################### func is_question(index:int) -> bool: @@ -180,3 +184,4 @@ func is_question(index:int) -> bool: return true return false +#endregion diff --git a/addons/dialogic/Modules/Clear/event_clear.gd b/addons/dialogic/Modules/Clear/event_clear.gd index b60278ce6..c69acaa9d 100644 --- a/addons/dialogic/Modules/Clear/event_clear.gd +++ b/addons/dialogic/Modules/Clear/event_clear.gd @@ -28,7 +28,7 @@ func _execute() -> void: if clear_textbox and dialogic.has_subsystem("Text"): dialogic.Text.update_dialog_text('') - dialogic.Text.hide_text_boxes() + dialogic.Text.hide_textbox() dialogic.current_state = dialogic.States.IDLE if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout diff --git a/addons/dialogic/Modules/Core/subsystem_animation.gd b/addons/dialogic/Modules/Core/subsystem_animation.gd index ad80a9513..8ab0f2841 100644 --- a/addons/dialogic/Modules/Core/subsystem_animation.gd +++ b/addons/dialogic/Modules/Core/subsystem_animation.gd @@ -4,20 +4,23 @@ extends DialogicSubsystem signal finished -var prev_state : int = 0 +var prev_state: int = 0 -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### func is_animating() -> bool: return dialogic.current_state == dialogic.States.ANIMATING + func start_animating() -> void: prev_state = dialogic.current_state dialogic.current_state = dialogic.States.ANIMATING -func animation_finished(arg:String= "") -> void: + +func animation_finished(arg := "") -> void: dialogic.current_state = prev_state finished.emit() - + +#endregion diff --git a/addons/dialogic/Modules/Core/subsystem_expression.gd b/addons/dialogic/Modules/Core/subsystem_expression.gd index bb69750d4..11255cfbf 100644 --- a/addons/dialogic/Modules/Core/subsystem_expression.gd +++ b/addons/dialogic/Modules/Core/subsystem_expression.gd @@ -4,12 +4,10 @@ extends DialogicSubsystem ## This is used by conditions and to allow expresions as variables. - -#################################################################################################### -## MAIN METHODS +#region MAIN METHODS #################################################################################################### -func execute_string(string:String, default = null) -> Variant: +func execute_string(string:String, default: Variant = null) -> Variant: # Some methods are not supported by the expression class, but very useful. # Thus they are recreated below and secretly added. string = string.replace('range(', 'd_range(') @@ -47,9 +45,10 @@ func execute_condition(condition:String) -> bool: return true return false +#endregion -#################################################################################################### -## MAIN METHODS + +#region HELPERS #################################################################################################### func d_range(a1, a2=null,a3=null,a4=null) -> Array: if !a2: @@ -67,10 +66,12 @@ func d_len(arg:Variant) -> int: # Checks if there is a match in a string based on a regex pattern string. func d_regex(input: String, pattern: String, offset: int = 0, end: int = -1) -> bool: - var regex : RegEx = RegEx.create_from_string(pattern) + var regex: RegEx = RegEx.create_from_string(pattern) regex.compile(pattern) var match := regex.search(input, offset, end) if match: return true else: return false + +#endregion diff --git a/addons/dialogic/Modules/Core/subsystem_input.gd b/addons/dialogic/Modules/Core/subsystem_input.gd index 59d0561db..ea3381aba 100644 --- a/addons/dialogic/Modules/Core/subsystem_input.gd +++ b/addons/dialogic/Modules/Core/subsystem_input.gd @@ -2,11 +2,11 @@ extends DialogicSubsystem ## Subsystem that handles input, autoadvance & skipping. - signal dialogic_action_priority signal dialogic_action signal autoskip_timer_finished + var input_block_timer := Timer.new() var _auto_skip_timer_left: float = 0.0 var action_was_consumed := false @@ -14,13 +14,14 @@ var action_was_consumed := false var auto_skip: DialogicAutoSkip = null var auto_advance : DialogicAutoAdvance = null -####### SUBSYSTEM METHODS ###################################################### + #region SUBSYSTEM METHODS +################################################################################ + func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: if not is_node_ready(): await ready - set_manualadvance(true) @@ -36,10 +37,19 @@ func resume() -> void: var is_autoskip_timer_done := _auto_skip_timer_left > 0.0 set_process(!is_autoskip_timer_done) + +func post_install() -> void: + dialogic.Settings.connect_to_change('autoadvance_delay_modifier', auto_advance._update_autoadvance_delay_modifier) + auto_skip.toggled.connect(_on_autoskip_toggled) + add_child(input_block_timer) + input_block_timer.one_shot = true + + #endregion -####### MAIN METHODS ########################################################### + #region MAIN METHODS +################################################################################ func handle_input() -> void: if dialogic.paused or is_input_blocked(): @@ -103,22 +113,18 @@ func _ready() -> void: # We use the process method to count down the auto-start_autoskip_timer timer. set_process(false) -func post_install() -> void: - dialogic.Settings.connect_to_change('autoadvance_delay_modifier', auto_advance._update_autoadvance_delay_modifier) - auto_skip.toggled.connect(_on_autoskip_toggled) - add_child(input_block_timer) - input_block_timer.one_shot = true - -func stop() -> void: +func stop_timers() -> void: auto_advance.autoadvance_timer.stop() input_block_timer.stop() _auto_skip_timer_left = 0.0 #endregion -####### AUTO-SKIP ############################################################## + #region AUTO-SKIP +################################################################################ + ## This method will advance the timeline based on Auto-Skip settings. ## The state, whether Auto-Skip is enabled, is ignored. func start_autoskip_timer() -> void: @@ -132,6 +138,7 @@ func _on_autoskip_toggled(enabled: bool) -> void: if not enabled: _auto_skip_timer_left = 0.0 + ## Handles fine-grained Auto-Skip logic. ## The [method _process] method allows for a more precise timer than the ## [Timer] class. @@ -145,10 +152,12 @@ func _process(delta): else: autoskip_timer_finished.emit() set_process(false) + #endregion -####### MANUAL ADVANCE ######################################################### + #region MANUAL ADVANCE +################################################################################ func set_manualadvance(enabled:=true, temp:= false) -> void: if !dialogic.current_state_info.has('manual_advance'): @@ -164,8 +173,10 @@ func is_manualadvance_enabled() -> bool: #endregion -####### TEXT EFFECTS ########################################################### + #region TEXT EFFECTS +################################################################################ + func effect_input(text_node:Control, skipped:bool, argument:String) -> void: if skipped: @@ -190,4 +201,5 @@ func effect_autoadvance(text_node: Control, skipped:bool, argument:String) -> vo if argument.is_valid_float(): auto_advance.override_delay_for_current_event = float(argument) + #endregion diff --git a/addons/dialogic/Modules/History/subsystem_history.gd b/addons/dialogic/Modules/History/subsystem_history.gd index e1dc76ef4..d103f2086 100644 --- a/addons/dialogic/Modules/History/subsystem_history.gd +++ b/addons/dialogic/Modules/History/subsystem_history.gd @@ -2,6 +2,12 @@ extends DialogicSubsystem ## Subsystem that manages history storing. +signal already_read_event_reached +signal not_read_event_reached + +signal open_requested +signal close_requested + ## Simple history that stores limited information ## Used for the history display @@ -20,15 +26,8 @@ var already_read_history_enabled := false var already_read_history_content := {} var _was_last_event_already_read := false -signal already_read_event_reached -signal not_read_event_reached - -signal open_requested -signal close_requested - -#################################################################################################### -## INITIALIZE +#region INITIALIZE #################################################################################################### func _ready() -> void: @@ -40,7 +39,6 @@ func _ready() -> void: already_read_history_enabled = ProjectSettings.get_setting('dialogic/history/already_read_history_enabled', false) - func open_history() -> void: open_requested.emit() @@ -48,15 +46,10 @@ func open_history() -> void: func close_history() -> void: close_requested.emit() +#endregion -#################################################################################################### -## STATE -#################################################################################################### - -# nothing implemented right now -#################################################################################################### -## SIMPLE HISTORY +#region SIMPLE HISTORY #################################################################################################### func store_simple_history_entry(text:String, event_type:String, extra_info := {}) -> void: @@ -70,10 +63,10 @@ func store_simple_history_entry(text:String, event_type:String, extra_info := {} func get_simple_history() -> Array: return simple_history_content +#endregion -#################################################################################################### -## FULL EVENT HISTORY +#region FULL EVENT HISTORY #################################################################################################### # called on each event @@ -83,8 +76,7 @@ func store_full_event(event:DialogicEvent) -> void: full_event_history_changed.emit() -#################################################################################################### -## ALREADY READ HISTORY +#region ALREADY READ HISTORY #################################################################################################### ## Takes the current timeline event and creates a unique key for it. @@ -127,3 +119,5 @@ func check_already_read(event: DialogicEvent) -> void: func was_last_event_already_read() -> bool: return _was_last_event_already_read + +#endregion diff --git a/addons/dialogic/Modules/Jump/subsystem_jump.gd b/addons/dialogic/Modules/Jump/subsystem_jump.gd index 8a958d6c1..5a44b230f 100644 --- a/addons/dialogic/Modules/Jump/subsystem_jump.gd +++ b/addons/dialogic/Modules/Jump/subsystem_jump.gd @@ -6,27 +6,30 @@ signal switched_timeline(info:Dictionary) signal jumped_to_label(info:Dictionary) signal returned_from_jump(info:Dictionary) -#################################################################################################### -## STATE + +#region STATE #################################################################################################### -func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): +func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: dialogic.current_state_info['jump_stack'] = [] -func load_game_state(load_flag:=LoadFlags.FULL_LOAD): +func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: if not 'jump_stack' in dialogic.current_state_info: dialogic.current_state_info['jump_stack'] = [] +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### func jump_to_label(label:String) -> void: if label.is_empty(): dialogic.current_event_idx = 0 + jumped_to_label.emit({'timeline':dialogic.current_timeline, 'label':"TOP"}) return + var idx: int = -1 while true: idx += 1 @@ -45,12 +48,13 @@ func push_to_jump_stack() -> void: func resume_from_last_jump() -> void: - var sub_timeline : DialogicTimeline = dialogic.current_timeline - var stack_info :Dictionary = dialogic.current_state_info['jump_stack'].pop_back() + var sub_timeline: DialogicTimeline = dialogic.current_timeline + var stack_info: Dictionary = dialogic.current_state_info['jump_stack'].pop_back() dialogic.start_timeline(stack_info.timeline, stack_info.index+1) returned_from_jump.emit({'sub_timeline':sub_timeline, 'label':stack_info.label}) - -func is_jump_stack_empty(): +func is_jump_stack_empty() -> bool: return len(dialogic.current_state_info['jump_stack']) < 1 + +#endregion diff --git a/addons/dialogic/Modules/Save/subsystem_save.gd b/addons/dialogic/Modules/Save/subsystem_save.gd index 7656cf399..e458a1a47 100644 --- a/addons/dialogic/Modules/Save/subsystem_save.gd +++ b/addons/dialogic/Modules/Save/subsystem_save.gd @@ -14,23 +14,23 @@ enum ThumbnailMode {NONE, TAKE_AND_STORE, STORE_ONLY} var latest_thumbnail : Image = null -#################################################################################################### -## STATE +#region STATE #################################################################################################### ## Built-in, called by DialogicGameHandler. func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): _make_sure_slot_dir_exists() +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### ## Saves the current state to the given slot. ## If no slot is given the default slot is used (name can be set in the dialogic settings) ## If you want to change to the current slot use save(Dialogic.Save.get_latest_slot()) -func save(slot_name:String = '', is_autosave:bool = false, thumbnail_mode:=ThumbnailMode.TAKE_AND_STORE, slot_info :Dictionary = {}): +func save(slot_name := "", is_autosave := false, thumbnail_mode:=ThumbnailMode.TAKE_AND_STORE, slot_info := {}): # check if to save (if this is an autosave) if is_autosave and !ProjectSettings.get_setting('dialogic/save/autosave', false): return @@ -49,7 +49,7 @@ func save(slot_name:String = '', is_autosave:bool = false, thumbnail_mode:=Thumb save_slot_thumbnail(slot_name) if slot_info: - store_slot_info(slot_name, slot_info) + set_slot_info(slot_name, slot_info) saved.emit({"slot_name":slot_name, "is_autosave": is_autosave}) print('[Dialogic] Saved to slot "'+slot_name+'".') @@ -59,7 +59,7 @@ func save(slot_name:String = '', is_autosave:bool = false, thumbnail_mode:=Thumb ## If no slot is given, the default slot is used. ## To check if something is saved in that slot use has_slot(). ## If the slot does not exist, this method will fail. -func load(slot_name:String=""): +func load(slot_name := "") -> void: if slot_name.is_empty(): slot_name = get_default_slot() if !has_slot(slot_name): @@ -147,13 +147,14 @@ func get_global_info(key:String, default:Variant) -> Variant: ## Gets the encryption password from the project settings if it has been set. ## If no password has been set, an empty string is returned. func get_encryption_password() -> String: - if OS.is_debug_build() and ProjectSettings.get_setting('dialogic/save/encryption_on_exports_only', true): + if OS.is_debug_build() and ProjectSettings.get_setting('dialogic/save/encryption_on_exports_only', true): return "" return ProjectSettings.get_setting("dialogic/save/encryption_password", "") +#endregion -#################################################################################################### -## SLOT HELPERS + +#region SLOT HELPERS #################################################################################################### ## Returns a list of all available slots. Usefull for iterating over all slots ## (for example to build a UI list). @@ -194,7 +195,6 @@ func delete_slot(slot_name:String) -> void: ## this adds a new save folder with the given name -## func add_empty_slot(slot_name: String) -> void: if DirAccess.dir_exists_absolute(SAVE_SLOTS_DIR): var directory := DirAccess.open(SAVE_SLOTS_DIR) @@ -202,7 +202,7 @@ func add_empty_slot(slot_name: String) -> void: ## reset the state of the given save folder (or default) -func reset_slot(slot_name: String = '') -> void: +func reset_slot(slot_name := "") -> void: if slot_name.is_empty(): slot_name = get_default_slot() save_file(slot_name, 'state.txt', {}) @@ -220,7 +220,7 @@ func get_default_slot() -> String: ## Returns the latest slot or empty if nothing was saved yet func get_latest_slot() -> String: - var latest_slot :String = "" + var latest_slot: String = "" if Engine.get_main_loop().has_meta('dialogic_latest_saved_slot'): latest_slot = Engine.get_main_loop().get_meta('dialogic_latest_saved_slot', '') else: @@ -239,7 +239,7 @@ func set_latest_slot(slot_name:String) -> void: func _make_sure_slot_dir_exists() -> void: if not DirAccess.dir_exists_absolute(SAVE_SLOTS_DIR): DirAccess.make_dir_recursive_absolute(SAVE_SLOTS_DIR) - var global_info_path = SAVE_SLOTS_DIR.path_join('global_info.txt') + var global_info_path := SAVE_SLOTS_DIR.path_join('global_info.txt') if not FileAccess.file_exists(global_info_path): var config := ConfigFile.new() var password := get_encryption_password() @@ -248,23 +248,25 @@ func _make_sure_slot_dir_exists() -> void: else: config.save_encrypted_pass(global_info_path, password) +#endregion -#################################################################################################### -## SLOT INFO + +#region SLOT INFO #################################################################################################### -func store_slot_info(slot_name:String, info: Dictionary) -> void: +func set_slot_info(slot_name:String, info: Dictionary) -> void: if slot_name.is_empty(): slot_name = get_default_slot() save_file(slot_name, 'info.txt', info) -func get_slot_info(slot_name:String = '') -> Dictionary: +func get_slot_info(slot_name := "") -> Dictionary: if slot_name.is_empty(): slot_name = get_default_slot() return load_file(slot_name, 'info.txt', {}) +#endregion -#################################################################################################### -## SLOT IMAGE + +#region SLOT IMAGE #################################################################################################### ## Can be called manually to create a thumbnail. Then call save() with THUMBNAIL_MODE.STORE_ONLY @@ -287,9 +289,10 @@ func get_slot_thumbnail(slot_name:String) -> ImageTexture: return ImageTexture.create_from_image(Image.load_from_file(path)) return null +#endregion -#################################################################################################### -## AUTOSAVE + +#region AUTOSAVE #################################################################################################### ## Reference to the autosave timer. var autosave_timer := Timer.new() @@ -302,8 +305,8 @@ func _ready() -> void: autosave_timer.timeout.connect(_on_autosave_timer_timeout) add_child(autosave_timer) dialogic.event_handled.connect(_on_dialogic_event_handled) - dialogic.timeline_started.connect(autosave_start_end) - dialogic.timeline_ended.connect(autosave_start_end) + dialogic.timeline_started.connect(_on_start_or_end_autosave) + dialogic.timeline_ended.connect(_on_start_or_end_autosave) _on_autosave_timer_timeout() @@ -315,13 +318,15 @@ func _on_autosave_timer_timeout() -> void: func _on_dialogic_event_handled(event: DialogicEvent) -> void: if event is DialogicJumpEvent: - if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 1: + if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 0: save('', true) if event is DialogicTextEvent: - if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 1: + if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 2: save('', true) -func autosave_start_end() -> void: - if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 1: +func _on_start_or_end_autosave() -> void: + if ProjectSettings.get_setting('dialogic/save/autosave_mode', 0) == 0: save('', true) + +#endregion diff --git a/addons/dialogic/Modules/Settings/subsystem_settings.gd b/addons/dialogic/Modules/Settings/subsystem_settings.gd index 269b241fc..2d489f2ef 100644 --- a/addons/dialogic/Modules/Settings/subsystem_settings.gd +++ b/addons/dialogic/Modules/Settings/subsystem_settings.gd @@ -9,11 +9,10 @@ extends DialogicSubsystem ## Settings stored there can also be changed with the Settings event. var settings := {} - var _connections := {} -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### ## Built-in, called by DialogicGameHandler. @@ -54,8 +53,10 @@ func _setting_changed(property:StringName, value:Variant) -> void: for i in _connections[property]: i.call(value) -#################################################################################################### -## HANDY METHODS +#endregion + + +#region HANDY METHODS #################################################################################################### func get_setting(property:StringName, default:Variant) -> Variant: @@ -84,3 +85,5 @@ func connect_to_change(setting:StringName, callable:Callable) -> void: if !setting in _connections: _connections[setting] = [] _connections[setting].append(callable) + +#endregion diff --git a/addons/dialogic/Modules/Style/subsystem_styles.gd b/addons/dialogic/Modules/Style/subsystem_styles.gd index c94c69fb9..03da9a659 100644 --- a/addons/dialogic/Modules/Style/subsystem_styles.gd +++ b/addons/dialogic/Modules/Style/subsystem_styles.gd @@ -4,8 +4,8 @@ extends DialogicSubsystem signal style_changed(info:Dictionary) -#################################################################################################### -## STATE + +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): @@ -17,9 +17,10 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD): return load_style(dialogic.current_state_info.get('style', '')) +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### func load_style(style_name:="", is_base_style:=true) -> Node: @@ -71,7 +72,7 @@ func load_style(style_name:="", is_base_style:=true) -> Node: func create_layout(style:DialogicStyle) -> DialogicLayoutBase: # Load base scene - var base_scene : DialogicLayoutBase + var base_scene: DialogicLayoutBase if style.base_scene == null: base_scene = DialogicUtil.get_default_layout_base().instantiate() else: @@ -89,7 +90,7 @@ func create_layout(style:DialogicStyle) -> DialogicLayoutBase: if not ResourceLoader.exists(layer.path): continue - var layer_scene : DialogicLayoutLayer = null + var layer_scene: DialogicLayoutLayer = null if ResourceLoader.load_threaded_get_status(layer.path) == ResourceLoader.THREAD_LOAD_LOADED: layer_scene = ResourceLoader.load_threaded_get(layer.path).instantiate() @@ -138,13 +139,16 @@ func get_layout_node() -> Node: return null + ## Similar to get_tree().get_first_node_in_group('group_name') but filtered to the active layout node subtree func get_first_node_in_layout(group_name : String): var layout_node := get_layout_node() if null == layout_node: return null - var nodes = get_tree().get_nodes_in_group(group_name) + var nodes := get_tree().get_nodes_in_group(group_name) for node in nodes: if layout_node.is_ancestor_of(node): return node return null + +#endregion diff --git a/addons/dialogic/Modules/Text/auto_advance.gd b/addons/dialogic/Modules/Text/auto_advance.gd index cd0315b5c..96e1a3398 100644 --- a/addons/dialogic/Modules/Text/auto_advance.gd +++ b/addons/dialogic/Modules/Text/auto_advance.gd @@ -173,7 +173,7 @@ func _on_toggled(is_enabled: bool) -> void: # If auto-advance is disabled and we are auto-advancing, # we want to cancel the auto-advance mode. elif !is_enabled and is_advancing(): - DialogicUtil.autoload().Inputs.stop() + DialogicUtil.autoload().Inputs.stop_timers() #endregion #region AUTOADVANCE HELPERS diff --git a/addons/dialogic/Modules/Text/event_text.gd b/addons/dialogic/Modules/Text/event_text.gd index 02b9c9211..b5b9d7902 100644 --- a/addons/dialogic/Modules/Text/event_text.gd +++ b/addons/dialogic/Modules/Text/event_text.gd @@ -150,7 +150,7 @@ func _execute() -> void: # We must skip text animation before we potentially return when there # is a Choice event. if dialogic.Inputs.auto_skip.enabled: - dialogic.Text.skip_text_animation() + dialogic.Text.skip_text_reveal() else: await dialogic.Text.text_finished @@ -189,14 +189,14 @@ func _execute() -> void: func _on_dialogic_input_action(): match state: States.REVEALING: - if dialogic.Text.can_skip_text_reveal(): - dialogic.Text.skip_text_animation() - dialogic.Inputs.stop() + if dialogic.Text.is_text_reveal_skippable(): + dialogic.Text.skip_text_reveal() + dialogic.Inputs.stop_timers() dialogic.Inputs.block_input(ProjectSettings.get_setting('dialogic/text/text_reveal_skip_delay', 0.1)) _: if dialogic.Inputs.is_manualadvance_enabled(): advance.emit() - dialogic.Inputs.stop() + dialogic.Inputs.stop_timers() dialogic.Inputs.block_input(ProjectSettings.get_setting('dialogic/text/text_reveal_skip_delay', 0.1)) @@ -218,7 +218,7 @@ func _on_auto_skip_enable(enabled: bool): advance.emit() States.REVEALING: - dialogic.Text.skip_text_animation() + dialogic.Text.skip_text_reveal() ################################################################################ diff --git a/addons/dialogic/Modules/Text/subsystem_text.gd b/addons/dialogic/Modules/Text/subsystem_text.gd index c31b2c912..58ee55951 100644 --- a/addons/dialogic/Modules/Text/subsystem_text.gd +++ b/addons/dialogic/Modules/Text/subsystem_text.gd @@ -2,6 +2,8 @@ extends DialogicSubsystem ## Subsystem that handles showing of dialog text (+text effects & modifiers), name label, and next indicator +#region SIGNALS + signal about_to_show_text(info:Dictionary) signal text_finished(info:Dictionary) signal speaker_updated(character:DialogicCharacter) @@ -16,22 +18,25 @@ signal meta_hover_ended(meta:Variant) signal meta_hover_started(meta:Variant) signal meta_clicked(meta:Variant) +#endregion + + # used to color names without searching for all characters each time var character_colors := {} var color_regex := RegEx.new() var text_already_read := false var text_effects := {} -var parsed_text_effect_info : Array[Dictionary]= [] +var parsed_text_effect_info: Array[Dictionary] = [] var text_effects_regex := RegEx.new() enum TextModifierModes {ALL=-1, TEXT_ONLY=0, CHOICES_ONLY=1} enum TextTypes {DIALOG_TEXT, CHOICE_TEXT} var text_modifiers := [] -# set by the [speed] effect, multies the letter speed and [pause] effects +## set by the [speed] effect, multies the letter speed and [pause] effects var _speed_multiplier := 1.0 -# stores the pure letter speed (unmultiplied) +## stores the pure letter speed (unmultiplied) var _pure_letter_speed := 0.1 var _letter_speed_absolute := false @@ -40,8 +45,7 @@ var _voice_synced_text := false var _autopauses := {} -#################################################################################################### -## STATE +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: @@ -52,6 +56,7 @@ func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> set_text_reveal_skippable(ProjectSettings.get_setting('dialogic/text/initial_text_reveal_skippable', true)) + # TODO check whether this can happen on the node directly for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'): if text_node.start_hidden: text_node.textbox_root.hide() @@ -59,7 +64,7 @@ func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: update_dialog_text(dialogic.current_state_info.get('text', ''), true) - var character:DialogicCharacter = null + var character: DialogicCharacter = null if dialogic.current_state_info.get('speaker', ""): character = load(dialogic.current_state_info.get('speaker', "")) @@ -67,12 +72,17 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: update_name_label(character) -#################################################################################################### -## MAIN METHODS +func post_install(): + dialogic.Settings.connect_to_change('text_speed', _update_user_speed) + +#endregion + + +#region MAIN METHODS #################################################################################################### ## Applies modifiers, effects and coloring to the text -func parse_text(text:String, type:int=TextTypes.DIALOG_TEXT, variables:= true, glossary:= true, modifiers:= true, effects:= true, color_names:= true) -> String: +func parse_text(text:String, type:int=TextTypes.DIALOG_TEXT, variables := true, glossary := true, modifiers:= true, effects:= true, color_names:= true) -> String: if variables and dialogic.has_subsystem('VAR'): text = dialogic.VAR.parse_variables(text) if modifiers: @@ -85,14 +95,15 @@ func parse_text(text:String, type:int=TextTypes.DIALOG_TEXT, variables:= true, g text = dialogic.Glossary.parse_glossary(text) return text + ## When an event updates the text spoken, this can adjust the state of ## the dialog text box. ## This method is async. -func update_text_boxes(text: String, instant: bool = false) -> void: +func update_text_boxes(text: String, instant := false) -> void: if text.is_empty(): - await hide_text_boxes(instant) + await hide_textbox(instant) else: - await show_text_boxes(instant) + await show_textbox(instant) if !dialogic.current_state_info['text'].is_empty(): animation_textbox_new_text.emit() @@ -133,7 +144,7 @@ func update_dialog_text(text: String, instant := false, additional := false) -> dialogic.Inputs.auto_advance.enabled_until_next_event = false dialogic.Inputs.auto_advance.override_delay_for_current_event = -1 dialogic.Inputs.set_manualadvance(true, true) - + set_text_reveal_skippable(true, true) return text @@ -176,8 +187,23 @@ func update_typing_sound_mood(mood:Dictionary = {}) -> void: typing_sound.load_overwrite(mood) +## instant skips the signal and thus possible animations +func show_textbox(instant:=false) -> void: + var emitted := instant + for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'): + if !text_node.textbox_root.visible and !emitted: + animation_textbox_show.emit() + text_node.textbox_root.show() + if dialogic.Animations.is_animating(): + await dialogic.Animations.finished + textbox_visibility_changed.emit(true) + emitted = true + else: + text_node.textbox_root.show() + + ## Instant skips the signal and thus possible animations -func hide_text_boxes(instant:=false) -> void: +func hide_textbox(instant:=false) -> void: dialogic.current_state_info['text'] = '' var emitted := instant for name_label in get_tree().get_nodes_in_group('dialogic_name_label'): @@ -197,21 +223,6 @@ func is_textbox_visible() -> bool: return get_tree().get_nodes_in_group('dialogic_dialog_text').any(func(x): return x.textbox_root.visible) -## instant skips the signal and thus possible animations -func show_text_boxes(instant:=false) -> void: - var emitted := instant - for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'): - if !text_node.textbox_root.visible and !emitted: - animation_textbox_show.emit() - text_node.textbox_root.show() - if dialogic.Animations.is_animating(): - await dialogic.Animations.finished - textbox_visibility_changed.emit(true) - emitted = true - else: - text_node.textbox_root.show() - - func show_next_indicators(question:=false, autoadvance:=false) -> void: for next_indicator in get_tree().get_nodes_in_group('dialogic_next_indicator'): if next_indicator.enabled: @@ -221,7 +232,8 @@ func show_next_indicators(question:=false, autoadvance:=false) -> void: else: next_indicator.hide() -func hide_next_indicators(_fake_arg = null) -> void: + +func hide_next_indicators(_fake_arg :Variant= null) -> void: for next_indicator in get_tree().get_nodes_in_group('dialogic_next_indicator'): next_indicator.hide() @@ -281,11 +293,21 @@ func set_text_reveal_skippable(skippable:= true, temp:=false) -> void: dialogic.current_state_info['text_reveal_skippable']['enabled'] = skippable -func can_skip_text_reveal() -> bool: +func is_text_reveal_skippable() -> bool: return dialogic.current_state_info['text_reveal_skippable']['enabled'] and dialogic.current_state_info['text_reveal_skippable'].get('temp_enabled', true) -################### Text Effects & Modifiers ################################################### +func skip_text_reveal() -> void: + for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'): + if text_node.is_visible_in_tree(): + text_node.finish_text() + if dialogic.has_subsystem('Voice'): + dialogic.Voice.stop_audio() + +#endregion + + +#region TEXT EFFECTS & MODIFIERS #################################################################################################### func collect_text_effects() -> void: @@ -326,14 +348,14 @@ func parse_text_effects(text:String) -> String: return text -func execute_effects(current_index:int, text_node:Control, skipping:bool= false) -> void: +func execute_effects(current_index:int, text_node:Control, skipping := false) -> void: # might have to execute multiple effects while true: if parsed_text_effect_info.is_empty(): return if current_index != -1 and current_index < parsed_text_effect_info[0]['index']: return - var effect :Dictionary= parsed_text_effect_info.pop_front() + var effect: Dictionary = parsed_text_effect_info.pop_front() await (effect['execution_info']['callable'] as Callable).call(text_node, skipping, effect['value']) @@ -356,19 +378,10 @@ func parse_text_modifiers(text:String, type:int=TextTypes.DIALOG_TEXT) -> String return text -func skip_text_animation() -> void: - for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'): - if text_node.is_visible_in_tree(): - text_node.finish_text() - if dialogic.has_subsystem('Voice'): - dialogic.Voice.stop_audio() - - -func get_current_speaker() -> DialogicCharacter: - return (load(dialogic.current_state_info.get('speaker', "")) as DialogicCharacter) +#endregion -#################### HELPERS & OTHER STUFF ######################################################### +#region HELPERS & OTHER STUFF #################################################################################################### func _ready(): @@ -378,13 +391,13 @@ func _ready(): dialogic.event_handled.connect(hide_next_indicators) _autopauses = {} - var autopause_data :Dictionary= ProjectSettings.get_setting('dialogic/text/autopauses', {}) + var autopause_data: Dictionary = ProjectSettings.get_setting('dialogic/text/autopauses', {}) for i in autopause_data.keys(): _autopauses[RegEx.create_from_string('(? DialogicCharacter: + return (load(dialogic.current_state_info.get('speaker', "")) as DialogicCharacter) func _update_user_speed(user_speed:float) -> void: @@ -405,6 +418,10 @@ func connect_meta_signals(text_node: Node) -> void: func emit_meta_signal(meta:Variant, sig:String) -> void: emit_signal(sig, meta) +#endregion + +#region AUTOCOLOR NAMES +################################################################################ func color_names(text:String) -> String: if !ProjectSettings.get_setting('dialogic/text/autocolor_names', false): @@ -442,9 +459,10 @@ func collect_character_names() -> void: color_regex.compile('(?<=\\W|^)(?'+str(character_colors.keys()).trim_prefix('["').trim_suffix('"]').replace('", "', '|')+')(?=\\W|$)') +#endregion -################################################################################ -## DEFAULT TEXT EFFECTS & MODIFIERS + +#region DEFAULT TEXT EFFECTS & MODIFIERS ################################################################################ func effect_pause(text_node:Control, skipped:bool, argument:String) -> void: @@ -504,10 +522,10 @@ func effect_mood(text_node:Control, skipped:bool, argument:String) -> void: var modifier_words_select_regex := RegEx.create_from_string("(?]+(\\/[^\\>]*)\\>") func modifier_random_selection(text:String) -> String: for replace_mod_match in modifier_words_select_regex.search_all(text): - var string :String= replace_mod_match.get_string().trim_prefix("<").trim_suffix(">") + var string: String= replace_mod_match.get_string().trim_prefix("<").trim_suffix(">") string = string.replace('//', '') - var list :PackedStringArray= string.split('/') - var item :String= list[randi()%len(list)] + var list: PackedStringArray= string.split('/') + var item: String= list[randi()%len(list)] item = item.replace('', '/') text = text.replace(replace_mod_match.get_string(), item.strip_edges()) return text @@ -529,3 +547,4 @@ func modifier_autopauses(text:String) -> String: text = text.insert(result.get_end()+offset, '[pause='+str(_autopauses[i])+']') offset += len('[pause='+str(_autopauses[i])+']') return text +#endregion diff --git a/addons/dialogic/Modules/TextInput/subsystem_text_input.gd b/addons/dialogic/Modules/TextInput/subsystem_text_input.gd index 8a64f511e..6a76504f8 100644 --- a/addons/dialogic/Modules/TextInput/subsystem_text_input.gd +++ b/addons/dialogic/Modules/TextInput/subsystem_text_input.gd @@ -7,19 +7,19 @@ signal input_confirmed(input:String) signal input_shown(info:Dictionary) -#################################################################################################### -## STATE +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: hide_text_input() +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### -func show_text_input(text:String = '', default:String = '', placeholder:String = '', allow_empty:bool = false) -> void: +func show_text_input(text:= "", default:= "", placeholder:= "", allow_empty:= false) -> void: for node in get_tree().get_nodes_in_group('dialogic_text_input'): node.show() if node.has_method('set_allow_empty'): node.set_allow_empty(allow_empty) @@ -32,3 +32,5 @@ func show_text_input(text:String = '', default:String = '', placeholder:String = func hide_text_input() -> void: for node in get_tree().get_nodes_in_group('dialogic_text_input'): node.hide() + +#endregion diff --git a/addons/dialogic/Modules/Variable/subsystem_variables.gd b/addons/dialogic/Modules/Variable/subsystem_variables.gd index 4267925fb..dbb8359d8 100644 --- a/addons/dialogic/Modules/Variable/subsystem_variables.gd +++ b/addons/dialogic/Modules/Variable/subsystem_variables.gd @@ -8,8 +8,7 @@ signal variable_changed(info:Dictionary) signal variable_was_set(info:Dictionary) -#################################################################################################### -## STATE +#region STATE #################################################################################################### func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR): @@ -23,26 +22,17 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD): return dialogic.current_state_info['variables'] = merge_folder(dialogic.current_state_info['variables'], ProjectSettings.get_setting('dialogic/variables', {}).duplicate(true)) +#endregion -func merge_folder(new, defs) -> Dictionary: - # also go through all groups in this folder - for x in new.keys(): - if x in defs and typeof(new[x]) == TYPE_DICTIONARY: - new[x] = merge_folder(new[x], defs[x]) - # add all new variables - for x in defs.keys(): - if not x in new: - new[x] = defs[x] - return new +#region MAIN METHODS #################################################################################################### -## MAIN METHODS -#################################################################################################### + ## This function will try to get the value of variables provided inside curly brackets ## and replace them with their values. ## It will: ## - look for the strings to replace -## - search all tree nodes (autoloads) +## - search all autoloads ## - try to get the value from context ## ## So if you provide a string like `Hello, how are you doing {Game.player_name} @@ -88,7 +78,7 @@ func set_variable(variable_name: String, value: Variant) -> bool: return false -func get_variable(variable_path:String, default :Variant= null) -> Variant: +func get_variable(variable_path:String, default: Variant = null) -> Variant: if variable_path.begins_with('{') and variable_path.ends_with('}') and variable_path.count('{') == 1: variable_path = variable_path.trim_prefix('{').trim_suffix('}') @@ -109,26 +99,19 @@ func get_variable(variable_path:String, default :Variant= null) -> Variant: ## Resets all variables or a specific variable to the value(s) defined in the variable editor -func reset(variable:='') -> void: +func reset(variable:="") -> void: if variable.is_empty(): - dialogic.current_state_info['variables'] = ProjectSettings.get_setting('dialogic/variables', {}).duplicate(true) + dialogic.current_state_info['variables'] = ProjectSettings.get_setting("dialogic/variables", {}).duplicate(true) else: DialogicUtil._set_value_in_dictionary(variable, dialogic.current_state_info['variables'], DialogicUtil._get_value_in_dictionary(variable, ProjectSettings.get_setting('dialogic/variables', {}))) ## Returns true if a variable with the given path exists -func has(variable:='') -> bool: +func has(variable:="") -> bool: return DialogicUtil._get_value_in_dictionary(variable, dialogic.current_state_info['variables']) != null -func get_autoloads() -> Array: - var autoloads := [] - for c in get_tree().root.get_children(): - autoloads.append(c) - return autoloads - - ## Allows to set dialogic built-in variables func _set(property, value) -> bool: property = str(property) @@ -166,17 +149,45 @@ func variables(absolute:=false) -> Array: if not dialogic.current_state_info['variables'][i] is Dictionary: result.append(i) return result +#endregion + +#region HELPERS +################################################################################ +func get_autoloads() -> Array: + var autoloads := [] + for c in get_tree().root.get_children(): + autoloads.append(c) + return autoloads + + +func merge_folder(new:Dictionary, defs:Dictionary) -> Dictionary: + # also go through all groups in this folder + for x in new.keys(): + if x in defs and typeof(new[x]) == TYPE_DICTIONARY: + new[x] = merge_folder(new[x], defs[x]) + # add all new variables + for x in defs.keys(): + if not x in new: + new[x] = defs[x] + return new + +#endregion + +#region VARIABLE FOLDER +################################################################################ class VariableFolder: var data := {} var path := "" - var outside - func _init(_data, _path, _outside): + var outside : DialogicSubsystem + + func _init(_data:Dictionary, _path:String, _outside:DialogicSubsystem): data = _data path = _path outside = _outside - func _get(property): + + func _get(property:StringName): property = str(property) if property in data: if typeof(data[property]) == TYPE_DICTIONARY: @@ -184,15 +195,18 @@ class VariableFolder: else: return DialogicUtil.logical_convert(data[property]) - func _set(property, value) -> bool: + + func _set(property:StringName, value:Variant) -> bool: property = str(property) if not value is VariableFolder: DialogicUtil._set_value_in_dictionary(path+"."+property, outside.dialogic.current_state_info['variables'], value) return true - func has(key) -> bool: + + func has(key:String) -> bool: return key in data + func folders() -> Array: var result := [] for i in data.keys(): @@ -200,6 +214,7 @@ class VariableFolder: result.append(VariableFolder.new(data[i], path+"."+i, outside)) return result + func variables(absolute:=false) -> Array: var result := [] for i in data.keys(): @@ -209,3 +224,5 @@ class VariableFolder: else: result.append(i) return result + +#endregion diff --git a/addons/dialogic/Modules/Voice/subsystem_voice.gd b/addons/dialogic/Modules/Voice/subsystem_voice.gd index 72f88d7e0..19b765c7c 100644 --- a/addons/dialogic/Modules/Voice/subsystem_voice.gd +++ b/addons/dialogic/Modules/Voice/subsystem_voice.gd @@ -9,11 +9,10 @@ signal voiceline_finished(info:Dictionary) signal voiceline_stopped(info:Dictionary) -var current_audio_file:String +var current_audio_file: String var voice_player := AudioStreamPlayer.new() -#################################################################################################### -## STATE +#region STATE #################################################################################################### func pause() -> void: @@ -23,9 +22,10 @@ func pause() -> void: func resume() -> void: voice_player.stream_paused = false +#endregion -#################################################################################################### -## MAIN METHODS + +#region MAIN METHODS #################################################################################################### func _ready() -> void: @@ -40,34 +40,34 @@ func is_voiced(index:int) -> bool: return false -func play_voice(): +func play_voice() -> void: voice_player.play() voiceline_started.emit({'file':current_audio_file}) -func set_file(path:String): +func set_file(path:String) -> void: if current_audio_file == path: return current_audio_file = path - var audio:AudioStream = load(path) + var audio: AudioStream = load(path) voice_player.stream = audio -func set_volume(value:float): +func set_volume(value:float) -> void: voice_player.volume_db = value -func set_bus(value:String): +func set_bus(value:String) -> void: voice_player.bus = value -func stop_audio(): +func stop_audio() -> void: if voice_player.playing: voiceline_stopped.emit({'file':current_audio_file, 'remaining_time':get_remaining_time()}) voice_player.stop() -func _on_voice_finnished(): +func _on_voice_finnished() -> void: voiceline_finished.emit({'file':current_audio_file, 'remaining_time':get_remaining_time()}) @@ -79,3 +79,5 @@ func get_remaining_time() -> float: func is_running() -> bool: return get_remaining_time() > 0.0 + +#endregion diff --git a/addons/dialogic/Modules/Wait/event_wait.gd b/addons/dialogic/Modules/Wait/event_wait.gd index 6c4c02045..15e90e22e 100644 --- a/addons/dialogic/Modules/Wait/event_wait.gd +++ b/addons/dialogic/Modules/Wait/event_wait.gd @@ -26,7 +26,7 @@ func _execute() -> void: if hide_text and dialogic.has_subsystem("Text"): dialogic.Text.update_dialog_text('') - dialogic.Text.hide_text_boxes() + dialogic.Text.hide_textbox() dialogic.current_state = dialogic.States.WAITING await dialogic.get_tree().create_timer(time, true, DialogicUtil.is_physics_timer()).timeout dialogic.current_state = dialogic.States.IDLE diff --git a/addons/dialogic/Modules/WaitInput/event_wait_input.gd b/addons/dialogic/Modules/WaitInput/event_wait_input.gd index 8ecd71501..e1f13b5e8 100644 --- a/addons/dialogic/Modules/WaitInput/event_wait_input.gd +++ b/addons/dialogic/Modules/WaitInput/event_wait_input.gd @@ -12,7 +12,7 @@ var hide_textbox := true func _execute() -> void: if hide_textbox: - dialogic.Text.hide_text_boxes() + dialogic.Text.hide_textbox() dialogic.current_state = DialogicGameHandler.States.IDLE dialogic.Inputs.auto_skip.enabled = false await dialogic.Inputs.dialogic_action diff --git a/addons/dialogic/Other/Dialogic_Subsystem.gd b/addons/dialogic/Other/Dialogic_Subsystem.gd index 57d5d0ad0..4b742a788 100644 --- a/addons/dialogic/Other/Dialogic_Subsystem.gd +++ b/addons/dialogic/Other/Dialogic_Subsystem.gd @@ -1,5 +1,5 @@ -extends Node class_name DialogicSubsystem +extends Node var dialogic: DialogicGameHandler = null @@ -10,21 +10,25 @@ enum LoadFlags {FULL_LOAD, ONLY_DNODES} func post_install() -> void: pass + # To be overriden by sub-classes # Fill in everything that should be cleared (for example before loading a different state) func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: pass + # To be overriden by sub-classes # Fill in everything that should be loaded using the dialogic_game_handler.current_state_info # This is called when a save is loaded func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: pass + # To be overriden by sub-classes func pause() -> void: pass + # To be overriden by sub-classes func resume() -> void: pass From 36180c9c354b0d821cfc99f15c077a09f45d52a9 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Tue, 23 Jan 2024 15:04:46 +0100 Subject: [PATCH 2/3] Small empty line changes --- addons/dialogic/Resources/CharacterResourceLoader.gd | 2 +- addons/dialogic/Resources/TimelineResourceLoader.gd | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/dialogic/Resources/CharacterResourceLoader.gd b/addons/dialogic/Resources/CharacterResourceLoader.gd index f77be430c..05a942d74 100644 --- a/addons/dialogic/Resources/CharacterResourceLoader.gd +++ b/addons/dialogic/Resources/CharacterResourceLoader.gd @@ -15,7 +15,7 @@ func _get_resource_type(path: String) -> String: var ext = path.get_extension().to_lower() if ext == "dch": return "Resource" - + return "" diff --git a/addons/dialogic/Resources/TimelineResourceLoader.gd b/addons/dialogic/Resources/TimelineResourceLoader.gd index b417325a6..2f143357a 100644 --- a/addons/dialogic/Resources/TimelineResourceLoader.gd +++ b/addons/dialogic/Resources/TimelineResourceLoader.gd @@ -15,7 +15,7 @@ func _get_resource_type(path: String) -> String: var ext = path.get_extension().to_lower() if ext == "dtl": return "Resource" - + return "" @@ -28,8 +28,8 @@ func _handles_type(typename: StringName) -> bool: func _load(path: String, original_path: String, use_sub_threads: bool, cache_mode: int): if FileAccess.file_exists(path): var file := FileAccess.open(path, FileAccess.READ) - + var tml := DialogicTimeline.new() tml.from_text(file.get_as_text()) - + return tml From d8a5e0d38531752d549919ec6f02513a409551a4 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Tue, 23 Jan 2024 15:15:59 +0100 Subject: [PATCH 3/3] Small code style changes --- addons/dialogic/Other/DialogicGameHandler.gd | 12 +-- addons/dialogic/Other/DialogicUtil.gd | 14 ++-- addons/dialogic/Resources/dialogic_style.gd | 4 +- addons/dialogic/Resources/event.gd | 83 ++++++++++++-------- 4 files changed, 64 insertions(+), 49 deletions(-) diff --git a/addons/dialogic/Other/DialogicGameHandler.gd b/addons/dialogic/Other/DialogicGameHandler.gd index 032e589be..3ad4a381f 100644 --- a/addons/dialogic/Other/DialogicGameHandler.gd +++ b/addons/dialogic/Other/DialogicGameHandler.gd @@ -64,8 +64,8 @@ signal dialogic_paused signal dialogic_resumed -signal timeline_ended() -signal timeline_started() +signal timeline_ended +signal timeline_started signal event_handled(resource:DialogicEvent) ## Emitted when the Signal event was reached @@ -132,7 +132,6 @@ var Voice := preload("res://addons/dialogic/Modules/Voice/subsystem_voice.gd").n ## Autoloads are added first, so this happens REALLY early on game startup. func _ready() -> void: - DialogicResourceUtil.update() collect_subsystems() @@ -157,7 +156,7 @@ func start(timeline:Variant, label:Variant="") -> Node: return null # Otherwise make sure there is a style active. - var scene :Node= null + var scene: Node= null if !self.Styles.has_active_layout_node(): scene = self.Styles.load_style() else: @@ -206,6 +205,7 @@ func start_timeline(timeline:Variant, label_or_idx:Variant = "") -> void: timeline_started.emit() handle_next_event() + ## Preloader function, prepares a timeline and returns an object to hold for later # TODO: Question: why is this taking a variant and then only allowing a string? func preload_timeline(timeline_resource:Variant) -> Variant: @@ -346,7 +346,7 @@ func get_subsystem(_name:String) -> DialogicSubsystem: func add_subsystem(_name:String, _script_path:String) -> DialogicSubsystem: - var node:Node = Node.new() + var node: Node = Node.new() node.name = _name node.set_script(load(_script_path)) node = node as DialogicSubsystem @@ -370,4 +370,4 @@ func _on_timeline_ended() -> void: @warning_ignore("unsafe_method_access") get_tree().get_meta('dialogic_layout_node', '').hide() -#endregion Helpers +#endregion diff --git a/addons/dialogic/Other/DialogicUtil.gd b/addons/dialogic/Other/DialogicUtil.gd index 2b9b3c989..b9b6ab508 100644 --- a/addons/dialogic/Other/DialogicUtil.gd +++ b/addons/dialogic/Other/DialogicUtil.gd @@ -32,7 +32,7 @@ static func autoload() -> DialogicGameHandler: #region FILE SYSTEM ################################################################################ -static func listdir(path: String, files_only: bool = true, throw_error:bool = true, full_file_path:bool = false, include_imports := false) -> Array: +static func listdir(path: String, files_only:= true, throw_error:= true, full_file_path:= false, include_imports := false) -> Array: var files: Array = [] if path.is_empty(): path = "res://" if DirAccess.dir_exists_absolute(path): @@ -84,10 +84,10 @@ static func get_indexers(include_custom := true, force_reload := false) -> Array if Engine.get_main_loop().has_meta('dialogic_indexers') and !force_reload: return Engine.get_main_loop().get_meta('dialogic_indexers') - var indexers : Array[DialogicIndexer] = [] + var indexers: Array[DialogicIndexer] = [] for file in listdir(DialogicUtil.get_module_path(''), false): - var possible_script:String = DialogicUtil.get_module_path(file).path_join("index.gd") + var possible_script: String = DialogicUtil.get_module_path(file).path_join("index.gd") if FileAccess.file_exists(possible_script): indexers.append(load(possible_script).new()) @@ -205,9 +205,9 @@ enum VarTypes {ANY, STRING, FLOAT, INT, BOOL} static func get_default_variables() -> Dictionary: return ProjectSettings.get_setting('dialogic/variables', {}) + # helper that converts a nested variable dictionary into an array with paths static func list_variables(dict:Dictionary, path := "", type:=VarTypes.ANY) -> Array: - var array := [] for key in dict.keys(): if typeof(dict[key]) == TYPE_DICTIONARY: @@ -266,7 +266,6 @@ static func _get_value_in_dictionary(path:String, dictionary:Dictionary, default - #region STYLES ################################################################################ @@ -347,7 +346,7 @@ static func get_scene_export_defaults(node:Node) -> Dictionary: ################################################################################ static func setup_script_property_edit_node(property_info: Dictionary, value:Variant, property_changed:Callable) -> Control: - var input :Control = null + var input: Control = null match property_info['type']: TYPE_BOOL: input = CheckBox.new() @@ -413,7 +412,7 @@ static func setup_script_property_edit_node(property_info: Dictionary, value:Var input.value_changed.connect(DialogicUtil._on_export_file_submitted.bind(property_changed)) elif property_info['hint'] & PROPERTY_HINT_ENUM: input = OptionButton.new() - var options :PackedStringArray = [] + var options: PackedStringArray = [] for x in property_info['hint_string'].split(','): options.append(x.split(':')[0].strip_edges()) input.add_item(options[-1]) @@ -435,6 +434,7 @@ static func setup_script_property_edit_node(property_info: Dictionary, value:Var input.text_submitted.connect(DialogicUtil._on_export_input_text_submitted.bind(property_info.name, property_changed)) return input + static func _on_export_input_text_submitted(text:String, property_name:String, callable: Callable) -> void: callable.call(property_name, var_to_str(text)) diff --git a/addons/dialogic/Resources/dialogic_style.gd b/addons/dialogic/Resources/dialogic_style.gd index 89e887d13..2fb0b664e 100644 --- a/addons/dialogic/Resources/dialogic_style.gd +++ b/addons/dialogic/Resources/dialogic_style.gd @@ -12,7 +12,7 @@ class_name DialogicStyle return "Unkown Style" return name -@export var inherits : DialogicStyle = null +@export var inherits: DialogicStyle = null @export var base_scene: PackedScene = null @export var base_overrides := {} @@ -149,7 +149,7 @@ func get_inheritance_root() -> DialogicStyle: if inherits == null: return self - var style : DialogicStyle = self + var style: DialogicStyle = self while style.inherits != null: style = style.inherits diff --git a/addons/dialogic/Resources/event.gd b/addons/dialogic/Resources/event.gd index 2667ddc0d..71b519545 100644 --- a/addons/dialogic/Resources/event.gd +++ b/addons/dialogic/Resources/event.gd @@ -9,11 +9,11 @@ extends Resource ## Emmited when the event starts. ## The signal is emmited with the event resource [code]event_resource[/code] -signal event_started(event_resource) +signal event_started(event_resource:DialogicEvent) ## Emmited when the event finish. ## The signal is emmited with the event resource [code]event_resource[/code] -signal event_finished(event_resource) +signal event_finished(event_resource:DialogicEvent) ### Main Event Properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -101,16 +101,17 @@ enum ValueType { var editor_list: Array = [] ## Singal that notifies the visual editor block to update signal ui_update_needed -signal ui_update_warning(text) +signal ui_update_warning(text:String) ## Makes this resource printable. func _to_string() -> String: return "[{name}:{id}]".format({"name":event_name, "id":get_instance_id()}) +#endregion -################################################################################ -## EXECUTION + +#region EXECUTION ################################################################################ ## Executes the event behaviour. In subclasses [_execute] (not this one) should be overriden! @@ -129,9 +130,10 @@ func finish() -> void: func _execute() -> void: finish() +#endregion -################################################################################ -## OVERRIDABLES + +#region OVERRIDABLES ################################################################################ ## to be overridden by sub-classes @@ -154,9 +156,10 @@ func get_end_branch_control() -> Control: func should_execute_this_branch() -> bool: return false +#endregion -################################################################################ -## TRANSLATIONS + +#region TRANSLATIONS ################################################################################ ## Overwrite if this events needs translation. @@ -192,15 +195,16 @@ func get_property_translation_key(property_name:String) -> String: ## Call this whenever you are using a translatable property func get_property_translated(property_name:String) -> String: if !_translation_id.is_empty() and ProjectSettings.get_setting('dialogic/translation/enabled', false): - var translation = tr(get_property_translation_key(property_name)) + var translation := tr(get_property_translation_key(property_name)) # if no translation is found tr() returns the id, but we want to fallback to the original return translation if translation != get_property_translation_key(property_name) else _get_property_original_translation(property_name) else: return _get_property_original_translation(property_name) +#endregion -################################################################################ -## SAVE / LOAD (internal, don't override) + +#region SAVE / LOAD (internal, don't override) ################################################################################ ### These functions are used by the timeline loader/saver ### They mainly use the overridable behaviour below, but enforce the unique_id saving @@ -242,9 +246,10 @@ func _test_event_string(string:String) -> bool: return is_valid_event(string.get_slice('#id:', 0)) return is_valid_event(string.strip_edges()) +#endregion -################################################################################ -## SAVE / LOAD + +#region SAVE / LOAD ################################################################################ ### All of these functions can/should be overridden by the sub classes @@ -261,9 +266,9 @@ func get_shortcode_parameters() -> Dictionary: ## returns a readable presentation of the event (This is how it's stored) ## by default it uses a shortcode format, but can be overridden func to_text() -> String: - var result_string : String = "["+self.get_shortcode() - var params : Dictionary = get_shortcode_parameters() - var custom_defaults :Dictionary = DialogicUtil.get_custom_event_defaults(event_name) + var result_string: String = "["+self.get_shortcode() + var params: Dictionary = get_shortcode_parameters() + var custom_defaults: Dictionary = DialogicUtil.get_custom_event_defaults(event_name) for parameter in params.keys(): if (typeof(get(params[parameter].property)) != typeof(custom_defaults.get(params[parameter].property, params[parameter].default))) or \ (get(params[parameter].property) != custom_defaults.get(params[parameter].property, params[parameter].default)): @@ -291,13 +296,13 @@ func to_text() -> String: ## loads the variables from the string stored above ## by default it uses the shortcode format, but can be overridden func from_text(string:String) -> void: - var data : Dictionary = parse_shortcode_parameters(string) - var params : Dictionary = get_shortcode_parameters() + var data: Dictionary = parse_shortcode_parameters(string) + var params: Dictionary = get_shortcode_parameters() for parameter in params.keys(): if not parameter in data: continue - var value :Variant + var value: Variant match typeof(get(params[parameter].property)): TYPE_STRING: value = data[parameter].replace('\\=', '=') @@ -332,20 +337,21 @@ func is_string_full_event(string:String) -> bool: ## used to get all the shortcode parameters in a string as a dictionary func parse_shortcode_parameters(shortcode : String) -> Dictionary: - var regex:RegEx = RegEx.new() + var regex: RegEx = RegEx.new() regex.compile('((?[^\\s=]*)\\s*=\\s*"(?([^=]|\\\\=)*)(? Resource: - var _icon_file_name = "res://addons/dialogic/Editor/Images/Pieces/closed-icon.svg" # Default + var _icon_file_name := "res://addons/dialogic/Editor/Images/Pieces/closed-icon.svg" # Default if FileAccess.file_exists(self.get_script().get_path().get_base_dir() + "/icon.png"): _icon_file_name = self.get_script().get_path().get_base_dir() + "/icon.png" if FileAccess.file_exists(self.get_script().get_path().get_base_dir() + "/icon.svg"): @@ -353,7 +359,7 @@ func _get_icon() -> Resource: return load(_icon_file_name) -func set_default_color(value) -> void: +func set_default_color(value:Variant) -> void: dialogic_color_name = value event_color = DialogicUtil.get_color(value) @@ -362,7 +368,10 @@ func set_default_color(value) -> void: func _enter_visual_editor(timeline_editor:DialogicEditor) -> void: pass -####################### CODE COMPLETION ######################################## +#endregion + + +#region CODE COMPLETION ################################################################################ ## This method can be overwritten to implement code completion for custom syntaxes @@ -373,15 +382,19 @@ func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:Str func _get_start_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit) -> void: pass +#endregion + -#################### SYNTAX HIGHLIGHTING ####################################### +#region SYNTAX HIGHLIGHTING ################################################################################ func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary: return dict +#endregion -#################### EVENT FIELDS ############################################## + +#region EVENT FIELDS ################################################################################ func get_event_editor_info() -> Array: @@ -410,7 +423,7 @@ func build_event_editor() -> void: ## @extra_info: Allows passing a lot more info to the field. ## What info can be passed is differnet for every field -func add_header_label(text:String, condition:String = "") -> void: +func add_header_label(text:String, condition:= "") -> void: editor_list.append({ "name" : "something", "type" :+ TYPE_STRING, @@ -422,7 +435,7 @@ func add_header_label(text:String, condition:String = "") -> void: }) -func add_header_edit(variable:String, editor_type = ValueType.LABEL, extra_info:Dictionary = {}, condition:String = "") -> void: +func add_header_edit(variable:String, editor_type := ValueType.LABEL, extra_info:= {}, condition:= "") -> void: editor_list.append({ "name" : variable, "type" : typeof(get(variable)), @@ -436,7 +449,7 @@ func add_header_edit(variable:String, editor_type = ValueType.LABEL, extra_info: }) -func add_header_button(text:String, callable:Callable, tooltip:String, icon: Variant = null, condition:String = "") -> void: +func add_header_button(text:String, callable:Callable, tooltip:String, icon: Variant = null, condition:= "") -> void: editor_list.append({ "name" : "Button", "type" : TYPE_STRING, @@ -448,7 +461,7 @@ func add_header_button(text:String, callable:Callable, tooltip:String, icon: Var }) -func add_body_edit(variable:String, editor_type = ValueType.LABEL, extra_info:Dictionary = {}, condition:String = "") -> void: +func add_body_edit(variable:String, editor_type := ValueType.LABEL, extra_info:= {}, condition:= "") -> void: editor_list.append({ "name" : variable, "type" : typeof(get(variable)), @@ -462,7 +475,7 @@ func add_body_edit(variable:String, editor_type = ValueType.LABEL, extra_info:Di }) -func add_body_line_break(condition:String = "") -> void: +func add_body_line_break(condition:= "") -> void: editor_list.append({ "name" : "linebreak", "type" : TYPE_BOOL, @@ -470,3 +483,5 @@ func add_body_line_break(condition:String = "") -> void: "usage" : PROPERTY_USAGE_DEFAULT, "condition" : condition, }) + +#endregion