feat: add procedural doors and room roles
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
extends GutTest
|
||||
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
|
||||
const RoomGraphType = preload("res://scripts/domain/world/room_graph.gd")
|
||||
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
const ROOM_KINDS := [
|
||||
&"entrance", &"combat", &"treasure", &"trap", &"sanctuary", &"shop",
|
||||
&"mystery", &"puzzle", &"arena", &"narrative", &"refuge", &"guild", &"boss",
|
||||
]
|
||||
|
||||
func test_exit_uses_a_different_farthest_room_on_the_spanning_tree() -> void:
|
||||
var floor := FloorGeneratorType.generate("B3-farthest-exit", 1, ContentCatalogType.new())
|
||||
var graph := RoomGraphType.from_dict(floor.metadata["room_graph"])
|
||||
var entrance_index := _room_index(floor, floor.entrance)
|
||||
var exit_index := _room_index(floor, floor.exit)
|
||||
var distances := graph.tree_distances(entrance_index)
|
||||
var maximum_distance := 0
|
||||
for distance in distances.values():
|
||||
maximum_distance = maxi(maximum_distance, int(distance))
|
||||
|
||||
assert_ne(exit_index, entrance_index)
|
||||
assert_eq(distances[exit_index], maximum_distance)
|
||||
assert_eq(graph.tree_edges.size(), floor.rooms.size() - 1)
|
||||
|
||||
func test_tree_corridors_have_closed_openable_boundary_doors() -> void:
|
||||
var floor := FloorGeneratorType.generate("B3-tree-doors", 2, ContentCatalogType.new())
|
||||
var tree_doors: Array = floor.metadata["tree_door_cells"]
|
||||
|
||||
assert_gt(tree_doors.size(), 0)
|
||||
for serialized_cell: Array in tree_doors:
|
||||
var door_cell := Vector2i(int(serialized_cell[0]), int(serialized_cell[1]))
|
||||
assert_eq(floor.map.get_cell(door_cell), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
assert_true(_has_adjacent_room(floor.map, door_cell), "door %s is at a room/corridor boundary" % door_cell)
|
||||
|
||||
func test_room_roles_follow_ascii_weights_and_floor_gates() -> void:
|
||||
var first_floor := FloorGeneratorType.generate("B3-role-gates", 1, ContentCatalogType.new())
|
||||
var boss_floor := FloorGeneratorType.generate("B3-role-gates", 5, ContentCatalogType.new())
|
||||
|
||||
_assert_valid_roles(first_floor)
|
||||
_assert_valid_roles(boss_floor)
|
||||
assert_eq(_room_for_cell(first_floor, first_floor.entrance).kind, &"entrance")
|
||||
assert_eq(_room_for_cell(first_floor, first_floor.exit).kind, &"combat")
|
||||
assert_eq(_room_for_cell(boss_floor, boss_floor.exit).kind, &"boss")
|
||||
for room in first_floor.rooms:
|
||||
assert_ne(room.kind, &"shop", "shops are gated until floor 3")
|
||||
assert_ne(room.kind, &"boss", "boss rooms are gated to boss floors")
|
||||
|
||||
func _assert_valid_roles(floor: FloorState) -> void:
|
||||
for room in floor.rooms:
|
||||
assert_has(ROOM_KINDS, room.kind, "%s has a supported B3 room kind" % room.id)
|
||||
|
||||
func _room_index(floor: FloorState, cell: Vector2i) -> int:
|
||||
var id := floor.map.get_room_id(cell)
|
||||
for index in range(floor.rooms.size()):
|
||||
if floor.rooms[index].id == id:
|
||||
return index
|
||||
return -1
|
||||
|
||||
func _room_for_cell(floor: FloorState, cell: Vector2i) -> RoomState:
|
||||
return floor.rooms[_room_index(floor, cell)]
|
||||
|
||||
func _has_adjacent_room(map: GridMapState, cell: Vector2i) -> bool:
|
||||
for direction in [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN]:
|
||||
if not map.get_room_id(cell + direction).is_empty():
|
||||
return true
|
||||
return false
|
||||
@@ -0,0 +1 @@
|
||||
uid://cl11r8ohwnjfb
|
||||
Reference in New Issue
Block a user