Files
DungeonCrawlerWorld/tests/unit/test_floor_generator_rooms.gd
T

37 lines
1.5 KiB
GDScript

extends GutTest
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
const MAP_SIZE := Vector2i(80, 50)
const ROOM_PADDING := 2
func test_generator_creates_deterministic_padded_rooms_inside_the_minimal_floor() -> void:
var catalog := ContentCatalogType.new()
var first := FloorGeneratorType.generate("B2-rooms-contract", 1, catalog)
var second := FloorGeneratorType.generate("B2-rooms-contract", 1, catalog)
assert_eq(first.map.size, MAP_SIZE)
assert_gte(first.rooms.size(), 8)
assert_eq(first.to_dict(), second.to_dict())
for room in first.rooms:
assert_gte(room.bounds.size.x, 5, "%s minimum room width" % room.id)
assert_gte(room.bounds.size.y, 4, "%s minimum room height" % room.id)
assert_true(_is_inside_map(room.bounds), "%s is inside the map" % room.id)
for first_index in range(first.rooms.size()):
for second_index in range(first_index + 1, first.rooms.size()):
var first_padded := first.rooms[first_index].bounds.grow(ROOM_PADDING)
var second_padded := first.rooms[second_index].bounds.grow(ROOM_PADDING)
assert_false(
first_padded.intersects(second_padded),
"%s and %s respect padding" % [first.rooms[first_index].id, first.rooms[second_index].id]
)
func _is_inside_map(bounds: Rect2i) -> bool:
return bounds.position.x >= 0 \
and bounds.position.y >= 0 \
and bounds.end.x <= MAP_SIZE.x \
and bounds.end.y <= MAP_SIZE.y