Crate twmap[][src]

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

Structs

Enums

Traits