diff options
author | sadbeast <sadbeast@sadbeast.com> | 2024-04-15 18:08:28 -0700 |
---|---|---|
committer | sadbeast <sadbeast@sadbeast.com> | 2024-05-18 17:23:35 -0700 |
commit | a4711cad923d6c7480e596685d9dcaefa241fe3b (patch) | |
tree | f0c36edea9b32b8a1825270436868bb020689657 /example | |
download | tmz-a4711cad923d6c7480e596685d9dcaefa241fe3b.tar.gz tmz-a4711cad923d6c7480e596685d9dcaefa241fe3b.tar.bz2 |
Diffstat (limited to 'example')
-rw-r--r-- | example/build.zig | 71 | ||||
-rw-r--r-- | example/build.zig.zon | 67 | ||||
-rw-r--r-- | example/src/main.zig | 19 | ||||
-rw-r--r-- | example/src/map.tmj | 101 | ||||
-rw-r--r-- | example/src/tiles.png | bin | 0 -> 3572 bytes | |||
-rw-r--r-- | example/src/tiles.tsj | 51 |
6 files changed, 309 insertions, 0 deletions
diff --git a/example/build.zig b/example/build.zig new file mode 100644 index 0000000..5563386 --- /dev/null +++ b/example/build.zig @@ -0,0 +1,71 @@ +const std = @import("std"); + +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "example", + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const tmz = b.addModule("tmz", .{ .root_source_file = b.path("../src/tmz.zig") }); + exe.root_module.addImport("tmz", tmz); + + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // By making the run step depend on the install step, it will be run from the + // installation directory rather than directly from within the cache directory. + // This is not necessary, however, if the application depends on other installed + // files, this ensures they will be present and in the expected location. + run_cmd.step.dependOn(b.getInstallStep()); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` + if (b.args) |args| { + run_cmd.addArgs(args); + } + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const exe_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_exe_unit_tests.step); +} diff --git a/example/build.zig.zon b/example/build.zig.zon new file mode 100644 index 0000000..df70c89 --- /dev/null +++ b/example/build.zig.zon @@ -0,0 +1,67 @@ +.{ + .name = "game", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + // See `zig fetch --save <url>` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + }, + + // Specifies the set of files and directories that are included in this package. + // Only files and directories listed here are included in the `hash` that + // is computed for this package. + // Paths are relative to the build root. Use the empty string (`""`) to refer to + // the build root itself. + // A directory listed here means that all files within, recursively, are included. + .paths = .{ + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", + }, +} diff --git a/example/src/main.zig b/example/src/main.zig new file mode 100644 index 0000000..44fa08f --- /dev/null +++ b/example/src/main.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const tmz = @import("tmz"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + defer _ = gpa.deinit(); + + 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(); // don't forget to flush! +} diff --git a/example/src/map.tmj b/example/src/map.tmj new file mode 100644 index 0000000..d8e0888 --- /dev/null +++ b/example/src/map.tmj @@ -0,0 +1,101 @@ +{ "class":"bar", + "compressionlevel":-1, + "height":30, + "infinite":false, + "layers":[ + { + "class":"bar", + "compression":"zstd", + "data":"KLUv\/WAADo0WAOLOIhewJekMw4AmSQqb4zwHkkxSSmknYWS3FL3tKaVakYricx+o1U0H6HiOrIpawkr20Ux75XaikAGvO8JVvSFVRWuob50v1ZNByLH9iAJCBkQmKGTQgZDD\/WGhIIdCDjO2j9CPWlvYpqHXVGnohm1sxA6qOnn4WvVpVV3oXLbp3WZeyPtZjbWonpMkkg+BU6jB6QvNAaEEyChHMWcHEZCIwJGEiChKBs0ag\/WoKoS5gp76\/p+G5cawdf2AkXsGPwUnt+jgPJ7zhrn26D9Aeus6Hyyf6BNbJaeIEfzi8uPDXHvFbzPJALzjJyR7H9sz5+4BuY89HqnnOJ6YyUnYVfZjDPgrOc29sHaf911o19ny2Yo58M+3Ee1LTfmVdy836PBu\/4kzFZMp\/4Y0PPPvTF9qH4AaMV9IHKfF7C2h4vr\/SDtjE30QBqzZ3iPh7svCD7wNB\/2ny34\/E8yAS8tQezmPVwbhvqPAQdCy4pCyFt6Tdp9r2v4Xx2CcloneN8Qv9sWDW9z+N3sUXpk9skLP2xL3T7JzZv3wBHjSlj3P3Ptr6QNxfwVWFFdkMJVZ5IPo31F8cD\/0\/vp5+nuMePDMtP1JJ\/6K\/14vYucn32yTSW8XH7kc787uXO+RwXmDw4ryMw+TVHYe\/\/3sQO2OeB0nPV0PBm1YpvDFOnri3bbBlrnF4cD\/aPaKOOeHpJ\/t5aFunfuFD57AhmcPMaptd5vEwfQL6LJOfBdHuN5czo+tQLzpP4r9aQ1dBmj0+7vxZ3IDeW4W\/uHxA0krKXi2Bj6Eo32cd0qD1yicts8yzwZU9uivOzf9+26Mwzc6j7d0dCsWYEWJXcZk8QCbKY3OH8Po\/SavNPGeOx8sxt3JgHPU20x24EAb\/MJ3YD8BjZhLnBznCu\/3v3Y\/g6PwQb+W8hNPenxROT6V3WnwE5\/PoXjgT9hhuOqtPPNXuvlotZ1rLng1VAE=", + "encoding":"base64", + "height":30, + "id":1, + "name":"ground", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":32, + "x":0, + "y":0 + }, + { + "draworder":"topdown", + "id":2, + "name":"objects", + "objects":[ + { + "height":16, + "id":1, + "name":"pool", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":88, + "y":96 + }, + { + "height":20, + "id":2, + "name":"", + "rotation":0, + "text": + { + "color":"#241f31", + "fontfamily":"Serif", + "text":"tmz", + "wrap":true + }, + "type":"", + "visible":true, + "width":30, + "x":70, + "y":16 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + }, + { + "id":3, + "image":"tiles.png", + "name":"tile_image", + "offsetx":1, + "offsety":1, + "opacity":1, + "type":"imagelayer", + "visible":true, + "x":0, + "y":0 + }], + "nextlayerid":4, + "nextobjectid":3, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.10.2", + "tileheight":8, + "tilesets":[ + { + "firstgid":1, + "source":"src/tiles.tsj" + }, + { + "columns":4, + "firstgid":17, + "image":"tiles.png", + "imageheight":32, + "imagewidth":32, + "margin":0, + "name":"embedded_tiles", + "spacing":0, + "tilecount":16, + "tileheight":8, + "tilewidth":8 + }], + "tilewidth":8, + "type":"map", + "version":"1.10", + "width":32 +} diff --git a/example/src/tiles.png b/example/src/tiles.png Binary files differnew file mode 100644 index 0000000..499259c --- /dev/null +++ b/example/src/tiles.png diff --git a/example/src/tiles.tsj b/example/src/tiles.tsj new file mode 100644 index 0000000..4e0ca0d --- /dev/null +++ b/example/src/tiles.tsj @@ -0,0 +1,51 @@ +{ "columns":4, + "image":"tiles.png", + "imageheight":32, + "imagewidth":32, + "margin":0, + "name":"tiles", + "spacing":0, + "tilecount":16, + "tiledversion":"1.10.2", + "tileheight":8, + "tiles":[ + { + "id":8, + "probability":3 + }, + { + "id":14, + "probability":0.25 + }], + "tilewidth":8, + "type":"tileset", + "version":"1.10", + "wangsets":[ + { + "colors":[ + { + "color":"#ff0000", + "name":"", + "probability":1, + "tile":-1 + }, + { + "color":"#00ff00", + "name":"", + "probability":1, + "tile":-1 + }], + "name":"corners", + "tile":-1, + "type":"corner", + "wangtiles":[ + { + "tileid":0, + "wangid":[0, 1, 0, 1, 0, 1, 0, 1] + }, + { + "tileid":1, + "wangid":[0, 2, 0, 2, 0, 2, 0, 2] + }] + }] +}
\ No newline at end of file |