SupaLidlGame/addons/dialogue_manager/dialogue_line.gd

99 lines
3.1 KiB
GDScript
Raw Permalink Normal View History

2024-04-08 14:42:12 -07:00
## A line of dialogue returned from [code]DialogueManager[/code].
2023-07-27 11:39:38 -07:00
class_name DialogueLine extends RefCounted
2024-04-08 14:42:12 -07:00
const _DialogueConstants = preload("./constants.gd")
2023-07-27 11:39:38 -07:00
2024-04-08 14:42:12 -07:00
## The ID of this line
var id: String
## The internal type of this dialogue object. One of [code]TYPE_DIALOGUE[/code] or [code]TYPE_MUTATION[/code]
var type: String = _DialogueConstants.TYPE_DIALOGUE
## The next line ID after this line.
2023-07-27 11:39:38 -07:00
var next_id: String = ""
2024-04-08 14:42:12 -07:00
## The character name that is saying this line.
2023-07-27 11:39:38 -07:00
var character: String = ""
2024-04-08 14:42:12 -07:00
## A dictionary of variable replacements fo the character name. Generally for internal use only.
2023-07-27 11:39:38 -07:00
var character_replacements: Array[Dictionary] = []
2024-04-08 14:42:12 -07:00
## The dialogue being spoken.
2023-07-27 11:39:38 -07:00
var text: String = ""
2024-04-08 14:42:12 -07:00
## A dictionary of replacements for the text. Generally for internal use only.
2023-07-27 11:39:38 -07:00
var text_replacements: Array[Dictionary] = []
2024-04-08 14:42:12 -07:00
## The key to use for translating this line.
2023-07-27 11:39:38 -07:00
var translation_key: String = ""
2024-04-08 14:42:12 -07:00
## A map for when and for how long to pause while typing out the dialogue text.
2023-07-27 11:39:38 -07:00
var pauses: Dictionary = {}
2024-04-08 14:42:12 -07:00
## A map for speed changes when typing out the dialogue text.
2023-07-27 11:39:38 -07:00
var speeds: Dictionary = {}
2024-04-08 14:42:12 -07:00
## A map of any mutations to run while typing out the dialogue text.
2023-07-27 11:39:38 -07:00
var inline_mutations: Array[Array] = []
2024-04-08 14:42:12 -07:00
## A list of responses attached to this line of dialogue.
2023-07-27 11:39:38 -07:00
var responses: Array[DialogueResponse] = []
2024-04-08 14:42:12 -07:00
## A list of any extra game states to check when resolving variables and mutations.
2023-07-27 11:39:38 -07:00
var extra_game_states: Array = []
2024-04-08 14:42:12 -07:00
## How long to show this line before advancing to the next. Either a float (of seconds), [code]"auto"[/code], or [code]null[/code].
var time: String = ""
## Any #tags that were included in the line
var tags: PackedStringArray = []
## The mutation details if this is a mutation line (where [code]type == TYPE_MUTATION[/code]).
2023-07-27 11:39:38 -07:00
var mutation: Dictionary = {}
2024-04-08 14:42:12 -07:00
## The conditions to check before including this line in the flow of dialogue. If failed the line will be skipped over.
var conditions: Dictionary = {}
2023-07-27 11:39:38 -07:00
func _init(data: Dictionary = {}) -> void:
if data.size() > 0:
2024-04-08 14:42:12 -07:00
id = data.id
2023-07-27 11:39:38 -07:00
next_id = data.next_id
type = data.type
2024-04-08 14:42:12 -07:00
extra_game_states = data.get("extra_game_states", [])
2023-07-27 11:39:38 -07:00
match type:
2024-04-08 14:42:12 -07:00
_DialogueConstants.TYPE_DIALOGUE:
2023-07-27 11:39:38 -07:00
character = data.character
2024-04-08 14:42:12 -07:00
character_replacements = data.get("character_replacements", [] as Array[Dictionary])
2023-07-27 11:39:38 -07:00
text = data.text
2024-04-08 14:42:12 -07:00
text_replacements = data.get("text_replacements", [] as Array[Dictionary])
translation_key = data.get("translation_key", data.text)
pauses = data.get("pauses", {})
speeds = data.get("speeds", {})
inline_mutations = data.get("inline_mutations", [] as Array[Array])
time = data.get("time", "")
tags = data.get("tags", [])
_DialogueConstants.TYPE_MUTATION:
2023-07-27 11:39:38 -07:00
mutation = data.mutation
2024-04-08 14:42:12 -07:00
func _to_string() -> String:
match type:
_DialogueConstants.TYPE_DIALOGUE:
return "<DialogueLine character=\"%s\" text=\"%s\">" % [character, text]
_DialogueConstants.TYPE_MUTATION:
return "<DialogueLine mutation>"
return ""
func get_tag_value(tag_name: String) -> String:
var wrapped := "%s=" % tag_name
for t in tags:
if t.begins_with(wrapped):
return t.replace(wrapped, "").strip_edges()
return ""