Added OnDiagonal Modifier [Modifier 2 of 4]#2693
Added OnDiagonal Modifier [Modifier 2 of 4]#2693Crepestrom wants to merge 28 commits intoPixelGuys:masterfrom
Conversation
| const Encased = struct { | ||
| tag: main.Tag, | ||
| amount: usize, | ||
| range: usize, |
There was a problem hiding this comment.
Please use an optional and if not present check the entire size of the tool. Tools may not be limited to 5×5 in the future.
| } | ||
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + @as(i32, @intCast(dx - self.range)); | ||
| const checkedY = y - @as(i32, (@intCast(dx - self.range))); |
There was a problem hiding this comment.
| const checkedY = y - @as(i32, (@intCast(dx - self.range))); | |
| const checkedY = y - @as(i32, @intCast(dx - self.range)); |
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + @as(i32, @intCast(dx - self.range)); | ||
| const checkedY = y - @as(i32, (@intCast(dx - self.range))); | ||
| if (!(dx == 0)) { |
There was a problem hiding this comment.
| if (!(dx == 0)) { | |
| if (dx != 0) { |
| pub const encased = @import("encased.zig"); | ||
| pub const not = @import("not.zig"); | ||
| pub const @"or" = @import("or.zig"); | ||
| pub const OnDiagonal = @import("onDiagonal.zig"); |
There was a problem hiding this comment.
| pub const OnDiagonal = @import("onDiagonal.zig"); | |
| pub const onDiagonal = @import("onDiagonal.zig"); |
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
|
please fix the formatting |
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
|
Requested Changes have been made |
| if (self.range > gridSize) { | ||
| rangeChecked = gridSize; | ||
| } else { | ||
| if (self.range == 0) { |
There was a problem hiding this comment.
Please use an optional instead of magic value 0.
const rangeChecked = @min(self.range orelse gridSize, gridSize);There was a problem hiding this comment.
Ive finally gotten around to it
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
|
rip formatting |
IntegratedQuantum
left a comment
There was a problem hiding this comment.
Please also test this on your own by adding it to a test item and checking if it works. Just by looking at it, I already see a case where it will definitely crash.
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + @as(i32, @intCast(dx - rangeChecked)); | ||
| const checkedY = y + @as(i32, @intCast(dx - rangeChecked)); | ||
| if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1; |
There was a problem hiding this comment.
Missing the dx != 0 check from below
| const highBound = rangeChecked*2 + 1; | ||
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + @as(i32, @intCast(dx - rangeChecked)); | ||
| const checkedY = y + @as(i32, @intCast(dx - rangeChecked)); |
There was a problem hiding this comment.
This looks wrong, using dx for y. Also dx convention is for delta values, but only dx - rangedCheck is the actual delta.
I'd suggest to rename it.
| const lowBound = 0; | ||
| const highBound = rangeChecked*2 + 1; | ||
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + @as(i32, @intCast(dx - rangeChecked)); |
There was a problem hiding this comment.
This looks like a crash
| const checkedX = x + @as(i32, @intCast(dx - rangeChecked)); | |
| const checkedX = x + @as(i32, @intCast(dx)) - rangeChecked; |
From #2650

-onDiagonal
Default range is 0 (this covers the entire available crafting space on diagonals)