79 lines
2.4 KiB
GDScript
79 lines
2.4 KiB
GDScript
class_name SimulationContentPack
|
|
extends Resource
|
|
|
|
@export var pack_id: StringName
|
|
@export var display_name: String
|
|
@export var required_pack_ids: Array[StringName] = []
|
|
@export var required_handler_ids: Array[StringName] = []
|
|
@export var actions: Array[ActionDefinition] = []
|
|
@export var professions: Array[ProfessionDefinition] = []
|
|
@export var items: Array[ItemDefinition] = []
|
|
@export var enemies: Array[EnemyDefinition] = []
|
|
|
|
|
|
func validate() -> Array[String]:
|
|
var errors: Array[String] = []
|
|
if pack_id.is_empty():
|
|
errors.append("pack_id is empty")
|
|
if display_name.is_empty():
|
|
errors.append("display_name is empty for pack '%s'" % pack_id)
|
|
_validate_dependency_ids(required_pack_ids, "required pack", errors)
|
|
_validate_dependency_ids(required_handler_ids, "required handler", errors)
|
|
if pack_id in required_pack_ids:
|
|
errors.append("pack '%s' cannot require itself" % pack_id)
|
|
_validate_actions(errors)
|
|
_validate_professions(errors)
|
|
_validate_items(errors)
|
|
_validate_enemies(errors)
|
|
return errors
|
|
|
|
|
|
func _validate_actions(errors: Array[String]) -> void:
|
|
for definition in actions:
|
|
if definition == null:
|
|
errors.append("actions contains a null definition")
|
|
continue
|
|
for error in definition.validate():
|
|
errors.append("ActionDefinition: " + error)
|
|
|
|
|
|
func _validate_professions(errors: Array[String]) -> void:
|
|
for definition in professions:
|
|
if definition == null:
|
|
errors.append("professions contains a null definition")
|
|
continue
|
|
for error in definition.validate():
|
|
errors.append("ProfessionDefinition: " + error)
|
|
|
|
|
|
func _validate_items(errors: Array[String]) -> void:
|
|
for definition in items:
|
|
if definition == null:
|
|
errors.append("items contains a null definition")
|
|
continue
|
|
for error in definition.validate():
|
|
errors.append("ItemDefinition: " + error)
|
|
|
|
|
|
func _validate_enemies(errors: Array[String]) -> void:
|
|
for definition in enemies:
|
|
if definition == null:
|
|
errors.append("enemies contains a null definition")
|
|
continue
|
|
for error in definition.validate():
|
|
errors.append("EnemyDefinition: " + error)
|
|
|
|
|
|
static func _validate_dependency_ids(
|
|
ids: Array[StringName], label: String, errors: Array[String]
|
|
) -> void:
|
|
var seen := {}
|
|
for dependency_id in ids:
|
|
if dependency_id.is_empty():
|
|
errors.append("%s ID is empty" % label)
|
|
continue
|
|
if seen.has(dependency_id):
|
|
errors.append("duplicate %s '%s'" % [label, dependency_id])
|
|
continue
|
|
seen[dependency_id] = true
|