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 Image
s and Sound
s 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
androtate_right
- if you want to leave out the checks on the decompressed data, you can use the
load_unchecked
methods
Fields
version: Version
info: Info
images: Vec<Image>
envelopes: Vec<Envelope>
groups: Vec<Group>
sounds: Vec<Sound>
Implementations
Returns a reference to the physics group.
Returns a mutable reference to the physics group.
For parsing a binary map file.
For parsing the datafile of a binary map.
Saves the map in the binary format. Will overwrite if that file already exists.
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.
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.
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
Auto Trait Implementations
impl RefUnwindSafe for TwMap
impl UnwindSafe for TwMap
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V