mirror of https://git.sr.ht/~kikoodx/kble
Add versioning byte. Remove bloat goal from README.md
I don't want to ever use this, but if someone want to add weird stuff to this format I think it's for the best to do this.
This commit is contained in:
parent
5abd8cbff3
commit
0f318e509e
|
@ -7,10 +7,9 @@ This is a work in progress program in unusable state.
|
|||
Subject to change.
|
||||
* Efficiency, simplicity and clarity are key goals.
|
||||
* Fully keyboard driven modal editing. Mouse support is secondary.
|
||||
* GUI application made in [Zig](https://ziglang.org/) with
|
||||
* GUI software made in [Zig](https://ziglang.org/) with
|
||||
[raylib](https://www.raylib.com/).
|
||||
* Configurable (format unknown).
|
||||
* [LDtk](https://ldtk.io/) inspired tiling rulesets.
|
||||
|
||||
# Build instructions
|
||||
Build requirements: [Zig](https://ziglang.org/download/) master branch,
|
||||
|
@ -44,7 +43,7 @@ Verbs:
|
|||
|
||||
File (read/write):
|
||||
* `e`: load level contained in `sample.kble`
|
||||
* `w`: write level to `sample.kble`
|
||||
* `w`: write level to `sample.kble`
|
||||
*See `kbleformat.md` for technical informations.*
|
||||
|
||||
Modes:
|
||||
|
|
|
@ -4,9 +4,10 @@ Recommanded extension: `.kble`
|
|||
Data stored: level size, level content.
|
||||
|
||||
Encoding:
|
||||
* first byte indicates how big is a chunk of data (in bytes)
|
||||
* second and third bytes indicates level width
|
||||
* fourth and fifth bytes indicates level height
|
||||
* 6th => (6 + data_size * width * height) contains level data
|
||||
* 1st byte indicates format version (`0` currently)
|
||||
* 2nd byte indicates how big is a chunk of data (in bytes)
|
||||
* 3rd and 4th bytes indicates level width
|
||||
* 5th and 6th bytes indicates level height
|
||||
* 7th → (7 + data_size × width × height) contains level data
|
||||
|
||||
If the encoding is incorrect, return an error or crash the program.
|
||||
|
|
BIN
sample.kble
BIN
sample.kble
Binary file not shown.
|
@ -9,7 +9,6 @@ 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");
|
||||
|
@ -72,10 +71,16 @@ pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
|
|||
// Get reader.
|
||||
var reader: std.fs.File.Reader = file.reader();
|
||||
|
||||
// Read first byte and check than the value matches the size of cell_type.
|
||||
// Read first byte and check than the value matches the current format version.
|
||||
{
|
||||
const version = try reader.readByte();
|
||||
if (version != 0) unreachable;
|
||||
}
|
||||
|
||||
// Read second 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);
|
||||
if (cell_spec_byte != expected_bytes_per_cell) unreachable;
|
||||
}
|
||||
|
||||
// Read four bytes and use them for width and height. Two bytes each.
|
||||
|
@ -99,8 +104,8 @@ pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
|
|||
});
|
||||
|
||||
// Non-null width and height.
|
||||
assert(width > 0);
|
||||
assert(height > 0);
|
||||
if (width == 0) unreachable;
|
||||
if (height == 0) unreachable;
|
||||
|
||||
self = try Self.init(allocator, width, height);
|
||||
}
|
||||
|
@ -130,7 +135,9 @@ pub fn write(self: Self, kble_file_path: []const u8) !void {
|
|||
// Get writer.
|
||||
var writer: std.fs.File.Writer = file.writer();
|
||||
|
||||
// Write first byte, indicates cell size in bytes.
|
||||
// Write first byte, kbleformat version number (hopefully will never have to increase).
|
||||
try writer.writeByte(0);
|
||||
// Write second byte, indicates cell size in bytes.
|
||||
try writer.writeByte(expected_bytes_per_cell);
|
||||
|
||||
// Write level height and level width.
|
||||
|
|
Loading…
Reference in New Issue