Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some method renames and code cleanup #2042

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 19 additions & 12 deletions addons/dialogic/Modules/Audio/subsystem_audio.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)


Expand All @@ -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
17 changes: 8 additions & 9 deletions addons/dialogic/Modules/Background/subsystem_backgrounds.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Loading
Loading