mirror of https://git.sr.ht/~kikoodx/kble
28 lines
923 B
Zig
28 lines
923 B
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");
|
||
|
|
||
|
/// 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;
|
||
|
}
|
||
|
}
|