mirror of https://git.sr.ht/~kikoodx/kble
Backup project on read and exit (#3)
Can be turned off in `src/conf.zig`.
This commit is contained in:
parent
4eefad9062
commit
f412956c83
|
@ -90,6 +90,12 @@ Modes:
|
|||
* Shift + right click: rectangle unselection.
|
||||
* Left or right click while un·selecting: end selection.
|
||||
|
||||
# Backups
|
||||
*Can be disabled in the configuration.*
|
||||
Safety backups are made when:
|
||||
* Reading operation is started (`backup_read.kble`)
|
||||
* The program exit (`backup_exit.kble`)
|
||||
|
||||
# License
|
||||
Copyright (c) 2021 KikooDX
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@ pub const mouse_right_btn: c_int = 1;
|
|||
// * true: click to enter, draw, release to exit.
|
||||
pub const mouse_graphic_tablet: bool = false;
|
||||
|
||||
// The editor will save the level before reading, exiting and other
|
||||
// dangerous operations to avoid unexpected data loss.
|
||||
pub const safety_backup = true;
|
||||
|
||||
pub const default_grid_size = .{
|
||||
.width = 16,
|
||||
.height = 16,
|
||||
|
|
|
@ -169,6 +169,9 @@ pub fn write(self: Self, kble_file_path: [*:0]const u8) !void {
|
|||
|
||||
/// Wrapper around `init_read`.
|
||||
pub fn action_read(self: *Self, allocator: *std.mem.Allocator, kble_file_path: [*:0]const u8) void {
|
||||
// Safety backup before reading.
|
||||
if (conf.safety_backup)
|
||||
self.action_write(allocator, "backup_read.kble");
|
||||
self.deinit(allocator);
|
||||
self.* = Self.init_read(allocator, kble_file_path) catch unreachable;
|
||||
}
|
||||
|
|
|
@ -272,6 +272,9 @@ pub fn main() void {
|
|||
mouse.draw(scale, camera);
|
||||
//ray.DrawFPS(0, 0);
|
||||
}
|
||||
// Safety backup before exiting.
|
||||
if (conf.safety_backup)
|
||||
level.write("backup_exit.kble") catch unreachable;
|
||||
}
|
||||
|
||||
fn add_key_to_buffer(input_buffer: *[input_buffer_len]u32, input_cursor: *u8, key: c_int) void {
|
||||
|
|
Loading…
Reference in New Issue