70 lines
3.6 KiB
GDScript
70 lines
3.6 KiB
GDScript
extends GutTest
|
|
|
|
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
|
const SurfaceGeneratorType = preload("res://scripts/domain/world/surface_generator.gd")
|
|
const FloorTransitionType = preload("res://scripts/domain/run/floor_transition.gd")
|
|
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
|
|
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
|
|
|
|
const ASCII_CATALOG_PATH := "res://data/ascii"
|
|
|
|
func test_floor_zero_is_hand_authored_and_floor_one_is_seed_floor_one_procedural() -> void:
|
|
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
|
var run := RunStateType.new("B5-surface-contract")
|
|
var transitions := FloorTransitionType.new(catalog)
|
|
|
|
var surface := transitions.initial_floor(run)
|
|
var descend := transitions.transition(run, surface, surface.exit)
|
|
var first_floor: FloorState = descend["floor"]
|
|
|
|
assert_eq(surface.floor_number, 0)
|
|
assert_true(surface.metadata.get("hand_authored", false))
|
|
assert_eq(surface.map.size, Vector2i(42, 16))
|
|
assert_eq(surface.entrance, Vector2i(4, 7))
|
|
assert_eq(surface.exit, Vector2i(39, 7))
|
|
assert_eq(surface.map.get_cell(Vector2i(36, 7)), GridMapStateType.CellKind.CLOSED_DOOR)
|
|
assert_eq(surface.map.get_cell(surface.exit), GridMapStateType.CellKind.STAIRS)
|
|
assert_true(surface.enemies.is_empty())
|
|
assert_true(surface.chests.is_empty())
|
|
assert_eq(first_floor.floor_number, 1)
|
|
assert_false(first_floor.metadata.get("hand_authored", false))
|
|
assert_eq(first_floor.seed, _seed_value("B5-surface-contract", 1))
|
|
assert_eq(first_floor.map.get_cell(first_floor.entrance), GridMapStateType.CellKind.STAIRS)
|
|
assert_eq(first_floor.map.get_cell(first_floor.exit), GridMapStateType.CellKind.STAIRS)
|
|
assert_eq(descend["arrival"], first_floor.entrance)
|
|
|
|
var independently_authored := SurfaceGeneratorType.generate("another-seed")
|
|
assert_eq(independently_authored.to_dict(), surface.to_dict(), "floor zero is authored rather than seed-generated")
|
|
|
|
func test_transition_cache_keeps_mutated_floor_state_and_arrival_cells_across_return_trip() -> void:
|
|
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
|
|
var run := RunStateType.new("B5-cache-contract")
|
|
var transitions := FloorTransitionType.new(catalog)
|
|
var surface := transitions.initial_floor(run)
|
|
var first_descent := transitions.transition(run, surface, surface.exit)
|
|
var first_floor: FloorState = first_descent["floor"]
|
|
first_floor.chests[Vector2i(3, 3)] = {"opened": true}
|
|
first_floor.enemies.clear()
|
|
first_floor.events.append({"id": "first-floor-event", "resolved": true})
|
|
|
|
var ascent := transitions.transition(run, first_floor, first_floor.entrance)
|
|
var returned_surface: FloorState = ascent["floor"]
|
|
returned_surface.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
|
|
var second_descent := transitions.transition(run, returned_surface, returned_surface.exit)
|
|
var cached_first_floor: FloorState = second_descent["floor"]
|
|
|
|
assert_same(returned_surface, surface)
|
|
assert_eq(ascent["arrival"], surface.exit)
|
|
assert_same(cached_first_floor, first_floor)
|
|
assert_eq(second_descent["arrival"], first_floor.entrance)
|
|
assert_eq(cached_first_floor.chests[Vector2i(3, 3)], {"opened": true})
|
|
assert_eq(cached_first_floor.enemies.size(), 0)
|
|
assert_true(cached_first_floor.events.has({"id": "first-floor-event", "resolved": true}))
|
|
assert_eq(surface.map.get_cell(Vector2i(4, 7)), GridMapStateType.CellKind.FLOOR)
|
|
|
|
func _seed_value(seed: String, floor_number: int) -> int:
|
|
var value := 0
|
|
for index in range(seed.length()):
|
|
value = (value * 31 + seed.unicode_at(index)) % 2147483647
|
|
return value + floor_number
|