From f00e70e28cd47e526ceb344be5b68264bd779e81 Mon Sep 17 00:00:00 2001 From: H41ogen Date: Fri, 12 Jun 2026 13:24:50 -0500 Subject: [PATCH] remove getAtIndex and getChildAtIndex from zon.zig --- src/items.zig | 14 ++++++++------ src/zon.zig | 24 ------------------------ 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/items.zig b/src/items.zig index 8080774516..03e6fae644 100644 --- a/src/items.zig +++ b/src/items.zig @@ -759,9 +759,10 @@ pub const ProceduralItem = struct { // MARK: ProceduralItem } fn extractItemsFromZon(zonArray: ZonElement) [craftingGridSize]?BaseItemIndex { - var items: [craftingGridSize]?BaseItemIndex = undefined; - for (&items, 0..) |*item, i| { - item.* = .fromId(zonArray.getAtIndex([]const u8, i, "null")); + const itemZonArray = zonArray.toSlice(); + var items: [craftingGridSize]?BaseItemIndex = @splat(null); + for (&items, itemZonArray) |*item, itemZon| { + item.* = .fromId(itemZon.as([]const u8) orelse "null"); if (item.* != null and item.*.?.material() == null) item.* = null; } return items; @@ -1307,10 +1308,11 @@ pub fn registerProceduralItem(assetFolder: []const u8, id: []const u8, zon: ZonE val.destination = ProceduralItemProperty.fromString(paramZon.get([]const u8, "destination", "not specified")); val.resultScale = paramZon.get(f32, "factor", 1.0); val.method = PropertyMatrix.Method.fromString(paramZon.get([]const u8, "method", "not specified")) orelse .sum; - const matrixZon = paramZon.getChild("matrix"); + const weightMatrix = paramZon.getChild("matrix").toSlice(); + @memset(&val.weights, 0.0); var total_weight: f32 = 0.0; - for (0..25) |i| { - val.weights[i] = matrixZon.getAtIndex(f32, i, 0.0); + for (weightMatrix, 0..25) |weightZon, i| { + if (weightZon.as(f32)) |weight| val.weights[i] = weight; } for (0..25) |i| { total_weight += val.weights[i]; diff --git a/src/zon.zig b/src/zon.zig index a84a70b6b3..4b1d5f4b2e 100644 --- a/src/zon.zig +++ b/src/zon.zig @@ -27,30 +27,6 @@ pub const ZonElement = union(enum) { // MARK: Zon return .{.array = list}; } - pub fn getAtIndex(self: *const ZonElement, comptime T: type, index: usize, replacement: T) T { - if (self.* != .array) { - return replacement; - } else { - if (index < self.array.items.len) { - return self.array.items[index].as(T) orelse replacement; - } else { - return replacement; - } - } - } - - pub fn getChildAtIndex(self: *const ZonElement, index: usize) ZonElement { - if (self.* != .array) { - return .null; - } else { - if (index < self.array.items.len) { - return self.array.items[index]; - } else { - return .null; - } - } - } - pub fn get(self: *const ZonElement, comptime T: type, key: []const u8, replacement: T) T { if (self.* != .object) { return replacement;