compile checks (WIP)
This commit is contained in:
47
src/data.zig
47
src/data.zig
@@ -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 = &.{};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user