kble/src/verbs.zig

36 lines
1.1 KiB
Zig

// SPDX-License-Identifier: MIT
// Copyright (c) 2021 KikooDX
// This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
//! Act on level using selection.
const conf = @import("conf.zig");
const Level = @import("level.zig");
/// Clear selection (deselect everything).
pub fn clear_selection(level: *Level, arg: conf.arg_type) void {
var i: u32 = 0;
while (i < level.width * level.height) : (i += 1) {
level.selection[i] = false;
}
}
/// Delete selected cells (set to 0).
pub fn delete(level: *Level, arg: conf.arg_type) void {
var i: u32 = 0;
while (i < level.width * level.height) : (i += 1) {
if (level.selection[i])
level.content[i] = 0;
}
}
/// Replace selected cells with `arg`.
pub fn replace(level: *Level, arg: conf.arg_type) void {
const casted_arg = @intCast(Level.cell_type, arg);
var i: u32 = 0;
while (i < level.width * level.height) : (i += 1) {
if (level.selection[i])
level.content[i] = arg;
}
}