compile checks (WIP)

This commit is contained in:
2026-04-04 14:49:31 +02:00
parent a22a5702fa
commit 6e0ecaed83
2 changed files with 48 additions and 3 deletions

View File

@@ -1,6 +1,15 @@
const Type = enum { ailment, recipe, ingredient };
const std = @import("std");
const NodeID = enum(u16) { sellery_juice };
const Type = enum {
ailment,
recipe,
ingredient,
};
const NodeID = enum {
sellery_juice,
salt_craving,
};
const Node = struct {
name: []const u8,
@@ -14,5 +23,37 @@ const Edge = struct {
dest: NodeID,
};
var nodes: []const Node = &.{};
fn validated(arr: std.EnumArray(NodeID, Node)) std.EnumArray(NodeID, Node) {
for (std.enums.values(NodeID)) |id| {
const desc = arr.get(id).description;
var i: usize = 0;
while (i + 1 < desc.len) : (i += 1) {
if (desc[i] == '[' and desc[i + 1] == '[') {
const start = i + 2;
var j = start;
while (j + 1 < desc.len and !(desc[j] == ']' and desc[j + 1] == ']')) : (j += 1) {}
const ref = desc[start..j];
if (std.meta.stringToEnum(NodeID, ref) == null) {
@compileLog("Unknown node reference: ", ref);
@compileError("Invalid wiki link in node description (see log above)");
}
i = j + 1;
}
}
}
return arr;
}
pub const nodes = validated(std.EnumArray(NodeID, Node).init(.{
.sellery_juice = .{
.name = "Sellery Juice",
.description = "A healing drink made from celery.",
.type = .recipe,
},
.salt_craving = .{
.name = "Salt craving",
.description = "Can be caused by sodium deficincy. Can be fixed with [[sellery_juice]].",
.type = .recipe,
},
}));
var edges: []const Edge = &.{};

View File

@@ -2,6 +2,10 @@ const std = @import("std");
const rl = @import("raylib");
const builtin = @import("builtin");
const math = std.math;
const data = @import("data.zig");
comptime {
_ = data.nodes;
}
const NODE_R: f32 = 42.0;