Jazz2::Formats::LevelWriter class

Writes a level, section by section.

The sections have to be written in the order they are declared in, every one of them, then the level is completed by Finish(), which writes the whole level to the target and checks every write. Nothing reaches the target before. LevelFlags::HasPreview is derived from the chunks written, whatever its value in the flags given. A string, a list or a count that doesn't fit its field is cut with a warning logged, a string never in the middle of a UTF-8 sequence. The reserved bits of the records are never written.

Constructors, destructors, conversion operators

LevelWriter(Stream& target, LevelFlags flags, std::int32_t compressionLevel = 9)
Starts writing a level into the stream.
LevelWriter(const LevelWriter&) deleted

Public functions

auto operator=(const LevelWriter&) -> LevelWriter& deleted
void WriteProperties(const LevelProperties& properties)
Writes the level properties, strings longer than 255 bytes are cut.
void WritePalettes(const std::uint32_t* levelPalette, ArrayView<const PaletteRecord> additionalPalettes)
Writes the level palette and the additional palettes.
void WriteExtraTileSets(ArrayView<const ExtraTileSetRecord> tileSets)
Writes the extra tile sets.
void WriteTileDiffuseOverrides(ArrayView<const TileDiffuseOverride> overrides)
Writes the overridden tile diffuse.
void WriteTileMaskOverrides(ArrayView<const TileMaskOverride> overrides)
Writes the overridden tile masks.
void WriteTexts(ArrayView<const String> texts)
Writes the level texts, at most 255 of them.
void WriteAnimatedTiles(std::uint16_t animatedTilesOffset, ArrayView<const AnimatedTileRecord> animatedTiles)
Writes the first animated tile ID and the animated tiles.
void WriteLayerCount(std::int32_t count)
Writes the number of layers, at most 255.
void WriteLayerHeader(const LayerRecord& layer)
Writes the description of the next layer, its tiles have to be written next.
void WriteLayerTiles(ArrayView<const TileRecord> tiles)
Writes tiles of the layer whose description was written last, it can be called repeatedly.
void WriteEvent(const EventRecord& event)
Writes an event of the grid, it has to be called for every tile of the sprite layer, row by row.
void WriteOffGridEvents(ArrayView<const OffGridEventRecord> events)
Writes the off-grid events.
void WriteChunks(ArrayView<const ChunkRecord> chunks, bool stripEditorOnly)
Writes the optional chunks.
void WriteChunks(ArrayView<const ChunkRecord> first, ArrayView<const ChunkRecord> second, bool stripEditorOnly)
Writes the optional chunks of two lists as a single one, those of first first, so neither has to be copied into the other.
auto Finish() -> bool
Completes the level and writes it to the target.

Function documentation

void Jazz2::Formats::LevelWriter::WritePalettes(const std::uint32_t* levelPalette, ArrayView<const PaletteRecord> additionalPalettes)

Writes the level palette and the additional palettes.

The level palette (256 entries) is written only with LevelFlags::UseLevelPalette, which then requires it.

void Jazz2::Formats::LevelWriter::WriteEvent(const EventRecord& event)

Writes an event of the grid, it has to be called for every tile of the sprite layer, row by row.

EventRecord::NoParams is derived from the parameters, whatever its value in event.

void Jazz2::Formats::LevelWriter::WriteChunks(ArrayView<const ChunkRecord> chunks, bool stripEditorOnly)

Writes the optional chunks.

Nothing at all is written if there are no chunks left after editor-only ones were dropped as requested.

bool Jazz2::Formats::LevelWriter::Finish()

Completes the level and writes it to the target.

Returns false if the level couldn't be compressed, or if any write to the target or flushing it failed, such as on a full disk.