Skip to content

Added OnDiagonal Modifier [Modifier 2 of 4]#2693

Open
Crepestrom wants to merge 28 commits intoPixelGuys:masterfrom
Crepestrom:Modifier-OnDiagonal
Open

Added OnDiagonal Modifier [Modifier 2 of 4]#2693
Crepestrom wants to merge 28 commits intoPixelGuys:masterfrom
Crepestrom:Modifier-OnDiagonal

Conversation

@Crepestrom
Copy link
Copy Markdown
Contributor

@Crepestrom Crepestrom commented Mar 7, 2026

From #2650
-onDiagonal
diagonal-visual
Default range is 0 (this covers the entire available crafting space on diagonals)

@Wunka Wunka moved this to Low Priority in PRs to review Mar 8, 2026
const Encased = struct {
tag: main.Tag,
amount: usize,
range: usize,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub const OnDiagonal = @import("onDiagonal.zig");
pub const onDiagonal = @import("onDiagonal.zig");

@IntegratedQuantum IntegratedQuantum moved this from Low Priority to In review in PRs to review Mar 14, 2026
Crepestrom and others added 3 commits March 14, 2026 14:30
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
@IntegratedQuantum
Copy link
Copy Markdown
Member

please fix the formatting

@Crepestrom
Copy link
Copy Markdown
Contributor Author

Requested Changes have been made
and also copied to OnOrthogonal

if (self.range > gridSize) {
rangeChecked = gridSize;
} else {
if (self.range == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an optional instead of magic value 0.

const rangeChecked = @min(self.range orelse gridSize, gridSize);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive finally gotten around to it

Comment thread src/tool/modifiers/restrictions/onDiagonal.zig
@H41ogen
Copy link
Copy Markdown
Contributor

H41ogen commented Mar 20, 2026

rip formatting

Copy link
Copy Markdown
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a crash

Suggested change
const checkedX = x + @as(i32, @intCast(dx - rangeChecked));
const checkedX = x + @as(i32, @intCast(dx)) - rangeChecked;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants