refactor: unify animal content packs
This commit is contained in:
@@ -54,6 +54,10 @@ func _test_core_pack() -> void:
|
||||
_enemy_ids(catalog.get_enemies()) == [&"enemy_boar", &"enemy_raider", &"enemy_wolf"],
|
||||
"Core enemies should enumerate by stable ID"
|
||||
)
|
||||
_check(
|
||||
_animal_ids(catalog.get_animals()) == [&"domestic_goat", &"domestic_sheep"],
|
||||
"Core animals should enumerate through the same content pack"
|
||||
)
|
||||
var food := catalog.get_item(SimulationIds.RESOURCE_FOOD)
|
||||
var wood := catalog.get_item(SimulationIds.RESOURCE_WOOD)
|
||||
var sword := catalog.get_item(SimulationIds.ITEM_SWORD)
|
||||
@@ -133,6 +137,17 @@ func _test_duplicate_ids_fail_without_overrides() -> void:
|
||||
errors = catalog.rebuild(duplicate_packs)
|
||||
_check(_has_error(errors, "Duplicate pack_id 'first'"), "Duplicate pack IDs should fail")
|
||||
|
||||
first = _pack(&"first", "First")
|
||||
second = _pack(&"second", "Second")
|
||||
first.animals = [_animal(&"shared_animal", &"feed_animal")]
|
||||
second.animals = [_animal(&"shared_animal", &"feed_animal")]
|
||||
var duplicate_animal_packs: Array[SimulationContentPack] = [second, first]
|
||||
errors = catalog.rebuild(duplicate_animal_packs)
|
||||
_check(
|
||||
_has_error(errors, "Duplicate animal_definition_id 'shared_animal'"),
|
||||
"Duplicate animal definitions should fail without an override"
|
||||
)
|
||||
|
||||
|
||||
func _test_unknown_references_categories_and_handlers() -> void:
|
||||
var broken := _pack(&"broken", "Broken")
|
||||
@@ -162,9 +177,11 @@ func _test_unknown_references_categories_and_handlers() -> void:
|
||||
weapon_cost.completion_cost_amount = 1.0
|
||||
var missing_weapon := _enemy(&"missing_weapon_enemy", &"unknown_weapon")
|
||||
var non_weapon := _enemy(&"non_weapon_enemy", ordinary_resource.item_id)
|
||||
var missing_animal_action := _animal(&"unsupported_animal", &"unknown_animal_action")
|
||||
broken.items = [invalid_item, ordinary_resource, weapon_item]
|
||||
broken.actions = [missing_profession, missing_action, missing_cost_item, weapon_cost]
|
||||
broken.enemies = [missing_weapon, non_weapon]
|
||||
broken.animals = [missing_animal_action]
|
||||
var packs: Array[SimulationContentPack] = [broken]
|
||||
var known_handlers: Array[StringName] = [&"known_handler"]
|
||||
var catalog := ContentCatalog.new()
|
||||
@@ -184,6 +201,7 @@ func _test_unknown_references_categories_and_handlers() -> void:
|
||||
"non-resource completion cost item 'test_weapon'",
|
||||
"unknown weapon 'unknown_weapon'",
|
||||
"non-weapon item 'ordinary_resource'",
|
||||
"Animal 'unsupported_animal' references unknown action 'unknown_animal_action'",
|
||||
]:
|
||||
_check(_has_error(errors, expected), "Catalog should report %s: %s" % [expected, errors])
|
||||
_check(not catalog.is_valid(), "Unknown references should invalidate the complete catalog")
|
||||
@@ -233,6 +251,16 @@ func _enemy(enemy_id: StringName, weapon_id: StringName) -> EnemyDefinition:
|
||||
return enemy
|
||||
|
||||
|
||||
func _animal(animal_definition_id: StringName, action_id: StringName) -> AnimalDefinition:
|
||||
var animal := AnimalDefinition.new()
|
||||
animal.animal_definition_id = animal_definition_id
|
||||
animal.species_id = &"test_species"
|
||||
animal.display_name = String(animal_definition_id).capitalize()
|
||||
animal.supported_action_ids = [action_id]
|
||||
animal.presentation_scene_path = "res://world/animals/grazer/cozy_grazer.tscn"
|
||||
return animal
|
||||
|
||||
|
||||
func _pack_ids(packs: Array[SimulationContentPack]) -> Array[StringName]:
|
||||
var ids: Array[StringName] = []
|
||||
for pack in packs:
|
||||
@@ -268,6 +296,13 @@ func _enemy_ids(enemies: Array[EnemyDefinition]) -> Array[StringName]:
|
||||
return ids
|
||||
|
||||
|
||||
func _animal_ids(animals: Array[AnimalDefinition]) -> Array[StringName]:
|
||||
var ids: Array[StringName] = []
|
||||
for animal in animals:
|
||||
ids.append(animal.animal_definition_id)
|
||||
return ids
|
||||
|
||||
|
||||
func _has_error(errors: Array[String], fragment: String) -> bool:
|
||||
for error in errors:
|
||||
if fragment in error:
|
||||
|
||||
Reference in New Issue
Block a user