-
-
Notifications
You must be signed in to change notification settings - Fork 219
Added OnOrthogonal Modifier [Modifier 3 of 4] #2694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Crepestrom
wants to merge
23
commits into
PixelGuys:master
Choose a base branch
from
Crepestrom:Modifier-OnOrthoganal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
928bc2a
added orthogonal
Crepestrom f37cdce
not supposed to be there
Crepestrom 7971bea
Update onOrthogonal.zig
Crepestrom 4352e53
default zig formatter turned off
Crepestrom d9e0364
formatting
Crepestrom 5c0f02b
Update onOrthogonal.zig
Crepestrom 6a6686e
Update onOrthogonal.zig
Crepestrom b72965d
Update onOrthogonal.zig
Crepestrom 12b3975
Update onOrthogonal.zig
Crepestrom 8881707
Update onOrthogonal.zig
Crepestrom 86ab7e6
Update onOrthogonal.zig
Crepestrom e50b5c1
Update onOrthogonal.zig
Crepestrom cba0be5
Update onOrthogonal.zig
Crepestrom b4bf115
Update onOrthogonal.zig
Crepestrom 8e509d3
Update onOrthogonal.zig
Crepestrom 43b3782
Update onOrthogonal.zig
Crepestrom 46d6c68
fix
Crepestrom 9f414da
Merge remote-tracking branch 'upstream/master' into Modifier-OnOrthog…
Crepestrom 1fffd51
Update onOrthogonal.zig
Crepestrom 6979f78
critical fix
Crepestrom 8493a9a
Merge remote-tracking branch 'upstream/master' into Modifier-OnOrthog…
Crepestrom 24e3aec
Update on_orthogonal.zig
Crepestrom e845405
Update on_orthogonal.zig
Crepestrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/proceduralItem/modifiers/restrictions/on_orthogonal.zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const NeverFailingAllocator = main.heap.NeverFailingAllocator; | ||
| const ModifierRestriction = main.items.ModifierRestriction; | ||
| const ProceduralItem = main.items.ProceduralItem; | ||
| const ZonElement = main.ZonElement; | ||
|
|
||
| const On_orthogonal = struct { | ||
| tag: main.Tag, | ||
| amount: usize, | ||
| range: ?usize, | ||
| }; | ||
|
|
||
| pub fn satisfied(self: *const On_orthogonal, proceduralItem: *const ProceduralItem, x: i32, y: i32) bool { | ||
| var count: usize = 0; | ||
| const gridSize: usize = proceduralItem.materialGrid.len - 1; | ||
| const rangeChecked = @min(self.range orelse gridSize, gridSize); | ||
| const lowBound = 0; | ||
| const highBound = rangeChecked*2 + 1; | ||
| for (lowBound..highBound) |dx| { | ||
| const checkedX = x + (@as(i32, @intCast(dx)) - rangeChecked); | ||
| const checkedY = y + (@as(i32, @intCast(0)) - rangeChecked); | ||
| if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1; | ||
| } | ||
| for (lowBound..highBound) |dy| { | ||
| const checkedX = x + (@as(i32, @intCast(0)) - rangeChecked); | ||
| const checkedY = y + (@as(i32, @intCast(dy)) - rangeChecked); | ||
| if (dy != 0) { // prevents double counting | ||
| if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1; | ||
| } | ||
| } | ||
| return count >= self.amount; | ||
| } | ||
|
|
||
| pub fn loadFromZon(allocator: NeverFailingAllocator, zon: ZonElement) *const On_orthogonal { | ||
| const result = allocator.create(On_orthogonal); | ||
| result.* = .{ | ||
| .tag = main.Tag.find(zon.get([]const u8, "tag", "not specified")), | ||
| .amount = zon.get(usize, "amount", 8), | ||
| .range = zon.get(?usize, "range", null), | ||
| }; | ||
| return result; | ||
| } | ||
|
|
||
| pub fn printTooltip(self: *const On_orthogonal, outString: *main.List(u8)) void { | ||
| if (self.range == null) { | ||
| outString.print("{} .{s} {s}", .{self.amount, self.tag.getName(), "on orthoganal axis"}); | ||
| } else { | ||
| outString.print("{} .{s} {s} {?}", .{self.amount, self.tag.getName(), "in orthoganal range", self.range}); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed range restrictions will be supported with #3092, please remove this parameter