mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-05 12:17:53 -04:00
Prevent settings from breaking when no previous file is present. (#1719)
Fix #1718
This commit is contained in:
parent
08c78ff48d
commit
a47c8d14a1
@ -183,7 +183,7 @@ pub fn deinit() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn save() void { // MARK: save()
|
pub fn save() void { // MARK: save()
|
||||||
const guiZon = ZonElement.initObject(main.stackAllocator);
|
var guiZon = ZonElement.initObject(main.stackAllocator);
|
||||||
defer guiZon.deinit(main.stackAllocator);
|
defer guiZon.deinit(main.stackAllocator);
|
||||||
for(windowList.items) |window| {
|
for(windowList.items) |window| {
|
||||||
const windowZon = ZonElement.initObject(main.stackAllocator);
|
const windowZon = ZonElement.initObject(main.stackAllocator);
|
||||||
@ -218,7 +218,7 @@ pub fn save() void { // MARK: save()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge with the old settings file to preserve unknown settings.
|
// Merge with the old settings file to preserve unknown settings.
|
||||||
const oldZon: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, "gui_layout.zig.zon") catch |err| blk: {
|
var oldZon: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, "gui_layout.zig.zon") catch |err| blk: {
|
||||||
if(err != error.FileNotFound) {
|
if(err != error.FileNotFound) {
|
||||||
std.log.err("Could not read gui_layout.zig.zon: {s}", .{@errorName(err)});
|
std.log.err("Could not read gui_layout.zig.zon: {s}", .{@errorName(err)});
|
||||||
}
|
}
|
||||||
@ -226,7 +226,13 @@ pub fn save() void { // MARK: save()
|
|||||||
};
|
};
|
||||||
defer oldZon.deinit(main.stackAllocator);
|
defer oldZon.deinit(main.stackAllocator);
|
||||||
|
|
||||||
|
if(oldZon == .object) {
|
||||||
oldZon.join(guiZon);
|
oldZon.join(guiZon);
|
||||||
|
} else {
|
||||||
|
oldZon.deinit(main.stackAllocator);
|
||||||
|
oldZon = guiZon;
|
||||||
|
guiZon = .null;
|
||||||
|
}
|
||||||
|
|
||||||
main.files.cubyzDir().writeZon("gui_layout.zig.zon", oldZon) catch |err| {
|
main.files.cubyzDir().writeZon("gui_layout.zig.zon", oldZon) catch |err| {
|
||||||
std.log.err("Could not write gui_layout.zig.zon: {s}", .{@errorName(err)});
|
std.log.err("Could not write gui_layout.zig.zon: {s}", .{@errorName(err)});
|
||||||
|
@ -124,7 +124,7 @@ pub fn deinit() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn save() void {
|
pub fn save() void {
|
||||||
const zonObject = ZonElement.initObject(main.stackAllocator);
|
var zonObject = ZonElement.initObject(main.stackAllocator);
|
||||||
defer zonObject.deinit(main.stackAllocator);
|
defer zonObject.deinit(main.stackAllocator);
|
||||||
|
|
||||||
inline for(@typeInfo(@This()).@"struct".decls) |decl| {
|
inline for(@typeInfo(@This()).@"struct".decls) |decl| {
|
||||||
@ -154,7 +154,7 @@ pub fn save() void {
|
|||||||
zonObject.put("keyboard", keyboard);
|
zonObject.put("keyboard", keyboard);
|
||||||
|
|
||||||
// Merge with the old settings file to preserve unknown settings.
|
// Merge with the old settings file to preserve unknown settings.
|
||||||
const oldZonObject: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, settingsFile) catch |err| blk: {
|
var oldZonObject: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, settingsFile) catch |err| blk: {
|
||||||
if(err != error.FileNotFound) {
|
if(err != error.FileNotFound) {
|
||||||
std.log.err("Could not read settings file: {s}", .{@errorName(err)});
|
std.log.err("Could not read settings file: {s}", .{@errorName(err)});
|
||||||
}
|
}
|
||||||
@ -162,7 +162,13 @@ pub fn save() void {
|
|||||||
};
|
};
|
||||||
defer oldZonObject.deinit(main.stackAllocator);
|
defer oldZonObject.deinit(main.stackAllocator);
|
||||||
|
|
||||||
|
if(oldZonObject == .object) {
|
||||||
oldZonObject.join(zonObject);
|
oldZonObject.join(zonObject);
|
||||||
|
} else {
|
||||||
|
oldZonObject.deinit(main.stackAllocator);
|
||||||
|
oldZonObject = zonObject;
|
||||||
|
zonObject = .null;
|
||||||
|
}
|
||||||
|
|
||||||
main.files.cubyzDir().writeZon(settingsFile, oldZonObject) catch |err| {
|
main.files.cubyzDir().writeZon(settingsFile, oldZonObject) catch |err| {
|
||||||
std.log.err("Couldn't write settings to file: {s}", .{@errorName(err)});
|
std.log.err("Couldn't write settings to file: {s}", .{@errorName(err)});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user