Skip to content

Commit

Permalink
Restore loading a save when using Styles (#1959) (#1960)
Browse files Browse the repository at this point in the history
* Restore loading a save when using Styles (#1959)

Restore load functionality.

* Small adjustments

---------

Co-authored-by: Jowan-Spooner <[email protected]>
  • Loading branch information
sudisk and Jowan-Spooner authored Dec 19, 2023
1 parent ad962fb commit 3e90442
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
12 changes: 8 additions & 4 deletions addons/dialogic/Modules/Background/subsystem_backgrounds.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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', ''))
update_background(dialogic.current_state_info.get('background_scene', ''), dialogic.current_state_info.get('background_argument', ''), 0.0, default_transition, true)


####################################################################################################
Expand All @@ -35,8 +35,12 @@ 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) -> void:
var background_holder: DialogicNode_BackgroundHolder = get_tree().get_first_node_in_group('dialogic_background_holders')
func update_background(scene:String = '', argument:String = '', fade_time:float = 0.0, transition_path:=default_transition, force:bool = false) -> void:
var background_holder: DialogicNode_BackgroundHolder
if dialogic.has_subsystem('Styles'):
background_holder = Dialogic.Styles.get_first_node_in_layout('dialogic_background_holders')
else:
background_holder = get_tree().get_first_node_in_group('dialogic_background_holders')
if background_holder == null:
return

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

if argument == dialogic.current_state_info.get('background_argument', ''):
if not force and argument == dialogic.current_state_info.get('background_argument', ''):
return

for old_bg in background_holder.get_children():
Expand Down
14 changes: 11 additions & 3 deletions addons/dialogic/Modules/Style/subsystem_styles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ func load_style(style_name:="", is_base_style:=true) -> Node:
if is_base_style:
dialogic.current_state_info['base_style'] = style_name

# This will include stuff from parent-styles (for inherited styles)
#var full_info := DialogicUtil.get_inherited_style_info(style_name)
# TODO something!
# if this style is the same style as before
var previous_layout := get_layout_node()
if (is_instance_valid(previous_layout)
Expand Down Expand Up @@ -134,3 +131,14 @@ func get_layout_node() -> Node:
return tree.get_meta('dialogic_layout_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)
for node in nodes:
if layout_node.is_ancestor_of(node):
return node
return null
26 changes: 16 additions & 10 deletions addons/dialogic/Other/DialogicGameHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,26 @@ func get_full_state() -> Dictionary:
func load_full_state(state_info:Dictionary) -> void:
clear()
current_state_info = state_info
if current_state_info.get('current_timeline', null):
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))

## The Style subsystem needs to run first for others to load correctly.
if has_subsystem('Style'):
get_subsystem('Style').load_full_state()
var scene: Node = null
if has_subsystem('Styles'):
get_subsystem('Styles').load_game_state()
scene = self.Styles.get_layout_node()

await get_tree().process_frame
if current_state_info.get('current_timeline', null):
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))

for subsystem in get_children():
if subsystem.name == 'Style':
continue
var load_subsystems := func():
for subsystem in get_children():
if subsystem.name == 'Styles':
continue
subsystem.load_game_state()

subsystem.load_game_state()
if null != scene and not scene.is_node_ready():
scene.ready.connect(load_subsystems)
else:
await get_tree().process_frame
load_subsystems.call()

#endregion

Expand Down

0 comments on commit 3e90442

Please sign in to comment.