Struct twmap::TwMap[][src]

pub struct TwMap {
    pub version: Version,
    pub info: Info,
    pub images: Vec<Image>,
    pub envelopes: Vec<Envelope>,
    pub groups: Vec<Group>,
    pub sounds: Vec<Sound>,
}
Expand description

The TwMap struct represents a Teeworlds 0.7 map or a DDNet 0.6 map. Which one of those it is will always be determined during the parsing process and is stored in the version field.

The library cares a lot about the integrity of the struct. The check method verifies that all limitations are met.

Parsing

TwMap has several different parsing methods: parse, parse_path, parse_file, parse_dir, parse_datafile

Each of them execute the check method to finalize the process.

If you want to leave out the checks, you can use the _unchecked variation of that parsing method if it is provided. Note that the _unchecked variation might also exclude some common fixes.

Saving

TwMap can save maps in the binary format (save, save_file) and in the MapDir format (save_dir).

Each saving method will first execute check, if the map fails the check, it will not be saved.

Loading

When loading a map from the binary format, a lot of data will be decompressed in the process. Since this is the main slowdown factor, some larger data chunks will be left compressed. The compressed parts are the data field in Images and Sounds and the tiles field in tile map layers. If you want to save the map at the end anyways, then you can simply use the load method on the entire map. If not, use the load method only on the images, sounds and tile map layers that you want to use.

Note:

  • you can also use load on slices and vectors of Images, Sounds, Layers, Groups with layers,
  • some methods rely on having parts of the map loaded, especially more abstract methods like mirror and rotate_right
  • if you want to leave out the checks on the decompressed data, you can use the load_unchecked methods

Fields

version: Versioninfo: Infoimages: Vec<Image>envelopes: Vec<Envelope>groups: Vec<Group>sounds: Vec<Sound>

Implementations

Returns a empty map struct with only the version set.

Returns a reference to the physics group.

Returns a mutable reference to the physics group.

For parsing a binary map file.

For parsing binary map data.

For parsing the datafile of a binary map.

Saves the map in the binary format. Will overwrite if that file already exists.

Saves the map in the binary format. Since it uses a dyn Write as a parameter, you are free to save it into a vec, file, etc.

Returns a reference to the specified physics layer, if the map contains it. Note that every map must have a Game layer to pass the checks.

Parses binary as well as MapDir maps.

Removes duplicate physics layers of each type. Note that every map must have at most 1 physics layer of each type to pass the checks. The removal process prioritizes removing the layers in front.

Combination of every other remove_unused method.

Removes all layers for which is_empty returns true.

Removes all groups that contain zero layers.

Returns true if the image index is set for a tiles layer or a quad.

For easy remapping of all image indices in tiles layers and quads.

Removes all images for which is_image_in_use returns true. Return value: (count of removed external images, count of removed embedded images)

Returns true if the sound index is set for a sounds layer.

For easy remapping of all sound indices in sounds layers.

Removes all sounds for which is_sound_in_use returns true.

Returns true if the envelope index is in use.

For easy remapping of all envelope indices in tiles, quads and sounds layers.

Removes all sounds for which is_env_in_use returns true.

Fill in all OPAQUE tile flags.

Increases the size of the tilemap layers by the specified tile amount in each direction. To keep the look of the map the same, this also moves the quads in quads layers and adjust the offset of groups as well as their clipping.

Downsizes all tile map layers as much as possible. Note that this will also reduce the size of physics layers and thereby moves the world border!

Downsizes all tiles layers as much as possible.

Mirrors the map. Switches left and right.

Rotates the map clockwise.

Saves the map in the MapDir format to the passed path. Will not overwrite existing files/directories, this would result in an IO-error.

For parsing a TwMap map directory.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.