@@ -9,21 +9,35 @@ import {
9
9
duplicateTilemap ,
10
10
getDungeonDimensions ,
11
11
getTileSize ,
12
+ padNodes ,
12
13
} from "./utils" ;
13
14
15
+ interface DrawOptions {
16
+ /** The amount of padding to apply to the dungeon's tilemap. */
17
+ padding ?: number ;
18
+ /** Wether or not to draw debugging widgets (ex: grid lines, connections, ids, etc.). */
19
+ debugWidgets ?: boolean ;
20
+ }
21
+
14
22
/**
15
23
* Entrypoint method to:
16
24
* - Get a reference to the Canvas' context
17
25
* - Transform rooms and corridors to tiles
18
- * - Draw widgets such as room names and connections
26
+ * - Draw widgets such as room names and connections (optional)
19
27
*
20
28
* Note: all transformations to data are done by reference.
21
29
*/
22
- export function draw ( rootNode : Node < Room > ) {
30
+ export function draw ( rootNode : Node < Room > , options : DrawOptions = { } ) {
23
31
const { context, canvasDimensions } = initializeContext ( ) ;
24
32
33
+ const padding =
34
+ ! ! options . padding && ! isNaN ( options . padding ) && options . padding > 0
35
+ ? options . padding
36
+ : 0 ;
37
+ const debugWidgets = ! ! options . debugWidgets ;
38
+
25
39
// Find dungeon's width and height
26
- const dungeonDimensions = getDungeonDimensions ( rootNode ) ;
40
+ const dungeonDimensions = getDungeonDimensions ( rootNode , padding ) ;
27
41
const tileSize = getTileSize ( canvasDimensions , dungeonDimensions ) ;
28
42
29
43
// Create empty tilesmap
@@ -33,21 +47,23 @@ export function draw(rootNode: Node<Room>) {
33
47
TilesTypes . WALL
34
48
) ;
35
49
50
+ // Add some padding to the tilemap for a more visually appealing result
51
+ padNodes ( rootNode , padding ) ;
52
+
36
53
// Carve rooms and corridors into the tilesmap
37
54
tiles = carveRooms ( tiles , rootNode ) ;
38
55
tiles = carveCorridors ( tiles , rootNode ) ;
39
56
40
- // Add some padding to the tilemap for a more visually appealing result (optional)
41
- // tiles = padTilemap(tiles, 3, TilesTypes.WALL);
42
-
43
57
// Draw tiles
44
58
drawTilesMask ( context , tileSize , tiles ) ;
45
59
drawTiles ( context , tileSize , tiles ) ;
46
60
47
61
// Draw widgets
48
- drawGrid ( context , tileSize , canvasDimensions ) ;
49
- drawConnections ( context , tileSize , rootNode ) ;
50
- drawRoomIds ( context , tileSize , rootNode ) ;
62
+ if ( debugWidgets ) {
63
+ drawGrid ( context , tileSize , canvasDimensions ) ;
64
+ drawConnections ( context , tileSize , rootNode ) ;
65
+ drawRoomIds ( context , tileSize , rootNode ) ;
66
+ }
51
67
}
52
68
53
69
//
@@ -258,7 +274,7 @@ function drawTilesMask(
258
274
}
259
275
}
260
276
261
- export function normalizeTilemap ( tiles : Tiles ) : Tiles {
277
+ function normalizeTilemap ( tiles : Tiles ) : Tiles {
262
278
const copy = duplicateTilemap ( tiles ) ;
263
279
264
280
for ( let y = 0 ; y < copy . length ; y ++ ) {
0 commit comments