aboutsummaryrefslogtreecommitdiffstats

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

  1. 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",
    },
},
  1. Add tmz to your build.zig
const tmz = b.dependency("tmz", .{
    .target = target,
    .optimize = optimize,
});

exe.root_module.addImport("tmz", tmz.module("tmz"));
  1. 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

Generated docs

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 0.12.0
  • kcov (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 to sadbeast@sadbeast.com