Compare commits

...

2 Commits

Author SHA1 Message Date
KikooDX 8cc9aeb129 Add build manifest. 2021-02-25 10:16:43 +01:00
KikooDX 3c084730b2 Command line argument ; take path to open and/or save to.
+ README.md update
2021-02-24 23:54:24 +01:00
5 changed files with 55 additions and 18 deletions

13
.build.yml Normal file
View File

@ -0,0 +1,13 @@
image: archlinux
packages:
- git
- zig
- raylib
sources:
- https://git.sr.ht/~kikoodx/kble
tasks:
- build: |
cd kble
zig build -Drelease-small
artifacts:
- kble/zig-cache/bin/kble

View File

@ -11,17 +11,35 @@ Subject to change.
[raylib](https://www.raylib.com/).
* Configurable (format unknown).
# Build instructions
# Installation
Runtime requirements: [raylib](https://www.raylib.com).
## Precompiled binaries
[![builds.sr.ht status](https://builds.sr.ht/~kikoodx/kble.svg)](https://builds.sr.ht/~kikoodx/kble?)
https://builds.sr.ht/~kikoodx/kble
## Manual compilation
Build requirements: [Zig](https://ziglang.org/download/) master branch,
[raylib](https://www.raylib.com). For Arch users, `zig-git` is available
in the AUR.
[raylib](https://www.raylib.com).
For Arch users, `zig-dev-bin` and `zig-git` are available in the AUR.
```sh
$ # Clone this repository
$ git clone https://git.sr.ht/~kikoodx/kble && cd kble
$ zig build run
$ zig build
$ zig-cache/bin/kble
```
Press escape to close the program.
# Command line argument
**Not available on Windows.** Accept a path to KBLE file to open.
If the file doesn't exist, the given path will be used for saving.
Defaults to `level.kble` if no argument given.
```sh
$ kble #level.kble
$ kble sample.kble
$ kble $HOME/projects/kble/sample.kble
```
# Default keybindings
Movement:
* `h`: left
@ -42,8 +60,8 @@ Verbs:
* `=`: reset scale
File (read/write):
* `e`: load level contained in `sample.kble`
* `w`: write level to `sample.kble`
* `e`: read (load) level
* `w`: write (save) level
*See `kbleformat.md` for technical informations.*
Modes:

View File

@ -29,7 +29,7 @@ pub const Action = struct {
function_move: fn (*Vec2, conf.arg_type) movement.SelectionUpdate = movement.move_left,
function_verb: fn (*Level, conf.arg_type) void = verbs.delete,
function_scale: fn (scaling.scale_type) scaling.scale_type = scaling.scale_reset,
function_file: fn (*Level, *std.mem.Allocator, []const u8) void = Level.action_write,
function_file: fn (*Level, *std.mem.Allocator, [*:0]const u8) void = Level.action_write,
next_mode: Mode = Mode.normal,
};

View File

@ -57,13 +57,13 @@ pub fn deinit(self: *Self, allocator: *std.mem.Allocator) void {
/// Load level content from given absolute or relative path.
/// Expect the KBLE file format (see `kbleformat.md` for more details).
pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Self {
pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: [*:0]const u8) !Self {
var self: Self = undefined;
// Open directory.
var dir: std.fs.Dir = std.fs.cwd();
// Open file in read mode.
const file: std.fs.File = try dir.openFile(kble_file_path, std.fs.File.OpenFlags{
const file: std.fs.File = try dir.openFileZ(kble_file_path, std.fs.File.OpenFlags{
.read = true,
.write = false,
});
@ -126,11 +126,11 @@ pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: []const u8) !Sel
/// Write header and level content to given absolute or relative path.
/// Uses the KBLE file format (see `kbleformat.md` for more details).
pub fn write(self: Self, kble_file_path: []const u8) !void {
pub fn write(self: Self, kble_file_path: [*:0]const u8) !void {
// Open directory.
var dir: std.fs.Dir = std.fs.cwd();
// Open file in write mode.
const file: std.fs.File = try dir.createFile(kble_file_path, std.fs.File.CreateFlags{});
const file: std.fs.File = try dir.createFileZ(kble_file_path, std.fs.File.CreateFlags{});
defer file.close();
// Get writer.
var writer: std.fs.File.Writer = file.writer();
@ -169,13 +169,13 @@ pub fn write(self: Self, kble_file_path: []const u8) !void {
}
/// Wrapper around `init_read`.
pub fn action_read(self: *Self, allocator: *std.mem.Allocator, kble_file_path: []const u8) void {
pub fn action_read(self: *Self, allocator: *std.mem.Allocator, kble_file_path: [*:0]const u8) void {
self.deinit(allocator);
self.* = Self.init_read(allocator, kble_file_path) catch unreachable;
}
/// Wrapper around `write`.
pub fn action_write(self: *Self, allocator: *std.mem.Allocator, kble_file_path: []const u8) void {
pub fn action_write(self: *Self, allocator: *std.mem.Allocator, kble_file_path: [*:0]const u8) void {
self.write(kble_file_path) catch unreachable;
}

View File

@ -26,10 +26,14 @@ const Mode = @import("modes.zig").Mode;
const char_range = 255;
// TODO: make this a command line parameter.
const level_path = "sample.kble";
pub fn main() void {
const level_path: [*:0]const u8 = if (std.os.argv.len > 1)
std.os.argv[1]
else nopath: {
std.log.notice("No path provided, defaults to \"level.kble\".", .{});
break :nopath "level.kble";
};
// Create allocator
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
@ -43,8 +47,10 @@ pub fn main() void {
// Limit FPS for performance.
ray.SetTargetFPS(60);
// Create level.
var level: Level = Level.init(allocator, 16, 16) catch unreachable;
// Try to load level, is doesn't exist create it.
var level: Level = Level.init_read(allocator, level_path) catch create: {
break :create Level.init(allocator, 16, 16) catch unreachable;
};
defer level.deinit(allocator);
// Create camera.