38 lines
1.1 KiB
Zig
38 lines
1.1 KiB
Zig
const std = @import("std");
|
|
const Store = @import("../store.zig");
|
|
const json_utils = @import("../json_utils.zig");
|
|
const json = std.json;
|
|
const Allocator = std.mem.Allocator;
|
|
const EnumStringUtils = @import("../enum_string_utils.zig").EnumStringUtils;
|
|
|
|
const MapContent = @This();
|
|
|
|
pub const Type = enum {
|
|
monster,
|
|
resource,
|
|
workshop,
|
|
bank,
|
|
grand_exchange,
|
|
tasks_master,
|
|
};
|
|
pub const TypeUtils = EnumStringUtils(Type, .{
|
|
.{ "monster" , Type.monster },
|
|
.{ "resource" , Type.resource },
|
|
.{ "workshop" , Type.workshop },
|
|
.{ "bank" , Type.bank },
|
|
.{ "grand_exchange", Type.grand_exchange },
|
|
.{ "tasks_master" , Type.tasks_master },
|
|
});
|
|
|
|
type: Type,
|
|
code_id: Store.CodeId,
|
|
|
|
pub fn parse(store: *Store, obj: json.ObjectMap) MapContent {
|
|
const content_type = json_utils.getString(obj, "type") orelse return error.MissingProperty;
|
|
|
|
return MapContent{
|
|
.type = TypeUtils.fromString(content_type) orelse return error.InvalidContentType,
|
|
.code = (try store.getCodeIdJson(obj, "code")) orelse return error.MissingProperty
|
|
};
|
|
}
|