67 lines
2.0 KiB
GDScript
67 lines
2.0 KiB
GDScript
@tool
|
|
@icon("./assets/icon.svg")
|
|
|
|
## A collection of dialogue lines for use with [code]DialogueManager[/code].
|
|
class_name DialogueResource extends Resource
|
|
|
|
const _DialogueManager = preload("./dialogue_manager.gd")
|
|
const DialogueLine = preload("./dialogue_line.gd")
|
|
|
|
## A list of state shortcuts
|
|
@export var using_states: PackedStringArray = []
|
|
|
|
## A map of titles and the lines they point to.
|
|
@export var titles: Dictionary = {}
|
|
|
|
## A list of character names.
|
|
@export var character_names: PackedStringArray = []
|
|
|
|
## The first title in the file.
|
|
@export var first_title: String = ""
|
|
|
|
## A map of the encoded lines of dialogue.
|
|
@export var lines: Dictionary = {}
|
|
|
|
## raw version of the text
|
|
@export var raw_text: String
|
|
|
|
|
|
## Get the next printable line of dialogue, starting from a referenced line ([code]title[/code] can
|
|
## be a title string or a stringified line number). Runs any mutations along the way and then returns
|
|
## the first dialogue line encountered.
|
|
func get_next_dialogue_line(
|
|
title: String,
|
|
extra_game_states: Array = [],
|
|
mutation_behaviour: _DialogueManager.MutationBehaviour = _DialogueManager.MutationBehaviour.Wait
|
|
) -> DialogueLine:
|
|
return await Engine.get_singleton("DialogueManager").get_next_dialogue_line(
|
|
self, title, extra_game_states, mutation_behaviour
|
|
)
|
|
|
|
|
|
## Get the list of any titles found in the file.
|
|
func get_titles() -> Array:
|
|
return titles.keys()
|
|
|
|
|
|
func get_ordered_titles() -> Array:
|
|
var splitted = raw_text.split("\n")
|
|
var ordered_titles = []
|
|
for line in splitted:
|
|
if line.begins_with("~ "):
|
|
ordered_titles.append(line.substr(2).strip_edges())
|
|
# # check ordered_titles consistency to titles
|
|
# for title in ordered_titles:
|
|
# if not titles.has(title):
|
|
# printerr("Title %s not found in titles" % title)
|
|
# ordered_titles.remove(title)
|
|
# for title in titles.keys():
|
|
# if not ordered_titles.has(title):
|
|
# printerr("Title %s not found in ordered_titles" % title)
|
|
# ordered_titles.append(title)
|
|
return ordered_titles
|
|
|
|
|
|
func _to_string() -> String:
|
|
return '<DialogueResource titles="%s">' % [",".join(titles.keys())]
|