Remove redundant window ids. They were asserted to be equal to the file name, now they are initialized to the file name, removing the need for setting it manually.

This makes adding new windows simpler, also affects #273.
This commit is contained in:
IntegratedQuantum 2024-03-19 22:17:46 +01:00
parent 4ea46a6cde
commit 899083569d
24 changed files with 5 additions and 26 deletions

View File

@ -293,7 +293,6 @@ pub const Chunk = struct {
}
pub fn getNeighbors(self: *const Chunk, x: i32, y: i32, z: i32, neighborsArray: *[6]Block) void {
std.debug.assert(neighborsArray.length == 6);
x &= chunkMask;
y &= chunkMask;
z &= chunkMask;

View File

@ -52,7 +52,7 @@ contentSize: Vec2f,
scale: f32 = 1,
spacing: f32 = 0,
relativePosition: [2]RelativePosition = .{.{.ratio = 0.5}, .{.ratio = 0.5}},
id: []const u8,
id: []const u8 = undefined,
rootComponent: ?GuiComponent = null,
showTitleBar: bool = true,
titleBarExpanded: bool = false,

View File

@ -131,7 +131,7 @@ pub fn init() void {
openWindows = List(*GuiWindow).init(main.globalAllocator);
inline for(@typeInfo(windowlist).Struct.decls) |decl| {
const windowStruct = @field(windowlist, decl.name);
std.debug.assert(std.mem.eql(u8, decl.name, windowStruct.window.id)); // id and file name should be the same.
windowStruct.window.id = decl.name;
addWindow(&windowStruct.window);
if(@hasDecl(windowStruct, "init")) {
windowStruct.init();

View File

@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "change_name",
};
var textComponent: *TextInput = undefined;

View File

@ -19,7 +19,6 @@ pub var window: GuiWindow = GuiWindow {
},
.scale = 0.75,
.contentSize = Vec2f{128, 256},
.id = "chat",
.showTitleBar = false,
.hasBackground = false,
.isHud = true,

View File

@ -13,7 +13,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "controls",
};
const padding: f32 = 8;

View File

@ -19,7 +19,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} },
},
.contentSize = Vec2f{64*8, 64*4},
.id = "creative_inventory",
};
const padding: f32 = 8;

View File

@ -13,7 +13,6 @@ const GuiComponent = gui.GuiComponent;
const size: f32 = 64;
pub var window = GuiWindow {
.contentSize = Vec2f{size, size},
.id = "crosshair",
.showTitleBar = false,
.hasBackground = false,
.isHud = true,

View File

@ -16,7 +16,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{128, 16},
.id = "debug",
.isHud = false,
.showTitleBar = false,
.hasBackground = false,

View File

@ -17,7 +17,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} },
},
.contentSize = Vec2f{192, 128},
.id = "debug_network",
.isHud = false,
.showTitleBar = false,
.hasBackground = false,

View File

@ -77,7 +77,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{256, 16},
.id = "gpu_performance_measuring",
.isHud = false,
.showTitleBar = false,
.hasBackground = false,

View File

@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "graphics",
};
const padding: f32 = 8;

View File

@ -19,7 +19,6 @@ pub var window = GuiWindow {
.{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{128, 16},
.id = "healthbar",
.isHud = true,
.showTitleBar = false,
.hasBackground = false,

View File

@ -19,7 +19,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} },
},
.contentSize = Vec2f{64*8, 64},
.id = "hotbar",
.isHud = true,
.showTitleBar = false,
.hasBackground = false,

View File

@ -22,7 +22,6 @@ pub var window = GuiWindow {
.{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{64*8, 64*4},
.id = "inventory",
};
const padding: f32 = 8;

View File

@ -25,7 +25,6 @@ pub var window = GuiWindow {
.{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} },
},
.contentSize = Vec2f{64*8, 64*4},
.id = "inventory_crafting",
};
const padding: f32 = 8;

View File

@ -11,7 +11,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "main",
};
const padding: f32 = 8;

View File

@ -15,7 +15,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "multiplayer",
};
var ipAddressLabel: *Label = undefined;

View File

@ -18,7 +18,6 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} },
.{ .attachedToWindow = .{.reference = &chat.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} },
},
.id = "performance_graph",
.isHud = false,
.showTitleBar = false,
.hasBackground = false,

View File

@ -17,7 +17,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "save_selection",
};
const padding: f32 = 8;

View File

@ -11,7 +11,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window: GuiWindow = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "settings",
};
const padding: f32 = 8;

View File

@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig");
pub var window = GuiWindow {
.contentSize = Vec2f{128, 256},
.id = "sound",
};
fn musicCallback(newValue: f32) void {

View File

@ -28,7 +28,6 @@ pub var window = GuiWindow {
.{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{64*8, 64*4},
.id = "workbench",
};
const padding: f32 = 8;

View File

@ -139,8 +139,8 @@ pub const std_options: std.Options = .{
}
types = &[_]type{[]const u8} ++ types ++ &[_]type{[]const u8};
comptime var comptimeTuple: std.meta.Tuple(types) = undefined;
comptime std.debug.assert(std.meta.Tuple(types) == std.meta.Tuple(types));
const ArgsType = std.meta.Tuple(types);
comptime var comptimeTuple: ArgsType = undefined;
comptime var len: usize = 0;
i_1 = 0;
i_2 = 0;
@ -156,7 +156,7 @@ pub const std_options: std.Options = .{
}
comptimeTuple[0] = filePrefix;
comptimeTuple[comptimeTuple.len - 1] = fileSuffix;
var resultArgs: std.meta.Tuple(types) = comptimeTuple;
var resultArgs: ArgsType = comptimeTuple;
len = 0;
i_1 = 0;
i_2 = 0;