34 lines
1.1 KiB
GDScript
34 lines
1.1 KiB
GDScript
class_name SituationPredicate
|
|
extends Resource
|
|
|
|
const SOURCE_EVENT := &"event"
|
|
const SOURCE_STATE := &"state"
|
|
|
|
@export var predicate_id: StringName
|
|
@export var evaluator_id: StringName
|
|
@export_enum("event", "state") var source: String = String(SOURCE_EVENT)
|
|
@export var parameters: Dictionary = {}
|
|
|
|
|
|
func validate() -> Array[String]:
|
|
var errors: Array[String] = []
|
|
if predicate_id.is_empty():
|
|
errors.append("predicate_id is empty")
|
|
if evaluator_id.is_empty():
|
|
errors.append("evaluator_id is empty for predicate '%s'" % predicate_id)
|
|
if StringName(source) not in [SOURCE_EVENT, SOURCE_STATE]:
|
|
errors.append("predicate '%s' has invalid source '%s'" % [predicate_id, source])
|
|
for key in parameters:
|
|
if not key is String and not key is StringName:
|
|
errors.append("predicate '%s' has a non-string parameter key" % predicate_id)
|
|
return errors
|
|
|
|
|
|
func duplicate_predicate() -> SituationPredicate:
|
|
var copy := SituationPredicate.new()
|
|
copy.predicate_id = predicate_id
|
|
copy.evaluator_id = evaluator_id
|
|
copy.source = source
|
|
copy.parameters = parameters.duplicate(true)
|
|
return copy
|