Skip to content

material cycle and picker keys#505

Merged
Ralith merged 5 commits intoRalith:masterfrom
shadow-kestrel:master
Mar 8, 2026
Merged

material cycle and picker keys#505
Ralith merged 5 commits intoRalith:masterfrom
shadow-kestrel:master

Conversation

@shadow-kestrel
Copy link
Contributor

this pr adds keys to cycle the selected material through all materials, and select the material the player is looking at. implements #411

there's a case to be made for scrollwheel/middle-click bindings, but mine doesnt work reliably so i cant do so myself. #403 would make this a non-issue though

Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks!


pub fn prev_material(&mut self) {
self.selected_material = Material::VALUES
[(self.selected_material as usize - 1 + Material::COUNT) % Material::COUNT];
Copy link
Owner

Choose a reason for hiding this comment

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

Use wrapping_add and reorder operations (or also use wrapping_sub) to avoid underflow/overflow.

Copy link
Collaborator

@patowen patowen Mar 8, 2026

Choose a reason for hiding this comment

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

I agree that reordering operations is needed here to avoid underflow. However, I don't think wrapping_add is necessary for the same reason as #505 (comment), and I expect using it anyway could cause panics to become logic errors.

Copy link
Owner

@Ralith Ralith Mar 8, 2026

Choose a reason for hiding this comment

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

nit: prefer to include changes to code introduced in the same PR in the commit that introduced the revised code. This makes for easier review.

};

let hit = ray_casting_result?;
let hit = self.looking_at()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice refactor!

@Ralith Ralith merged commit 6518957 into Ralith:master Mar 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants