API Reference

This page shows and explains every JavaScript Call method.

Maze Generator / $DungeonGenerator

While the Generator has been renamed into „Maze Generator“, the JS code is still „$dungeonGenerator“ for historical reasons.

Every Call consists of

$dungeonGenerator.
<algorithm>
<parameters>
<makeWayOut>
.generate()
<entrance, exit>
<drawDecorations>
<spawnPlayerAt>
.finalize();

Algorithms + Parameters

Choose from

  • prims()
  • randomWalk()

Prims Algorithm

The Prims algorithm outputs a classical maze consisting of corridors only. You can add optional parameters; the order will affect the output maze.

$dungeonGenerator.prims()
.cutOffDeadEnds(n)    // optional
.mergeDeadEnds(p)     // optional
.generate()

cutOffDeadEnds

cutOffDeadEnds(n)    // n = natural number > 0

This method looks for corridors with dead ends and removes the dead end so the corridor becomes shorter. The argument n stands for the number of repetitions, e.g. having a corridor with length of 4 and using n=2, the corridor will have a length of 2 afterwards.

mergeDeadEnds

mergeDeadEnds(p)    // p = decimal number 0.0 < p <= 1.0

This method looks for dead ends and will create new tunnels back into the maze, lowering the number of dead ends and making the maze imperfect, allowing multiple solutions for the Player. The argument p stands for the probability that a tunnel is created; 1.0 = always, 0.0 = never.

Random Walk Algorithm

TODO

This algorithm requires you to setup at least one „snippetsArea“ and „snippetsTransitions“ Map.

$dungeonGenerator.randomWalk()
.start("bottom")
.exit("top")
.allowGoingBack(true / false)     // optional
.allowLargeAreas(true / false)    // optional
.allowRevisit(true / false)       // optional
.generate()

allowGoingBack

Default: true. If disabled, the step-wise Random Walk is not allowed to walk back to its starting point, e.g. when start = „bottom“ the step-wise walker can walk only to the left, right or top.

allowLargeAreas

Default: true. If disabled, the walker walks in a way that no large Areas are built.

allowRevisit

Default: false. If enabled, the walker can walk on cells that he already visited before.

Entrance, Exit, and makeWayOut

...
.generate()
.placeEntranceOn("bottom")
.placeExitOn("top")

Choose from „top“, „bottom“, „left“, „right“, or „any“

OR

...
.makeWayOut("bottom")
.makeWayOut("top")
.generate()

Choose from „top“, „bottom“, „left“, or „right“. These call must be above generate(). It’s not limited to use exactly 2 calls; you can have less or more of them.

Decorations

...
.drawDecorations([1, 2, 3])
.drawDecorationXTimes(24, 1, 3)
...

drawDecorations

.drawDecorations(regionIds)    // regionIds = e.g. [1, 2, 3]
.drawDecorations()

This function will draw assets associated with the given Region Ids on every Region Tile on the snippets. Leaving this argument out, assets from all available Region Ids are drawn.

drawDecorationXTimes

.drawDecorationXTimes(regionId)

draws an asset from given Region Id exactly once.

.drawDecorationXTimes(regionId, n)

draws assets from given Region Id exactly n-times.

.drawDecorationXTimes(regionId, n, m)

draws assets from given Region Id n-times at least and m-times at most.

Spawn Player At

Use this method when you want the Player to spawn at a different location than the Main entrance, e.g. when you use a seedable RNG.

.spawnPlayerAt(direction, regionId)

direction: Choose from „top“, „bottom“, „left“, „right“, and „any“

regionId: (optional)

See also: Spawn Player At Custom Position

Finalize

Call finalize() at the end.


Noise Map Generator

$noiseMapGenerator.
<algorithm>
<parameters>
.generate()
<adjustments>
<spawnPlayerAt>
.finalize();

Algorithms + Parameters

Choose from

  • noiseMap
  • treeMap

Noise Map

$noiseMapGenerator.noiseMap()
.groundLevel(y)
.scale(n)
.array([])
.enforceSingleArea()
.thickness(n)
.spanningTree(mode)
.generate()

All lines except the first one and „generate()“ are optional.

Ground Level

On the Space Map, the highest tile that is passable is used as ground level for mathematical functions of the Generator. When you don’t use impassable ceiling tiles or any other reason, you can set a specific tile from the Space Map. The argument y stands for the y-coordinate of the Tile on the Space Map, starting from 0.

Scale

Sets the Noisemap’s scale. The higher the scale, the more stretched the Map will look like.

Array

By default, the Generator does calculations to roughly equalize the amount for each tile on the Space Map. If you don’t want that, you can pass an array that contains the thresholds for each level. The array must have the size of number of tiles on the Space Map - 1, as the first and last Tile is not included. Usually you are safer by adding / removing tiles on / from the Space Map than using this function.

Enforce Single Area

This line is optional and has no arguments. When using this line, the Generator builds paths to connect all areas with each other.

Thickness

When using „enforce single area“, you can set the path’s thickness here. Choose from 1, 2, 3, 4, 5. Other values are not supported yet.

Spanning Tree

When using „enforce single area“, the Generator will apply a Spanning Tree to connect all areas. Choose from:

  • „MST“
    to use Kruskal’s Algorithm to build a Minimal Spanning Tree
  • „random“
    to randomly connect all the nodes

Tree Map

$noiseMapGenerator.treeMap()
.groundLevel(y)
.nodes(n)
.thickness(n)
.spanningTree(mode)
.generate()

All lines except the first one and „generate()“ are optional.

Ground Level

On the Space Map, the highest tile that is passable is used as ground level for mathematical functions of the Generator. When you don’t use impassable ceiling tiles or any other reason, you can set a specific tile from the Space Map. The argument y stands for the y-coordinate of the Tile on the Space Map, starting from 0.

Nodes

The number of nodes that the Algorithm puts to connect them afterwards.

Thickness

When using „enforce single area“, you can set the path’s thickness here. Choose from 1, 2, 3, 4, 5. Other values are not supported yet.

Spanning Tree

When using „enforce single area“, the Generator will apply a Spanning Tree to connect all areas. Choose from:

  • „MST“
    to use Kruskal’s Algorithm to build a Minimal Spanning Tree
  • „random“
    to randomly connect all the nodes

Adjustments

All functions from this section are optional, can be used multiple times or left out. The order will affect the resulted Map.

Argument mapName: All functions have „mapName“ as argument, that stands for the Map that the function should read.

draw Path

.drawPath(A, B, mapName)

Draws a Path from one Map Border A to another Map Border B.

A, B: Choose from „North“, „South“, „West“, or „East“. It’s not required to choose contrary directions; you can e.g. select „North“ and „West“.

draw Structures

.drawStructures(mapName)

draw Shadings

.drawShadings(mapName, scale, minValue)

scale: Sets the Noisemap’s scale. The higher the scale, the more stretched the Map will look like.

minValue: Threshold that the value of a noisemap’s cell must have to apply an action. The higher the value, the less tiles will be transformed. Choose a decimal number 0.0 < p < 1.0.

draw Bioms

.drawBioms(mapName, scale, minValue, minSize)

scale, minValue: See „draw Shadings“

minSize: The mininum number of tiles that an area must have to be transformed, otherwise it will be skipped. Useful when you don’t want to have tiny deserts or snow fields on a world map.

draw Decoration X Times

This function does not accept a custom map name. It uses „Decoration“ instead.

.drawDecorationXTimes(regionId)

draws an asset from given Region Id exactly once.

.drawDecorationXTimes(regionId, n)

draws assets from given Region Id exactly n-times.

.drawDecorationXTimes(regionId, n, m)

draws assets from given Region Id n-times at least and m-times at most.

Spawn Player At

.spawnPlayerAt(direction)

Choose from „North“, „South“, „West“, or „East“.

See also: Spawn Player at Custom Position

Finalize

Call finalize() at the end.

Premium Features

Seedable RNG

Call one from these functions right before you generate a Map.

set Seed

$dungeonGenerator.setSeed(value)

Usually you store the Seed in a standard RPG Maker Variable. Get it by using this line:

let seed = $gameVariables.value(X);   // X: id of the variable
$dungeonGenerator.setSeed(seed);

disable seedable RNG

$dungeonGenerator.noSeedableRNG()

Meta Maze

Create

Meta Maze – Layouts

Update DungeonGenerator Calls

Remove these linesAnd replace them by one single line
placeEntranceAt(…)
placeExitAt(…)
placeExits()
makeWayOut(…)makeWaysOut()
drawPath(…)drawPaths(mapName, thickness)

Go to next Map

When the Player touches the Exit Event, call this:

$metaMaze.goTo(direction)

// direction: choose from "top", "left", "right", "bottom"

Check if still in Meta Maze

$metaMaze.isInsideMetaMaze()

Leave Meta Maze

$metaMaze.reset()

Additional Functions

$metaMaze.getWidth()
$metaMaze.getHeight()
$metaMaze.getCurrentPosition().x
$metaMaze.getCurrentPosition().y
$metaMaze.hasMainExitTop()       // also works for ..Left, ..Right, ..Bottom
$metaMaze.hasInnerExitTop()      // see above
$metaMaze.hasExitTop()           // returns true if mainExit OR innerExit

Save Self Switches

Call this method right before you generate a Map. You need to set an unique, indivual id, while the map id is already grabbed by the Plugin, so you don’t need to include this one. Usually the floor Id is just a number counting up.

$dungeonGenerator.setFloorId(floorId)

reset Self Switches

Calling this function will set all saved Self Switches belonging to the given Space Map to „false“.

$dungeonGenerator.resetSelfSwitches(mapId)

Calling this function will set all saved Self Switches by this Letter belonging to the given Space Map to „false“.

$dungeonGenerator.resetSelfSwitches(mapId, 'A')

Respawn Player at Custom Position

.spawnPlayerAt(x, y)

To get X and Y from Variables, use

let x = $gameVariables.value(XX);    // XX: id of the variable
let y = $gameVariables.value(YY);    // YY: id of the variable
$dungeonGenerator.spawnPlayerAt(x, y)