32 lines
1.1 KiB
Zig
32 lines
1.1 KiB
Zig
// zig fmt: off
|
|
const std = @import("std");
|
|
const Store = @import("../store.zig");
|
|
const json_utils = @import("../json_utils.zig");
|
|
const Character = @import("./character.zig");
|
|
const Cooldown = @import("./cooldown.zig");
|
|
const Map = @import("./map.zig");
|
|
|
|
const MoveResult = @This();
|
|
|
|
cooldown: Cooldown,
|
|
destination: Map,
|
|
character: Character,
|
|
|
|
fn parse(store: *Store, obj: std.json.ObjectMap) !MoveResult {
|
|
const cooldown = json_utils.getObject(obj, "cooldown") orelse return error.MissingProperty;
|
|
const character = json_utils.getObject(obj, "character") orelse return error.MissingProperty;
|
|
const destination = json_utils.getObject(obj, "destination") orelse return error.MissingProperty;
|
|
|
|
return MoveResult{
|
|
.character = try Character.parse(store, character),
|
|
.destination = try Map.parse(store, destination),
|
|
.cooldown = try Cooldown.parse(store, cooldown)
|
|
};
|
|
}
|
|
|
|
pub fn parseAndUpdate(store: *Store, obj: std.json.ObjectMap) !MoveResult {
|
|
const result = try parse(store, obj);
|
|
_ = try store.characters.appendOrUpdate(result.character);
|
|
return result;
|
|
}
|