Jazz2::Compatibility::JJ2Level class

Parses original .j2l level files.

Reads an original level layout, including its tile layers, per-tile events, animated tiles, palettes and MLLE extension data, and writes the converted level to the target path. Events are translated to the engine's native types via an EventConverter during conversion.

Public types

struct LevelToken
Episode name and level name.
struct AlternatePalette
Alternate palette.
struct ExtraTilesetEntry
Extra tileset used in the level.
enum class TilesetColorMode : std::uint8_t { Original8bit, Remapped8bit, Original24bit, AlternatePalette24bit }
Color mode of tile set.

Public static variables

static std::int32_t JJ2LayerCount constexpr
Number of layers in the original game.
static std::int32_t MaxMlleLayerCount constexpr
Most layers accepted from an MLLE stream, far above what real levels use (each further 8 layers is a file of its own).
static std::int32_t TextEventStringsCount constexpr
Number of level text entries in the original game.
static std::int32_t MaxAnimationFrames constexpr
Frames one animated tile can have.

Public static functions

static auto ReadExits(StringView path, String& nextLevel, String& secretLevel, String& bonusLevel) -> bool
Reads only the names of the levels the specified level leads to, without parsing the rest of it.

Constructors, destructors, conversion operators

JJ2Level()
Creates a new instance.

Public functions

auto Open(StringView path, bool strictParser) -> bool
Opens and parses the specified level file.
void Convert(StringView targetPath, EventConverter& eventConverter, Function<LevelToken(StringView)>&& levelTokenConversion = {}, Function<std::shared_ptr<const Formats::TileSetData>(StringView, ArrayView<const std::int32_t>, std::int32_t&)>&& tilesetLookup = {}, Function<bool(std::int32_t, std::uint8_t*)>&& textureLookup = {})
Converts the level and writes the result to the specified target path.
void AddLevelTokenTextID(std::uint8_t textId)
Marks the level text with the specified ID as a level token.
void AddEventMusic(StringView music)
Records a music track that an event of the level switches to, in the form the converted level asks for it.
auto GetEventMusic() const -> ArrayView<const String>
Returns the music tracks the events of the level switch to, filled in by Convert().
auto GetVersion() const -> JJ2Version
Returns target version of the level.
auto GetMaxSupportedTiles() const -> std::int32_t
Returns maximum number of supported tiles.
auto GetMaxSupportedAnims() const -> std::int32_t
Returns maximum number of supported animations.
auto GetAnimatedTilesOffset() const -> std::int32_t
Returns the first tile ID of the animated tiles, the IDs below it are the tiles of the tile sets.
auto ConvertLayer(std::int32_t index, Formats::LayerRecord& record, SmallVectorImpl<Formats::TileRecord>& tiles) const -> bool
Converts a layer as the converted level has it, returns false if there's no such layer or it has no size.

Public variables

String LevelName
Internal name of the level.
String DisplayName
Display name of the level.
String Tileset
Name of the tile set used by the level.
SmallVector<AlternatePalette, 0> AlternatePalettes
List of alternate palettes.
SmallVector<ExtraTilesetEntry, 0> ExtraTilesets
List of extra tile sets used by the level.
String Music
Name of the music track.
String NextLevel
Name of the next level.
String BonusLevel
Name of the bonus level.
String SecretLevel
Name of the secret level.
std::uint8_t LightingMin
Minimum and starting lighting level.
std::uint8_t LightingStart
Function<String(StringView)> TileSetPathMapping
Maps a tile set name, lowercase without extension, to the path written into the converted level, if set.
Function<String(StringView)> MusicPathMapping
Maps a music file name, lowercase with extension, to the name written into the converted level, if set.

Enum documentation

enum class Jazz2::Compatibility::JJ2Level::TilesetColorMode : std::uint8_t

Color mode of tile set.

Enumerators
Original8bit

Original 8-bit palette is used

Remapped8bit

8-bit palette is remapped according to PaletteRemapping

Original24bit

Original 24-bit palette is used

AlternatePalette24bit

Alternate 24-bit palette is used

Function documentation

void Jazz2::Compatibility::JJ2Level::Convert(StringView targetPath, EventConverter& eventConverter, Function<LevelToken(StringView)>&& levelTokenConversion = {}, Function<std::shared_ptr<const Formats::TileSetData>(StringView, ArrayView<const std::int32_t>, std::int32_t&)>&& tilesetLookup = {}, Function<bool(std::int32_t, std::uint8_t*)>&& textureLookup = {})

Converts the level and writes the result to the specified target path.

With tilesetLookup, which converts tiles of an original tile set of a name into memory, or returns nullptr if there's no such tile set, the level gets a preview drawn with them (see Formats::LevelPreview). It's given the indices of the tiles the preview takes, sorted, returns them in the same order (one past the end of the tile set empty) and sets the last argument to the number of tiles of the whole tile set. A level whose default tile set isn't there gets none, the tiles of an extra tile set that isn't there are left out.

With textureLookup, which fills Formats::LayerPropertiesChunk::TextureSize × Formats::LayerPropertiesChunk::TextureSize palette indices with a texture of JJ2+ by its number (TEXTURE::Texture, from 1) and returns false if there's no such texture, a textured layer of a level made for JJ2+ gets the texture it names. Without it, or without the texture, the layer gets a texture made up of smooth noise in the same colors, which ripples a reflection alike.

ArrayView<const String> Jazz2::Compatibility::JJ2Level::GetEventMusic() const

Returns the music tracks the events of the level switch to, filled in by Convert().

The level's own track (Music) is not among them. A boss fight plays one of its own, and only the activating event names it, so a content tree that carries only what the levels name has to ask here.

bool Jazz2::Compatibility::JJ2Level::ConvertLayer(std::int32_t index, Formats::LayerRecord& record, SmallVectorImpl<Formats::TileRecord>& tiles) const

Converts a layer as the converted level has it, returns false if there's no such layer or it has no size.

index is 0 to 7 for the layers of the original, more for the additional layers of MLLE. The tile IDs are those of this level, the animated tiles from GetAnimatedTilesOffset() up. A texture of its own of a textured layer isn't converted. Meant for scripts, which take layers of other levels (jjLayersFromLevel() of JJ2+).

Variable documentation

static std::int32_t Jazz2::Compatibility::JJ2Level::MaxAnimationFrames constexpr

Frames one animated tile can have.

What the format stores per tile, and the size of AnimatedTileSection::Frames. The count that accompanies them is a single byte, so a file can name up to 255 - see LoadAnimatedTiles().