24 lines
742 B
GDScript
24 lines
742 B
GDScript
class_name DialogueState
|
|
extends RefCounted
|
|
|
|
var definition: Dictionary = {}
|
|
var dialogue_id: StringName = &""
|
|
var node_id: StringName = &""
|
|
var ended := false
|
|
|
|
func _init(dialogue_definition: Dictionary = {}) -> void:
|
|
definition = dialogue_definition.duplicate(true)
|
|
dialogue_id = StringName(definition.get("id", ""))
|
|
node_id = StringName(definition.get("start", ""))
|
|
ended = dialogue_id.is_empty() or node_id.is_empty() or current_node().is_empty()
|
|
|
|
func current_node() -> Dictionary:
|
|
var nodes: Variant = definition.get("nodes", {})
|
|
if not nodes is Dictionary:
|
|
return {}
|
|
var node: Variant = nodes.get(String(node_id), {})
|
|
return node if node is Dictionary else {}
|
|
|
|
func is_over() -> bool:
|
|
return ended or node_id == &"__SHOP__"
|