[][src]Module rs_tiled_json::layer

The Layer struct contains all of the necessary information required to build a layer of any kind.

There are four types of layers:

  • Tile layers
  • Object groups
  • Image layers
  • Groups

See relevant data and structure information at:

https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer

Each is contained within its own enum LayerDataContainer accessible through a field of Layer called layerdata. LayerDataContainer has 4 variants, each with its own set of relevant variables:

  • LayerDataContainer::TileLayer
    data: Vec<u32>
  • LayerDataContainer::ObjectGroup
    draworder: tiled_json::DrawOrder
    objects:   Vec<tiled_json::Object>
  • LayerDataContainer::ImageLayer
    image:            String
    transparentcolor: Option<tiled_json::Color>
  • LayerDataContainer::Group
    layers: Vec<tiled_json::Layer>

This layer class provides a number of convenience functions to enable ease of working with the enum structures provided. It is not unreasonable to assume that you will know the type of layer you are accessing, so I've included the following functions to reduce verbosity:

    tiled_json::Layer::is_tile_layer(&self) -> bool;
    tiled_json::Layer::is_object_group(&self) -> bool;
    tiled_json::Layer::is_image_layer(&self) -> bool;
    tiled_json::Layer::is_group(&self) -> bool;

    // Get tile layer data if self is a tile layer.
    tiled_json::Layer::get_data(&self) -> Option<&Vec<u32>>;

    // The following get object group data if layer refers to an object group:
    tiled_json::Layer::get_draworder(&self) -> Option<DrawOrder>;
    tiled_json::Layer::get_objects_vector(&self) -> Option<&Vec<Object>>;

    // The following get image layer data if the layer refers to an image layer:
    tiled_json::Layer::get_image(&self) -> Option<&String>;
    tiled_json::Layer::get_transparentcolor(&self) -> Option<Color>;

    // Get group data if the layer refers to a group of layers.
    tiled_json::Layer::get_layers(&self) -> Option<&Vec<Layer>>;

This struct implements the trait HasProperty, which enables easy access of Tiled properties for layers. The relevant functions are:

    tiled_json::Layer::get_property(&self, name: &str) -> Option<&tiled_json::Property>;
    tiled_json::Layer::get_property_vector(&self) -> &Vec<tiled_json::Property>;
    tiled_json::Layer::get_property_value(&self, name: &str) -> Option<&tiled_json::PropertyValue>;
    // See the tiled_json::Property struct to see functionality offered.

Structs

Layer

The primary method of describing nodes in maps.

Enums

DrawOrder

The DrawOrder for the layer. This is only used on Object Group layers. You can call to_string() on variants of this enum.

LayerDataContainer

The LayerDataContainer is an enum that describes the four different types of layers that can be present within a map. You can access these values directly if need be, but I have included layer methods that will retrieve this data without the need to resolve the enum yourself. The code can be quite verbose when working with namespaces and identifiers this large.

LayerType

LayerType telling us the type of Layer this is. This is used more interally than anything else. You can call to_string() on this enum.

Constants

DRAWORDER_INDEX
DRAWORDER_TOPDOWN
LAYER_GROUP
LAYER_IMAGE
LAYER_OBJGROUP
LAYER_TILE