From 96270d84b289321c550bcce665ccc6eaa5d3b347 Mon Sep 17 00:00:00 2001 From: multi arm Date: Sat, 6 Jan 2024 18:48:50 -0500 Subject: [PATCH] Feedback changes changed create_map(_layout) > create_map(floors_width) added room padding to both before and after rooms are generated changed tests to use a fixed list --- Map/MapManager.gd | 25 +++++++++++++------------ Tests/test_map.gd | 13 +++++++------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Map/MapManager.gd b/Map/MapManager.gd index adb2337d..66ff521f 100644 --- a/Map/MapManager.gd +++ b/Map/MapManager.gd @@ -2,27 +2,28 @@ extends Node2D ## Class to manage backend for rooms (generation and such) #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 +static func create_map(floors_width: 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 = _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 _max_floor_size: int = floors_width.max() + for index_height: int in range(floors_width.size()): ## loop through the floor and append null to create a square grid + - var _floor_width : int = _layout[index_height] + var _floor_width : int = floors_width[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) + var _padding:Array = [] + _padding.resize(_padding_size) + _padding.fill(null) + _grid.append([]) + _grid[index_height].append_array(_padding) - 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() + for index_width: int in range(floors_width[index_height]):## loop through elements of the grid and assign a room type + var _rand_type_index: int = randi_range(0, GlobalVar.EVENTS_CLASSIFICATION.size() - 1) var _room_event: EventBase = GlobalVar.EVENTS_CLASSIFICATION[_rand_type_index].new() var _generated_room: RoomBase = RoomBase.new() - _generated_room.room_event = _room_event - _grid[index_height].insert(index_width+_padding_size,_generated_room as RoomBase) - #print(_grid) + _grid[index_height].append_array(_padding) _map.rooms = _grid return _map as MapBase diff --git a/Tests/test_map.gd b/Tests/test_map.gd index 4e603f85..d1c27c08 100644 --- a/Tests/test_map.gd +++ b/Tests/test_map.gd @@ -5,9 +5,10 @@ var test_generator = load("res://Map/MapManager.gd") func test_map_gen(): var test_width: Array[int] = [1,3,5,3,1] var test_map: MapBase = test_generator.create_map(test_width) - for index_height in test_map.rooms.size(): - var _padding_loop : int = (5 - test_width[index_height])/2 - var _padding_size : int = (5 + test_width[index_height])/2 - for index_padding in _padding_loop: - assert_null(test_map.rooms[index_height][index_padding]) - assert_null(test_map.rooms[index_height][index_padding+_padding_size]) + var expected_null_array: Array[Array] = [[0,0], [0,1], [0,3],[0,4],[1,0],[1,4],[3,0],[3,4],[4,0],[4,1],[4,3],[4,4]] + var expected_exists_array: Array[Array] = [[0,2],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[2,4],[3,1],[3,2],[3,3],[4,2]] + for couple: Array[int] in expected_null_array: + assert_null(test_map.rooms[couple[0]][couple[1]], "expected null at"+str(couple)) + + for couple: Array[int] in expected_exists_array: + assert_not_null(test_map.rooms[couple[0]][couple[1]], "expected not null at"+str(couple))