Skip to content

Commit 75e1708

Browse files
committed
Convert button works! 🎉
1 parent 48a245c commit 75e1708

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

‎build.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub fn build(b: *std.Build) void {
4747
zglfw_pkg.link(exe);
4848
zgpu_pkg.link(exe);
4949

50+
const converter = b.addModule("converter", .{
51+
// TODO: Stop hardcoding
52+
.source_file = .{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/src/convert.zig" },
53+
});
54+
exe.addModule("converter", converter);
55+
5056
// This declares intent for the executable to be installed into the
5157
// standard location when the user invokes the "install" step (the default
5258
// step when running `zig build`).

‎build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
2-
.name = "zig-gamedev",
3-
.version = "0.1.0",
2+
.name = "cc-legacy-mod-converter",
3+
.version = "1.0.0",
44
.dependencies = .{
55
.dawn_x86_64_windows_gnu = .{
66
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-windows-gnu/archive/d3a68014e6b6b53fd330a0ccba99e4dcfffddae5.tar.gz",
@@ -16,11 +16,11 @@
1616
},
1717
.dawn_aarch64_macos = .{
1818
.url = "https://github.com/michal-z/webgpu_dawn-aarch64-macos/archive/d2360cdfff0cf4a780cb77aa47c57aca03cc6dfe.tar.gz",
19-
.hash = "12201fe677e9c7cfb8984a36446b329d5af23d03dc1e4f79a853399529e523a007fa"
19+
.hash = "12201fe677e9c7cfb8984a36446b329d5af23d03dc1e4f79a853399529e523a007fa",
2020
},
2121
.dawn_x86_64_macos = .{
2222
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-macos/archive/901716b10b31ce3e0d3fe479326b41e91d59c661.tar.gz",
2323
.hash = "1220b1f02f2f7edd98a078c64e3100907d90311d94880a3cc5927e1ac009d002667a",
2424
},
25-
}
25+
},
2626
}

‎src/main.zig

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const std = @import("std");
22

3+
const converter = @import("converter");
4+
35
const zglfw = @import("zglfw");
46
const zgpu = @import("zgpu");
57
const zgui = @import("zgui");
@@ -54,6 +56,54 @@ pub fn main() !void {
5456
if (zgui.begin("Button list", .{})) {
5557
if (zgui.button("Convert", .{ .w = 200.0 })) {
5658
std.debug.print("Converting...\n", .{});
59+
60+
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
61+
defer arena.deinit();
62+
var allocator = arena.allocator();
63+
64+
const cwd = std.fs.cwd();
65+
66+
var input_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
67+
const input_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/in", &input_mod_path_buffer);
68+
69+
var output_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
70+
const output_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/out", &output_mod_path_buffer);
71+
72+
var diagnostics: converter.Diagnostics = .{};
73+
converter.convert(
74+
input_mod_path,
75+
output_mod_path,
76+
allocator,
77+
&diagnostics,
78+
) catch |err| switch (err) {
79+
error.UnexpectedToken => {
80+
const token = diagnostics.token orelse "null";
81+
const file_path = diagnostics.file_path orelse "null";
82+
const line = diagnostics.line orelse -1;
83+
const column = diagnostics.column orelse -1;
84+
85+
std.debug.print("Error: Unexpected token\nToken: '{s}'\nFile path: {s}\nLine: {}\nColumn: {} (roughly)\n", .{
86+
token,
87+
file_path,
88+
line,
89+
column,
90+
});
91+
},
92+
error.TooManyTabs => {
93+
const file_path = diagnostics.file_path orelse "null";
94+
const line = diagnostics.line orelse -1;
95+
const column = diagnostics.column orelse -1;
96+
97+
std.debug.print("Error: Too many tabs\nFile path: {s}\nLine: {} (roughly)\nColumn: {} (roughly)\n", .{
98+
file_path,
99+
line,
100+
column,
101+
});
102+
},
103+
else => |e| return e,
104+
};
105+
106+
std.debug.print("Done converting!\n", .{});
57107
}
58108
}
59109
zgui.end();

0 commit comments

Comments
 (0)