Expand description
This crate provides a library for safe parsing, editing and saving of Teeworlds and DDNet maps. Goals of this library are:
- performance
- reasonable map standards
- compatibility with all Teeworlds maps (0.7) and DDNet (0.6) maps
In the very center of this library is the TwMap
struct.
For more information and the complete list of its available methods, check out its documentation page.
Note that library is a aware of the origin of the map (Teeworlds 0.7 or DDNet 0.6).
On parsing a map it will store its Version
in the version
field, which in turn is used to perform the appropriate checks and save in the correct version.
§Examples:
Note that for better readability, some lines of code are left out in the examples, most notably use twmap::*;
at the top.
Loading a binary map, accessing its version and image names and saving it again in the binary format:
let mut map = TwMap::parse_file(dm1_path)?;
assert_eq!(map.version, Version::Teeworlds07);
assert_eq!(map.images[0].name(), "bg_cloud1");
assert_eq!(map.images[6].name(), "sun");
map.save_file(output_path)?;
Loading a MapDir or binary map, removing unused envelopes, layers, groups, images, sounds and saving it again in the MapDir format:
let mut map = TwMap::parse_path(map_path)?;
map.remove_everything_unused();
map.save_dir(output_path)?;
Loading a MapDir map, flipping it upside down and saving the map data into a vector:
let mut map = TwMap::parse_dir(map_path)?;
// Usually you would match the Option<TwMap> return values
// -> or wrap it into a function that also returns an Option
// To take up less space, we insert an error that we return in place of the None value
map = map.rotate_right().ok_or(e)?;
map = map.rotate_right().ok_or(e)?;
map = map.mirror().ok_or(e)?;
let mut map_data = Vec::new();
map.save(&mut map_data)?;
Modules§
- automapper
- compression
- constants
- convert
- datafile
- edit
- Complex methods for map structs
Structs§
- Automapper
Config - Bezier
Curve - Embedded
Image - Env
- EnvPoint
- External
Image - Front
Layer - Game
Layer - Game
Tile - Group
- I16
- Required to make the Speedup tile struct 1-byte-aligned
- Image
Load Info - Info
- Note that all strings have size limits, check the constants associated with this struct.
- MapDir
Parse Error - MapError
- MapParse
Error - Position
- Quad
- Quads
Layer - Sound
- Sound
Source - Sounds
Layer - Speedup
- Speedup
Layer - Switch
- Switch
Layer - Tele
- Tele
Layer - Tile
- Tile
Flags - These bitflags are found in many of the tile types found in tilemap layers. Note that the naming of the flags is very confusing and it is almost never a good idea to edit them directly. Use the helper methods instead, as they will have much more expected behavior!
- Tiles
Layer - Tiles
Load Info - Tune
- Tune
Layer - TwMap
- 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. - Volume
Enums§
- Compressed
Data - Holds compressed data. Use
Load
orLoadMultiple
to decompress this. Too construct with the already loaded data, simply useCompressedData::from
. - Curve
Kind - Belongs to a envelope point. Describes the change in value from this point to the next.
- Envelope
- Error
- Image
- Invalid
Layer Kind - Layer
- Layer
Kind - Sound
Area - Version
Traits§
- AnyLayer
- AnyTile
- Bezier
Default - Default bezier tangent values are all zeroes. This trait implements the constructors for those values. only I32Color needs to implement this manually, since volume (i32) and Position are already all zeroes in their default values.
- Load
- Load
Multiple - Physics
Layer - Marker trait, implemented for all physics layers
- Tilemap
Layer