twmap

Parse, edit and save Teeworlds and DDNet maps

20 releases (11 breaking)

0.12.4 Aug 7, 2024
0.12.3 Jul 18, 2024
0.12.2 Apr 30, 2024
0.12.0 Dec 13, 2023
0.2.1 Mar 12, 2021
Download history 2/week @ 2024-07-10 122/week @ 2024-07-17 174/week @ 2024-07-24 62/week @ 2024-07-31 149/week @ 2024-08-07 25/week @ 2024-08-14 44/week @ 2024-08-21 17/week @ 2024-08-28 9/week @ 2024-09-04 24/week @ 2024-09-11 33/week @ 2024-09-18 80/week @ 2024-09-25 39/week @ 2024-10-02 21/week @ 2024-10-09

175 downloads per month
Used in 11 crates (10 directly)

AGPL-3.0-only

435KB
10K SLoC

TwMap

Safely parse, edit and save Teeworlds and DDNet maps.

Also check out: TwGpu (Renderer), Python bindings, Blender Addon

Goals of this library:

The binary map format is documented in the libtw2 repo here.

Note that the library does support compilation to webassembly. Since version 0.10.0, saving maps in webassembly should produce the same binary output.

Usage

  • Add twmap = 0.12.4 in your Cargo.toml
  • Check out the docs

Supported map formats

  • DDNet (0.6)
  • Vanilla (0.7)
  • MapDir
    • folder/directory based format
    • embedded images as .png files
    • embedded sounds as .opus files
    • all other parts of the struct as .json files

Compression

Parts of the binary map data are compressed with zlib compression, this is the main slowdown factor when loading maps. To compensate for this, the library will not load layer, image and sound data on parsing, instead this can be done manually.

If you want to save the map again, then the library will decompress everything anyways (its included in the save method). However, if that is not the case, and you only want to read some part of it, you can hold off on performing the load method on the map struct. Instead, perform load only on the compressed parts of the map that you want to read.

Note that some methods provided by the library require parts of it to be loaded properly. Keep that in mind while playing around with partially unloaded maps.

Checks

This library has a lot of constraints on its map struct that it enforces on saving maps. For instance every map must have a Game group, Game layer, layer names must be at most 11 bytes, etc. All constraints are put into place to ensure proper saving and parsing, meaning that the library guarantees you well-behaved maps.

Note that many methods provided by the library require certain constraints to be fulfilled. Keep that in mind when using parse_unchecked instead of parse, which will leave out most of the checks.

Dependencies

~10–23MB
~289K SLoC