diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/game.zig | 24 | ||||
-rw-r--r-- | examples/map.tmj | 66 |
2 files changed, 90 insertions, 0 deletions
diff --git a/examples/game.zig b/examples/game.zig new file mode 100644 index 0000000..e86eede --- /dev/null +++ b/examples/game.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +const tmz = @import("tmz"); + +pub fn main() !void { + var buffer: [10_000]u8 = undefined; + const file = try std.fs.cwd().readFile("examples/map.tmj", &buffer); + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + defer _ = gpa.deinit(); + + var arena = std.heap.ArenaAllocator.init(allocator); + defer arena.deinit(); + + const map = try tmz.parse(file, arena.allocator()); + + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + + try stdout.print("Map: {any}\n", .{map}); + + try bw.flush(); // don't forget to flush! +} diff --git a/examples/map.tmj b/examples/map.tmj new file mode 100644 index 0000000..ddfa9f3 --- /dev/null +++ b/examples/map.tmj @@ -0,0 +1,66 @@ +{ + "compressionlevel": -1, + "height": 30, + "class": "bar", + "infinite": false, + "layers": [ + { + "class": "bar", + "data": [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 19, 15, 19, 15, 19, 15, 19, 15, 19, 15, + 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 15, 14, 15, 15, 15, 14, 15, 15, 15, 14, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 14, 15, 19, 15, 19, 15, 19, 15, 19, 15, + 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 15, 14, 15, 14, 15, 15, 15, 15, 15, 14, + 4, 4, 4, 4, 4, 4, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 3, 3, 14, 14, 14, 15, 19, 15, 19, 15, 19, 15, + 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 3, 3, 14, 14, 15, 14, 15, 14, 15, 14, 15, 14, + 6, 6, 6, 6, 6, 6, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 16, 16, 16, 16, 14, 15, 19, 15, 19, 15, 19, 15, + 6, 6, 6, 6, 6, 6, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 16, 16, 16, 16, 15, 14, 15, 15, 15, 14, 15, 14, + 6, 6, 6, 6, 6, 6, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 3, 16, 16, 16, 16, 14, 14, 19, 15, 19, 15, 19, 15, + 7, 7, 7, 7, 7, 7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 13, 13, 13, 13, 8, 9, 8, 14, 15, 14, 15, 14, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 8, 19, 15, 19, 15, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 10, 8, 14, 15, 14, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 2147483659, 10, 17, 15, 19, 15, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 1073741835, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3221225483, 10, 8, 14, 15, 14, + 4, 4, 4, 4, 4, 4, 10, 10, 10, 10, 1073741835, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3221225483, 10, 10, 17, 15, 19, 15, + 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 1073741835, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3221225483, 10, 10, 17, 15, 15, 15, 14, + 6, 6, 6, 6, 6, 6, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 18, 17, 15, 19, 15, 19, 15, + 6, 6, 6, 6, 6, 6, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 15, 15, 15, 14, 15, 14, + 6, 6, 6, 6, 6, 6, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1, 3, 1, 3, 1, 2, 1, 3, 1, 3, 1, 2, 19, 15, 19, 15, + 7, 7, 7, 7, 7, 7, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 15, 14, 15, 14, + 1, 2, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1, 3, 1, 2, 1, 2, 1, 2, 1, 3, 1, 2, 1, 2, 1, 2, 1, 2, 19, 15, + 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 15, 14, + 1, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 19, 15, + 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 15, 14, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1], + "height": 30, + "id": 1, + "name": "Tile Layer 1", + "opacity": 1, + "type": "tilelayer", + "visible": true, + "width": 32, + "x": 0, + "y": 0 + } + ], + "nextlayerid": 2, + "nextobjectid": 1, + "orientation": "orthogonal", + "renderorder": "right-down", + "tiledversion": "1.10.0", + "tileheight": 8, + "tilesets": [ + { + "firstgid": 1, + "source": "tiles.tsj" + } + ], + "tilewidth": 8, + "type": "map", + "version": "1.10", + "width": 32 +} |