artificer/api/schemas/task_data.zig

28 lines
944 B
Zig

const std = @import("std");
const Server = @import("../server.zig");
const json_utils = @import("../json_utils.zig");
const json = std.json;
const Allocator = std.mem.Allocator;
const Cooldown = @import("./cooldown.zig");
const Character = @import("./character.zig");
const Task = @import("./task.zig");
const TaskData = @This();
cooldown: Cooldown,
character: Character,
task: Task,
pub fn parse(api: *Server, obj: json.ObjectMap, allocator: Allocator) !TaskData {
const cooldown = json_utils.getObject(obj, "cooldown") orelse return error.MissingProperty;
const character = json_utils.getObject(obj, "character") orelse return error.MissingProperty;
const task = json_utils.getObject(obj, "task") orelse return error.MissingProperty;
return TaskData{
.cooldown = try Cooldown.parse(cooldown),
.character = try Character.parse(api, character, allocator),
.task = try Task.parse(api, task)
};
}