45 lines
1.4 KiB
GDScript
45 lines
1.4 KiB
GDScript
class_name ConversationTemplateCatalog
|
|
extends Resource
|
|
|
|
@export var line_templates: Dictionary = {}
|
|
@export var option_templates: Dictionary = {}
|
|
|
|
|
|
func validate(intent_ids: Array[StringName] = ConversationIntentIds.ALL) -> Array[String]:
|
|
var errors: Array[String] = []
|
|
_validate_templates(line_templates, "line", intent_ids, errors)
|
|
_validate_templates(option_templates, "option", intent_ids, errors)
|
|
errors.sort()
|
|
return errors
|
|
|
|
|
|
func get_line_templates(intent_id: StringName) -> Array[String]:
|
|
return _get_templates(line_templates, intent_id)
|
|
|
|
|
|
func get_option_templates(intent_id: StringName) -> Array[String]:
|
|
return _get_templates(option_templates, intent_id)
|
|
|
|
|
|
func _get_templates(source: Dictionary, intent_id: StringName) -> Array[String]:
|
|
var result: Array[String] = []
|
|
var values: Variant = source.get(String(intent_id), [])
|
|
if values is Array or values is PackedStringArray:
|
|
for value in values:
|
|
if value is String:
|
|
result.append(value)
|
|
return result
|
|
|
|
|
|
func _validate_templates(
|
|
source: Dictionary, kind: String, intent_ids: Array[StringName], errors: Array[String]
|
|
) -> void:
|
|
for intent_id in intent_ids:
|
|
var templates := _get_templates(source, intent_id)
|
|
if templates.is_empty():
|
|
errors.append("Missing %s templates for '%s'" % [kind, intent_id])
|
|
continue
|
|
for template in templates:
|
|
if template.strip_edges().is_empty():
|
|
errors.append("Empty %s template for '%s'" % [kind, intent_id])
|