Sample file should now be correct, added check in level loading.

This commit is contained in:
KikooDX 2021-02-24 10:52:54 +01:00
parent 98bfeb385b
commit 6d732d65b1
2 changed files with 11 additions and 0 deletions

Binary file not shown.

View File

@ -9,6 +9,7 @@ const ray = @cImport({
});
const std = @import("std");
const expect = std.testing.expect;
const assert = std.debug.assert;
const Vec2 = @import("vec2.zig");
const Rect = @import("rect.zig");
@ -58,6 +59,8 @@ pub fn init_load(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
.selection = undefined,
};
const expected_bytes_per_cell = @sizeOf(cell_type);
// Open directory.
var dir: std.fs.Dir = std.fs.cwd();
// Open file in read mode.
@ -66,6 +69,14 @@ pub fn init_load(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
.write = false,
});
defer file.close();
// Get reader.
var reader: std.fs.File.Reader = file.reader();
// Read first byte and check than the value matches the size of cell_type.
{
const cell_spec_byte = try(reader.readByte());
assert(cell_spec_byte == expected_bytes_per_cell);
}
return self;
}