Add and allow for more optional slots (#1612)

This checks slots based on texture connectivity. It really is just a
gimmick at this point, but it has potential to be more than that with
the right modifier restrictions.
![Screenshot at 2025-06-07
10-03-05](https://github.com/user-attachments/assets/e2aa96d4-8add-47cf-abc4-97f383c5fe41)
![Screenshot at 2025-06-07
09-59-46](https://github.com/user-attachments/assets/6aa00d24-8a97-4200-8c77-86b9751d2e2d)
![Screenshot at 2025-06-07
09-54-42](https://github.com/user-attachments/assets/247a2fdd-29ce-4467-85ff-3183f0ec36f1)

The big questions I have for you are:
- Is it obvious why some tools don't work while others do or is this too
confusing?
- @careeoki can you improve the texture to look better for these crooked
tools? Many slots do just seem to produce a thin line of diagonally
connected pixels, and this really doesn't look good and the algorithm
doesn't accept those as valid connections.

fixes #1589
This commit is contained in:
IntegratedQuantum 2025-06-08 11:32:56 +02:00 committed by GitHub
parent a24729eb40
commit cd4cd8e9b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 54 additions and 13 deletions

View File

@ -9,9 +9,9 @@
},
.optional = .{
1, 1, 0, 0, 0,
1, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 1, 0, 0,
1, 1, 1, 0, 0,
0, 1, 1, 1, 0,
0, 0, 1, 1, 0,
0, 0, 0, 0, 0,
},
.parameters = .{

View File

@ -8,10 +8,10 @@
1, 1, 1, 1, 0,
},
.optional = .{
1, 1, 0, 0, 0,
1, 0, 1, 0, 0,
0, 1, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 1, 1, 0,
1, 1, 1, 0, 0,
1, 1, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 0,
},
.parameters = .{

View File

@ -9,8 +9,8 @@
},
.optional = .{
1, 0, 1, 0, 0,
0, 0, 0, 1, 0,
1, 0, 0, 1, 0,
0, 1, 1, 1, 0,
1, 1, 1, 1, 0,
0, 1, 1, 0, 0,
0, 0, 0, 0, 0,
},

View File

@ -9,9 +9,9 @@
},
.optional = .{
0, 1, 1, 1, 0,
1, 0, 0, 0, 1,
0, 0, 0, 0, 1,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
0, 0, 0, 1, 1,
0, 0, 0, 1, 0,
0, 0, 0, 0, 0,
},
.parameters = .{

View File

@ -112,7 +112,7 @@ pub fn render() void {
const offsetY = 4*ItemSlot.sizeWithBorder;
const fontSize = 16;
main.graphics.draw.print("#ffffff{} durability", .{@as(usize, @intFromFloat(currentResult.tool.maxDurability))}, offsetX, offsetY, fontSize, .left);
main.graphics.draw.print("{s}{} durability", .{if(currentResult.tool.maxDurability != 0) "#ffffff" else "#ff0000", @as(usize, @intFromFloat(currentResult.tool.maxDurability))}, offsetX, offsetY, fontSize, .left);
main.graphics.draw.print("#ffffff{d:.1} swings/s", .{1.0/currentResult.tool.swingTime}, offsetX, offsetY + fontSize, fontSize, .left);
main.graphics.draw.print("#ffffff{d:.1} damage", .{currentResult.tool.damage}, offsetX, offsetY + 2*fontSize, fontSize, .left);
}

View File

@ -435,6 +435,47 @@ const ToolPhysics = struct { // MARK: ToolPhysics
tool.maxDurability = @round(tool.maxDurability);
if(tool.maxDurability < 1) tool.maxDurability = 1;
tool.durability = std.math.lossyCast(u32, tool.maxDurability);
if(!checkConnectivity(tool)) {
tool.maxDurability = 0;
tool.durability = 1;
}
}
fn checkConnectivity(tool: *Tool) bool {
var gridCellsReached: [16][16]bool = @splat(@splat(false));
var floodfillQueue = main.utils.CircularBufferQueue(Vec2i).init(main.stackAllocator, 16);
defer floodfillQueue.deinit();
outer: for(tool.materialGrid, 0..) |row, x| {
for(row, 0..) |entry, y| {
if(entry != null) {
floodfillQueue.enqueue(.{@intCast(x), @intCast(y)});
gridCellsReached[x][y] = true;
break :outer;
}
}
}
while(floodfillQueue.dequeue()) |pos| {
for([4]Vec2i{.{-1, 0}, .{1, 0}, .{0, -1}, .{0, 1}}) |delta| {
const newPos = pos + delta;
if(newPos[0] < 0 or newPos[0] >= gridCellsReached.len) continue;
if(newPos[1] < 0 or newPos[1] >= gridCellsReached.len) continue;
const x: usize = @intCast(newPos[0]);
const y: usize = @intCast(newPos[1]);
if(gridCellsReached[x][y]) continue;
if(tool.materialGrid[x][y] == null) continue;
gridCellsReached[x][y] = true;
floodfillQueue.enqueue(newPos);
}
}
for(tool.materialGrid, 0..) |row, x| {
for(row, 0..) |entry, y| {
if(entry != null and !gridCellsReached[x][y]) {
return false;
}
}
}
return true;
}
};