tmz
A library for parsing and loading Tiled JSON Maps and JSON Tilesets in 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
- Add tmz to your
build.zig.zon
zig fetch --save https://git.sadbeast.com/tmz/snapshot/tmz-main.tar.gz
or manually:
.dependencies = .{
.tmz = .{
.url = "https://git.sadbeast.com/tmz/snapshot/tmz-main.tar.gz",
.hash = "122049a7810f7bd222fc2d65204c85d0cf867ab03063bb11c8086b452092d9f1a4b5",
},
},
- Add tmz to your
build.zig
const tmz = b.dependency("tmz", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("tmz", tmz.module("tmz"));
- Import module and parse a .tmj file
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
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
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.