56 lines
2.1 KiB
GDScript
56 lines
2.1 KiB
GDScript
class_name SituationAlternativeDefinition
|
|
extends Resource
|
|
|
|
@export var alternative_id: StringName
|
|
@export var display_name: String
|
|
@export_multiline var description: String
|
|
@export var resolution_predicate_ids: Array[StringName] = []
|
|
@export var dialogue_topic_ids: Array[StringName] = []
|
|
@export var commitment_terms: Dictionary = {}
|
|
|
|
|
|
func validate() -> Array[String]:
|
|
var errors: Array[String] = []
|
|
if alternative_id.is_empty():
|
|
errors.append("alternative_id is empty")
|
|
if display_name.is_empty():
|
|
errors.append("display_name is empty for alternative '%s'" % alternative_id)
|
|
if resolution_predicate_ids.is_empty():
|
|
errors.append("alternative '%s' has no resolution predicates" % alternative_id)
|
|
var seen_predicate_ids := {}
|
|
for predicate_id in resolution_predicate_ids:
|
|
if predicate_id.is_empty():
|
|
errors.append("alternative '%s' has an empty resolution predicate ID" % alternative_id)
|
|
elif seen_predicate_ids.has(predicate_id):
|
|
errors.append(
|
|
(
|
|
"alternative '%s' has duplicate resolution predicate '%s'"
|
|
% [alternative_id, predicate_id]
|
|
)
|
|
)
|
|
seen_predicate_ids[predicate_id] = true
|
|
var seen_topic_ids := {}
|
|
for topic_id in dialogue_topic_ids:
|
|
if topic_id.is_empty():
|
|
errors.append("alternative '%s' has an empty dialogue topic ID" % alternative_id)
|
|
elif seen_topic_ids.has(topic_id):
|
|
errors.append(
|
|
"alternative '%s' has duplicate dialogue topic '%s'" % [alternative_id, topic_id]
|
|
)
|
|
seen_topic_ids[topic_id] = true
|
|
for term_key in commitment_terms:
|
|
if not term_key is String and not term_key is StringName:
|
|
errors.append("alternative '%s' has a non-string commitment term key" % alternative_id)
|
|
return errors
|
|
|
|
|
|
func duplicate_alternative() -> SituationAlternativeDefinition:
|
|
var copy := SituationAlternativeDefinition.new()
|
|
copy.alternative_id = alternative_id
|
|
copy.display_name = display_name
|
|
copy.description = description
|
|
copy.resolution_predicate_ids = resolution_predicate_ids.duplicate()
|
|
copy.dialogue_topic_ids = dialogue_topic_ids.duplicate()
|
|
copy.commitment_terms = commitment_terms.duplicate(true)
|
|
return copy
|