const std = @import("std"); const Store = @import("../store.zig"); const json_utils = @import("../json_utils.zig"); const BoundedSlotsArray = @import("./slot_array.zig").BoundedSlotsArray; const json = std.json; const Skill = @import("./skill.zig").Skill; const SkillUtils = @import("./skill.zig").SkillUtils; const Items = BoundedSlotsArray(8); const Craft = @This(); skill: Skill, level: u64, quantity: u64, items: Items, pub fn parse(store: *Store, obj: json.ObjectMap) !Craft { const skill = json_utils.getString(obj, "skill") orelse return error.MissingProperty; const level = json_utils.getInteger(obj, "level") orelse return error.MissingProperty; if (level < 1) return error.InvalidLevel; const quantity = json_utils.getInteger(obj, "quantity") orelse return error.MissingProperty; if (quantity < 1) return error.InvalidQuantity; const items = json_utils.getArray(obj, "items") orelse return error.MissingProperty; return Craft{ .skill = SkillUtils.fromString(skill) orelse return error.InvalidSkill, .level = @intCast(level), .quantity = @intCast(quantity), .items = try Items.parse(store, items) }; }