Framing out level loading and specify KBLE file format

This commit is contained in:
KikooDX 2021-02-23 11:44:11 +01:00
parent b5972abd1c
commit 63ebdee01f
2 changed files with 25 additions and 0 deletions

12
kbleformat.md Normal file
View File

@ -0,0 +1,12 @@
# .kble file format
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
* 7th => (7 + data_size * width * height) contains level data
If the encoding is incorrect, return an error or crash the program.

View File

@ -48,6 +48,19 @@ pub fn init(allocator: *std.mem.Allocator, width: u16, height: u16) !Self {
return self;
}
/// Load level content from given absolute path. Expect the KBLE file format (see
/// `kbleformat.md` for more details.
pub fn init_load(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Self {
var self = Self{
.width = undefined,
.height = undefined,
.content = undefined,
.selection = undefined,
};
return self;
}
/// Free the level content.
pub fn deinit(self: *Self, allocator: *std.mem.Allocator) void {
allocator.free(self.selection);