LibLevelGen.lua¶
Functions¶
libLevelGen.new¶
Creates a new libLevelGen generator instance.
Parameters:
| Name | Type | Description |
|---|---|---|
ev |
LibLevelGen.LevelGenerationEventParameters |
Parameters from the level generation event |
Returns: LibLegelGen.Instance
libLevelGen.registerGenerator¶
libLevelGen.registerGenerator(name: string, func: function, data?: LibLevelGen.Config, modeData?: GameSession.Mode.Data): number,number,number
Registers a new generator (it will appear in the extra modes menu). Returns IDs of the generator, regular and seeded game modes created.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string |
Name of the generator |
func |
function |
The callback function that will be called to generate the level |
data? |
LibLevelGen.Config |
Generator configuration, fields can be left empty to provide default values. |
modeData? |
GameSession.Mode.Data |
Game mode data, fields can be left empty to provide default values. |
Returns: number,number,number
Classes¶
LibLevelGen.RunState¶
RunState used by LibLevelGen levels, compatible with the vanilla runState format.
Properties:
| Name | Type | Description |
|---|---|---|
libLevelGenDataInitialized |
boolean |
Whether the runState has been initialized with libLevelGen-specific fields. Used when transitioning from vanilla runState format. |
previousLevelMinibosses |
table |
List of minibosses from the previous level. |
secretShopLevels |
table<number,number> |
Level number to shop ID mapping of secret shop levels. |
seenItems |
table<string,number> |
Mapping of seen item counts. |
seenShrines |
number[] |
Seen shrine IDs |
shrineLevels |
table<number,number> |
Level number to shrine ID mapping of levels where shrines should spawn. |
shopkeeperDead |
boolean |
Whether the shopkeeper has been killed. |
shopkeeperGhostLevel |
number |
What level the shopkeeper ghost should spawn in (relative to start of the zone) |
shopkeeperGhostDepth |
number |
What depth the shopkeeper ghost should spawn in |
peaceRingActive |
boolean |
Whether the ring of peace is active |
warRingActive |
boolean |
Whether the ring of war is active |
warShrineActive |
boolean |
Whether the shrine of war is active |
bossShrineActive |
boolean |
Whether the boss shrine is active |
spaceShrineActive |
boolean |
Whether the space shrine is active |
lockedShopPlaced |
boolean |
Whether a locked shop has been placed in this run |
secretRockRoomPlaced |
boolean |
Whether a vault has been placed in this run |
urnPlaced |
boolean |
Whether an urn has been placed in this run |
LibLevelGen.Config¶
Configuration that enables or disables various built-in features of libLevelGen.
Properties:
| Name | Type | Description |
|---|---|---|
allowLevel1Shrine |
boolean |
Whether a shrine is allowed to spawn on 1-1 or not |
allowOldShrines |
boolean |
Whether shrines that have been disabled in the AMPLIFIED DLC can spawn |
disableEnemyUpgrades |
boolean |
Whether enemy upgrades (or downgrades) through ring of war/peace/shrines etc should be disabled |
zones |
number |
Amount of zones |
levelsPerZone |
number |
Amount of levels per zone |
maxLevel |
number |
Max level number |
placeSecretShops |
boolean |
Whether secret shops should be automatically placed |
placeShrines |
boolean |
Whether shrines should be automatically placed |
allowSecretShopPlacementFailures |
boolean |
Whether errors related to secret shop generation should be suppressed. |
sequenceClb |
fun(ev:Event.LevelSequenceUpdate, cfg: LibLevelGen.Config) |
Function which will be used to generate level sequence data. |
LibLevelGen.Generator¶
LibLevelGen generation data registered by LibLevelGen.registerGenerator.
Properties:
| Name | Type | Description |
|---|---|---|
name |
string |
Name of the generator |
func |
function |
Callback function of the generator |
data |
LibLevelGen.Config |
Configuration of the generator |
LibLevelGen.LevelGenerationOptions extends LevelGenerator.Options¶
Configuration of the currently generated level
Properties:
| Name | Type | Description |
|---|---|---|
number |
integer |
1-indexed sequential identifier of this level in the whole run. Preserved across sub-runs |
type |
LevelGenerator.Type |
Stores the string ID of the generator to use for this level |
modeID |
GameSession.Mode |
Stores the string ID of the game mode to use for this level |
isFinal? |
boolean |
If true, completing this level counts as a victory and ends the run |
isLoopFinal? |
boolean |
If true, completing this level counts as a victory for the current loop |
initialCharacters? |
table<integer,string> |
Maps initially present player IDs to chosen characters |
seed |
integer |
Specifies the seed to generate this level with |
runState |
RunState |
Stores the current run state table |
loopID |
integer |
1-index loop counter, tracking how many sub-runs have been performed within this run |
overridePastLevels? |
Level.Data |
Overwrites all past levels to reduce memory usage |
primaryPlayerID? |
Player.ID |
Optionally designates a player as the in-turn host for the current session |
zone |
number |
Current zone number |
depth |
number |
Current depth number |
floor |
number |
Current floor number |
LibLevelGen.LevelGenerationEventParameters¶
Data passed by level generation event
Properties:
| Name | Type | Description |
|---|---|---|
callback |
function |
The function that should be called with the generated level data as the argument |
data |
LibLevelGen.LevelGenerationOptions |
Configuration of the current level |
failMaps |
number |
Amount of times the generator has failed to generate this level |
libLevelGenGeneratorData |
LibLevelGen.Config |
Configuration of the level generator |
runState |
LibLevelGen.RunState |
State of the current run |
LibLevelGen.MusicData¶
Structure that specifies music for the level
Properties:
| Name | Type | Description |
|---|---|---|
id |
string |
ID of the music set. Generally you want to set it to "OST", unless you're registering custom music. |
type |
string |
For id = "OST", it's either "zone" or "boss". |
level |
number |
Level number of the music |
zone |
number |
Zone number of the music |
LibLegelGen.Instance¶
Instance of a level generator, used to do basically everything as far as generating levels goes.
Properties:
| Name | Type | Description |
|---|---|---|
rng |
LibLevelGen.Rng |
RNG instance used by this generator instance |
levelGeneratorData |
LibLevelGen.Config |
Configuration of the generator used |
levelGenerationOptions |
LibLevelGen.LevelGenerationOptions |
Level generation options for the current level |
runState |
LibLevelGen.RunState |
RunState |
segments |
LibLevelGen.Segment[] |
Array of segments in this instance |
seed |
number |
Seed of the entire run |
isFinal |
boolean |
Whether the current level is the last one |
currentSeed |
number |
Seed of this level |
singleChoiceID |
number |
no description |
level |
number |
Current level number |
zone |
number |
Current zone |
depth |
number |
Current depth |
floor |
number |
Current floor |
music |
LibLevelGen.MusicData |
Music data for the generated level |
tileset |
string |
Tileset name that's inherited by newly created segments |
levelsPerZone |
number |
Amount of levels per zone |
boss |
number |
Whether the current level is a boss level. If it's not, boss is set to 0; Otherwise it's the boss ID. |
callback |
function |
Callback to call with the generated level data |
Methods:
LibLegelGen.Instance.getDepth¶
Get current depth
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance Returns:
number
LibLegelGen.Instance.getFloor¶
Get current floor
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance Returns:
number
LibLegelGen.Instance.setMusic¶
Set music for this level
Parameters:
Name Type Description selfLibLegelGen.Instancethe instance musicLibLevelGen.MusicDataMusic data
LibLegelGen.Instance.setTileset¶
Set default tileset
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance tilesetNamestringTileset name
LibLegelGen.Instance.rand¶
Generate a random 32-bit integer number.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance Returns:
number
LibLegelGen.Instance.randFloatRange¶
Generate a random float within the given range.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance minnumberMinimum value maxnumberMaximum value Returns:
number
LibLegelGen.Instance.randIntRange¶
Generate a random integer within the given range.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance minnumberMinimum value (inclusive) maxnumberMaximum value (not inclusive) Returns:
number
LibLegelGen.Instance.randChoice¶
Choose a random element from the given table.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance tT[]Table to choose an element from remove?booleanWhether the chosen element should be removed from the table, defaults to false Returns:
T
LibLegelGen.Instance.randChoiceMany¶
Choose n elements from the given table.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance choicesT[]Table to choose elements from nnumberNumber of elements to choose remove?booleanWhether the chosen elements should be removed from the table, defaults to false Returns:
T
LibLegelGen.Instance.randChance¶
Randomly returns boolean based on given probability.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance probabilitynumberValue between 0.0 and 1.0 Returns:
boolean
LibLegelGen.Instance.randWeightedChoice¶
Randomly choose a value from the weighted choice data.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance chancestable<string,number>Mapping of values that can be chosen to their probability (does not have to add up to 1) Returns:
string
LibLegelGen.Instance.createSegment¶
Creates a new segment.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance Returns:
LibLevelGen.Segment
LibLegelGen.Instance.finalize¶
Serialize the level and invoke the callback to load it. This should be the last thing your generator calls.
Parameters:
Name Type Description selfLibLegelGen.InstanceThe instance