mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 03:06:55 -04:00
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.    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:
parent
a24729eb40
commit
cd4cd8e9b9
@ -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 = .{
|
||||
|
@ -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 = .{
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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 = .{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user