@@ 41,46 41,43 @@ fn filedump(mepo: *Mepo, save_types: []const u8, filepath: []const u8) !void {
// 1. Preferences
if (std.mem.containsAtLeast(u8, save_types, 1, "r")) {
for (utilprefs.prefs_mapping) |pref| {
- const format_as: enum { Text, HexText, Number } = .Number;
-
+ const format_as: enum { Text, HexText, Number } = switch (pref.value) {
+ .t => .Text,
+ .b => .Number,
+ .u => .Number,
+ .f => .Number,
+ .u24 => .HexText
+ };
if (format_as == .Text) {
var args = std.StringArrayHashMap(std.json.Value).init(arena.allocator());
try args.put("pref", .{ .string = pref.name });
try args.put("value", .{ .string = if (pref.value.t) |tv| tv else "" });
try statements.append(.{
.cmd = "prefset_t",
- .args = try std.json.ArrayHashMap(std.json.Value).jsonParse(arena.allocator(), args, .{})
+ .args = try std.json.ArrayHashMap(std.json.Value).jsonParseFromValue(arena.allocator(), .{.object = args}, .{})
+ });
+ } else if (format_as == .Number) {
+ var args = std.StringArrayHashMap(std.json.Value).init(arena.allocator());
+ try args.put("pref", .{ .string = pref.name });
+ try args.put("value", .{ .float = switch (pref.value) {
+ .b => @floatFromInt(@intFromBool(pref.value.b)),
+ .u => @floatFromInt(pref.value.u),
+ .f => pref.value.f,
+ else => unreachable
+ }});
+ try statements.append(.{
+ .cmd = "prefset_n",
+ .args = try std.json.ArrayHashMap(std.json.Value).jsonParseFromValue(arena.allocator(), .{.object = args}, .{})
+ });
+ } else if (format_as == .HexText) {
+ var args = std.StringArrayHashMap(std.json.Value).init(arena.allocator());
+ try args.put("pref", .{ .string = pref.name });
+ try args.put("value", .{ .string = try std.fmt.allocPrint(arena.allocator(), "#{x}", .{pref.value.u24}) });
+ try statements.append(.{
+ .cmd = "prefset_t",
+ .args = try std.json.ArrayHashMap(std.json.Value).jsonParseFromValue(arena.allocator(), .{.object = args}, .{})
});
- //} else if (format_as == .Number) {
- // var args = std.StringArrayHashMap(std.json.Value).init(arena.allocator());
- // try args.put("pref", .{ .string = pref.name });
- // try args.put("value", .{ .float = switch (pref.value) {
- // .b => @floatFromInt(@intFromBool(pref.value.b)),
- // .u => @floatFromInt(pref.value.u),
- // .u24 => v: {
- // format_as = .HexText;
- // break :v -1;
- // },
- // .f => pref.value.f,
- // .t => v: {
- // format_as = .Text;
- // break :v -1;
- // },
- // }});
- // try statements.append(.{
- // .cmd = "prefset_n",
- // .args = std.json.ArrayHashMap(std.json.Value).jsonParse(arena.allocator(), args, .{})
- // });
- //} else {
- // var args = std.StringArrayHashMap(std.json.Value).init(arena.allocator());
- // try args.put("pref", .{ .string = pref.name });
- // try args.put("value", .{ .string = try std.fmt.allocPrint(arena.allocator(), "#{x}", .{pref.value.u24}) });
- // try statements.append(.{
- // .cmd = "prefset_t",
- // .args = try std.json.ArrayHashMap(std.json.Value).jsonParse(arena.allocator(), args, .{})
- // });
}
- //}
}
}
@@ 209,6 206,8 @@ fn filedump(mepo: *Mepo, save_types: []const u8, filepath: []const u8) !void {
// ));
//}
- const str = try std.json.stringifyAlloc(arena.allocator(), statements.items, .{});
+ const str = try std.json.stringifyAlloc(arena.allocator(), statements.items, .{
+ .whitespace = .indent_2,
+ });
try mepolang_file.writeAll(str);
}