92 lines
2.7 KiB
Zig
92 lines
2.7 KiB
Zig
const std = @import("std");
|
|
const json_utils = @import("../json_utils.zig");
|
|
const Store = @import("../store.zig");
|
|
const json = std.json;
|
|
|
|
const Equipment = @This();
|
|
|
|
const CodeId = Store.CodeId;
|
|
|
|
pub const Consumable = struct {
|
|
code_id: ?CodeId,
|
|
quantity: i64,
|
|
|
|
fn parse(store: *Store, obj: json.ObjectMap, name: []const u8, quantity: []const u8) !Consumable {
|
|
return Consumable{
|
|
.code_id = try store.getCodeIdJson(obj, name),
|
|
.quantity = try json_utils.getIntegerRequired(obj, quantity),
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const Slot = enum {
|
|
weapon,
|
|
shield,
|
|
helmet,
|
|
body_armor,
|
|
leg_armor,
|
|
boots,
|
|
ring1,
|
|
ring2,
|
|
amulet,
|
|
artifact1,
|
|
artifact2,
|
|
consumable1,
|
|
consumable2,
|
|
|
|
fn name(self: Slot) []const u8 {
|
|
return switch (self) {
|
|
.weapon => "weapon",
|
|
.shield => "shield",
|
|
.helmet => "helmet",
|
|
.body_armor => "body_armor",
|
|
.leg_armor => "leg_armor",
|
|
.boots => "boots",
|
|
.ring1 => "ring1",
|
|
.ring2 => "ring2",
|
|
.amulet => "amulet",
|
|
.artifact1 => "artifact1",
|
|
.artifact2 => "artifact2",
|
|
.consumable1 => "consumable1",
|
|
.consumable2 => "consumable2",
|
|
};
|
|
}
|
|
};
|
|
|
|
weapon: ?CodeId,
|
|
shield: ?CodeId,
|
|
helmet: ?CodeId,
|
|
body_armor: ?CodeId,
|
|
leg_armor: ?CodeId,
|
|
boots: ?CodeId,
|
|
|
|
ring1: ?CodeId,
|
|
ring2: ?CodeId,
|
|
amulet: ?CodeId,
|
|
|
|
artifact1: ?CodeId,
|
|
artifact2: ?CodeId,
|
|
artifact3: ?CodeId,
|
|
|
|
consumable1: Consumable,
|
|
consumable2: Consumable,
|
|
|
|
pub fn parse(store: *Store, obj: json.ObjectMap) !Equipment {
|
|
return Equipment{
|
|
.weapon = try store.getCodeIdJson(obj, "weapon_slot"),
|
|
.shield = try store.getCodeIdJson(obj, "shield_slot"),
|
|
.helmet = try store.getCodeIdJson(obj, "helmet_slot"),
|
|
.body_armor = try store.getCodeIdJson(obj, "body_armor_slot"),
|
|
.leg_armor = try store.getCodeIdJson(obj, "leg_armor_slot"),
|
|
.boots = try store.getCodeIdJson(obj, "boots_slot"),
|
|
.ring1 = try store.getCodeIdJson(obj, "ring1_slot"),
|
|
.ring2 = try store.getCodeIdJson(obj, "ring2_slot"),
|
|
.amulet = try store.getCodeIdJson(obj, "amulet_slot"),
|
|
.artifact1 = try store.getCodeIdJson(obj, "artifact1_slot"),
|
|
.artifact2 = try store.getCodeIdJson(obj, "artifact2_slot"),
|
|
.artifact3 = try store.getCodeIdJson(obj, "artifact3_slot"),
|
|
.consumable1 = try Consumable.parse(store, obj, "consumable1_slot", "consumable1_slot_quantity"),
|
|
.consumable2 = try Consumable.parse(store, obj, "consumable2_slot", "consumable2_slot_quantity"),
|
|
};
|
|
}
|