Skip to content

Commit

Permalink
Feedback changes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xone-mi committed Jan 6, 2024
1 parent af51f12 commit 96270d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
25 changes: 13 additions & 12 deletions Map/MapManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions Tests/test_map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 96270d8

Please sign in to comment.