mirror of https://git.sr.ht/~kikoodx/kble
Compare commits
No commits in common. "8cc9aeb129f47f3b6df21e4a95c303fb12987008" and "0f318e509e4051506100ae5825773d96b1457b80" have entirely different histories.
8cc9aeb129
...
0f318e509e
13
.build.yml
13
.build.yml
|
@ -1,13 +0,0 @@
|
|||
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
|
30
README.md
30
README.md
|
@ -11,35 +11,17 @@ Subject to change.
|
|||
[raylib](https://www.raylib.com/).
|
||||
* Configurable (format unknown).
|
||||
|
||||
# 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 instructions
|
||||
Build requirements: [Zig](https://ziglang.org/download/) master branch,
|
||||
[raylib](https://www.raylib.com).
|
||||
For Arch users, `zig-dev-bin` and `zig-git` are available in the AUR.
|
||||
[raylib](https://www.raylib.com). For Arch users, `zig-git` is available
|
||||
in the AUR.
|
||||
```sh
|
||||
$ # Clone this repository
|
||||
$ git clone https://git.sr.ht/~kikoodx/kble && cd kble
|
||||
$ zig build
|
||||
$ zig-cache/bin/kble
|
||||
$ zig build run
|
||||
```
|
||||
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
|
||||
|
@ -60,8 +42,8 @@ Verbs:
|
|||
* `=`: reset scale
|
||||
|
||||
File (read/write):
|
||||
* `e`: read (load) level
|
||||
* `w`: write (save) level
|
||||
* `e`: load level contained in `sample.kble`
|
||||
* `w`: write level to `sample.kble`
|
||||
*See `kbleformat.md` for technical informations.*
|
||||
|
||||
Modes:
|
||||
|
|
|
@ -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, [*:0]const u8) void = Level.action_write,
|
||||
function_file: fn (*Level, *std.mem.Allocator, []const u8) void = Level.action_write,
|
||||
next_mode: Mode = Mode.normal,
|
||||
};
|
||||
|
||||
|
|
|
@ -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: [*:0]const u8) !Self {
|
||||
pub fn init_read(allocator: *std.mem.Allocator, kble_file_path: []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.openFileZ(kble_file_path, std.fs.File.OpenFlags{
|
||||
const file: std.fs.File = try dir.openFile(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: [*:0]const u8) !
|
|||
|
||||
/// 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: [*:0]const u8) !void {
|
||||
pub fn write(self: Self, kble_file_path: []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.createFileZ(kble_file_path, std.fs.File.CreateFlags{});
|
||||
const file: std.fs.File = try dir.createFile(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: [*: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 {
|
||||
pub fn action_read(self: *Self, allocator: *std.mem.Allocator, kble_file_path: []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: [*:0]const u8) void {
|
||||
pub fn action_write(self: *Self, allocator: *std.mem.Allocator, kble_file_path: []const u8) void {
|
||||
self.write(kble_file_path) catch unreachable;
|
||||
}
|
||||
|
||||
|
|
16
src/main.zig
16
src/main.zig
|
@ -26,14 +26,10 @@ const Mode = @import("modes.zig").Mode;
|
|||
|
||||
const char_range = 255;
|
||||
|
||||
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";
|
||||
};
|
||||
// TODO: make this a command line parameter.
|
||||
const level_path = "sample.kble";
|
||||
|
||||
pub fn main() void {
|
||||
// Create allocator
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
defer arena.deinit();
|
||||
|
@ -47,10 +43,8 @@ pub fn main() void {
|
|||
// Limit FPS for performance.
|
||||
ray.SetTargetFPS(60);
|
||||
|
||||
// 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;
|
||||
};
|
||||
// Create level.
|
||||
var level: Level = Level.init(allocator, 16, 16) catch unreachable;
|
||||
defer level.deinit(allocator);
|
||||
|
||||
// Create camera.
|
||||
|
|
Loading…
Reference in New Issue