Skip to content

Commit

Permalink
Test changes
Browse files Browse the repository at this point in the history
create_map now has configurable width for testing
changed test for a small floor (reference)
  • Loading branch information
xone-mi committed Jan 2, 2024
1 parent 14ce1f6 commit 80740f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
11 changes: 6 additions & 5 deletions Map/MapManager.gd
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
extends Node2D
## Class to manage backend for rooms (generation and such)

static func create_map() -> MapBase: ## Generates and Populates a map with rooms that have random room types. More in depth algorithms will be added in the future
#layout changes the width of the map's floors
static func create_map(_layout: Array[int]) -> MapBase: ## Generates and Populates a map with rooms that have random room types. More in depth algorithms will be added in the future
var _map: MapBase = MapBase.new()
var _grid: Array[Array] = [] ## 2d array to return. this will be populated with rooms
var _max_floor_size: int = _map.floors_width.max()
for index_height: int in range(_map.floors_width.size()): ## loop through the floor and append null to create a square grid
var _max_floor_size: int = _layout.max()
for index_height: int in range(_layout.size()): ## loop through the floor and append null to create a square grid
_grid.append([])

var _floor_width : int = _map.floors_width[index_height]
var _floor_width : int = _layout[index_height]
var _padding_size : int = (_max_floor_size - _floor_width)/2

_grid[index_height].resize(_max_floor_size-_floor_width)
_grid[index_height].fill(null)

for index_width: int in range(_map.floors_width[index_height]):## loop through elements of the grid and assign a room type
for index_width: int in range(_layout[index_height]):## loop through elements of the grid and assign a room type
var _rand_type_index: int = randi() % GlobalVar.EVENTS_CLASSIFICATION.size()
var _room_event: EventBase = GlobalVar.EVENTS_CLASSIFICATION[_rand_type_index].new()
var _generated_room: RoomBase = RoomBase.new()
Expand Down
18 changes: 16 additions & 2 deletions Tests/test_map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ extends GutTest ## Tests for MapManager, more will be added in the future

var test_generator = load("res://Map/MapManager.gd")



func test_map_gen():
var result = test_generator.create_map()
assert_not_null(result, "Expected to return generated class")
var test_width: Array[int] = [1,3,5,3,1]
var test_map: MapBase = test_generator.create_map(test_width)
assert_null(test_map.rooms[0][0])
assert_null(test_map.rooms[0][1])
assert_null(test_map.rooms[0][3])
assert_null(test_map.rooms[0][4])
assert_null(test_map.rooms[4][0])
assert_null(test_map.rooms[4][1])
assert_null(test_map.rooms[4][3])
assert_null(test_map.rooms[4][4])
assert_null(test_map.rooms[1][0])
assert_null(test_map.rooms[1][4])
assert_null(test_map.rooms[3][0])
assert_null(test_map.rooms[3][4])

0 comments on commit 80740f6

Please sign in to comment.