Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
120 changes: 42 additions & 78 deletions addons/dialogic/Core/DialogicGameHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,71 +70,64 @@ var paused := false:

dialogic_resumed.emit()

## A timeline that will be played when dialog ends.
## By default this timeline only contains a clear event.
var dialog_ending_timeline: DialogicTimeline

## Emitted when [member paused] changes to `true`.
signal dialogic_paused
## Emitted when [member paused] changes to `false`.
signal dialogic_resumed


## Emitted when a timeline starts by calling either [method start]
## or [method start_timeline].
signal timeline_started
## Emitted when the timeline ends.
## This can be a timeline ending or [method end_timeline] being called.
signal timeline_ended
## Emitted when a timeline starts by calling either [method start]
## or [method start_timeline].
signal timeline_started
## Emitted when an event starts being executed.
## The event may not have finished executing yet.
signal event_handled(resource: DialogicEvent)

## Emitted when a [class SignalEvent] event was reached.
@warning_ignore("unused_signal") # This is emitted by the signal event.
signal signal_event(argument: Variant)

## Emitted when a signal event gets fired from a [class TextEvent] event.
@warning_ignore("unused_signal") # This is emitted by the text subsystem.
signal text_signal(argument: String)


# Careful, this section is repopulated automatically at certain moments.
#region SUBSYSTEMS

var Animations := preload("res://addons/dialogic/Modules/Core/subsystem_animation.gd").new():
get: return get_subsystem("Animations")

var Audio := preload("res://addons/dialogic/Modules/Audio/subsystem_audio.gd").new():
get: return get_subsystem("Audio")

var Backgrounds := preload("res://addons/dialogic/Modules/Background/subsystem_backgrounds.gd").new():
get: return get_subsystem("Backgrounds")

var Portraits := preload("res://addons/dialogic/Modules/Character/subsystem_portraits.gd").new():
get: return get_subsystem("Portraits")

var PortraitContainers := preload("res://addons/dialogic/Modules/Character/subsystem_containers.gd").new():
get: return get_subsystem("PortraitContainers")

var Choices := preload("res://addons/dialogic/Modules/Choice/subsystem_choices.gd").new():
get: return get_subsystem("Choices")

var Expressions := preload("res://addons/dialogic/Modules/Core/subsystem_expression.gd").new():
get: return get_subsystem("Expressions")

var Animations := preload("res://addons/dialogic/Modules/Core/subsystem_animation.gd").new():
get: return get_subsystem("Animations")

var Inputs := preload("res://addons/dialogic/Modules/Core/subsystem_input.gd").new():
get: return get_subsystem("Inputs")

var Glossary := preload("res://addons/dialogic/Modules/Glossary/subsystem_glossary.gd").new():
get: return get_subsystem("Glossary")

var History := preload("res://addons/dialogic/Modules/History/subsystem_history.gd").new():
get: return get_subsystem("History")

var Inputs := preload("res://addons/dialogic/Modules/Core/subsystem_input.gd").new():
get: return get_subsystem("Inputs")

var Jump := preload("res://addons/dialogic/Modules/Jump/subsystem_jump.gd").new():
get: return get_subsystem("Jump")

var PortraitContainers := preload("res://addons/dialogic/Modules/Character/subsystem_containers.gd").new():
get: return get_subsystem("PortraitContainers")

var Portraits := preload("res://addons/dialogic/Modules/Character/subsystem_portraits.gd").new():
get: return get_subsystem("Portraits")

var Save := preload("res://addons/dialogic/Modules/Save/subsystem_save.gd").new():
get: return get_subsystem("Save")

Expand Down Expand Up @@ -165,24 +158,19 @@ func _ready() -> void:

clear()

DialogicResourceUtil.update_event_cache()

dialog_ending_timeline = DialogicTimeline.new()
dialog_ending_timeline.from_text("[clear]")


#region TIMELINE & EVENT HANDLING
################################################################################

## Method to start a timeline AND ensure that a layout scene is present.
## For argument info, checkout [method start_timeline].
## -> returns the layout node
func start(timeline:Variant, label_or_idx:Variant="") -> Node:
func start(timeline:Variant, label:Variant="") -> Node:
# If we don't have a style subsystem, default to just start_timeline()
if not has_subsystem('Styles'):
printerr("[Dialogic] You called Dialogic.start() but the Styles subsystem is missing!")
clear(ClearFlags.KEEP_VARIABLES)
start_timeline(timeline, label_or_idx)
start_timeline(timeline, label)
return null

# Otherwise make sure there is a style active.
Expand All @@ -194,12 +182,10 @@ func start(timeline:Variant, label_or_idx:Variant="") -> Node:
scene.show()

if not scene.is_node_ready():
if not scene.ready.is_connected(clear.bind(ClearFlags.KEEP_VARIABLES)):
scene.ready.connect(clear.bind(ClearFlags.KEEP_VARIABLES))
if not scene.ready.is_connected(start_timeline.bind(timeline, label_or_idx)):
scene.ready.connect(start_timeline.bind(timeline, label_or_idx))
scene.ready.connect(clear.bind(ClearFlags.KEEP_VARIABLES))
scene.ready.connect(start_timeline.bind(timeline, label))
else:
start_timeline(timeline, label_or_idx)
start_timeline(timeline, label)

return scene

Expand All @@ -209,12 +195,12 @@ func start(timeline:Variant, label_or_idx:Variant="") -> Node:
## @label_or_idx can be a label (string) or index (int) to skip to immediatly.
func start_timeline(timeline:Variant, label_or_idx:Variant = "") -> void:
# load the resource if only the path is given
if typeof(timeline) in [TYPE_STRING, TYPE_STRING_NAME]:
if typeof(timeline) == TYPE_STRING:
#check the lookup table if it's not a full file name
if "://" in timeline:
timeline = load(timeline)
if (timeline as String).contains("res://"):
timeline = load((timeline as String))
else:
timeline = DialogicResourceUtil.get_timeline_resource(timeline)
timeline = DialogicResourceUtil.get_timeline_resource((timeline as String))

if timeline == null:
printerr("[Dialogic] There was an error loading this timeline. Check the filename, and the timeline for errors")
Expand All @@ -228,30 +214,24 @@ func start_timeline(timeline:Variant, label_or_idx:Variant = "") -> void:
event.dialogic = self
current_event_idx = -1

if typeof(label_or_idx) in [TYPE_STRING, TYPE_STRING_NAME]:
if typeof(label_or_idx) == TYPE_STRING:
if label_or_idx:
if has_subsystem('Jump'):
Jump.jump_to_label((label_or_idx as String))
elif typeof(label_or_idx) == TYPE_INT:
if label_or_idx >-1:
current_event_idx = label_or_idx -1

if not current_timeline == dialog_ending_timeline:
timeline_started.emit()

timeline_started.emit()
handle_next_event()


## Preloader function, prepares a timeline and returns an object to hold for later
## [param timeline_resource] can be either a path (string) or a loaded timeline (resource)
func preload_timeline(timeline_resource:Variant) -> Variant:
# I think ideally this should be on a new thread, will test
if typeof(timeline_resource) in [TYPE_STRING, TYPE_STRING_NAME]:
if "://" in timeline_resource:
timeline_resource = load(timeline_resource)
else:
timeline_resource = DialogicResourceUtil.get_timeline_resource(timeline_resource)

if typeof(timeline_resource) == TYPE_STRING:
timeline_resource = load((timeline_resource as String))
if timeline_resource == null:
printerr("[Dialogic] There was an error preloading this timeline. Check the filename, and the timeline for errors")
return null
Expand All @@ -262,37 +242,12 @@ func preload_timeline(timeline_resource:Variant) -> Variant:


## Clears and stops the current timeline.
## If [param skip_ending] is `true`, the dialog_ending_timeline is not getting played
func end_timeline(skip_ending := false) -> void:
if not skip_ending and dialog_ending_timeline and current_timeline != dialog_ending_timeline:
start(dialog_ending_timeline)
return

func end_timeline() -> void:
await clear(ClearFlags.TIMELINE_INFO_ONLY)

if Styles.has_active_layout_node() and Styles.get_layout_node().is_inside_tree():
match ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0):
0:
Styles.get_layout_node().get_parent().remove_child(Styles.get_layout_node())
Styles.get_layout_node().queue_free()
1:
Styles.get_layout_node().hide()

_on_timeline_ended()
timeline_ended.emit()


## Method to check if timeline exists.
## @timeline can be either a loaded timeline resource or a path to a timeline file.
func timeline_exists(timeline:Variant) -> bool:
if typeof(timeline) in [TYPE_STRING, TYPE_STRING_NAME]:
if "://" in timeline and ResourceLoader.exists(timeline):
return load(timeline) is DialogicTimeline
else:
return DialogicResourceUtil.timeline_resource_exists(timeline)

return timeline is DialogicTimeline


## Handles the next event.
func handle_next_event(_ignore_argument: Variant = "") -> void:
handle_event(current_event_idx+1)
Expand All @@ -313,7 +268,6 @@ func handle_event(event_index:int) -> void:
end_timeline()
return

# TODO: Check if necessary. This should be impossible.
#actually process the event now, since we didnt earlier at runtime
#this needs to happen before we create the copy DialogicEvent variable, so it doesn't throw an error if not ready
if current_timeline_events[event_index].event_node_ready == false:
Expand Down Expand Up @@ -413,7 +367,7 @@ func load_full_state(state_info:Dictionary) -> void:
if current_state_info.get('current_timeline', null):
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))
else:
end_timeline.call_deferred(true)
end_timeline.call_deferred()
#endregion


Expand Down Expand Up @@ -458,12 +412,22 @@ func add_subsystem(subsystem_name:String, script_path:String) -> DialogicSubsyst
#region HELPERS
################################################################################

## This handles the `Layout End Behaviour` setting that can be changed in the Dialogic settings.
func _on_timeline_ended() -> void:
if self.Styles.has_active_layout_node() and self.Styles.get_layout_node().is_inside_tree():
match ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0):
0:
self.Styles.get_layout_node().get_parent().remove_child(self.Styles.get_layout_node())
self.Styles.get_layout_node().queue_free()
1:
@warning_ignore("unsafe_method_access")
self.Styles.get_layout_node().hide()


func print_debug_moment() -> void:
if not current_timeline:
return

printerr("\tAt event ", current_event_idx+1, " (",current_timeline_events[current_event_idx].event_name, ' Event) in timeline "', current_timeline.get_identifier(), '" (',current_timeline.resource_path,').')
printerr("\tAt event ", current_event_idx+1, " (",current_timeline_events[current_event_idx].event_name, ' Event) in timeline "', DialogicResourceUtil.get_unique_identifier(current_timeline.resource_path), '" (',current_timeline.resource_path,').')
print("\n")
#endregion
1 change: 0 additions & 1 deletion addons/dialogic/Core/DialogicGameHandler.gd.uid

This file was deleted.

Loading