mirror of https://git.sr.ht/~kikoodx/kble
Sample file should now be correct, added check in level loading.
This commit is contained in:
parent
98bfeb385b
commit
6d732d65b1
BIN
sample.kble
BIN
sample.kble
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue