feat: add small size graphics
parent
680f56a39d
commit
695c4d6280
87
src/main.zig
87
src/main.zig
|
@ -155,6 +155,9 @@ pub fn main() !void {
|
||||||
// Set up input callbacks
|
// Set up input callbacks
|
||||||
_ = seizer.backend.glfw.c.glfwSetFramebufferSizeCallback(window, &glfw_framebuffer_size_callback);
|
_ = seizer.backend.glfw.c.glfwSetFramebufferSizeCallback(window, &glfw_framebuffer_size_callback);
|
||||||
|
|
||||||
|
var card_tilemap_small: ?DeckSprites = null;
|
||||||
|
defer if (card_tilemap_small) |*tilemap| tilemap.deinit(gpa.allocator());
|
||||||
|
|
||||||
var card_tilemap_medium: ?DeckSprites = null;
|
var card_tilemap_medium: ?DeckSprites = null;
|
||||||
defer if (card_tilemap_medium) |*tilemap| tilemap.deinit(gpa.allocator());
|
defer if (card_tilemap_medium) |*tilemap| tilemap.deinit(gpa.allocator());
|
||||||
|
|
||||||
|
@ -187,18 +190,25 @@ pub fn main() !void {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const render_large = framebuffer_size[1] > 1000;
|
switch (framebuffer_size[1]) {
|
||||||
if (render_large) {
|
0...300 => if (card_tilemap_small == null) {
|
||||||
if (card_tilemap_large == null) {
|
card_tilemap_small = try loadSmallCards(gpa.allocator());
|
||||||
card_tilemap_large = try loadLargeCards(gpa.allocator());
|
},
|
||||||
}
|
301...1000 => if (card_tilemap_medium == null) {
|
||||||
} else {
|
|
||||||
if (card_tilemap_medium == null) {
|
|
||||||
card_tilemap_medium = try loadMediumCards(gpa.allocator());
|
card_tilemap_medium = try loadMediumCards(gpa.allocator());
|
||||||
}
|
},
|
||||||
|
1001...std.math.maxInt(c_int) => if (card_tilemap_large == null) {
|
||||||
|
card_tilemap_large = try loadLargeCards(gpa.allocator());
|
||||||
|
},
|
||||||
|
else => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
const deck_sprites = if (framebuffer_size[1] > 1000) card_tilemap_large.? else card_tilemap_medium.?;
|
const deck_sprites = switch (framebuffer_size[1]) {
|
||||||
|
0...300 => card_tilemap_small.?,
|
||||||
|
301...1000 => card_tilemap_medium.?,
|
||||||
|
1001...std.math.maxInt(c_int) => card_tilemap_large.?,
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
for (0..4) |suit| {
|
for (0..4) |suit| {
|
||||||
for (1..14) |rank| {
|
for (1..14) |rank| {
|
||||||
const card = Card{ .suit = @enumFromInt(suit), .rank = @intCast(rank) };
|
const card = Card{ .suit = @enumFromInt(suit), .rank = @intCast(rank) };
|
||||||
|
@ -233,6 +243,65 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn loadSmallCards(gpa: std.mem.Allocator) !DeckSprites {
|
||||||
|
var tilesheet = try TileSheet.init(.{
|
||||||
|
.allocator = gpa,
|
||||||
|
.image_file_contents = @embedFile("./cardsSmall_tilemap.png"),
|
||||||
|
.tile_offset = .{ 0, 0 },
|
||||||
|
.tile_size = .{ 16, 16 },
|
||||||
|
.tile_stride = .{ 17, 17 },
|
||||||
|
.texture_options = .{
|
||||||
|
.min_filter = .nearest,
|
||||||
|
.mag_filter = .nearest,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
errdefer tilesheet.deinit();
|
||||||
|
|
||||||
|
var mapping = std.AutoHashMap(Card, u32).init(gpa);
|
||||||
|
errdefer mapping.deinit();
|
||||||
|
try mapping.ensureTotalCapacity(52);
|
||||||
|
|
||||||
|
const hearts_start_index: u32 = 0;
|
||||||
|
for (0..13) |rank| {
|
||||||
|
mapping.putAssumeCapacityNoClobber(
|
||||||
|
Card{ .suit = .hearts, .rank = @intCast(rank + 1) },
|
||||||
|
hearts_start_index + @as(u32, @intCast(rank)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const diamonds_start_index: u32 = 14;
|
||||||
|
for (0..13) |rank| {
|
||||||
|
mapping.putAssumeCapacityNoClobber(
|
||||||
|
Card{ .suit = .diamonds, .rank = @intCast(rank + 1) },
|
||||||
|
diamonds_start_index + @as(u32, @intCast(rank)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const clubs_start_index: u32 = 28;
|
||||||
|
for (0..13) |rank| {
|
||||||
|
mapping.putAssumeCapacityNoClobber(
|
||||||
|
Card{ .suit = .clubs, .rank = @intCast(rank + 1) },
|
||||||
|
clubs_start_index + @as(u32, @intCast(rank)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const spades_start_index: u32 = 42;
|
||||||
|
for (0..13) |rank| {
|
||||||
|
mapping.putAssumeCapacityNoClobber(
|
||||||
|
Card{ .suit = .spades, .rank = @intCast(rank + 1) },
|
||||||
|
spades_start_index + @as(u32, @intCast(rank)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DeckSprites{
|
||||||
|
.tilesheet = tilesheet,
|
||||||
|
.mapping = mapping.unmanaged,
|
||||||
|
// TODO: add better graphic for blank card
|
||||||
|
.blank = 59,
|
||||||
|
.back = 59,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn loadMediumCards(gpa: std.mem.Allocator) !DeckSprites {
|
fn loadMediumCards(gpa: std.mem.Allocator) !DeckSprites {
|
||||||
var tilesheet = try TileSheet.init(.{
|
var tilesheet = try TileSheet.init(.{
|
||||||
.allocator = gpa,
|
.allocator = gpa,
|
||||||
|
|
Loading…
Reference in New Issue