Improved resource docs and added setMany(...)
This commit is contained in:
parent
942380fd03
commit
35c1625f2a
3 changed files with 70 additions and 3 deletions
|
|
@ -85,8 +85,10 @@ const window_plugin: Plugin = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn ensureStuff(app: *Self) !void {
|
fn ensureStuff(app: *Self) !void {
|
||||||
try app.resources.set(Window{ .raw = 0 });
|
try app.resources.setMany(.{
|
||||||
try app.resources.set(Renderer{ .raw = 0 });
|
Window{ .raw = 0 },
|
||||||
|
Renderer{ .raw = 0 },
|
||||||
|
});
|
||||||
|
|
||||||
if (app.resources.getPtr(Window)) |win| {
|
if (app.resources.getPtr(Window)) |win| {
|
||||||
std.debug.print("[WINDOW] {}\n", .{win.raw});
|
std.debug.print("[WINDOW] {}\n", .{win.raw});
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,17 @@ pub fn deinit(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// const window_plugin: Plugin = .{
|
||||||
|
/// .name = "Window",
|
||||||
|
/// .description = "SDL3 Window",
|
||||||
|
/// .build = build,
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// try app.plugins.add(window_plugin);
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn add(
|
pub fn add(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ pub fn deinit(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// try app.resources.set(Window{ .raw = 0 });
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn set(
|
pub fn set(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
@ -42,6 +47,30 @@ pub fn set(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// try app.resources.setMany(.{
|
||||||
|
/// Window{ .raw = 0 },
|
||||||
|
/// Renderer{ .raw = 0 },
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
pub fn setMany(
|
||||||
|
self: *Self,
|
||||||
|
values: anytype,
|
||||||
|
) !void {
|
||||||
|
inline for (values) |value| {
|
||||||
|
try self.set(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// try app.resources.remove(Window);
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn remove(
|
pub fn remove(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
@ -51,6 +80,11 @@ pub fn remove(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// const window = try app.resources.getOrSet(Window{ .raw = 0 });
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn getOrSet(
|
pub fn getOrSet(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
@ -90,6 +124,11 @@ pub fn getOrSet(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// if (app.resources.getPtr(Window)) |window| {...}
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn getPtr(
|
pub fn getPtr(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
@ -100,8 +139,13 @@ pub fn getPtr(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// if (app.resources.get(Window)) |window| {...}
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn getConstPtr(
|
pub fn get(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
comptime T: type,
|
comptime T: type,
|
||||||
) ?*const T {
|
) ?*const T {
|
||||||
|
|
@ -110,6 +154,11 @@ pub fn getConstPtr(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// const window = try app.resources.require(Window);
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn require(
|
pub fn require(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
|
@ -171,6 +220,11 @@ pub fn getMany(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```zig
|
||||||
|
/// if (!app.resources.contains(Window)) {...}
|
||||||
|
/// ```
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn contains(
|
pub fn contains(
|
||||||
self: *const Self,
|
self: *const Self,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue