Skip to content

Commit 3e90442

Browse files
Restore loading a save when using Styles (#1959) (#1960)
* Restore loading a save when using Styles (#1959) Restore load functionality. * Small adjustments --------- Co-authored-by: Jowan-Spooner <[email protected]>
1 parent ad962fb commit 3e90442

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

addons/dialogic/Modules/Background/subsystem_backgrounds.gd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func clear_game_state(clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR):
1919

2020

2121
func load_game_state(load_flag:=LoadFlags.FULL_LOAD):
22-
update_background(dialogic.current_state_info.get('background_scene', ''), dialogic.current_state_info.get('background_argument', ''))
22+
update_background(dialogic.current_state_info.get('background_scene', ''), dialogic.current_state_info.get('background_argument', ''), 0.0, default_transition, true)
2323

2424

2525
####################################################################################################
@@ -35,8 +35,12 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD):
3535
## and use the same scene.
3636
## To do so implement [_should_do_background_update()] on the custom background scene.
3737
## Then [_update_background()] will be called directly on that previous scene.
38-
func update_background(scene:String = '', argument:String = '', fade_time:float = 0.0, transition_path:=default_transition) -> void:
39-
var background_holder: DialogicNode_BackgroundHolder = get_tree().get_first_node_in_group('dialogic_background_holders')
38+
func update_background(scene:String = '', argument:String = '', fade_time:float = 0.0, transition_path:=default_transition, force:bool = false) -> void:
39+
var background_holder: DialogicNode_BackgroundHolder
40+
if dialogic.has_subsystem('Styles'):
41+
background_holder = Dialogic.Styles.get_first_node_in_layout('dialogic_background_holders')
42+
else:
43+
background_holder = get_tree().get_first_node_in_group('dialogic_background_holders')
4044
if background_holder == null:
4145
return
4246

@@ -47,7 +51,7 @@ func update_background(scene:String = '', argument:String = '', fade_time:float
4751
# First try just updating the existing scene.
4852
if scene == dialogic.current_state_info.get('background_scene', ''):
4953

50-
if argument == dialogic.current_state_info.get('background_argument', ''):
54+
if not force and argument == dialogic.current_state_info.get('background_argument', ''):
5155
return
5256

5357
for old_bg in background_holder.get_children():

addons/dialogic/Modules/Style/subsystem_styles.gd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ func load_style(style_name:="", is_base_style:=true) -> Node:
3131
if is_base_style:
3232
dialogic.current_state_info['base_style'] = style_name
3333

34-
# This will include stuff from parent-styles (for inherited styles)
35-
#var full_info := DialogicUtil.get_inherited_style_info(style_name)
36-
# TODO something!
3734
# if this style is the same style as before
3835
var previous_layout := get_layout_node()
3936
if (is_instance_valid(previous_layout)
@@ -134,3 +131,14 @@ func get_layout_node() -> Node:
134131
return tree.get_meta('dialogic_layout_node')
135132

136133
return null
134+
135+
## Similar to get_tree().get_first_node_in_group('group_name') but filtered to the active layout node subtree
136+
func get_first_node_in_layout(group_name : String):
137+
var layout_node := get_layout_node()
138+
if null == layout_node:
139+
return null
140+
var nodes = get_tree().get_nodes_in_group(group_name)
141+
for node in nodes:
142+
if layout_node.is_ancestor_of(node):
143+
return node
144+
return null

addons/dialogic/Other/DialogicGameHandler.gd

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,26 @@ func get_full_state() -> Dictionary:
242242
func load_full_state(state_info:Dictionary) -> void:
243243
clear()
244244
current_state_info = state_info
245-
if current_state_info.get('current_timeline', null):
246-
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))
247-
248245
## The Style subsystem needs to run first for others to load correctly.
249-
if has_subsystem('Style'):
250-
get_subsystem('Style').load_full_state()
246+
var scene: Node = null
247+
if has_subsystem('Styles'):
248+
get_subsystem('Styles').load_game_state()
249+
scene = self.Styles.get_layout_node()
251250

252-
await get_tree().process_frame
251+
if current_state_info.get('current_timeline', null):
252+
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))
253253

254-
for subsystem in get_children():
255-
if subsystem.name == 'Style':
256-
continue
254+
var load_subsystems := func():
255+
for subsystem in get_children():
256+
if subsystem.name == 'Styles':
257+
continue
258+
subsystem.load_game_state()
257259

258-
subsystem.load_game_state()
260+
if null != scene and not scene.is_node_ready():
261+
scene.ready.connect(load_subsystems)
262+
else:
263+
await get_tree().process_frame
264+
load_subsystems.call()
259265

260266
#endregion
261267

0 commit comments

Comments
 (0)