# tmz A library for parsing and loading [Tiled](https://www.mapeditor.org/) [JSON Maps](https://doc.mapeditor.org/en/stable/reference/json-map-format/#map) and [JSON Tilesets](https://doc.mapeditor.org/en/stable/reference/json-map-format/#tileset) in [Zig](https://ziglang.org/). ```zig var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); const parsed_map = try tmz.parseMap(allocator, @embedFile("map.tmj")); defer parsed_map.deinit(); const map = parsed_map.value; std.debug.print("Map size: {}x{}, {} layers.\n", .{ map.height, map.width, map.layers.len }); ``` ## Use in your own projects 1. Add tmz to your `build.zig.zon` ``` zig fetch --save https://git.sadbeast.com/tmz/snapshot/tmz-main.tar.gz ``` or manually: ```zig .dependencies = .{ .tmz = .{ .url = "https://git.sadbeast.com/tmz/snapshot/tmz-main.tar.gz", .hash = "122049a7810f7bd222fc2d65204c85d0cf867ab03063bb11c8086b452092d9f1a4b5", }, }, ``` 2. Add tmz to your `build.zig` ```zig const tmz = b.dependency("tmz", .{ .target = target, .optimize = optimize, }); exe.root_module.addImport("tmz", tmz.module("tmz")); ``` 2. Import module and parse a .tmj file ```zig const std = @import("std"); const tmz = @import("tmz"); pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); const parsed_map = try tmz.parseMap(allocator, @embedFile("map.tmj")); defer parsed_map.deinit(); const stdout_file = std.io.getStdOut().writer(); var bw = std.io.bufferedWriter(stdout_file); const stdout = bw.writer(); try stdout.print("Map: {any}\n", .{parsed_map.value}); try bw.flush(); } ``` ## Documentation [Generated docs](https://sadbeast.com/tmz/docs/main) ## Building There are no executables or a library yet. To test: `zig build test` `zig build test -Dcover` to generate coverage in `zig-out/coverage` ### Dependencies * [Zig](https://ziglang.org/) 0.12.0 * [kcov](http://simonkagstrom.github.io/kcov/index.html) (optional - for test coverage) ### Nix If you have Nix with flakes enabled, run `nix develop` to get a development shell with above dependencies. If you also have direnv, run `direnv allow` to do this automatically. ## Contributing [Email patches](https://git-send-email.io/) to [sadbeast@sadbeast.com](mailto:sadbeast@sadbeast.com)