Jazz2::Editor::TerrainRules class

Tiles chosen by hand for ground with given neighbors, instead of those learned from levels.

The tools that choose tiles by their neighbors (see SmartTileModel) take these first. A rule is for one of the 47 ways the 8 cells around can be solid, a corner counting only when both sides next to it are solid too, as a corner can't be seen otherwise. A rule has one tile or more, one of which is chosen by the position of the cell.

A tile set can have several terrains — ground, a wall of bricks, a cloud — each with rules of its own, one of them is the one the tools use at a time. A rule may take tiles of an extra tile set too, they're kept by the name of the tile set and the index of the tile in it, so a level that has the tile set in another slot, or at another offset, gets the same tiles. Rules with tiles of a tile set the level doesn't have are kept, only not used in it.

Tiles of ground can be tagged as slopes, with the heights of their surface at both edges, or left out of the ground the ground line tool lays (see TileShapes). They're kept in the rules of the tile set (see RulesFile), as "terrains": [{ "name": ..., "patterns": { "<n>": [{ "i": ..., "f": ..., "s": ... }] } }] and "slopes": { "<i>": { "l": ..., "r": ... } | { "x": true } }.

Public types

struct SlopeTag
Slope tag of a tile of the default tile set.

Public static functions

static auto Reduce(std::uint8_t neighbors) -> std::uint8_t
Returns the pattern of neighbors as rules know it, corners only with both sides next to them.
static void GetPatterns(SmallVectorImpl<std::uint8_t>& patterns)
Returns all 47 patterns rules can be for, ordered by how many neighbors are solid.
static auto IsRuleTile(const LevelDocument& document, const TileRef& tile) -> bool
Returns whether a tile can be in a rule, a tile of the default tile set or an extra one in a file, not animated.

Constructors, destructors, conversion operators

TerrainRules()

Public functions

void Load(StringView tileSet)
Reads the rules of a tile set.
auto Save(StringView tileSet) const -> bool
Writes the rules into the rules of a tile set in the user content, nothing if the rules there can't be read, returns false then.
void Resolve(const LevelDocument& document)
Finds the tiles of extra tile sets in a level, call it whenever the level is used with the rules.
auto GetTerrainCount() const -> std::int32_t
Returns the number of terrains, there's always one.
auto GetTerrainName(std::int32_t index) const -> StringView
Returns the name of a terrain.
void RenameTerrain(std::int32_t index, StringView name)
Renames a terrain.
auto AddTerrain(StringView name) -> std::int32_t
Adds a terrain without rules, returns its index.
void RemoveTerrain(std::int32_t index)
Removes a terrain, the last one stays.
auto GetCurrentTerrain() const -> std::int32_t
Returns the terrain the rules are used of.
void SetCurrentTerrain(std::int32_t index)
Chooses the terrain the rules are used of.
auto Find(std::uint8_t neighbors) const -> const SmallVector<TileRef, 0>*
Returns the tiles of the rule of the current terrain for neighbors, or nullptr if there's none.
void Set(std::uint8_t pattern, ArrayView<const TileRef> tiles)
Sets the tiles of the rule of the current terrain for a pattern, no tiles remove it.
void Clear()
Removes all rules of the current terrain.
auto GetCount() const -> std::int32_t
Returns the number of rules of the current terrain.
auto FindSlope(std::uint16_t index) const -> const SlopeTag*
Returns the slope tag of a tile of the default tile set, or nullptr.
void SetSlope(std::uint16_t index, const SlopeTag* tag)
Tags a tile of the default tile set, or removes its tag with nullptr.
void GetSlopeTiles(SmallVectorImpl<std::uint16_t>& tiles) const
Returns the tiles with a slope tag, sorted.
auto GetRevision() const -> std::uint32_t
Returns a number that changes whenever the rules do.
auto GetSlopeRevision() const -> std::uint32_t
Returns a number that changes whenever the slope tags do, not with the rules of the terrains.